+
@@ -761,7 +800,7 @@ export default {
columnSortable: false,
status: true,
fixed: '',
- columnWidth: 240
+ columnWidth: 200
},
{
columnProp: 'createDate',
@@ -773,7 +812,7 @@ export default {
columnSortable: false,
status: true,
fixed: '',
- columnWidth: 140
+ columnWidth: 150
},
{
columnProp: 'createBy',
@@ -785,7 +824,7 @@ export default {
columnSortable: false,
status: true,
fixed: '',
- columnWidth: 140
+ columnWidth: 120
}
],
@@ -1296,9 +1335,9 @@ export default {
this.$set(this.modalData, 'commGroup1Desc', '')
this.$set(this.modalData, 'commGroup2Desc', '')
this.$set(this.modalData, 'commGroup3Desc', '')
- // 编辑时允许重新选择客户和项目
- this.$set(this.modalData, 'endCustomerFlag', false)
- this.$set(this.modalData, 'projectIdFlag', !this.modalData.endCustomer)
+ // 编辑时不允许修改最终客户和项目编码
+ this.$set(this.modalData, 'endCustomerFlag', true)
+ this.$set(this.modalData, 'projectIdFlag', true)
this.$set(this.modalData, 'createBy2', '')
this.$set(this.modalData, 'isReject', 'Y')
this.$set(this.modalData, 'tpProcessControl', 'N')
@@ -1584,18 +1623,42 @@ export default {
this.$message.warning('请至少选择一条项目物料')
return
}
- this.appendMaterialRows(this.projectMaterialSelections)
- this.projectMaterialDialogFlag = false
+ const appendResult = this.appendMaterialRows(this.projectMaterialSelections)
+ if (!appendResult.appendedCount) {
+ this.$message.warning('所选物料已存在,未新增数据')
+ return
+ }
+ if (!this.shouldPersistMaterialsImmediately()) {
+ this.$set(this.modalData, 'materialList', appendResult.materialList)
+ this.projectMaterialDialogFlag = false
+ this.$message.success('已加入材料列表,保存单据后写入数据库')
+ return
+ }
+ this.$confirm('确认新增选中材料?', '提示', {
+ confirmButtonText: '确定',
+ cancelButtonText: '取消',
+ type: 'warning'
+ }).then(() => {
+ this.persistMaterialList(appendResult.materialList, '新增材料成功', () => {
+ this.projectMaterialDialogFlag = false
+ this.projectMaterialSelections = []
+ if (this.$refs.projectMaterialTable) {
+ this.$refs.projectMaterialTable.clearSelection()
+ }
+ })
+ }).catch(() => {})
},
appendMaterialRows (rows) {
const materialList = Array.isArray(this.modalData.materialList) ? [...this.modalData.materialList] : []
const exists = new Set(materialList.map(item => item.testPartNo))
+ let appendedCount = 0
rows.forEach(row => {
const testPartNo = row.testPartNo || row.test_part_no
if (!testPartNo || exists.has(testPartNo)) {
return
}
exists.add(testPartNo)
+ appendedCount++
materialList.push({
site: this.modalData.site,
referenceNo: this.modalData.referenceNo,
@@ -1607,11 +1670,53 @@ export default {
partSpec: row.partSpec || row.part_spec || ''
})
})
- this.$set(this.modalData, 'materialList', materialList)
+ return {
+ materialList,
+ appendedCount
+ }
},
materialSelectionChange (rows) {
this.materialSelections = rows || []
},
+ shouldPersistMaterialsImmediately () {
+ return this.modalTitle === 'RoHs 编辑' && this.modalData && this.modalData.referenceNo && !String(this.modalData.referenceNo).startsWith('TEMP-')
+ },
+ normalizeMaterialListForSave (materialList) {
+ return (materialList || []).map((item, index) => {
+ return {
+ ...item,
+ lineNo: index + 1,
+ projectId: item.projectId || this.modalData.projectId || ''
+ }
+ })
+ },
+ persistMaterialList (materialList, successMsg, successCallback) {
+ const normalizedList = this.normalizeMaterialListForSave(materialList)
+ const payload = {
+ site: this.modalData.site,
+ referenceNo: this.modalData.referenceNo,
+ projectId: this.modalData.projectId,
+ materialList: normalizedList
+ }
+ api.updateRohsMaterials(payload).then(({data}) => {
+ if (data && data.code === 0) {
+ this.$set(this.modalData, 'materialList', normalizedList)
+ this.modalData.ifsPartNo = normalizedList.length > 0 ? normalizedList[0].testPartNo : ''
+ this.materialSelections = []
+ if (this.currentRow && this.currentRow.referenceNo === this.modalData.referenceNo) {
+ this.$set(this.currentRow, 'materialList', normalizedList)
+ }
+ this.$message.success(successMsg || '保存成功')
+ if (typeof successCallback === 'function') {
+ successCallback()
+ }
+ } else {
+ this.$message.error((data && data.msg) || '保存失败')
+ }
+ }).catch(() => {
+ this.$message.error('保存失败')
+ })
+ },
removeSelectedMaterialRows () {
if (this.showModalFlag) {
return
@@ -1622,8 +1727,19 @@ export default {
}
const removeSet = new Set(this.materialSelections.map(item => item.testPartNo))
const materialList = (this.modalData.materialList || []).filter(item => !removeSet.has(item.testPartNo))
- this.$set(this.modalData, 'materialList', materialList)
- this.materialSelections = []
+ if (!this.shouldPersistMaterialsImmediately()) {
+ this.$set(this.modalData, 'materialList', materialList)
+ this.materialSelections = []
+ this.$message.success('已删除材料,保存单据后写入数据库')
+ return
+ }
+ this.$confirm('确认删除选中材料?', '提示', {
+ confirmButtonText: '确定',
+ cancelButtonText: '取消',
+ type: 'warning'
+ }).then(() => {
+ this.persistMaterialList(materialList, '删除材料成功')
+ }).catch(() => {})
},
// ======== chooseList相关方法 ========
// 获取基础数据列表
@@ -1733,7 +1849,7 @@ export default {
if (data.rows && data.rows.length === 1) {
const customer = data.rows[0]
this.modalData.endCustomerName = customer.customerDesc || customer.Customer_desc || customer.customerName || ''
- this.modalData.projectIdFlag = false
+ this.modalData.projectIdFlag = !!this.modalData.endCustomerFlag
} else {
this.modalData.endCustomerName = ''
this.modalData.projectId = ''