fujunling
2023-06-20 1e55c3660b531d9463a564eddb71a16e0e920dfa
Source/UBCS-WEB/src/components/FormTemplate/index.vue
@@ -3,9 +3,8 @@
    :visible.sync="dialogVisible"
    v-if="dialogVisible"
    v-dialogDrag
    top="0vh"
    top="5vh"
    :title="title"
    class="avue-dialog avue-dialog--top"
    :width="width"
    append-to-body
    @opened="openDialog"
@@ -30,14 +29,15 @@
      "
    >
      <el-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
        <el-tab-pane label="码值申请" name="codeApply" v-if="showCodeApply">
        <el-tab-pane label="码值申请" name="codeApply">
          <FormTempalte
            v-bind="$attrs"
            :type="type"
            :selfColumnType="selfColumnType"
            :selfColumnConfig="selfColumnConfig"
            ref="CodeApply"
            @getFormData="getFormData"
            @getFormData="getCodeApplyFormData"
            @referConfigDataUpdate="referConfigDataUpdate"
          ></FormTempalte>
        </el-tab-pane>
        <el-tab-pane
@@ -59,9 +59,9 @@
    </div>
    <div class="avue-dialog__footer" v-if="type !== 'detail'">
      <el-button @click="close()">取 消</el-button>
      <el-button @click="submit()" type="primary" :loading="submitBtnLoading"
        >{{ submitText }}</el-button
      >
      <el-button @click="submit()" type="primary" :loading="submitBtnLoading">{{
        submitText
      }}</el-button>
      <el-button
        @click="resembleQuerySubmit"
        type="primary"
@@ -107,8 +107,8 @@
    },
    submitText: {
      type: String,
      default: '确 定'
    }
      default: "确 定",
    },
  },
  data() {
    return {
@@ -118,6 +118,7 @@
      resembleTableColumn: [],
      secVOList: [],
      form: {},
      codeApplyForm: {},
      activeName: "codeApply",
      showCodeApply: true,
      showResembleQuery: true,
@@ -132,6 +133,8 @@
          required: this.isRequired,
          dicData: this.getOptionList,
          type: this.getType,
          referConfig: this.getReferConfig,
          readOnly: this.getDisabled,
        },
        exchange: {
          text: "name",
@@ -151,6 +154,38 @@
          },
        },
      },
      defaultKeys: [
        "oid",
        "id",
        "name",
        "description",
        "revisionoid",
        "nameoid",
        "btmname",
        "lastr",
        "firstr",
        "lastv",
        "firstv",
        "creator",
        "createtime",
        "lastModifier",
        "lastmodifytime",
        "revisionrule",
        "revisionseq",
        "revisionvalue",
        "versionrule",
        "versionseq",
        "versionvalue",
        "lcstatus",
        "ts",
        "owner",
        "checkinby",
        "checkintime",
        "checkoutby",
        "checkouttime",
        "copyfromversion",
        "secretgrade",
      ],
    };
  },
  created() {},
@@ -167,7 +202,7 @@
  methods: {
    openDialog() {
      this.getFormTemplate();
      if (this.type === 'add') {
      if (this.type === "add") {
        this.getCodeRule();
      }
    },
@@ -188,15 +223,14 @@
              res.data.resembleTableVO.cols.length > 0;
            this.resembleTableColumn = res.data.resembleTableVO.cols || [];
            if (this.hasResemble) {
              this.activeName = 'resembleQuery'
              this.showResembleQuery = true
              this.activeName = "resembleQuery";
              this.showResembleQuery = true;
            }
            this.$refs.FormTempalte.templateRender(res.data.formDefineVO.items);
          }
        })
        .catch((err) => {
          this.loading = false;
          console.log(err);
        });
    },
    // 获取码值申请数据
@@ -213,12 +247,12 @@
            typeList.includes(item)
          );
          this.$nextTick(() => {
            if (this.secVOList.length > 0 && this.type === 'add') {
              this.showCodeApply = true
              this.activeName = 'codeApply'
            if (this.secVOList.length > 0 && this.type === "add") {
              this.showCodeApply = true;
              this.activeName = "codeApply";
              this.$refs.CodeApply.templateRender(this.secVOList);
            } else {
              this.showCodeApply = false
              this.showCodeApply = false;
            }
          });
        }
