Files
klp-oa/klp-ui/src/views/wms/purchasePlan/panels/merger.vue

165 lines
5.4 KiB
Vue
Raw Normal View History

2025-08-02 16:34:08 +08:00
<!-- 当新旧质保单不一致时, 需要用户选择处理方式, 在这个组件内处理通过confirm回调来通知父组件完成 -->
<template>
<div>
<el-row>
<el-alert title="质保单处理结果与历史质保单不一致,请选择处理方式" type="warning" />
</el-row>
<el-row :gutter="20" style="margin-top: 20px;">
<el-col :span="12">
<el-table :data="oldResult" style="width: 100%">
<el-table-column prop="attrKey" label="属性名称" />
<el-table-column prop="attrValue" label="属性值" />
</el-table>
</el-col>
<el-col :span="12">
2025-08-04 11:15:42 +08:00
<!-- 默认全部选中 -->
<el-table :data="newResult" style="width: 100%" @selection-change="handleSelectionChange" :default-sort="{ prop: 'attrKey', order: 'ascending' }">
<el-table-column type="selection" width="55" />
<el-table-column prop="attrKey" label="属性名称">
<template slot-scope="scope">
<el-input v-model="scope.row.attrKey" />
</template>
</el-table-column>
<el-table-column prop="attrValue" label="属性值">
<template slot-scope="scope">
<el-input v-model="scope.row.attrValue" />
</template>
</el-table-column>
2025-08-02 16:34:08 +08:00
</el-table>
</el-col>
</el-row>
<el-row style="margin-top: 20px;">
<el-col>
<el-radio-group v-model="uploadQualityCertificateForm.qualityCertificateType">
<el-radio v-for="item in options" :key="item.value" :label="item.value">{{ item.label }}</el-radio>
</el-radio-group>
</el-col>
</el-row>
<el-button type="primary" @click="handleConfirm">确认</el-button>
</div>
</template>
<script>
import { addBomItem } from '@/api/wms/bomItem'
import { addBom } from '@/api/wms/bom'
import { updateRawMaterial, addRawMaterial, getRawMaterial } from '@/api/wms/rawMaterial'
2025-08-02 17:12:07 +08:00
import { updatePurchasePlanDetail } from '@/api/wms/purchasePlanDetail'
2025-08-02 16:34:08 +08:00
export default {
name: 'Merger',
props: {
oldResult: {
type: Array,
required: true
},
newResult: {
type: Array,
required: true
2025-08-02 16:58:34 +08:00
},
info: {
type: Object,
required: true
2025-08-02 16:34:08 +08:00
}
},
data() {
return {
options: [
{
label: '使用旧的质保单',
value: 1
},
{
label: '使用新的质保单',
value: 2
},
{
label: '创建新物料',
value: 3
}
],
uploadQualityCertificateForm: {
qualityCertificateType: 1
2025-08-04 11:15:42 +08:00
},
selection: []
2025-08-02 16:34:08 +08:00
}
},
methods: {
2025-08-04 11:15:42 +08:00
handleSelectionChange(selection) {
this.selection = selection;
},
2025-08-02 16:34:08 +08:00
async handleConfirm() {
if (!this.uploadQualityCertificateForm.qualityCertificateType) {
this.$modal.msgError('请选择处理方式');
return;
}
this.$emit('confirm', {
status: 'start',
})
try {
if (this.uploadQualityCertificateForm.qualityCertificateType === 1) {
// 什么都不需要做,直接完成就可以
console.log('使用旧的质保单');
2025-08-02 16:58:34 +08:00
}
else if (this.uploadQualityCertificateForm.qualityCertificateType === 2) {
2025-08-02 16:34:08 +08:00
// 创建一个新的BOM
const bom = await addBom({
bomName: 'N' + new Date().getTime(),
bomCode: 'N' + new Date().getTime(),
})
// 将BOMID赋值给对应的materialId
await updateRawMaterial({
rawMaterialId: this.info.rawMaterialId,
bomId: bom.data.bomId,
})
2025-08-04 11:15:42 +08:00
// 逐项创建BOMItem, 只创建选中的
for (let i = 0; i < this.selection.length; i++) {
2025-08-02 16:34:08 +08:00
await addBomItem({
bomId: bom.data.bomId,
2025-08-04 11:15:42 +08:00
attrKey: this.selection[i].attrKey,
attrValue: this.selection[i].attrValue,
2025-08-02 16:34:08 +08:00
})
}
this.$store.dispatch('category/getBomMap');
this.$store.dispatch('category/getRawMaterialMap');
2025-08-02 16:34:08 +08:00
} else if (this.uploadQualityCertificateForm.qualityCertificateType === 3) {
// 创建一个新的BOM
const bom = await addBom({
bomName: 'N' + new Date().getTime(),
bomCode: 'N' + new Date().getTime(),
})
// 逐项创建BOMItem
2025-08-04 11:15:42 +08:00
for (let i = 0; i < this.selection.length; i++) {
2025-08-02 16:34:08 +08:00
await addBomItem({
bomId: bom.data.bomId,
2025-08-04 11:15:42 +08:00
attrKey: this.selection[i].attrKey,
attrValue: this.selection[i].attrValue,
2025-08-02 16:34:08 +08:00
})
}
// 创建一个新的物料,使用原有物料的信息, code使用时间戳
const { rawMaterialId, rawMaterialCode, ...rawMaterial } = (await getRawMaterial(this.info.rawMaterialId)).data
const newMaterial = await addRawMaterial({
...rawMaterial,
bomId: bom.data.bomId,
rawMaterialCode: 'N' + new Date().getTime(),
})
// 修改采购单据赋值为新的物料
await updatePurchasePlanDetail({
detailId: this.info.detailId,
rawMaterialId: newMaterial.data.rawMaterialId,
})
this.$store.dispatch('category/getBomMap');
this.$store.dispatch('category/getRawMaterialMap');
2025-08-02 16:34:08 +08:00
}
2025-08-02 16:34:08 +08:00
this.$emit('confirm', {
status: 'success',
})
} catch {
this.$emit('confirm', {
status: 'error',
})
}
}
}
}
</script>