pan
6 天以前 a7b15461d3dc6d07c18e065fa3a6acd234c2d7c8
ÏîÄ¿´úÂë/WIDESEA_WMSClient/src/extension/inbound/inboundOrder.js
@@ -1,4 +1,3 @@
//此js文件是用来自定义扩展业务代码,可以扩展一些自定义页面或者重新配置生成的代码
import http from '@/api/http.js'
import { h, createVNode, render, reactive, ref } from 'vue';
@@ -44,159 +43,159 @@
          this.$emit('openPalletDialog', targetRow.inboundOrderNo);
        }
      },
     {
                name: '撤销组盘',
                type: 'primary',
                value: '撤销组盘',
                onClick: function () {
                    console.log('撤销组盘按钮被点击');
                    const mountNode = document.createElement('div');
                    document.body.appendChild(mountNode);
      {
        name: '撤销组盘',
        type: 'primary',
        value: '撤销组盘',
        onClick: function () {
          console.log('撤销组盘按钮被点击');
          const mountNode = document.createElement('div');
          document.body.appendChild(mountNode);
                    // å“åº”式表单数据:托盘号(必填)
                    const formData = reactive({
                        palletCode: '', // æ‰˜ç›˜å·è¾“入框
                        barcode:''
                    });
          // å“åº”式表单数据:托盘号(必填)
          const formData = reactive({
            palletCode: '', // æ‰˜ç›˜å·è¾“入框
            barcode: ''
          });
                    // æäº¤è¡¨å•的统一逻辑
                    const submitForm = async () => {
                        const formRef = vnode.component.refs.cancelPalletForm;
                        try {
                            // æ‰§è¡Œè¡¨å•校验(托盘号必填)
                            await formRef.validate();
                        } catch (err) {
                            ElMessage.warning('请输入有效的托盘号');
                            return;
                        }
          // æäº¤è¡¨å•的统一逻辑
          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());
            // å‘起撤销组盘请求
            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);
                    };
              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();
            }
          };
                    // åˆ›å»ºå¯¹è¯æ¡†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上下文
                                }, '确认撤销')
                            ])
                        ])
                    });
          // é€‰ä¸­è¾“入框文本(方便重新输入)
          const selectPalletCodeInput = () => {
            setTimeout(() => {
              const inputRef = vnode.component.refs.palletCodeInput;
              if (inputRef) {
                const targetInput = inputRef.$el?.querySelector('input') || inputRef;
                targetInput?.focus();
                targetInput?.select();
              }
            }, 100);
          };
                    vnode.appContext = this.$.appContext;
                    render(vnode, mountNode);
                }
          // åˆ›å»ºå¯¹è¯æ¡†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',
@@ -427,30 +426,30 @@
    //下面这些方法可以保留也可以删除
    onInit() {
      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;
            }, {});
        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>';
          }
        };
      }
    });
              //每个物料项生成独立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() {
@@ -473,7 +472,6 @@
      return true;
    },
    searchAfter(result) {
      //查询后,result返回的查询数据,可以在显示到表格前处理表格的值
      return true;
    },
    addBefore(formData) {
@@ -498,4 +496,4 @@
    }
  }
};
export default extension;
export default extension;