wangting
2023-09-22 8cc891b06558d9998723942aacd20ca3d894336e
Source/UBCS-WEB/src/components/FormTemplate/FormTemplate.vue
@@ -26,6 +26,7 @@
      </template>
      <template :slot="item.prop + ''" v-for="item in slotColumnList">
        <vciWebRefer
          :key="item.prop" :data-key="item.prop"
          v-if="item.type == 'refer'"
          :referConfig="item.referConfig || {}"
          :value="form[item.referConfig.field] || item.value"
@@ -84,10 +85,19 @@
    trendsSpan: {
      type: Number,
      default: 8,
    },
    TreeValue:{
      type: String,
      default: "",
    },
    eventList:{
      type:Array
    }
  },
  data() {
    return {
      eventFlag:{},
      TreeValueForm:'',
      updateIndex: 0,
      form: {},
      option: {
@@ -117,6 +127,9 @@
  mounted() {
    this.handleResize();
  },
  created() {
  },
  computed: {
    localTrendsSpan() {
      if (this.trendsSpan) {
@@ -126,10 +139,38 @@
        return 24 / Math.floor(windowWidth / 500);
      }
    },
  },
  watch: {
    // 表单数据修改反馈到父组件
    form: {
      deep: true,
      immediate: true,
      handler(newV) {
        this.$emit("getFormData", newV);
      },
    },
    TreeValue:{
      handler(newval,oldval){
        if(newval){
          this.TreeValueForm=newval;
        }
      },
      deep:true,
      immediate:true
    }
  },
  methods: {
    // 渲染表单模板
    templateRender(formItemList) {
    templateRender(formItemList,TreeValue) {
      if (this.eventList) {
        this.eventFlag= this.eventList.some(item => {
          if (item.classifyInvokeEditFlag === 'true') {
            this.eventObject = item;
            return true;
          }
        });
      }
      // 无需分组数据
      let column = [];
      let group = [];
@@ -170,10 +211,11 @@
          trigger = "blur";
        }
        let fieldMapKey=''
        if( formItem.type == "refer"){
          if(!formItem.fieldMap){
            fieldMapKey=formItem.field+'Id'
          }
        if( formItem.type == "refer" && !formItem.fieldMap){
          fieldMapKey=formItem.field+'Id'
          formItem.fieldMap={}
          formItem.fieldMap[fieldMapKey]='id'
          formItem.fieldMap[formItem.field+'id']='id'
        }
        let columnItem = {
          label: formItem.text,
@@ -184,37 +226,40 @@
          field: formItem.field,
          type: this.columnType[formItem.type],
          dicData: this.getDataList(formItem.type, formItem.data),
          disabled: this.type === "detail" ? true : formItem.readOnly,
          disabled: this.type === "detail" ? true : formItem.readOnly || (formItem.codeValueApplyStatus && formItem.codeValueApplyStatus == 2 ?true : false) ,
          prepend: this.preOrSufFixShow("text", formItem.prefix),
          append: this.preOrSufFixShow("text", formItem.suffix),
          prefixIcon: this.preOrSufFixShow("icon", formItem.prefix),
          suffixIcon: this.preOrSufFixShow("icon", formItem.suffix),
          valueFormat: formItem.dateFormate,
          valueFormat:formItem.dateFormate,
          format: formItem.dateFormate,
          keyAttr: formItem.keyAttr,
          value: formItem.defaultValue,
          value: (formItem.dicData && formItem.dicData.length > 0 && formItem.secType == "codefixedsec" ? formItem.dicData[0].id : null) ||
            (formItem.secType == "codedatesec"?formItem.codeDateValue: null) || ( TreeValue&& formItem.secType == "codelevelsec" ? TreeValue : null) ,
          placeholder: formItem.inputTip,
          comboxKey: formItem.comboxKey,
          tip: formItem.tooltips,
          // hidden:formItem.secType && formItem.codeValueApplyStatus == 3 ? true : false,
          // readonly:formItem.codeValueApplyStatus && formItem.codeValueApplyStatus == 2 ?true : false ,
          display: !formItem.hidden,
          maxlength: formItem.maxlength,
          filterable: true,
          referConfig:
            formItem.type == "refer"
              ? {
                  title: formItem.text,
                  showField: formItem.showField || formItem.field,
                  field: formItem.field,
                  fieldMap:formItem.fieldMap || {fieldMapKey:'id'},
                  placeholder: formItem.inputTip,
                  options: formItem.referConfig
                }
                title: formItem.text,
                showField: formItem.showField || formItem.field,
                field: formItem.field,
                fieldMap:formItem.fieldMap || {},
                placeholder: formItem.inputTip,
                options: formItem.referConfig
              }
              : {},
          span: formItem.span
            ? formItem.span
            : formItem.type === "textarea"
            ? 24
            : this.localTrendsSpan,
              ? 24
              : this.localTrendsSpan,
          rules: [
            {
              required: formItem.required,
@@ -250,6 +295,121 @@
      this.geDictData(dictKeys);
      this.getFormDetail();
    },
    //修改级联项
    changeChildItem(items,TreeValue) {
      let column = this.option.column;
      let group = this.option.group;
      items.forEach((item) => {
        let formItem = this.resetFormConfig(item);
        if (formItem.field == "lcstatus") {
          formItem.field = formItem.field + "_text";
          formItem.readOnly = true;
        }
        // 设置表单校验的规则,文本
        let message = "请选择";
        let trigger = "change";
        if (formItem.type === "text") {
          message = "请输入";
          trigger = "blur";
        }
        let fieldMapKey = ''
        if (formItem.type == "refer" && !formItem.fieldMap) {
          fieldMapKey = formItem.field + 'Id'
          formItem.fieldMap = {}
          formItem.fieldMap[fieldMapKey] = 'id'
          formItem.fieldMap[formItem.field + 'id'] = 'id'
        }
        let columnItem = {
          label: formItem.text,
          labelslot: true,
          prop: this.$utilFunc.isValuableObj(formItem.referConfig)
            ? formItem.showField || formItem.field
            : formItem.field,
          field: formItem.field,
          type: this.columnType[formItem.type],
          dicData: this.getDataList(formItem.type, formItem.data),
          disabled: this.type === "detail" ? true : formItem.readOnly || (formItem.codeValueApplyStatus && formItem.codeValueApplyStatus == 2 ? true : false),
          prepend: this.preOrSufFixShow("text", formItem.prefix),
          append: this.preOrSufFixShow("text", formItem.suffix),
          prefixIcon: this.preOrSufFixShow("icon", formItem.prefix),
          suffixIcon: this.preOrSufFixShow("icon", formItem.suffix),
          valueFormat: formItem.dateFormate,
          format: formItem.dateFormate,
          keyAttr: formItem.keyAttr,
          value: (formItem.dicData && formItem.dicData.length > 0 && formItem.secType == "codefixedsec" ? formItem.dicData[0].id : null) ||
            (formItem.secType == "codedatesec" ? formItem.codeDateValue : null) || (TreeValue && formItem.secType == "codelevelsec" ? TreeValue : null),
          placeholder: formItem.inputTip,
          comboxKey: formItem.comboxKey,
          tip: formItem.tooltips,
          // hidden:formItem.secType && formItem.codeValueApplyStatus == 3 ? true : false,
          // readonly:formItem.codeValueApplyStatus && formItem.codeValueApplyStatus == 2 ?true : false ,
          display: !formItem.hidden,
          maxlength: formItem.maxlength,
          filterable: true,
          referConfig:
            formItem.type == "refer"
              ? {
                title: formItem.text,
                showField: formItem.showField || formItem.field,
                field: formItem.field,
                fieldMap: formItem.fieldMap || {},
                placeholder: formItem.inputTip,
                options: formItem.referConfig
              }
              : {},
          span: formItem.span
            ? formItem.span
            : formItem.type === "textarea"
              ? 24
              : this.localTrendsSpan,
          rules: [
            {
              required: formItem.required,
              message: `${message}${formItem.text}`,
              trigger,
            },
            {
              // 如果没有正则则匹配任何字符
              pattern: formItem.verify ? formItem.verify : /[\s\S.]*/g,
              message: formItem.tooltips,
              trigger,
            },
          ],
          props: {
            label: "value",
            value: "key",
          },
        };
        if (group.length === 0) {
          this.slotColumnList.forEach((index, colItem) => {
            if (colItem.field == columnItem.field) {
              this.slotColumnList[index] = columnItem;
              column[index] = columnItem;
              return;
            }
          })
        } else {
          this.slotColumnList.forEach((index, colItem) => {
            if (colItem.field == columnItem.field) {
              this.slotColumnList[index] = columnItem;
              return;
            }
          })
          group.forEach((index, groupItem) => {
            groupItem.column.forEach((colIndex, colItem) => {
              if (colItem.field == columnItem.field) {
                group[index].column[colIndex] = columnItem;
                return;
              }
            })
          });
        }
      });
      this.$set(this.option, "column", column);
      this.$set(this.option, "group", group);
    },
    // 使用传入的表单数据配置
    resetFormConfig(formItem) {
@@ -371,21 +531,24 @@
              if (!_item.attributes) {
                _item.attributes = _item;
              }
              if (!_item.attributes.data) {
                _item.attributes.data = {};
              }
              if (mapFields.length == 1) {
                var mapField = mapFields[0];
                if (mapField.indexOf("attribute.") > -1) {
                  temp = _item['attributes'][mapField.subString("attribute.".length)];
                  temp = _item['attributes'][mapField.subString("attribute.".length)] || _item['attributes']['data'][mapField.subString("attribute.".length)];
                } else {
                  temp = _item['attributes'][mapField] || _item[mapField];
                  temp = _item['attributes'][mapField] ||_item['attributes']['data'][mapField] || _item[mapField];
                }
              } else {
                //有多个
                var mutiTemp = [];
                layui.each(mapFields, function (_indexField, _itemField) {
                  if (_itemField.indexOf("attribute.") > -1) {
                    mutiTemp.push(_item['attributes'][_itemField.subString("attribute.".length)]);
                    mutiTemp.push(_item['attributes'][_itemField.subString("attribute.".length)] || _item['attributes']['data'][_itemField.subString("attribute.".length)]);
                  } else {
                    mutiTemp.push(_item['attributes'][_itemField] || _item[_itemField]);
                    mutiTemp.push(_item['attributes'][_itemField] || _item['attributes']['data'][_itemField] || _item[_itemField]);
                  }
                });
                temp = mutiTemp.join(' ');
@@ -397,19 +560,9 @@
            this.form[key] = value.join(',');
          }
        }
        this.$emit("getFormData", this.form);
        this.$emit("referConfigDataUpdate", data);
        this.$emit("getFormData", this.form);
      }
    },
  },
  watch: {
    // 表单数据修改反馈到父组件
    form: {
      deep: true,
      immediate: true,
      handler(newV) {
        this.$emit("getFormData", newV);
      },
    },
  },
};