165 lines
5.4 KiB
Vue
165 lines
5.4 KiB
Vue
<!-- 当新旧质保单不一致时, 需要用户选择处理方式, 在这个组件内处理通过confirm回调来通知父组件完成 -->
|
|
<template>
|
|
<div>
|
|
<el-row>
|
|
<el-alert title="质保单处理结果与历史质保单不一致,请选择处理方式" type="warning" />
|
|
</el-row>
|
|
<el-row :gutter="20" style="margin-top: 20px;">
|
|
<el-col :span="12">
|
|
<KLPTable :data="oldResult" style="width: 100%">
|
|
<el-table-column prop="attrKey" label="属性名称" />
|
|
<el-table-column prop="attrValue" label="属性值" />
|
|
</KLPTable>
|
|
</el-col>
|
|
<el-col :span="12">
|
|
<!-- 默认全部选中 -->
|
|
<KLPTable :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>
|
|
</KLPTable>
|
|
</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'
|
|
import { updatePurchasePlanDetail } from '@/api/wms/purchasePlanDetail'
|
|
|
|
export default {
|
|
name: 'Merger',
|
|
props: {
|
|
oldResult: {
|
|
type: Array,
|
|
required: true
|
|
},
|
|
newResult: {
|
|
type: Array,
|
|
required: true
|
|
},
|
|
info: {
|
|
type: Object,
|
|
required: true
|
|
}
|
|
},
|
|
data() {
|
|
return {
|
|
options: [
|
|
{
|
|
label: '使用旧的质保单',
|
|
value: 1
|
|
},
|
|
{
|
|
label: '使用新的质保单',
|
|
value: 2
|
|
},
|
|
{
|
|
label: '创建新物料',
|
|
value: 3
|
|
}
|
|
],
|
|
uploadQualityCertificateForm: {
|
|
qualityCertificateType: 1
|
|
},
|
|
selection: []
|
|
}
|
|
},
|
|
methods: {
|
|
handleSelectionChange(selection) {
|
|
this.selection = selection;
|
|
},
|
|
async handleConfirm() {
|
|
if (!this.uploadQualityCertificateForm.qualityCertificateType) {
|
|
this.$modal.msgError('请选择处理方式');
|
|
return;
|
|
}
|
|
this.$emit('confirm', {
|
|
status: 'start',
|
|
})
|
|
try {
|
|
if (this.uploadQualityCertificateForm.qualityCertificateType === 1) {
|
|
// 什么都不需要做,直接完成就可以
|
|
console.log('使用旧的质保单');
|
|
}
|
|
else if (this.uploadQualityCertificateForm.qualityCertificateType === 2) {
|
|
// 创建一个新的参数
|
|
const bom = await addBom({
|
|
bomName: 'N' + new Date().getTime(),
|
|
bomCode: 'N' + new Date().getTime(),
|
|
})
|
|
// 将参数ID赋值给对应的materialId
|
|
await updateRawMaterial({
|
|
rawMaterialId: this.info.rawMaterialId,
|
|
bomId: bom.data.bomId,
|
|
})
|
|
// 逐项创建参数Item, 只创建选中的
|
|
for (let i = 0; i < this.selection.length; i++) {
|
|
await addBomItem({
|
|
bomId: bom.data.bomId,
|
|
attrKey: this.selection[i].attrKey,
|
|
attrValue: this.selection[i].attrValue,
|
|
})
|
|
}
|
|
this.$store.dispatch('category/getBomMap');
|
|
this.$store.dispatch('category/getRawMaterialMap');
|
|
} else if (this.uploadQualityCertificateForm.qualityCertificateType === 3) {
|
|
// 创建一个新的参数
|
|
const bom = await addBom({
|
|
bomName: 'N' + new Date().getTime(),
|
|
bomCode: 'N' + new Date().getTime(),
|
|
})
|
|
// 逐项创建参数Item
|
|
for (let i = 0; i < this.selection.length; i++) {
|
|
await addBomItem({
|
|
bomId: bom.data.bomId,
|
|
attrKey: this.selection[i].attrKey,
|
|
attrValue: this.selection[i].attrValue,
|
|
})
|
|
}
|
|
// 创建一个新的物料,使用原有物料的信息, 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');
|
|
}
|
|
|
|
this.$emit('confirm', {
|
|
status: 'success',
|
|
})
|
|
} catch {
|
|
this.$emit('confirm', {
|
|
status: 'error',
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script> |