@@ -226,6 +260,21 @@
    },
    getFormData(form) {
      this.form = form;
    },
    getCodeApplyFormData(codeApplyForm) {
      this.codeApplyForm = codeApplyForm;
    },
    // 参照组件数据变更
    referConfigDataUpdate(data) {
      const { field } = data;
      this.secVOList = this.secVOList.map((item) => {
        if (item.parentClassifySecOid === field) {
          this.$refs.CodeApply.form[item.oid] = undefined;
          this.$refs.CodeApply.form[item.name] = undefined;
        }
        return item;
      });
      this.$refs.CodeApply.templateRender(this.secVOList);
    },
    resembleQuerySubmit() {
      this.activeName = "resembleQuery";
@@ -243,7 +292,8 @@
      let codeValidate = true;
      // 进行码值申请校验
      if (this.showCodeApply) {
        codeValidate = await this.$refs.codeApply.validate();
        codeValidate = await this.$refs.CodeApply.validate();
        console.log(9999);
        if (!codeValidate) return;
      }
      // 进行相似项查询
@@ -251,7 +301,20 @@
        this.form
      );
      if (resembleQueryList.length === 0) {
        this.$emit("submit", this.form);
        let resForm = {}
        const { defaultValue, formValue } = this.getDefaultValueAndFormValues(this.form)
        resForm.data = formValue
        resForm = Object.assign({}, resForm, defaultValue)
        resForm.secDTOList = []
        for (const key in this.codeApplyForm) {
        if (Object.hasOwnProperty.call(this.codeApplyForm, key)) {
          const value = this.codeApplyForm[key];
          if (value) {
            resForm.secDTOList.push({[key]: value})
          }
        }
      }
        this.$emit("submit", resForm);
      } else {
        this.$confirm(
          `该物料已有${resembleQueryList.length}条相似数据,是否继续保存?`,
@@ -268,9 +331,89 @@
          .catch(() => {});
      }
    },
    getDefaultValueAndFormValues(form) {
      let defaultValue = {};
      let formValue = {};
      for (const key in form) {
        if (Object.hasOwnProperty.call(form, key)) {
          const element = form[key];
          if (this.defaultKeys.includes(key)) {
            defaultValue[key] = element;
          } else {
            formValue[key] = element;
          }
        }
      }
      return {
        defaultValue,
        formValue,
      };
    },
    getType(item) {
      return this.selfColumnType[item.sectype];
    },
    getReferConfig(item) {
      let params = {};
      if (item.sectype == "codeclassifysec") {
        params = {
          isMuti: false,
          type: "grid",
          tableConfig: {
            limit: -1,
            cols: [
              {
                field: "id",
                title: "英文名称",
                sort: true,
                width: 150,
              },
              {
                field: "name",
                title: "中文名称",
                sort: true,
                width: 150,
              },
              {
                field: "description",
                title: "描述",
                width: 250,
              },
            ],
            queryColumns: [
              {
                field: "id",
                title: "英文名称",
              },
              {
                field: "name",
                title: "中文名称",
              },
            ],
          },
          url: "api/ubcs-code/ubcs-code/mdmEngineController/listCodeClassifyValueBySecOid",
          extraParams: {
            classifySecOid: item.oid,
            parentClassifyValueOid: item.parentClassifySecOid
              ? this.codeApplyForm[item.parentClassifySecOid]
              : "",
          },
        };
      } else if (item.sectype == "coderefersec") {
        params = JSON.parse(item.referValueInfo);
      }
      return params;
    },
    getDisabled(item) {
      if (item.sectype === "codeclassifysec") {
        if (item.parentClassifySecOid) {
          if (!this.codeApplyForm[item.parentClassifySecOid]) {
            return true;
          } else {
            return false;
          }
        }
      }
    },
    isRequired(item) {
      return item.nullableFlag != "true";
    },