647556386
2026-01-27 1378fc4cd7abc24ed3a982e09437c2c8a74e9f2f
ÏîÄ¿´úÂë/WIDESEA_WMSClient/src/extension/stock/stockView.js
@@ -1,4 +1,5 @@
import { createVNode, render, h, reactive } from 'vue';
import { ElDialog, ElForm, ElFormItem, ElSelect, ElOption, ElButton, ElMessage, ElLoading } from 'element-plus';
let extension = {
  components: {
    //查询界面扩展组件
@@ -156,6 +157,171 @@
          }
        }
      })
      let SelectTake = this.buttons.find(x => x.value == 'SelectStockTake');
if (SelectTake) {
  // æ”¹ä¸ºç®­å¤´å‡½æ•°ç¡®ä¿this指向Vue组件实例
  SelectTake.onClick = async () => {
    // èŽ·å–é€‰ä¸­æ•°æ®ï¼ˆä¸ŽåŽŸé€»è¾‘ä¸€è‡´ï¼Œç¡®ä¿æ˜¯æ•°ç»„æ ¼å¼ï¼‰
    let stockViews = this.$refs.table.getSelected();
    // æ•°æ®æ ¡éªŒï¼šè‡³å°‘选择一条数据
    if (stockViews.length === 0) return ElMessage.error("请选择需要操作的数据!");
    // ç«™å°é€‰é¡¹ï¼ˆå¯æ ¹æ®å®žé™…业务调整选项值)
    const stationOptions = [
      { label: "站台2", value: "2-1" },
      { label: "站台3", value: "3-1" },
      { label: "站台4", value: "4-1" },
    ];
    // åˆ›å»ºå¼¹çª—挂载节点
    const mountNode = document.createElement("div");
    document.body.appendChild(mountNode);
    // è¡¨å•数据(绑定选中的站台)
    const formData = reactive({
      outStation: stationOptions[0].value, // é»˜è®¤é€‰ä¸­ç¬¬ä¸€ä¸ªç«™å°
    });
    // åˆ›å»ºå¼¹çª—VNode
    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: {
                outStation: [
                  { required: true, message: "请选择出库站台", trigger: "change" },
                ],
              },
              ref: "stockTakeForm", // è¡¨å•ref标识
              labelWidth: "100px",
              style: {
                padding: "0 30px",
              },
            },
            [
              // ç«™å°é€‰æ‹©ä¸‹æ‹‰æ¡†
              h(ElFormItem, {
                label: "出库站台",
                prop: "outStation",
                style: { marginBottom: "24px" },
              }, [
                h(ElSelect, {
                  placeholder: "请选择出库站台",
                  modelValue: formData.outStation,
                  "onUpdate:modelValue": (val) => {
                    formData.outStation = val;
                  },
                  style: {
                    width: "100%",
                    height: "40px",
                    borderRadius: "4px",
                    borderColor: "#dcdfe6",
                  },
                }, stationOptions.map((station) =>
                  h(ElOption, { label: station.label, value: station.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 () => {
                    // ç¡®ä¿è¡¨å•ref已挂载
                    await this.$nextTick();
                    const formRef = vnode.component.refs.stockTakeForm;
                    if (!formRef) {
                      ElMessage.error("表单初始化失败,请重试");
                      return;
                    }
                    // è¡¨å•验证
                    try {
                      await formRef.validate();
                    } catch (err) {
                      return;
                    }
                    const requestBody = stockViews;
                    const outStation = formData.outStation;
                    try {
                      const url = `api/Task/TakeOutbound?outStation=${encodeURIComponent(outStation)}`;
                      const x = await this.http.post(
                        url, // å¸¦æŸ¥è¯¢å‚æ•°çš„URL
                        requestBody, // è¯·æ±‚体:stockViews数组
                        "数据处理中"
                      );
                      if (!x.status) {
                        ElMessage.error(x.message || "库存操作失败");
                        return;
                      }
                      ElMessage.success("操作成功");
                      this.refresh(); // åŽŸåˆ·æ–°é€»è¾‘ä¿ç•™
                    } catch (error) {
                      console.error("库存接口请求失败:", error);
                      ElMessage.error("请求失败,请稍后重试");
                    } finally {
                      // æ— è®ºæˆåŠŸå¤±è´¥ï¼Œå…³é—­å¼¹çª—
                      render(null, mountNode);
                      document.body.removeChild(mountNode);
                    }
                  },
                  style: { borderRadius: "4px", padding: "8px 20px" },
                }, "确定操作"),
              ]),
            ]),
      }
    );
    // ç»‘定app上下文(确保弹窗内组件正常工作)
    vnode.appContext = this.$.appContext;
    render(vnode, mountNode);
  };
}
    },
    onInited() {
      //框架初始化配置后