ludc
2023-12-08 c892580371ef4679c858e2da98f71a9345aa3d80
Source/UBCS-WEB/src/components/FormTemplate/FormTemplate.vue
@@ -3,36 +3,37 @@
<template>
  <div>
    <avue-form
      v-model="form"
      :option="option"
      v-loading="loading"
      ref="form"
      :style="{ minHeight: loading ? '300px' : '' }"
      :key="updateIndex"
      ref="form"
      v-model="form"
      v-loading="loading"
      :option="option"
      :style="{ minHeight: loading ? '300px' : '' }"
    >
      <template :slot="item.prop + 'Label'" v-for="item in slotColumnList">
      <template v-for="item in slotColumnList" :slot="item.prop + 'Label'">
        <span>
          <span>{{ item.label }} </span>
          <el-tooltip
            v-if="item.keyAttr"
            class="item"
            effect="dark"
            content="该属性为关键属性"
            effect="dark"
            placement="top-start"
          >
            <i class="el-icon-star-on key_attr_icon"></i>
          </el-tooltip>
        </span>
      </template>
      <template :slot="item.prop + ''" v-for="item in slotColumnList">
      <template v-for="item in slotColumnList" :slot="item.prop + ''">
        <vciWebRefer
          :key="item.prop" :data-key="item.prop"
          v-if="item.type == 'refer'"
          :referConfig="item.referConfig || {}"
          :value="form[item.referConfig.field] || item.value"
          :text="form[item.referConfig.showField]"
          v-if="item.type == 'refer'" :key="item.dataKey"
          :data-key="item.dataKey"
          :disabled="item.disabled"
          :display="item.display"
          :referConfig="item.referConfig || {}"
          :reloadData="item.referConfig.reloadData || false"
          :text="form[item.referConfig.showField]"
          :value="form[item.referConfig.field] || item.value"
          @setReferValue="setReferValue"
        ></vciWebRefer>
      </template>
