heshaofeng
2025-12-29 266e4bf654c55ce2f7e9271048e4625f1b8b49f6
ÏîÄ¿´úÂë/WIDESEA_WMSClient/src/extension/outbound/outboundOrder.js
@@ -3,7 +3,6 @@
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 gridBody from './extend/outOrderDetail.vue'
import gridHeader from './extend/NoStockOut.vue'
import gridFooter from './extend/EmptyTrayOutbound.vue'
@@ -325,8 +324,6 @@
            table.clearSelection();
            table.toggleRowSelection(row, true);
          }
          const rowId = row.id;
          console.log(rowId);
          this.$refs.gridBody.open(row);
        }
      });
@@ -340,15 +337,18 @@
          if (!selectedRows || selectedRows.length === 0) {
            return _this.$Message.warning('请先选择需要处理的单据');
          }
          const requestParams = {
            orderNos: selectedRows.map(row => row.orderNo),
            inout: 2
          };
          if (selectedRows.length > 1) {
            return _this.$Message.warning('请选择一条数据');
          }
          // const requestParams = {
          //   orderNos: selectedRows.map(row => row.orderNo),
          //   inout: 2
          // };
          _this.http
            .post("api/InboundOrder/BatchOrderFeedbackToMes", requestParams, "数据处理中...")
            .post(`api/MesFeedback/OutboundFeedback?orderNo=${selectedRows[0].orderNo}`, {}, "数据处理中...")
            .then((x) => {
              if (x.status) {
                _this.$Message.success('分批出库回调完成');
                _this.$Message.success(x.message);
                _this.refresh();
              } else {
                return _this.$Message.error(x.message);
@@ -356,7 +356,7 @@
            })
            .catch((error) => {
              // å¢žåŠ å¼‚å¸¸æ•èŽ·ï¼Œå¤„ç†ç½‘ç»œé”™è¯¯ç­‰æƒ…å†µ
              _this.$Message.error('请求失败:' + (error.message || '未知错误'));
              //_this.$Message.error('请求失败:' + (error.message || '未知错误'));
            });
        };
      }
