1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<template>
  <div>
    <el-dialog
      v-model="dialogVisible"
      title="采购入库"
      width="900px"
      @close="closeDialog"
    >
      <el-skeleton :loading="loading" animated>
        <template #template>
          <el-skeleton-item variant="h3" style="width: 30%" />
          <el-skeleton-item variant="text" style="width: 100%" />
          <el-skeleton-item variant="text" style="width: 100%" />
        </template>
        <template #default>
          <el-empty
            v-if="!currentPurchase || !currentPurchase.purchaseContractNumber"
            description="未查询到采购单据"
          />
          <template v-else>
            <el-descriptions :column="2" border>
              <el-descriptions-item label="采购合同号">{{ currentPurchase.purchaseContractNumber }}</el-descriptions-item>
              <el-descriptions-item label="供应商">{{ currentPurchase.supplierName }}</el-descriptions-item>
              <el-descriptions-item label="项目名称">{{ currentPurchase.projectName }}</el-descriptions-item>
              <el-descriptions-item label="销售合同号">{{ currentPurchase.salesContractNo }}</el-descriptions-item>
              <el-descriptions-item label="签订日期">{{ currentPurchase.executionDate }}</el-descriptions-item>
              <el-descriptions-item label="录入日期">{{ currentPurchase.entryDate }}</el-descriptions-item>
            </el-descriptions>
 
            <div style="margin-top: 20px;">
              <h4>产品明细</h4>
              <el-table :data="currentPurchase.productData || []" border style="width: 100%">
                <el-table-column prop="productCategory" label="产品名称" />
                <el-table-column prop="specificationModel" label="图纸编号" />
                <el-table-column prop="unit" label="单位" />
                <el-table-column prop="quantity" label="数量" />
                <el-table-column label="库位" min-width="180">
                  <template #default="scope">
                    <el-input
                      v-model="scope.row.stockLocation"
                      placeholder="请填写库位"
                      clearable
                    />
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </template>
        </template>
      </el-skeleton>
 
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="handleInbound">确认入库</el-button>
          <el-button @click="closeDialog">取消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
 
<script setup>
import { getCurrentInstance, ref } from "vue";
import { getPurchaseByCode } from "@/api/procurementManagement/procurementLedger.js";
import { purchaseApprove } from "@/api/collaborativeApproval/approvalProcess.js";
 
const emit = defineEmits(["close"]);
const { proxy } = getCurrentInstance();
 
const dialogVisible = ref(false);
const loading = ref(false);
const currentPurchase = ref({});
 
const openDialog = (type, row) => {
  if (type !== "inbound") {
    return;
  }
 
  dialogVisible.value = true;
  loading.value = true;
  currentPurchase.value = {};
 
  const purchaseContractNumber = row?.approveReason;
  if (!purchaseContractNumber) {
    loading.value = false;
    proxy.$modal.msgError("未找到采购合同号");
    return;
  }
 
  getPurchaseByCode({ purchaseContractNumber })
    .then((res) => {
      currentPurchase.value = {
        ...res,
        productData: (res?.productData || []).map((item) => ({
          ...item,
          stockLocation: item.stockLocation || "",
        })),
      };
    })
    .catch((err) => {
      console.error("加载采购信息失败:", err);
      proxy.$modal.msgError("加载采购信息失败");
    })
    .finally(() => {
      loading.value = false;
    });
};
 
const closeDialog = () => {
  dialogVisible.value = false;
  loading.value = false;
  currentPurchase.value = {};
  emit("close");
};
 
const handleInbound = () => {
  const productData = currentPurchase.value?.productData || [];
  if (productData.length === 0) {
    proxy.$modal.msgError("未找到采购明细");
    return;
  }
 
  const emptyRow = productData.find((item) => !item.stockLocation || !String(item.stockLocation).trim());
  if (emptyRow) {
    proxy.$modal.msgError(`请先填写产品【${emptyRow.productCategory || emptyRow.specificationModel || "未知"}】的库位`);
    return;
  }
 
  const payload = productData.map((item) => ({
    ...item,
    stockLocation: String(item.stockLocation).trim(),
  }));
 
  purchaseApprove(payload)
    .then(() => {
      proxy.$modal.msgSuccess("入库成功");
      closeDialog();
    })
    .catch((err) => {
      console.error("入库失败:", err);
      proxy.$modal.msgError("入库失败");
    });
};
 
defineExpose({
  openDialog,
});
</script>