ludc
2024-07-10 083e907c2567ba53c892a45cf2605172715922ab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
<template>
  <el-dialog title="最大流水号" width="30%" append-to-body="true" class="avue-dialog avue-dialog--top" top="-3%" :visible.sync="dialogVisible">
    <el-form :label-position="right" ref="ruleForm" label-width="80px" :model="formModel" :rules="rules"  v-loading="loading">
      <el-form-item label="流水号" prop="maxSecNum">
        <el-input v-model="formModel.maxSecNum" @blur="handleBlur"></el-input>
      </el-form-item>
    </el-form>
    <el-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
      <el-tab-pane label="最大流水号" name="codeApply">
        <form-template key="codeApplyMaxForm" data-key="codeApplyMaxForm" v-bind="$attrs" type="add" :selfColumnType="selfColumnType" :trendsSpan="24"
                       :selfColumnConfig="selfColumnConfig" ref="CodeApply" @getFormData="getCodeApplyFormData"
                       @referConfigDataUpdate="referConfigDataUpdate"></form-template>
      </el-tab-pane>
    </el-tabs>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">取 消</el-button>
      <el-button type="primary" :loading="confirmLoadding" @click="comfirm">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import FormTemplate from "@/components/FormTemplate/FormTemplate";
import { getCodePrice, saveMaxSerialNum, getMaxSerialNumber } from "@/api/code/maxSerialNum.js"
export default {
  name: 'maxSerialnumDialog',
  components: {
    FormTemplate
  },
  props: {
    // 是否打开
    visible: {
      typeof: Boolean,
      default: false
    },
    // ruleOid
    ruleOid: {
      typeof: String,
      default: ""
    }
  },
  watch: {
    visible(n) {
      this.dialogVisible = n;
    },
    dialogVisible(n) {
      this.$emit('update:visible', n)
      if (n) this.apiGetCode()
    },
    selfColumnConfig: {
      handler(newval) {
        // console.log('selfColumnConfig', newval)
      },
      immediate: true,
      deep: true
    },
  },
  mounted() {
  },
  data() {
    return {
      loading:false,
      maxNum:Number,
      ruleFormFlag:Boolean,
      dialogVisible: this.visible,
      activeName: 'codePrice',
      confirmLoadding: false,
      codeApplyForm: {},
      secVOList: [],
      formModel: {
        maxSecNum: '',
        codeRuleOid: '',
        secDTOList: []
      },
      rules: {
        maxSecNum: [
          { required: true, message: '请输入流水号', trigger: 'blur' },
          {
            validator: (rule, value, callback) => {
              if (value < this.maxNum) {
                callback(new Error('不能小于当前最大流水号'));
              } else {
                callback();
              }
            },
            trigger: 'blur'
          }
        ],
      },
      selfColumnType: {
        codefixedsec: "combox",//固定码段
        codeclassifysec: "refer",//分类码段
        codevariablesec: "text",//可变码段
        coderefersec: "refer",//引用码段
        codeattrsec: "text",
        codelevelsec: "text",
        codedatesec: "date"
      },
      selfColumnConfig: {
        function: {
          required: this.isRequired,
          dicData: this.getOptionList,
          type: this.getType,
          referConfig: this.getReferConfig,
          readOnly: this.getDisabled,
        },
        exchange: {
          text: "name",
          field: "oid",
          prop: "oid",
          showField: "name",
          parentClassifySecOid: "parentClassifySecOid",
          label: "name",
          maxlength: "codeSecLength",
          data: "fixedValueVOList",
          dateFormate: "codeDateFormatStr"
        },
        directVoluation: {
          search: true,
          props: {
            label: "id",
            value: "id",
          },
        },
      },
    }
  },
  methods: {
    //清除正则
    handleBlur() {
      this.$refs.ruleForm.clearValidate('maxSecNum');
    },
    // 获取码段
    async apiGetCode() {
      this.activeName = "codeApply";
      const response = await getCodePrice({ ruleOid: this.ruleOid })
      const res = response.data
      if (res.success && res.code === 200) {
        const typeList = [
          "codefixedsec",
          "codeclassifysec",
          "codevariablesec",
          "coderefersec",
          "codeattrsec",
          "codelevelsec",
          "codedatesec"
        ];
        this.secVOList = (res.data.secVOList || []).filter((item) =>
          typeList.includes(item.secType)
        );
        if (this.secVOList.length > 0) {
          this.$nextTick(() => {
            this.$refs.CodeApply.templateRender(this.secVOList);
          });
        } else {
          this.$refs.CodeApply.loading = false;
        }
      }
    },
    handleClick(tab, event) {
      // console.log(event)
    },
    getCodeApplyFormData(codeApplyForm) {
      this.codeApplyForm = codeApplyForm;
      //最大流水Number
      const objcodekey = Object.keys(codeApplyForm)
      const filteredObj = objcodekey.reduce((acc, key) => {
        const pattern = /[\u4e00-\u9fa5]/; // 匹配中文字符的正则表达式
        const patterns = /\$/;
        if (!pattern.test(key)&&!patterns.test(key)) {
          acc[key] = this.codeApplyForm[key];
        }
        return acc;
      }, {});
 
      /*const arrCode = Object.entries(filteredObj).map(([key, value]) => {
        return {
          secOid: key,
          secValue: value
        }
      })*/
 
      this.ruleFormFlag = Object.values(codeApplyForm).every(value => {
        return value !== null && value !== undefined && value !== '';
      });
      if (this.ruleFormFlag && this.secVOList.length>0) {
        this.loading=true;
        let params = {};
        params['codeRuleOid'] = this.ruleOid;
        Object.keys(filteredObj).forEach((key) => {
          params[key] = filteredObj[key];
        });
        getMaxSerialNumber(params).then(res => {
          this.formModel.maxSecNum = res.data.data;
          this.loading=false;
          this.maxNum=res.data.data
        });
      }
    },
 
    // 取消
    cancel() {
      this.dialogVisible = false
      this.formModel['secDTOList'] = []
      this.formModel['codeRuleOid'] = ''
      this.formModel['maxSecNum'] = ''
      this.$refs.ruleForm.clearValidate('maxSecNum')
 
    },
    // 确认
    async comfirm() {
      const objcodekey = Object.keys(this.codeApplyForm)
      const filteredObj = objcodekey.reduce((acc, key) => {
        const pattern = /[\u4e00-\u9fa5]/; // 匹配中文字符的正则表达式
        const patterns = /\$/;
        if (!pattern.test(key)&&!patterns.test(key)) {
          acc[key] = this.codeApplyForm[key];
        }
        return acc;
      }, {});
      const arrCode = Object.entries(filteredObj).map(([key, value]) => {
        return {
          secOid: key,
          secValue: value
        }
      })
      this.formModel['secDTOList'] = arrCode
      this.formModel['codeRuleOid'] = this.ruleOid
      this.confirmLoadding = true;
      // this.FormRule= await this.$refs.CodeApply.validate();
      const rule = await this.$refs.CodeApply.validate();
      // console.log(rule)
      this.$refs.ruleForm.validate(res => {
        if (rule && res) {
          // console.log(rule,res)
          saveMaxSerialNum(this.formModel).then(res => {
            if (res.data.success) {
              this.$message.success('操作成功!');
              this.confirmLoadding = false
              this.cancel()
            }
          }).catch(error=>{
            this.confirmLoadding = false
          })
        } else {
          this.confirmLoadding = false
        }
      })
 
    },
    // 参照组件数据变更
    referConfigDataUpdate(data) {
      const {field} = data;
      let childItems=[];
      this.secVOList = this.secVOList.map((item) => {
        if (item.parentClassifySecOid === field) {
          this.$refs.CodeApply.form[item.oid] = undefined;
          this.$refs.CodeApply.form[item.name] = undefined;
          item.readOnly = false;
          item.referConfig.extraParams.parentClassifyValueOid = data.value;
          item.referConfig.reloadData = true;
          item.dataKey=item.oid+'_'+new Date().getTime();
          childItems.push(item)
        }
        return item;
      });
      //this.$refs.CodeApply.templateRender(this.secVOList);
      this.$refs.CodeApply.changeChildItem(childItems);
    },
    isRequired(item) {
      return item.nullableFlag != "true";
    },
    getType(item) {
      return this.selfColumnType[item.secType];
    },
    getDisabled(item) {
      if (item.secType === "codeclassifysec") {
        if (item.parentClassifySecOid) {
          if (!this.codeApplyForm[item.parentClassifySecOid]) {
            return true;
          } else {
            return false;
          }
        }
      }
    },
    getReferConfig(item) {
      let params = {};
      if (item.secType == "codeclassifysec") {
        params = {
          isMuti: false,
          valueField: 'oid',
          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);
      }
      // console.log(params)
      return params;
 
    },
    getOptionList(item) {
      if (
        Array.isArray(item.fixedValueVOList) &&
        item.fixedValueVOList.length > 0
      ) {
        const configAttr = {
          key: "id",
          value: "id",
        };
        const optionList = item.fixedValueVOList.map((item) => {
          for (const key in configAttr) {
            if (Object.hasOwnProperty.call(configAttr, key)) {
              const element = configAttr[key];
              item[key] = item[element];
            }
          }
          return item;
        });
        return optionList;
      } else {
        return [];
      }
    },
  }
}
</script>