huangxiaoqiang
2025-12-17 d4477875746611db054f1b0f6c9e4a08980d6923
新增撤销组盘与分批入库功能,修复路径问题

- Pallet.vue: 修复 `fetchUnpalletMaterialDetails` 方法中参数错误,新增调用以获取未组盘物料详情。
- inboundOrder.js: 修正 `gridBody` 的导入路径,确保组件加载正确。
- inboundOrder_a.js: 新增扩展文件,包含以下功能:
- 定义 `gridHeader` 和 `gridBody` 组件。
- 实现“撤销组盘”功能,支持弹窗表单输入托盘号并调用后端接口。
- 实现“分批入库”功能,校验选中行后批量提交入库请求。
- 动态绑定按钮事件,扩展查询参数,优化生命周期方法。
- inboundOrder.vue: 更新扩展文件路径,确保使用最新逻辑。
已添加1个文件
已修改3个文件
340 ■■■■■ 文件已修改
项目代码/WIDESEA_WMSClient/src/extension/inbound/extend/Pallet.vue 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WIDESEA_WMSClient/src/extension/inbound/inboundOrder.js 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WIDESEA_WMSClient/src/extension/inbound/inboundOrder_a.js 333 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/WIDESEA_WMSClient/src/views/inbound/inboundOrder.vue 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ÏîÄ¿´úÂë/WIDESEA_WMSClient/src/extension/inbound/extend/Pallet.vue
@@ -317,7 +317,7 @@
    // æ ¹æ®æ¡ç åˆ—表获取详细数据
    async fetchUnpalletMaterialDetails() {
      try {
        const response = await http.post('/api/InboundOrder/UnPalletGroupBarcode?orderNo=' + this.docNo, {});
        const response = await http.post('/api/InboundOrder/UnPalletGroupBarcode?orderNo=' + this.orderNo, {});
        if (response.status && Array.isArray(response.data)) {
          this.unpalletMaterials = response.data;
          this.unpalletBarcodes = response.data.map(item => item.barcode || '');
@@ -656,6 +656,7 @@
        });
        this.orderNo = materialData[0].orderNo;
        await this.fetchStockStatistics(materialData[0].orderNo);
        await this.fetchUnpalletMaterialDetails();
        // æ¸…空物料输入框并保持聚焦
        this.barcode = '';
        this.scanCode = ''; // æ¸…空扫码缓存
ÏîÄ¿´úÂë/WIDESEA_WMSClient/src/extension/inbound/inboundOrder.js
@@ -1,6 +1,6 @@
//此js文件是用来自定义扩展业务代码,可以扩展一些自定义页面或者重新配置生成的代码
import gridHeader from './extend/EmptyTrayInbound.vue'
import gridBody from '../inbound/extend/Pallet.vue'
import gridBody from './extend/Pallet.vue'
let extension = {
  components: {
    //查询界面扩展组件
ÏîÄ¿´úÂë/WIDESEA_WMSClient/src/extension/inbound/inboundOrder_a.js
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,333 @@
//此js文件是用来自定义扩展业务代码,可以扩展一些自定义页面或者重新配置生成的代码
import gridHeader from './extend/EmptyTrayInbound.vue'
import gridBody from '../inbound/extend/Pallet.vue'
let extension = {
  components: {
    //查询界面扩展组件
    gridHeader: gridHeader,
    gridBody: gridBody,
    gridFooter: '',
    //新建、编辑弹出框扩展组件
    modelHeader: '',
    modelBody: '',
    modelFooter: ''
  },
  tableAction: '', //指定某张表的权限(这里填写表名,默认不用填写)
  buttons: {
    view: [
      // {
      //   name: '组盘',
      //   type: 'primary',
      //   value: '组盘',
      //   onClick: function () { // ä¿®å¤1:移除无用row参数,加日志调试
      //     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('网络异常或接口错误,请稍后重试');
          }
        }
      },
    ], box: [], detail: []
  },
  methods: {
    //下面这些方法可以保留也可以删除
    onInit() {
      var EmptyTrayInboundBtn = this.buttons.find(x => x.value == "EmptyTrayInbound");
        if (EmptyTrayInboundBtn != null) {
          EmptyTrayInboundBtn.onClick = () => {
               this.$refs.gridHeader.open();
            }
        }
        var GroupPalletBtn = this.buttons.find(x => x.value == "GroupPallet");
        if (GroupPalletBtn != null) {
          GroupPalletBtn.onClick = () => {
               this.$refs.gridBody.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;
ÏîÄ¿´úÂë/WIDESEA_WMSClient/src/views/inbound/inboundOrder.vue
@@ -6,7 +6,7 @@
  </view-grid>
</template>
<script>
import extend from "@/extension/inbound/inboundOrder_copy.js";
import extend from "@/extension/inbound/inboundOrder.js";
import { ref, defineComponent } from "vue";
export default defineComponent({
  setup() {