@@ -367,12 +367,188 @@
        }
      }
      var EmptyTrayOutboundBtn = this.buttons.find(x => x.value == "EmptyTrayOutbound");
        if (EmptyTrayOutboundBtn != null) {
          EmptyTrayOutboundBtn.onClick = () => {
               this.$refs.gridFooter.open();
            }
      if (EmptyTrayOutboundBtn != null) {
        EmptyTrayOutboundBtn.onClick = () => {
          this.$refs.gridFooter.open();
        }
      }
      let OrderOutBtn = this.buttons.find(x => x.value == 'OrderOut');
if (OrderOutBtn) {
  // 1. æ”¹ä¸ºç®­å¤´å‡½æ•°ï¼Œç¡®ä¿this指向Vue组件实例(原普通函数this指向按钮本身)
  OrderOutBtn.onClick = async () => {
    // çŽ°åœ¨this是Vue组件实例,能正确获取$refs
    let rows = this.$refs.table.getSelected();
    if (rows.length == 0) return this.$error("请选择数据!");
    if (rows.length > 1) return this.$error("请选择一条数据!");
    // ç¡®ä¿é€‰ä¸­è¡Œæœ‰id(根据实际表格数据字段调整,比如rows[0].detailId等)
    const selectedId = rows[0].id || rows[0].detailId;
    if (!selectedId) return this.$error("选中数据缺少必要ID字段!");
    if(rows[0].orderStatus!=0&&rows[0].orderStatus!=1)return this.$error("该单据已经完成");
    const platformOptions = [
      { label: "站台2", value: "2-1" },
      { label: "站台3", value: "3-1" },
    ];
    const mountNode = document.createElement("div");
    document.body.appendChild(mountNode);
    const formData = reactive({
      selectedPlatform: platformOptions[0].value,
    });
    const vnode = createVNode(
      ElDialog,
      {
        title: "出库操作 - é€‰æ‹©å‡ºåº“站台",
        width: "500px",
        modelValue: true,
        appendToBody: true,
        "onUpdate:modelValue": (isVisible) => {
          if (!isVisible) {
            render(null, mountNode);
            document.body.removeChild(mountNode);
          }
        },
        style: {
          padding: "20px 0",
          borderRadius: "8px",
        },
      },
      {
        default: () =>
          h(
            ElForm,
            {
              model: formData,
              rules: {
                selectedPlatform: [
                  { required: true, message: "请选择出库站台", trigger: "change" },
                ],
              },
              ref: "outboundForm", // è¡¨å•ref
              labelWidth: "100px",
              style: {
                padding: "0 30px",
              },
            },
            [
              h(ElFormItem, {
                label: "出库站台",
                prop: "selectedPlatform",
                style: {
                  marginBottom: "24px",
                },
              }, [
                h(ElSelect, {
                  placeholder: "请选择出库站台(3-12)",
                  modelValue: formData.selectedPlatform,
                  "onUpdate:modelValue": (val) => {
                    formData.selectedPlatform = val;
                  },
                  style: {
                    width: "100%",
                    height: "40px",
                    borderRadius: "4px",
                    borderColor: "#dcdfe6",
                  },
                }, platformOptions.map((platform) =>
                  h(ElOption, { label: platform.label, value: platform.value })
                )),
              ]),
              h("div", {
                style: {
                  textAlign: "right",
                  marginTop: "8px",
                  paddingRight: "4px",
                },
              }, [
                h(ElButton, {
                  type: "text",
                  onClick: () => {
                    render(null, mountNode);
                    document.body.removeChild(mountNode);
                    ElMessage.info("取消出库操作");
                  },
                  style: {
                    marginRight: "8px",
                    color: "#606266",
                  },
                }, "取消"),
                h(ElButton, {
                  type: "primary",
                  onClick: async () => {
                    // 2. ç¡®ä¿è¡¨å•ref已挂载(用nextTick避免获取不到)
                    await this.$nextTick();
                    const formRef = vnode.component.refs.outboundForm;
                    if (!formRef) {
                      ElMessage.error("表单初始化失败,请重试");
                      return;
                    }
                    try {
                      await formRef.validate();
                    } catch (err) {
                      return;
                    }
                    var param = rows[0].orderNo;
                    const requestParams = {
                      detailIds: [],
                      outboundTargetLocation: formData.selectedPlatform,
                      outboundQuantity: 1,
                      operator: this.currentOperator || "admin",
                      orderNo: param,
                    };
                    try {
                      const x = await this.http.post(
                        "api/Outbound/ProcessPickingOutbound",
                        requestParams,
                        "数据处理中"
                      );
                      if (!x.status) {
                        ElMessage.error(x.message || "操作失败");
                        return;
                      }
                      ElMessage.success("操作成功");
                      this.showDetialBox = false;
                      this.$emit("parentCall", ($vue) => {
                        $vue.getData();
                      });
                    } catch (error) {
                      // 5. æ‰“开错误捕获,方便调试
                      console.error("出库接口请求失败:", error);
                      ElMessage.error("请求失败,请稍后重试");
                    } finally {
                      // æ— è®ºæˆåŠŸå¤±è´¥ï¼Œéƒ½å…³é—­å¼¹çª—
                      render(null, mountNode);
                      document.body.removeChild(mountNode);
                    }
                  },
                  style: {
                    borderRadius: "4px",
                    padding: "8px 20px",
                  },
                }, "确定出库"),
              ]),
            ]),
      }
    );
    vnode.appContext = this.$.appContext;
    render(vnode, mountNode);
  };
}
    },
    onInited() {
@@ -381,10 +557,9 @@
      //this.detailOptions.columns.forEach(column=>{ });
    },
    searchBefore(param) {
      //界面查询前,可以给param.wheres添加查询参数
      //返回false,则不会执行查询
      return true;
    },
    searchAfter(result) {
@@ -405,9 +580,9 @@
    },
    modelOpenAfter(row) {
      if (this.currentAction === 'Add') { // åˆ¤æ–­å½“前是新建操作
                const currentUser = this.$store.state.userInfo?.userTrueName || 'system';
                this.editFormFields.operator = currentUser;
            }
        const currentUser = this.$store.state.userInfo?.userTrueName || 'system';
        this.editFormFields.operator = currentUser;
      }
      //点击编辑、新建按钮弹出框后,可以在此处写逻辑,如,从后台获取数据
      //(1)判断是编辑还是新建操作: this.currentAction=='Add';
      //(2)给弹出框设置默认值