@@ -41,12 +42,13 @@
</template>
<script>
import { getFormDetail } from "@/api/formTemplate";
import { getDictionary } from "../../api/system/dict";
import {getFormDetail} from "@/api/formTemplate";
import {getEnumDictionary} from "../../api/system/dict";
import vciWebRefer from "../refer/vciWebRefer.vue";
export default {
  name: "FormTemplate",
  components: { vciWebRefer },
  components: {vciWebRefer},
  props: {
    // 默认禁用元素
    disabledProp: {
@@ -60,6 +62,10 @@
    codeClassifyOid: {
      type: String,
      default: "",
    },
    LoadingStatus: {
      type: String,
      default: "code"
    },
    // 列表数据oid
    rowOid: {
@@ -86,18 +92,39 @@
      type: Number,
      default: 8,
    },
    TreeValue:{
    TreeValue: {
      type: String,
      default: "",
    },
    eventList:{
      type:Array
    eventList: {
      type: Array
    },
    status: {
      type: String,
      default: "",
    },
    selectRow: {
      type: Array,
      default: []
    }
  },
  data() {
    return {
      eventFlag:{},
      TreeValueForm:'',
      selectValue: "",
      //年代号
      dataYearCode: {
        type: "",
        value: ""
      },
      filteredObject: {},
      filteredArray: [],
      isSeriesType: {},
      attrList: [],
      add: '',
      codeattrsecValue: '',
      ValidataValue: false,
      eventFlag: {},
      TreeValueForm: '',
      updateIndex: 0,
      form: {},
      option: {
@@ -122,14 +149,19 @@
      // 表单属性
      attributes: [],
      slotColumnList: [],
      isShow: "",
    };
  },
  mounted() {
    this.handleResize();
  },
  updated() {
  },
  created() {
    },
    if (this.LoadingStatus === 'code') {
      this.loading = false;
    }
  },
  computed: {
    localTrendsSpan() {
      if (this.trendsSpan) {
@@ -150,40 +182,75 @@
        this.$emit("getFormData", newV);
      },
    },
    TreeValue:{
      handler(newval,oldval){
        if(newval){
          this.TreeValueForm=newval;
          // console.log(this.TreeValueForm)
    attrList: {
      deep: true,
      immediate: true,
      handler(newVal, oldVal) {
        if (newVal) {
          this.$emit("attrList", newVal)
        }
      }
    },
    TreeValue: {
      handler(newval, oldval) {
        if (newval) {
          this.TreeValueForm = newval;
        }
      },
      deep:true,
      immediate:true
      deep: true,
      immediate: true
    },
    isShow: {
      handler(newV) {
        this.$emit("isShow", newV)
      }
    },
    dataYearCode: {
      deep: true,
      immediate: true,
      handler(newV) {
        this.$emit("dataYearCode", newV)
      }
    },
    selectRow: {
      handler(newval) {
        // console.log(newval);
        let ids = newval.map(item => item.id);
        this.selectValue = ids.join(",");
      },
      deep: true,
      immediate: true
    }
  },
  methods: {
    // 渲染表单模板
    templateRender(formItemList,TreeValue) {
    templateRender(formItemList, TreeValue) {
      if (this.eventList) {
        this.eventFlag= this.eventList.some(item => {
        this.eventFlag = this.eventList.some(item => {
          if (item.classifyInvokeEditFlag === 'true') {
            // console.log('even', item);
            this.eventObject = item;
            return true;
          }
        });
        // console.log('add',add)
      }
      // 无需分组数据
      let column = [];
      let group = [];
      let dictKeys = [];
      let slotColumnList = [];
      let value=''
      formItemList.forEach((formItem) => {
        formItem = this.resetFormConfig(formItem);
        // console.log(formItem)
        // console.log('formItem.dicData.value',formItem.dicData)
        //属性码段规则
        if (formItem.secType === "codeattrsec") {
          this.attrList.push(formItem);
        }
        //系列号规则
        if (formItem.field === "codeStandardEditType") {
          if (this.status === "amend") {
            formItem.readOnly = true;
          }
        }
        if (formItem.type === "line") {
          group.push({
            label: formItem.text,
@@ -199,7 +266,7 @@
          (!Array.isArray(formItem.dicData) || formItem.dicData.length === 0) &&
          (!Array.isArray(formItem.data) || formItem.data.length === 0)
        ) {
          dictKeys.push({ dictKey: formItem.comboxKey, field: formItem.field });
          dictKeys.push({dictKey: formItem.comboxKey, field: formItem.field});
        }
        // 禁用部分属性(外部传值禁用和参照禁用)
        if (this.disabledProp.includes(formItem.field)) {
@@ -216,13 +283,39 @@
          message = "请输入";
          trigger = "blur";
        }
        let fieldMapKey=''
        if( formItem.type == "refer"){
          if(!formItem.fieldMap){
            fieldMapKey=formItem.field+'Id'
          }
        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 = {
          change: (val) => {
            if (val.column.field === "drawingno") {
              this.codeattrsecValue = val.value;
              return;
            }
            //修订为-系列号
            if (val.column.field === "reviseSeries") {
              if (val.value === "false") {
                this.isShow = true;
              } else {
                this.isShow = false;
              }
            }
            if (val.column.field === "releaseDate") {
              if (val.value) {
                this.dataYearCode.type = val.column.valueFormat;
                this.dataYearCode.value = val.value;
              } else {
                this.dataYearCode.type = "";
                this.dataYearCode.value = "";
              }
            }
          },
          dataKey: formItem.dataKey || formItem.field,
          label: formItem.text,
          labelslot: true,
          prop: this.$utilFunc.isValuableObj(formItem.referConfig)
@@ -231,40 +324,43 @@
          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) ,
          disabled: this.type === "detail" ? true : formItem.readOnly || (formItem.codeValueApplyStatus && formItem.codeValueApplyStatus == 2 ? true : false) ||
            (this.status === 'amend' ? (formItem.field === "reviseSeries" ? (formItem.value == 'false' ? true : false) : false) : 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 || "yyyy-MM-dd HH:mm:ss",
          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) ,
          value: formItem.defaultValue || (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) ||
            (formItem.secType == "codeattrsec" ? this.add : null) || (this.status === "apply" && formItem.field === "codeStandardEditType" ? "1" : null) ||
            (this.status === "amend" && formItem.field === "codeStandardEditType" ? "2" : null) ||
            //父组件如果是参照数据会将selectRow置空,selectRow不为空就说明不是参照要回填源标准号数据
            (this.status === "amend" ? (this.selectRow && (formItem.field === "oldcode" ? this.selectValue : null)) : 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,
@@ -283,15 +379,15 @@
            value: "key",
          },
        };
        // console.log('columnItem',columnItem)
        this.filteredObject = columnItem
        slotColumnList.push(columnItem);
        // console.log('slotColumnList',slotColumnList)
        if (group.length === 0) {
          column.push(columnItem);
        } else {
          group[group.length - 1]["column"].push(columnItem);
        }
      });
      this.slotColumnList = slotColumnList;
      this.$set(this.option, "column", column);
      this.$set(this.option, "group", group);
@@ -302,12 +398,249 @@
      this.geDictData(dictKeys);
      this.getFormDetail();
      // console.log('selfColumnConfig',this.selfColumnConfig)
    },
    //修改级联项
    changeChildItem(items, TreeValue, type) {
      type = type || "add";
      let column = this.option.column;
      let group = this.option.group;
      // let column = [];
      // let group = [];
      let that = this;
      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) ||
            (this.status  ? (formItem.field === "reviseSeries" ? (formItem.value == 'false' ? true : false) : false) : 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 || "yyyy-MM-dd HH:mm:ss",
          format: formItem.dateFormate,
          keyAttr: formItem.keyAttr,
          value: formItem.defaultValue || (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) ||
            (formItem.secType == "codeattrsec" ? this.add : null) || (this.status === "apply" && formItem.field === "codeStandardEditType" ? "1" : null) ||
            (this.status === "amend" && formItem.field === "codeStandardEditType" ? "2" : null) ||
            //父组件如果是参照数据会将selectRow置空,selectRow不为空就说明不是参照要回填源标准号数据
            (this.status === "amend" ? (this.selectRow && (formItem.field === "oldcode" ? this.selectValue : null)) : null),
          placeholder: formItem.inputTip,
          comboxKey: formItem.comboxKey,
          tip: formItem.tooltips,
          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) {
          that.slotColumnList.forEach((colItem, index) => {
            if (colItem.field == columnItem.field) {
              that.slotColumnList[index] = columnItem;
              column[index] = columnItem;
              return;
            }
          })
        } else {
          that.slotColumnList.forEach((colItem, index) => {
            if (colItem.field == columnItem.field) {
              that.slotColumnList[index] = columnItem;
              return;
            }
          })
          group.forEach((groupItem, index) => {
            groupItem.column.forEach((colItem, colIndex) => {
              if (colItem.field == columnItem.field) {
                group[index].column[colIndex] = columnItem;
                return;
              }
            })
          });
        }
      });
      that.$set(that.option, "column", column);
      that.$set(that.option, "group", group);
    },
    //标准-修订
    changeStatusItem(items, TreeValue, type) {
      type = type || "add";
      // let column = this.option.column;
      // let group = this.option.group;
      let column = [];
      let group = [];
      let that = this;
      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) ||
            (this.status === 'amend' ? (formItem.field === "reviseSeries" ? (formItem.value == 'false' ? true : false) : false) : 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 || "yyyy-MM-dd HH:mm:ss",
          format: formItem.dateFormate,
          keyAttr: formItem.keyAttr,
          value: formItem.defaultValue || (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) ||
            (formItem.secType == "codeattrsec" ? this.add : null) || (this.status === "apply" && formItem.field === "codeStandardEditType" ? "1" : null) ||
            (this.status === "amend" && formItem.field === "codeStandardEditType" ? "2" : null) ||
            //父组件如果是参照数据会将selectRow置空,selectRow不为空就说明不是参照要回填源标准号数据
            (this.status === "amend" ? (this.selectRow && (formItem.field === "oldcode" ? this.selectValue : null)) : null),
          placeholder: formItem.inputTip,
          comboxKey: formItem.comboxKey,
          tip: formItem.tooltips,
          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) {
          that.slotColumnList.forEach((colItem, index) => {
            if (colItem.field == columnItem.field) {
              that.slotColumnList[index] = columnItem;
              column[index] = columnItem;
              return;
            }
          })
        } else {
          that.slotColumnList.forEach((colItem, index) => {
            if (colItem.field == columnItem.field) {
              that.slotColumnList[index] = columnItem;
              return;
            }
          })
          group.forEach((groupItem, index) => {
            groupItem.column.forEach((colItem, colIndex) => {
              if (colItem.field == columnItem.field) {
                group[index].column[colIndex] = columnItem;
                return;
              }
            })
          });
        }
      });
      that.$set(that.option, "column", column);
      that.$set(that.option, "group", group);
    },
    // 使用传入的表单数据配置
    resetFormConfig(formItem) {
      // console.log(this.selfColumnConfig)
      for (const configType in this.selfColumnConfig) {
        if (Object.hasOwnProperty.call(this.selfColumnConfig, configType)) {
          const element = this.selfColumnConfig[configType];
@@ -323,9 +656,7 @@
              if (Object.hasOwnProperty.call(element, newAttr)) {
                const oldAttr = element[newAttr];
                formItem[newAttr] = formItem[oldAttr];
                // console.log(formItem)
                // console.log(newAttr,oldAttr)
                // console.log(formItem[newAttr],formItem[oldAttr])
              }
            }
          } else if (configType === "directVoluation") {
@@ -375,13 +706,13 @@
    // 异步获取字典数据
    geDictData(dictKeys) {
      dictKeys.forEach((dictObj) => {
        getDictionary({ code: dictObj.dictKey }).then((res) => {
        getEnumDictionary({code: dictObj.dictKey}).then((res) => {
          if (res.data && res.data.code === 200) {
            this.option.column = this.option.column.map((item) => {
              if (item.field === dictObj.field) {
                let dictData = (res.data.data || []).map((itm) => {
                  itm.value = itm.dictValue;
                  itm.key = itm.dictKey;
                  itm.value = itm.itemName;
                  itm.key = itm.itemValue;
                  return itm;
                });
                item.dicData = dictData;
@@ -399,6 +730,7 @@
          if (valid) {
            done();
            resolve(true);
            this.ValidataValue = true;
          } else {
            resolve(false);
          }
@@ -408,15 +740,18 @@
    // 获取表单详情数据
    getFormDetail() {
      if (this.type === "add") return;
      getFormDetail({ templateOid: this.templateOid, oid: this.rowOid }).then(
        (res) => {
          this.form = Object.assign(this.form, res.data.data[0]);
          this.loading = false;
        }
      );
      if (this.templateOid) {
        getFormDetail({templateOid: this.templateOid, oid: this.rowOid}).then(
          (res) => {
            this.form = Object.assign(this.form, res.data.data[0]);
            this.loading = false;
          }
        );
        return;
      }
    },
    setReferValue(data) {
      // console.log(data)
      if (data.field) {
        this.form[data.field] = data.value || "";
        this.form[data.showField] = data.text || "";
@@ -430,21 +765,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(' ');
@@ -456,8 +794,8 @@
            this.form[key] = value.join(',');
          }
        }
        this.$emit("getFormData", this.form);
        this.$emit("referConfigDataUpdate", data);
        this.$emit("getFormData", this.form);
      }
    },
  },