cuiqian2004
2025-03-03 15dcf7158d4c5d66d4b196e4e0b2030e1070d448
pages/modal/form/index.vue
@@ -8,7 +8,7 @@
               <uni-forms-item v-if="item.name != 'Layout'" :label="item.label ?item.label +':':'' "
                  :label-width="item.labelWidth+'px'">
                  <uni-data-picker v-if="item.name=='Select'" :class="item.disabled?'input-disabled':''"
                     v-model="item.value" :localdata="item.dict" @change="onEnterChange(item)"
                     v-model="item.value" :localdata="item.useDict ? item.dict : item.selections" @change="onEnterChange(item)"
                     :readonly="item.disabled" :clear-icon="false" :popup-title="item.label"></uni-data-picker>
                  <view class="input-wrapper" v-if="item.name=='Input' || item.name=='InputNumber'">
                     <text v-if="item.setting.prefix" class="uni-icon" :class="[item.setting.prefix]"
@@ -50,9 +50,9 @@
                  <uni-col
                     :span=" item.setting.spanList && item.setting.spanList[key]? item.setting.spanList[key] : 24 / item.setting.col"
                     v-for="(col,key) in item.setting.colList">
                     <uni-forms-item :label="col.label ? col.label +':':''" :label-width="col.labelWidth+'px'">
                     <uni-forms-item v-if="col!=null" :label="col.label ? col.label +':':''" :label-width="col.labelWidth+'px'">
                        <uni-data-picker v-if="col.name=='Select'" :class="col.disabled?'input-disabled':''"
                           v-model="col.value" :localdata="col.dict" @change="onEnterChange(col)"
                           v-model="col.value" :localdata="col.useDict ? col.dict : col.selections" @change="onEnterChange(col)"
                           :readonly="col.disabled" :clear-icon="false"
                           :popup-title="col.label"></uni-data-picker>
                        <view class="input-wrapper" v-if="col.name=='Input' || col.name=='InputNumber'">
