647556386
3 天以前 91ead18d0e92b6e1ed916c5159f3431bf2071a56
ÏîÄ¿´úÂë/WIDESEA_WMSClient/src/extension/inbound/inboundOrder.js
@@ -2,11 +2,11 @@
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: gridHeader,
    gridBody: '',
    gridFooter: '',
    //新建、编辑弹出框扩展组件
@@ -233,7 +233,7 @@
            const { status, message, data } = response;
            if (status) {
              console.log('分批入库成功,后端返回:', data);
              ElMessage.success(`分批入库成功!共处理${inboundOrderNos.length}条单据`);
              ElMessage.success(`分批入库成功!`);
              this.refresh(); // å…¥åº“成功后刷新列表(复用原有逻辑)
            } else {
              console.log('分批入库失败,后端提示:', message);
@@ -245,186 +245,194 @@
          }
        }
      },
      {
        name: '空托盘入库',
        type: 'primary',
        value: '空托盘入库',
      // {
      //   name: '空托盘入库',
      //   type: 'primary',
      //   value: '空托盘入库',
        onClick: function () {
          const mountNode = document.createElement('div');
          document.body.appendChild(mountNode);
      //   onClick: function () {
      //     const mountNode = document.createElement('div');
      //     document.body.appendChild(mountNode);
          // å“åº”式表单数据:料箱码(必填,扫码枪/手动输入)
          const formData = reactive({
            boxCode: '',
            warehouseCode: ''
          });
      //     // å“åº”式表单数据:料箱码(必填,扫码枪/手动输入)
      //     const formData = reactive({
      //       boxCode: '',
      //       warehouseCode: ''
      //     });
          const warehouses = ref([]);
          const isLoadingWarehouses = ref(false);
      //     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 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;
            }
      //     // æäº¤è¡¨å•的统一逻辑(供回车触发和按钮点击共用)
      //     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 = '';
      //       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();
            });
          };
      //           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,
      //     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
                }, '确定')
              ])
            ])
          });
      //       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);
        }
      }
      //     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) => {