heshaofeng
2026-01-06 b13d3d2c634df625dcaa74371f1d36a8376851b4
ÏîÄ¿´úÂë/WIDESEA_WMSClient/src/extension/inbound/inboundOrder.js
@@ -1,24 +1,13 @@
//此js文件是用来自定义扩展业务代码,可以扩展一些自定义页面或者重新配置生成的代码
import gridHeader from "./extend/EmptyTrayInbound.vue";
import gridBody from "./extend/Pallet.vue";
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";
import gridFooter from "./extend/UndoPalletGroup.vue";
let extension = {
  components: {
    //查询界面扩展组件
    gridHeader: gridHeader,
    gridBody: gridBody,
    gridFooter: "",
    gridFooter: gridFooter,
    //新建、编辑弹出框扩展组件
    modelHeader: "",
    modelBody: "",
@@ -27,243 +16,7 @@
  tableAction: "", //指定某张表的权限(这里填写表名,默认不用填写)
  buttons: {
    view: [
      {
        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 {
              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);
                this.refresh(); // æˆåŠŸåŽåˆ·æ–°åˆ—è¡¨
                // å…³é—­å¯¹è¯æ¡†
                render(null, mountNode);
                document.body.removeChild(mountNode);
              } else {
                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: [],
@@ -277,6 +30,14 @@
      if (EmptyTrayInboundBtn != null) {
        EmptyTrayInboundBtn.onClick = () => {
          this.$refs.gridHeader.open();
        };
      }
      var UndoPalletGroupBtn = this.buttons.find(
        (x) => x.value == "UndoPalletGroup"
      );
      if (UndoPalletGroupBtn != null) {
        UndoPalletGroupBtn.onClick = () => {
          this.$refs.gridFooter.open();
        };
      }
      var BatchInOrderFeedbackToMesBtn = this.buttons.find(
@@ -307,35 +68,6 @@
            });
        };
      }
      // let BatchInOrderFeedbackToMesBtn = this.buttons.find((x) => x.value == "BatchInOrderFeedbackToMes");
      // if (BatchInOrderFeedbackToMesBtn != null) {
      //   BatchInOrderFeedbackToMesBtn.onClick = ()=> {
      //     let selectedRows = this.$refs.table.getSelected();
      //     // æ ¡éªŒæ˜¯å¦æœ‰é€‰ä¸­æ•°æ®
      //     if (!selectedRows || selectedRows.length === 0) {
      //       return this.$Message.warning("请先选择需要处理的单据");
      //     }
      //     if (selectedRows.length > 1) {
      //       return this.$Message.warning("请选择一条数据");
      //     }
      //     this.http.post(`api/Inbound/BatchInOrderFeedbackToMes?orderNo=${selectedRows[0].orderNo}`,{},"数据处理中...")
      //       .then((x) => {
      //         if (x.status) {
      //           this.$Message.success("分批出库回调完成");
      //           this.refresh();
      //         } else {
      //           return this.$Message.error("分批出库回调失败");
      //         }
      //       })
      //       .catch((error) => {
      //         // å¢žåŠ å¼‚å¸¸æ•èŽ·ï¼Œå¤„ç†ç½‘ç»œé”™è¯¯ç­‰æƒ…å†µ
      //         //_this.$Message.error('请求失败:' + (error.message || '未知错误'));
      //       });
      //   };
      // }
      var GroupPalletBtn = this.buttons.find((x) => x.value == "GroupPallet");
      if (GroupPalletBtn != null) {
        GroupPalletBtn.onClick = () => {