xiejun
2023-12-04 007e33dd8728b4557917a2ffa2e2449865602742
Source/UBCS-WEB/src/components/FormTemplate/index.vue
@@ -21,9 +21,9 @@
      :templateOid="templateOid"
      :type="type"
      data-key="masterForm"
      @dataYearCode="dataYearHandler"
      @getFormData="getFormData"
      @isShow="isShowHandler"
      @dataYearValue="dataYearHandler"
    ></FormTemplate>
    <div
      v-if="
@@ -250,9 +250,11 @@
  },
  methods: {
    openDialog() {
      //新增和修改共同调用
      this.getFormTemplate();
      if (this.type === "add") {
      if (this.type === "add" || (this.type !== "add" && this.status === "amend")) {
        this.getCodeRule();
        return;
      }
    },
    close() {
@@ -260,6 +262,7 @@
    },
    // 接口获取表单数据
    getFormTemplate() {
      //新增和修改共同调用
      getFormTemplate({
        templateOid: this.templateOid,
        codeClassifyOid: this.codeClassifyOid,
@@ -277,6 +280,7 @@
            } else {
              this.showResembleQuery = false;
            }
            //传递表单上方区域数据 (新增和修改)
            this.$nextTick(() => {
              this.$refs.FormTemplate.templateRender(
                res.data.formDefineVO.items
@@ -319,7 +323,7 @@
          that.secVOList = (res.data.data.secVOList || []).filter((item) =>
            typeList.includes(item.secType)
          );
          if (that.secVOList.length > 0 && that.type === "add") {
          if (that.secVOList.length > 0 && that.type === "add" ||(that.type !== "add" &&  that.status === "amend")) {
            that.showCodeApply = true;
            that.activeName = "codeApply";
@@ -346,22 +350,32 @@
    },
    //系列号规则
    isShowHandler(val) {
      let that = this;
      this.isShowStatus = val;
        this.secVOList.forEach(item => {
          if (item.name === "系列号") {
            this.$set(item, "readOnly", val)
          }
        })
      if(this.$refs.CodeApply.changeChildItem ){
      this.secVOList.forEach(item => {
        if (item.name === "系列号") {
          this.$set(item, "readOnly", val)
        }
      })
      if (this.$refs.CodeApply) { // 添加一个判断语句,检查对象是否为undefined
        this.$refs.CodeApply.changeChildItem(this.secVOList, this.TreeValue, this.type);
      }
    },
    //年代号
    dataYearHandler(val){
      console.log("val",val)
    dataYearHandler(val) {
      const readOnlyValue = val && Object.values(val).every(value => value !== '');
      this.secVOList.forEach(item => {
        if (item.name === "年代号") {
          const year = readOnlyValue ? val.value.slice(0, 4) : item.codeDateValue;
          this.codeApplyForm[item.oid] = year;
          this.$set(item, "readOnly", readOnlyValue);
        }
      });
      if (this.$refs.CodeApply) {
        this.$refs.CodeApply.changeChildItem(this.secVOList, this.TreeValue, this.type);
      }
    },
    //属性码段赋值
    attrListForm(attrListForm) {
@@ -387,7 +401,7 @@
        return item;
      });
      //this.$refs.CodeApply.templateRender(this.secVOList,this.TreeValue);
      this.$refs.CodeApply.changeChildItem(childItems,this.TreeValue,this.type);
      this.$refs.CodeApply.changeChildItem(childItems, this.TreeValue, this.type);
    },
    resembleQuerySubmit() {
      this.activeName = "resembleQuery";
@@ -399,78 +413,160 @@
      }
    },
    async submit() {
      // 进行表单校验
      const formValidate = await this.$refs.FormTemplate.validate();
      if (!formValidate) return;
      let codeValidate = true;
      // 进行码值申请校验
      // if (this.showCodeApply) {
      //   codeValidate = await this.$refs.CodeApply.validate();
      //   if (!codeValidate) {
      //     this.activeName = "codeApply";
      //     return false;
      //   }
      // }
      let resembleQueryList = [];
      if (this.showResembleQuery && this.$refs.resembleQueryRef) {
        // 进行相似项查询
        resembleQueryList = await this.$refs.resembleQueryRef.resembleQuery(
      if(this.status){
        // 进行表单校验
        const formValidate = await this.$refs.FormTemplate.validate();
        if (!formValidate) return;
        let resembleQueryList = [];
        if (this.showResembleQuery && this.$refs.resembleQueryRef) {
          // 进行相似项查询
          resembleQueryList = await this.$refs.resembleQueryRef.resembleQuery(
            this.form
          );
        }
        if (resembleQueryList.length > 0) {
          await this.$confirm(
            `该物料已有${resembleQueryList.length}条相似数据,是否继续保存?`,
            "需要您确认",
            {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            }
          );
        }
        // 排除一些字段
        const noData = [
          "jiliangdwname",
          "materialtypeText",
          "morengongysname",
          "$caigouwl",
          "$xiaoshouwl",
          "$shifoupihaoguanli",
          "lcstatus_text",
          "hesuanfenleiname",
          "$kucunwl",
          "lastmodifier"
        ];
        let resForm = {};
        const {defaultValue, formValue} = this.getDefaultValueAndFormValues(
          this.form
        );
      }
      if (resembleQueryList.length > 0) {
        await this.$confirm(
          `该物料已有${resembleQueryList.length}条相似数据,是否继续保存?`,
          "需要您确认",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }
        );
      }
      // 排除一些字段
      const noData = [
        "jiliangdwname",
        "materialtypeText",
        "morengongysname",
        "$caigouwl",
        "$xiaoshouwl",
        "$shifoupihaoguanli",
        "lcstatus_text",
        "hesuanfenleiname",
        "$kucunwl",
        "oldcode",
        "lastmodifier"
      ];
      let resForm = {};
      const {defaultValue, formValue} = this.getDefaultValueAndFormValues(
        this.form
      );
      noData.forEach((item) => {
        this.$delete(formValue, item);
      });
      const keys = Object.keys(formValue);
      keys.forEach((item, index) => {
        keys.forEach((itm, idx) => {
          if ((item === ('$' + itm)) && idx !== index) {
            this.$delete(formValue, keys[index]);
          }
        })
      });
        noData.forEach((item) => {
          this.$delete(formValue, item);
        });
        const keys = Object.keys(formValue);
        keys.forEach((item, index) => {
          keys.forEach((itm, idx) => {
            if ((item === ('$' + itm)) && idx !== index) {
              this.$delete(formValue, keys[index]);
            }
          })
        });
      resForm.data = formValue;
      resForm = Object.assign({}, resForm, defaultValue);
      resForm.secDTOList = this.secVOList.map((item) => {
        return {
          secOid: item.oid,
          secValue: this.codeApplyForm[item.oid],
        resForm.data = formValue;
        resForm.data = Object.assign({}, resForm.data, defaultValue);
        resForm.secDTOList = this.secVOList.map((item) => {
          return {
            secOid: item.oid,
            secValue: this.codeApplyForm[item.oid],
          };
        });
        //标准特定
        const mappings = {
          codeStandardEditType: 'operationType',
          reviseSeries: 'series',
          oldcode: 'oldCode',
          releaseDate: 'releaseTime',
          isSeries: 'isEditseries'
        };
      });
      resForm.codeClassifyOid = this.codeClassifyOid;
      resForm.codeRuleOid = this.codeRuleOid;
      resForm.templateOid = this.templateOid;
      this.$emit("submit", resForm);
        for (const key in mappings) {
          if (formValue[key]) {
            resForm[mappings[key]] = formValue[key];
          }
        }
        //
        resForm.codeClassifyOid = this.codeClassifyOid;
        resForm.codeRuleOid = this.codeRuleOid;
        resForm.templateOid = this.templateOid;
        this.$emit("submit", resForm);
      }else {
        // 进行表单校验
        const formValidate = await this.$refs.FormTemplate.validate();
        if (!formValidate) return;
        let codeValidate = true;
        // 进行码值申请校验
        // if (this.showCodeApply) {
        //   codeValidate = await this.$refs.CodeApply.validate();
        //   if (!codeValidate) {
        //     this.activeName = "codeApply";
        //     return false;
        //   }
        // }
        let resembleQueryList = [];
        if (this.showResembleQuery && this.$refs.resembleQueryRef) {
          // 进行相似项查询
          resembleQueryList = await this.$refs.resembleQueryRef.resembleQuery(
            this.form
          );
        }
        if (resembleQueryList.length > 0) {
          await this.$confirm(
            `该物料已有${resembleQueryList.length}条相似数据,是否继续保存?`,
            "需要您确认",
            {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            }
          );
        }
        // 排除一些字段
        const noData = [
          "jiliangdwname",
          "materialtypeText",
          "morengongysname",
          "$caigouwl",
          "$xiaoshouwl",
          "$shifoupihaoguanli",
          "lcstatus_text",
          "hesuanfenleiname",
          "$kucunwl",
          "oldcode",
          "lastmodifier"
        ];
        let resForm = {};
        const {defaultValue, formValue} = this.getDefaultValueAndFormValues(
          this.form
        );
        noData.forEach((item) => {
          this.$delete(formValue, item);
        });
        const keys = Object.keys(formValue);
        keys.forEach((item, index) => {
          keys.forEach((itm, idx) => {
            if ((item === ('$' + itm)) && idx !== index) {
              this.$delete(formValue, keys[index]);
            }
          })
        });
        resForm.data = formValue;
        resForm = Object.assign({}, resForm, defaultValue);
        resForm.secDTOList = this.secVOList.map((item) => {
          return {
            secOid: item.oid,
            secValue: this.codeApplyForm[item.oid],
          };
        });
        resForm.codeClassifyOid = this.codeClassifyOid;
        resForm.codeRuleOid = this.codeRuleOid;
        resForm.templateOid = this.templateOid;
        this.$emit("submit", resForm);
      }
    },
    getDefaultValueAndFormValues(form) {
      let defaultValue = {};