1
huangxiaoqiang
2 天以前 4619d729fbf0f3a6971fbb236e40187454a9c6cf
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
//此js文件是用来自定义扩展业务代码,可以扩展一些自定义页面或者重新配置生成的代码
import http from '@/api/http.js'
import { h, createVNode, render, reactive, ref } from 'vue';
import { ElDialog, ElForm, ElFormItem, ElInput, ElButton, ElMessage, ElSelect, ElOption } from 'element-plus'; // 引入ElMessage,解决提示无反应
import gridHeader from './extend/EmptyTrayInbound.vue'
let extension = {
  components: {
    //查询界面扩展组件
    gridHeader: gridHeader,
    gridBody: '',
    gridFooter: '',
    //新建、编辑弹出框扩展组件
    modelHeader: '',
    modelBody: '',
    modelFooter: ''
  },
  tableAction: '', //指定某张表的权限(这里填写表名,默认不用填写)
  buttons: {
    view: [
      {
        name: '组盘',
        type: 'primary',
        value: '组盘',
        onClick: function () { // 修复1:移除无用row参数,加日志调试
          console.log('组盘按钮被点击,开始校验');
          const selectedRows = this.$refs.table.getSelected();
 
          // 校验1:是否选中行
          if (selectedRows.length === 0) {
            console.log('校验不通过:未选中任何单据');
            ElMessage.warning('请选择一条单据');
            return;
          }
          // 校验2:是否选中单行
          if (selectedRows.length > 1) {
            console.log('校验不通过:选中多行单据');
            ElMessage.warning('只能选择一条单据');
            return;
          }
 
          const targetRow = selectedRows[0];
 
          this.$emit('openPalletDialog', targetRow.inboundOrderNo);
        }
      },
      {
        name: '撤销组盘',
        type: 'primary',
        value: '撤销组盘',
        onClick: function () {
          console.log('撤销组盘按钮被点击');
          const mountNode = document.createElement('div');
          document.body.appendChild(mountNode);
 
          // 响应式表单数据:托盘号(必填)
          const formData = reactive({
            palletCode: '', // 托盘号输入框
            barcode: ''
          });
 
          // 提交表单的统一逻辑
          const submitForm = async () => {
            const formRef = vnode.component.refs.cancelPalletForm;
            try {
              // 执行表单校验(托盘号必填)
              await formRef.validate();
            } catch (err) {
              ElMessage.warning('请输入有效的托盘号');
              return;
            }
 
            // 发起撤销组盘请求
            try {
              //console.log('发起撤销组盘请求,托盘号:', formData.palletCode.trim());
              const response = await http.post('/api/InboundOrder/UndoPalletGroup?palletCode=' + formData.palletCode.trim() + '&barcode=' + formData.barcode.trim());
 
 
              const { status, message, data } = response;
              if (status) {
                ElMessage.success(response.message);
                console.log(response.message)
                this.refresh(); // 成功后刷新列表
                // 关闭对话框
                render(null, mountNode);
                document.body.removeChild(mountNode);
              } else {
                console.log('撤销组盘失败,后端提示:', message);
                ElMessage.error(message || data?.message || '撤销组盘失败');
                selectPalletCodeInput(); // 选中输入框方便重新输入
              }
            } catch (error) {
              console.error('撤销组盘请求异常:', error);
              ElMessage.error('网络异常或接口错误,请稍后重试');
              selectPalletCodeInput();
            }
          };
 
          // 选中输入框文本(方便重新输入)
          const selectPalletCodeInput = () => {
            setTimeout(() => {
              const inputRef = vnode.component.refs.palletCodeInput;
              if (inputRef) {
                const targetInput = inputRef.$el?.querySelector('input') || inputRef;
                targetInput?.focus();
                targetInput?.select();
              }
            }, 100);
          };
 
          // 创建对话框VNode
          const vnode = createVNode(ElDialog, {
            title: '撤销组盘',
            width: '400px',
            modelValue: true,
            appendToBody: true,
            onOpened: () => {
              // 对话框打开后自动聚焦输入框
              setTimeout(() => {
                const inputRef = vnode.component.refs.palletCodeInput;
                inputRef?.focus();
              }, 100);
            },
            'onUpdate:modelValue': (isVisible) => {
              if (!isVisible) {
                render(null, mountNode);
                document.body.removeChild(mountNode);
              }
            }
          }, {
            default: () => h(ElForm, {
              model: formData,
              rules: {
                palletCode: [
                  { required: true, message: '请输入托盘号', trigger: ['blur', 'enter'] },
                  { min: 1, max: 50, message: '托盘号长度不能超过50个字符', trigger: ['blur', 'input'] }
                ]
              },
              ref: 'cancelPalletForm'
            }, [
              // 托盘号输入项
              h(ElFormItem, { label: '托盘号', prop: 'palletCode', required: true }, [
                h(ElInput, {
                  type: 'text',
                  modelValue: formData.palletCode,
                  'onUpdate:modelValue': (val) => {
                    formData.palletCode = val;
                  },
                  ref: 'palletCodeInput',
                  placeholder: '扫码输入或手动输入托盘号',
                  maxLength: 50,
                  // 监听回车事件(扫码枪默认会发送回车)
                  onKeydown: (e) => {
                    if (e.key === 'Enter') {
                      e.preventDefault();
                      submitForm();
                    }
                  }
                })
              ]),
              h(ElFormItem, { label: '条码', prop: 'barcode' }, [
                h(ElInput, {
                  type: 'text',
                  modelValue: formData.barcode,
                  'onUpdate:modelValue': (val) => {
                    formData.barcode = val;
                  },
                  placeholder: '可选,扫码输入或手动输入条码',
                  maxLength: 50,
                  onKeydown: (e) => {
                    if (e.key === 'Enter') {
                      e.preventDefault();
                      submitForm();
                    }
                  }
                })
              ]),
              // 底部按钮区
              h('div', { style: { textAlign: 'right', marginTop: '16px' } }, [
                h(ElButton, {
                  type: 'text',
                  onClick: () => {
                    render(null, mountNode);
                    document.body.removeChild(mountNode);
                    ElMessage.info('取消撤销组盘');
                  }
                }, '取消'),
                h(ElButton, {
                  type: 'primary',
                  onClick: submitForm.bind(this) // 绑定this上下文
                }, '确认撤销')
              ])
            ])
          });
 
          vnode.appContext = this.$.appContext;
          render(vnode, mountNode);
        }
      },
      {
        name: '分批入库',
        type: 'primary',
        value: '分批入库',
        onClick: async function () {
          console.log('分批入库按钮被点击,开始校验');
          const selectedRows = this.$refs.table.getSelected();
 
          // 校验1:是否选中行(至少选择一条)
          if (selectedRows.length === 0) {
            console.log('校验不通过:未选中任何单据');
            ElMessage.warning('请选择至少一条单据');
            return;
          }
 
          // 收集所有选中单据的编号(过滤无单据号的异常行)
          const inboundOrderNos = selectedRows
            .filter(row => row.inboundOrderNo)
            .map(row => row.inboundOrderNo);
 
          // 校验2:是否有有效单据号
          if (inboundOrderNos.length === 0) {
            console.log('校验不通过:选中单据无有效编号');
            ElMessage.warning('选中的单据中无有效编号,请重新选择');
            return;
          }
 
          try {
            console.log('发起分批入库请求,参数:', { inboundOrderNos });
            const response = await http.post('/api/InboundOrder/BatchOrderFeedbackToMes', {
              orderNos: inboundOrderNos,
              inout: 1
            });
 
            const { status, message, data } = response;
            if (status) {
              console.log('分批入库成功,后端返回:', data);
              ElMessage.success(`分批入库成功!`);
              this.refresh(); // 入库成功后刷新列表(复用原有逻辑)
            } else {
              console.log('分批入库失败,后端提示:', message);
              ElMessage.error(message || data?.message || '分批入库失败');
            }
          } catch (error) {
            console.error('分批入库请求异常:', error);
            ElMessage.error('网络异常或接口错误,请稍后重试');
          }
        }
      },
      // {
      //   name: '空托盘入库',
      //   type: 'primary',
      //   value: '空托盘入库',
 
      //   onClick: function () {
      //     const mountNode = document.createElement('div');
      //     document.body.appendChild(mountNode);
 
      //     // 响应式表单数据:料箱码(必填,扫码枪/手动输入)
      //     const formData = reactive({
      //       boxCode: '',
      //       warehouseCode: ''
      //     });
 
      //     const warehouses = ref([]);
      //     const isLoadingWarehouses = ref(false);
 
      //     const getWarehouseList = async () => {
      //       isLoadingWarehouses.value = true;
      //       try {
      //         const { data, status } = await http.post('/api/LocationInfo/GetLocationTypes');
      //         if (status && Array.isArray(data)) {
      //           // 格式化仓库选项:适配ElSelect的label-value格式
      //           warehouses.value = data.map(item => ({
      //             label: item.locationTypeDesc,
      //             value: item.locationType
      //           }));
      //         } else {
      //           ElMessage.error('获取区域列表失败');
      //           warehouses.value = [];
      //         }
      //       } catch (err) {
      //         ElMessage.error('区域数据请求异常,请稍后重试');
      //         warehouses.value = [];
      //       } finally {
      //         isLoadingWarehouses.value = false;
      //       }
      //     };
 
      //     // 提交表单的统一逻辑(供回车触发和按钮点击共用)
      //     const submitForm = async () => {
      //       const formRef = vnode.component.refs.batchInForm;
      //       try {
      //         // 执行表单校验(料箱码必填)
      //         await formRef.validate();
      //       } catch (err) {
      //         ElMessage.warning('请输入有效的料箱码');
      //         return;
      //       }
 
 
      //       http.post('/api/InboundOrder/EmptyMaterielGroup', {
      //         palletCode: formData.boxCode.trim(),
      //         warehouseCode: formData.warehouseCode
      //       }).then(({ data, status, message }) => {
      //         if (status) {
      //           ElMessage.success(`入库成功,料箱码:${formData.boxCode.trim()}`);
      //           this.refresh();
      //           formData.boxCode = '';
 
      //           setTimeout(() => {
      //             const inputRef = vnode.component.refs.boxCodeInput;
      //             inputRef?.focus();
      //           }, 100);
      //         } else {
      //           ElMessage.error(message || data?.message || '入库失败');
      //           selectBoxCodeInput();
      //         }
      //       }).catch(() => {
      //         ElMessage.error('请求失败,请稍后重试');
      //         selectBoxCodeInput();
      //       });
      //     };
 
      //     const selectBoxCodeInput = () => {
      //       setTimeout(() => {
      //         const inputRef = vnode.component.refs.boxCodeInput;
      //         if (inputRef) {
      //           const targetInput = inputRef.$el?.querySelector('input') || inputRef;
      //           targetInput?.focus();
      //           targetInput?.select();
      //         }
      //       }, 100);
      //     }
      //     const vnode = createVNode(ElDialog, {
      //       title: '空托盘入库',
      //       width: '400px',
      //       modelValue: true,
      //       appendToBody: true,
 
      //       onOpened: async () => {
      //         await getWarehouseList();
      //         const inputRef = vnode.component.refs.boxCodeInput;
      //         inputRef?.focus();
      //       },
      //       'onUpdate:modelValue': (isVisible) => {
      //         if (!isVisible) {
      //           render(null, mountNode);
      //           document.body.removeChild(mountNode);
      //         }
      //       }
      //     }, {
      //       default: () => h(ElForm, {
      //         model: formData,
      //         rules: {
      //           boxCode: [
      //             { required: true, message: '请输入料箱码', trigger: ['blur', 'enter'] }
      //           ],
      //           warehouseCode: [
      //             { required: true, message: '请选择区域', trigger: ['change', 'blur'] }
      //           ]
      //         },
      //         ref: 'batchInForm'
      //       }, [
      //         //仓库数据
      //         h(ElFormItem, { label: '区域', prop: 'warehouseCode', required: true }, [
      //           h(ElSelect, {
      //             modelValue: formData.warehouseCode,
      //             'onUpdate:modelValue': (val) => {
      //               formData.warehouseCode = val;
      //             },
      //             placeholder: '请选择入库区域',
      //             filterable: true, // 支持搜索仓库
      //             loading: isLoadingWarehouses.value, // 加载状态
      //             style: { width: '100%' }
      //           }, [
      //             // 渲染仓库下拉选项
      //             warehouses.value.map(item => h(ElOption, {
      //               label: item.label,
      //               value: item.value
      //             }))
      //           ])
      //         ]),
      //         // 料箱码输入项(支持聚焦、回车提交)
      //         h(ElFormItem, { label: '料箱码', prop: 'boxCode', required: true }, [
      //           h(ElInput, {
      //             type: 'text',
      //             modelValue: formData.boxCode,
      //             'onUpdate:modelValue': (val) => {
      //               formData.boxCode = val;
      //             },
      //             ref: 'boxCodeInput',
      //             placeholder: '扫码输入或手动输入料箱码',
      //             // 监听回车事件(扫码枪默认会发送回车)
      //             onKeydown: (e) => {
      //               if (e.key === 'Enter') {
      //                 e.preventDefault();
      //                 submitForm();
      //               }
      //             }
      //           })
      //         ]),
      //         // 底部按钮区
      //         h('div', { style: { textAlign: 'right', marginTop: '16px' } }, [
      //           h(ElButton, {
      //             type: 'text',
      //             onClick: () => {
      //               render(null, mountNode);
      //               document.body.removeChild(mountNode);
      //               ElMessage.info('取消入库任务');
      //             }
      //           }, '取消'),
      //           h(ElButton, {
      //             type: 'primary',
      //             onClick: submitForm
      //           }, '确定')
      //         ])
      //       ])
      //     });
 
      //     vnode.appContext = this.$.appContext;
      //     render(vnode, mountNode);
      //   }
      // }
    ], box: [], detail: []
  },
  methods: {
    //下面这些方法可以保留也可以删除
    onInit() {
      var EmptyTrayInboundBtn = this.buttons.find(x => x.value == "EmptyTrayInbound");
        if (EmptyTrayInboundBtn != null) {
          EmptyTrayInboundBtn.onClick = () => {
               this.$refs.gridHeader.open();
            }
        }
 
 
      this.columns.forEach(column => {
        if (column.field === 'orderStatistics') {
          column.formatter = (row) => {
            // 校验details是否存在且有数据
            if (row.details && row.details.length > 0) {
              //按materielCode分组统计orderQuantity总和
              const materielSumMap = row.details.reduce((acc, item) => {
                const materielCode = item.materielCode || '未知物料';
                const quantity = Number(item.orderQuantity) || 0;
                acc[materielCode] = (acc[materielCode] || 0) + quantity;
                return acc;
              }, {});
 
              //每个物料项生成独立div,跨行显示
              const displayItems = Object.entries(materielSumMap).map(([code, total]) => {
                return `<div style="line-height: 1.5; white-space: normal;">${code}:${total}个</div>`;
              });
              const displayContent = displayItems.join('');
              return `<div style="color: #F56C6C; white-space: normal; word-break: break-all;">${displayContent}</div>`;
            } else {
              return '<span style="color: #F56C6C">无入库明细</span>';
            }
          };
        }
      });
    },
    onInited() {
 
      //框架初始化配置后
      //如果要配置明细表,在此方法操作
      //this.detailOptions.columns.forEach(column=>{ });
    },
    searchBefore(param) {
      //界面查询前,可以给param.wheres添加查询参数
      //返回false,则不会执行查询
      // this.searchFormFields.orderType=[0]
      let wheres = [{
        'name': 'orderType',
        'value': '0',
        'displayType': 'text'
      }];
 
 
      param.wheres.push(...wheres);
      return true;
    },
    searchAfter(result) {
      return true;
    },
    addBefore(formData) {
      //新建保存前formData为对象,包括明细表,可以给给表单设置值,自己输出看formData的值
      return true;
    },
    updateBefore(formData) {
      //编辑保存前formData为对象,包括明细表、删除行的Id
      return true;
    },
    rowClick({ row, column, event }) {
      //查询界面点击行事件
      this.$refs.table.$refs.table.toggleRowSelection(row); //单击行时选中当前行;
    },
    modelOpenAfter(row) {
      //点击编辑、新建按钮弹出框后,可以在此处写逻辑,如,从后台获取数据
      //(1)判断是编辑还是新建操作: this.currentAction=='Add';
      //(2)给弹出框设置默认值
      //(3)this.editFormFields.字段='xxx';
      //如果需要给下拉框设置默认值,请遍历this.editFormOptions找到字段配置对应data属性的key值
      //看不懂就把输出看:console.log(this.editFormOptions)
    }
  }
};
export default extension;