<template>
  <layout-form>
    <el-form
      :model="form"
      :loading="loading"
      :rules="rules"
      size="small"
      style="width: 100%"
      label-width="120px"
      ref="form"
    >
      <el-row>
        <Field
          label="业务名称"
          prop="name"
          v-model="form.name"
          placeholder="请输入业务名称"
        />
        <el-col span="24">
          <el-form-item label="空白样表" class="my-form-field">
            <FileUpload v-model="form.samplePath" prePath="/fileupload" />
          </el-form-item>
        </el-col>

        <el-col span="24">
          <el-form-item label="模板样表" class="my-form-field">
            <FileUpload v-model="form.docTemplateEntity.templatePath" :fileType=fileType prePath="/template" />
          </el-form-item>
        </el-col>
        <Field
          label="备注"
          prop="remark"
          v-model="form.remark"
          type="textarea"
          placeholder="请输入备注"
        />
      </el-row>
      <form-buttons @submit="submitForm" />
    </el-form>
  </layout-form>
</template>

<script>
import form from "@/assets/mixins/form";
export default {
  mixins: [form],
  components: {},
  toString: [],
  methods: {
    /** doc模板序号 */
    rowDocTemplateIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** doc模板添加按钮操作 */
    handleAddDocTemplate() {
      let obj = {};
      obj.name = "";
      obj.templatePath = "";
      obj.remark = "";
      obj.updateTime = "";
      obj.updateUser = "";
      obj.createTime = "";
      obj.createUser = "";
      this.docTemplateList.push(obj);
    },
    /** doc模板删除按钮操作 */
    handleDeleteDocTemplate() {
      if (this.checkedDocTemplate.length == 0) {
        this.$alert("请先选择要删除的doc模板数据", "提示", {
          confirmButtonText: "确定",
        });
      } else {
        this.docTemplateList.splice(this.checkedDocTemplate[0].index - 1, 1);
      }
    },
    /** 单选框选中数据 */
    handleDocTemplateSelectionChange(selection) {
      if (selection.length > 1) {
        this.$refs.docTemplate.clearSelection();
        this.$refs.docTemplate.toggleRowSelection(selection.pop());
      } else {
        this.checkedDocTemplate = selection;
      }
    },
    // 渲染前置处理
    beforeRender(data) {
      if (data.entity.docTemplateList) {
        this.docTemplateList = data.entity.docTemplateList;
      }
      return data;
    },
  },
  data() {
    return {
      fileType:["xml"],
      // 子表选中数据
      checkedDocTemplate: [],
      // doc模板表格数据
      docTemplateList: [],
      rules: {
        name: [{ trigger: "blur" }],
        samplePath: [{ trigger: "blur" }],
        remark: [{ trigger: "blur" }],
      },
    };
  },
};
</script>