<template>
  <div class="page">
    <LayoutTable :data="tableData" :config="tableConfig" notAdd notDel>
 
    </LayoutTable>
    
  </div>
</template>

<script>
import table from "@/assets/mixins/table";
export default {
  components: {},
  mixins: [table],
  created() {
    const { docId } = this.$route.query;
    this.config.addQuery = { docId: docId };
  },
  methods: {
    /**解析模板 */
    toParseXml(row) {
      this.loading = true;

      let form = Object.assign({}, row);
      this.$post("/doc/template/parseXmltoJson", form)
        .then((res) => {
          console.log("res", res);
          if (res && res.code && res.code == 1) {
            this.$message.success("解析模板成功！");
            this.getData();
          }
        })
        .catch((error) => {
          this.$message.error(error.message);
        });
    },
    /**表单配置 */
    toParseForm(row) {
     this.$router.push({
        path: "/doc/form/view",
        query: {
            //formId:row.docFormEntity.id,
            id: row.id,
        },
      });

    },
    /** 导入 */
    handleImport() {
      this.upload.title = "doc模板导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    downloadTemplate() {
      this.isExport = true;
      this.$download("/doc/template/downloadTemplate", {}, { type: "excel" })
        .then(() => (this.isExport = false))
        .catch((error) => {
          this.isExport = false;
          this.$message.error(error.message);
        });
    },
    /** 文件上传中处理 */
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    /** 文件上传成功处理 */
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
      this.getData();
    },
    /** 提交上传文件 */
    submitFileForm() {
      this.$refs.upload.submit();
    },
    doExport() {
      this.isExport = true;
      this.$download(
        "/doc/template/exportExcel",
        {
          "query.name": this.$route.query["query.name"],
          "query.docId": this.$route.query["query.docId"],
          "query.templatePath": this.$route.query["query.templatePath"],
        },
        { type: "excel" }
      )
        .then(() => (this.isExport = false))
        .catch((error) => {
          this.isExport = false;
          this.$message.error(error.message);
        });
    },
    renderTable(tableData) {
      return (
        <el-table stripe data={tableData} class="total-table">
          {this.columnSet.map((item) => this.renderTableColumn(item))}
        </el-table>
      );
    },
    renderTableColumn(options) {
      return (
        <el-table-column
          prop={options.prop}
          label={options.label}
        ></el-table-column>
      );
    },
  },
  data() {
    return {
      // 用户导入参数
      upload: {
        // 是否显示弹出层（doc模板导入）
        open: false,
        // 弹出层标题（doc模板导入）
        title: "导入doc模板数据",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的数据
        updateSupport: 0,
        // 上传的地址
        url: "/m/doc/template/importData",
      },
      isExport: false,
      columnSet: [
        { prop: "id", label: "ID,主键，自增长" },
        { prop: "templateId", label: "模板ID" },
        { prop: "formName", label: "表单名称" },
        { prop: "formContent", label: "表单内容" },
        { prop: "remark", label: "备注" },
        { prop: "updateTime", label: "变更时间" },
        { prop: "updateUser", label: "变更用户,登录名" },
        { prop: "createTime", label: "创建时间" },
        { prop: "createUser", label: "创建用户,登录名" },
      ],
      config: {
        search: [
          {
            name: "name",
            type: "text",
            label: "模板名称",
            fuzzy: true,
          },
          {
            name: "docId",
            type: "text",
            label: "doc主键ID",
            fuzzy: true,
          },
          {
            name: "templatePath",
            type: "text",
            label: "模板地址",
            fuzzy: true,
          },
        ],
        columns: [
          { type: "selection", width: 60 },

          { label: "模板名称", prop: "name" },

          { label: "模板地址", prop: "templatePath" },
          { label: "备注", prop: "remark" },

          {
            label: "创建时间",
            prop: "createTime",
            formatter: this.formatterDate,
          },
          { label: "创建用户", prop: "createUser" },

          {
            label: "操作",
            width: 320,
            formatter: (row) => {
              return (
                <div>
                  <el-button
                    type="primary"
                    icon="el-icon-edit"
                
                    size="mini"
                    onClick={() => {
                      this.toParseForm(row);
                    }}
                  >
                    表单配置
                  </el-button>
                </div>
              );
            },
          },
        ],
      },
    };
  },
};
</script>