@@ -147,7 +147,7 @@
      },
      data() {
         return {
            okLoading:false,
            okLoading: false,
            title: this.translateSys('add2'),
            type: '',
            editMode: false,
@@ -158,7 +158,8 @@
            focusOldFieldId: "",
            head_styledef: {
               form: {
                  items: []
                  items: [],
                  model: {}
               }
            },
            global_attr: [],
@@ -230,7 +231,7 @@
            this.ext_info = JSON.parse(options.extInfo);
         if (options.dataJson)
            this.data_json = JSON.parse(options.dataJson);
         this.title = this.param.ShowName? this.param.ShowName : options.titlename; //设置按钮文字
         this.title =  options.titlename ?  options.titlename : this.param.ShowName; //设置按钮文字
         // console.log(options)
         uni.setNavigationBarTitle({
            title: this.title
@@ -318,7 +319,7 @@
                                 styledefHead.form
                                    .model[ele.fieldId] = itemName;
                              }
                              ele.dict = selections.map((a) => {
                              ele.selections = selections.map((a) => {
                                 return {
                                    value: a.value,
                                    text: a.label
@@ -355,7 +356,7 @@
                                    styledefHead.form
                                       .model[col.fieldId] = itemName;
                                 }
                                 col.dict = selections.map((a) => {
                                 col.selections = selections.map((a) => {
                                    return {
                                       value: a.value,
                                       text: a.label
@@ -437,54 +438,42 @@
         },
         async loadFormData(objAttr) {
            let formData
            let attrs = []
            if (this.objId) {
               let info = await dataObjInfo({
                  class_id: this.clsId,
                  obj_id: this.objId,
               });
               formData = {};
               formData["id"] = info.id;
               formData["state"] = info.state;
               attrs = [{
                  attr: "id",
                  value: info.id
               }, {
                  attr: "state",
                  value: info.state
               }]
               info.attr_list.forEach(({
                  name,
                  value
               }) => {
                  formData[name] = value;
               });
            } else if (objAttr) {
               formData = {};
               Object.keys(objAttr).forEach((attr) => {
                  let value = objAttr[attr];
                  formData[attr] = value;
               });
            }
            //传入参数值
            if (formData) {
               if (this.head_styledef?.form) {
                  const items = this.head_styledef?.form?.items || []
                  const model = this.head_styledef?.form?.model || {}
                  Object.assign(model, formData);
                  items.forEach(async (ele, index) => {
                     if (ele.name != "Layout") {
                        let value = formData[ele.fieldId]
                        if (value)
                           ele.value = value
                     } else {
                        ele.setting.colList.forEach(async (col) => {
                           if (col) {
                              let value = formData[col.fieldId]
                              if (value)
                                 col.value = value
                           }
                        });
                     }
                  attrs.push({
                     attr: name,
                     value: value
                  })
                  this.$data.head_styledef.form.model = model
                  this.$data.head_styledef.form.items = items
               }
               });
               this.setFormValues(attrs)
            } else if (objAttr) {
               Object.keys(objAttr).forEach((attr) => {
                  attrs.push({
                     attr: attr,
                     value: objAttr[attr]
                  })
               });
               this.setFormValues(attrs)
            }
         },
         async loadInitialEvent() {
            try {
@@ -810,7 +799,7 @@
            // open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
            this.$refs.popup.open(this.popupType);
            this.dataObjRunCustomEvent_Return(onSuffixClickCallbackEvent.id, '', onSuffixClickEvent.id,
            this.dataObjRunCustomEvent_Return(onSuffixClickEvent.id, '', onSuffixClickCallbackEvent.id,
               item);
         },
@@ -983,110 +972,72 @@
            }
         },
         setFormValues(data) {
         setFormValues(attrs) {
            console.log(attrs)
            const head_styledef = this.head_styledef
            if (JSON.stringify(data) == '{}') {
            if (JSON.stringify(attrs) == '{}') {
               return;
            }
            head_styledef.form.items.forEach(async (ele, index) => {
               if (ele.name != "Layout") {
                  let curIndex = data.findIndex((attr, index2, arr) => {
                     return attr.attr == ele.fieldId;
                  })
                  if (curIndex > -1) {
                     const attr = data[curIndex]
                     if (ele.name ==
                        'Select' &&
                        attr
                        .choice_list
                     ) {
                        const
                           dictItemList = [];
                        const
                           choiceList =
                           attr
                           .choice_list || [];
                        for (let d in
                              choiceList) {
                           const
                              val =
                              choiceList[
                                 d
                              ];
                           dictItemList
                              .push({
                                 text: val,
                                 value: val
                              });
            attrs.forEach(async (attr, key) => {
               if (attr.choice_list) {
                  var dictItemList = [];
                  attr.choice_list.forEach(async (val, index) => {
                     dictItemList.push({
                        text: val,
                        value: val
                     });
                  });
                  head_styledef.form.items.forEach(async (attr_item, index) => {
                     if (attr_item.name != "Layout") {
                        if (attr_item.fieldId == attr.attr) {
                           if (attr_item.useDict) {
                              attr_item.dict = dictItemList;
                           } else {
                              attr_item.selections = dictItemList;
                           }
                        }
                        ele.dict =
                           dictItemList;
                     }
                     ele.value =
                        attr
                        .value;
                  }
               } else {
                  ele.setting
                     .colList
                     .forEach(
                        async (
                           col
                        ) => {
                           if (
                              col) {
                              let curIndex = data.findIndex((
                                 attr, index2, arr) => {
                                 return attr.attr == col.fieldId;
                              })
                              if (curIndex > -1) {
                                 const attr = data[curIndex]
                                 if (col.name ==
                                    'Select' &&
                                    attr
                                    .choice_list
                                 ) {
                                    const
                                       dictItemList = [];
                                    const
                                       choiceList =
                                       attr
                                       .choice_list || [];
                                    for (let d in
                                          choiceList) {
                                       const
                                          val =
                                          choiceList[
                                             d
                                          ];
                                       dictItemList
                                          .push({
                                             text: val,
                                             value: val
                                          });
                                    }
                                    col.dict =
                                       dictItemList;
                     } else if (attr_item.name == "Layout") {
                        attr_item.setting.colList.forEach((col) => {
                           if (col) {
                              if (col.fieldId == attr.attr) {
                                 if (col.useDict) {
                                    col.dict = dictItemList;
                                 } else {
                                    col.selections = dictItemList;
                                 }
                                 col.value =
                                    attr
                                    .value;
                              }
                           }
                        })
                        });
                     }
                  });
               }
            })
               head_styledef.form.model[attr.attr] = attr.value;
               head_styledef.form.items.forEach(async (ele, index) => {
                  if (ele.name != "Layout") {
                     if (ele.fieldId == attr.attr) {
                        ele.value = attr.value;
                        ele.oldvalue = attr.value;
                     }
                  } else if (ele.name == "Layout") {
                     ele.setting.colList.forEach((col) => {
                        if (col) {
                           if (col.fieldId == attr.attr) {
                              col.value = attr.value;
                              col.oldvalue = attr.value;
                           }
                        }
                     });
                  }
               })
               //判断表单里是否有返回字段,没有就装载到model里,点击确定提交的时候带上这些数据
            })
            console.log(head_styledef)
            this.setData({
               head_styledef: head_styledef
            })
         },
         popupChange(e) {
            console.log('当前模式:' + e.type + ',状态:' + e.show);
         },
@@ -1718,7 +1669,7 @@
               });
               this.okLoading = true
               var obj_attr = this.head_styledef.form.model || {};
                  console.log(obj_attr)
               console.log(obj_attr)
               let ret = await this.sava();
               this.okLoading = false
               uni.hideLoading();
@@ -1881,7 +1832,7 @@
         async afterOK() {
            try {
               var obj_attr = this.head_styledef.form.model ||{}
               var obj_attr = this.head_styledef.form.model || {}
               // console.log(obj_attr);
               var input_param = {
                  id: "",
@@ -1930,7 +1881,7 @@
         },
          async cancel(e) { //取消
         async cancel(e) { //取消
            try {
               if (!this.objId) {
                  if (this.editMode) {
@@ -1962,9 +1913,12 @@
                     value: obj_attr[a],
                  })),
               };
               let input_param = Base64.encode(JSON.stringify(inputParam));
               let global_attr = Base64.encode(JSON.stringify(this.global_attr))
               let data_json = Base64.encode(JSON.stringify(this.data_json))
               let input_param = Base64.encode(JSON.stringify(
                  inputParam));
               let global_attr = Base64.encode(JSON.stringify(this
                  .global_attr))
               let data_json = Base64.encode(JSON.stringify(this
                  .data_json))
               let ext_info = Base64.encode(JSON.stringify(this.ext_info))
               await runCustomEvent({
@@ -2005,10 +1959,14 @@
                     value: obj_attr[a],
                  })),
               };
               let input_param = Base64.encode(JSON.stringify(inputParam));
               let global_attr = Base64.encode(JSON.stringify(this.global_attr))
               let data_json = Base64.encode(JSON.stringify(this.data_json))
               let ext_info = Base64.encode(JSON.stringify(this.ext_info))
               let input_param = Base64.encode(JSON.stringify(
                  inputParam));
               let global_attr = Base64.encode(JSON.stringify(this
                  .global_attr))
               let data_json = Base64.encode(JSON.stringify(this
                  .data_json))
               let ext_info = Base64.encode(JSON.stringify(this
                  .ext_info))
               await runCustomEvent({
                  ed_type: 0,
@@ -2027,7 +1985,8 @@
               let exStr = JSON.stringify(ex)
               if (exStr == "{}")
                  exStr = ex
               let tip = typeof ex.errMsg == "string" ? ex.errMsg : exStr
               let tip = typeof ex.errMsg == "string" ? ex.errMsg :
                  exStr
               uni.showModal({
                  title: this.translateSys("tip") + "8.2",
                  content: tip,
@@ -2038,11 +1997,13 @@
            }
         },
         translate(t) {
            if (typeof this.$t == "function") return this.$t(`page.${t}`)
            if (typeof this.$t == "function") return this.$t(
               `page.${t}`)
            else return t;
         },
         translateSys(t) {
            if (typeof this.$t == "function") return this.$t(`sys.${t}`)
            if (typeof this.$t == "function") return this.$t(
               `sys.${t}`)
            else return t;
         },
      },
@@ -2119,7 +2080,7 @@
            margin: 0 10rpx;
            // padding: 5rpx 10rpx;
            background: #4D6AF4;
               font-size: 38rpx;
            font-size: 38rpx;
            border: none;
            color: #fff;
            float: left;