<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>
|