diff --git a/src/views/modules/sampleTracking/projectProofTracking.vue b/src/views/modules/sampleTracking/projectProofTracking.vue index 892da68..d645eff 100644 --- a/src/views/modules/sampleTracking/projectProofTracking.vue +++ b/src/views/modules/sampleTracking/projectProofTracking.vue @@ -297,7 +297,7 @@ - + @@ -513,7 +513,22 @@ - + + + @@ -642,7 +657,22 @@ - + + + @@ -842,6 +872,7 @@ import { updateProofTrackingComments, updateProofTrackingProcess } from '@/api/sampleTracking/sampleTracking' +import { searchExpApplyList } from '@/api/erf/erf' import { getCustomerNo, saveNewCustomer } from '@/api/eam/eamProject.js' import { getSiteAndBuByUserName } from '@/api/eam/eam.js' import { @@ -1071,10 +1102,16 @@ export default { oneKeyDialogMode: 'create', saveOneKeyLoading: false, oneKeyForm: {}, + oneKeyProofingApplyOptions: [], + oneKeyProofingApplyLoading: false, + oneKeyProofingApplyQueryToken: 0, proofDialogVisible: false, proofSaveLoading: false, proofDialogData: this.getDefaultProofDialogData(), + proofDialogApplyOptions: [], + proofDialogApplyLoading: false, + proofDialogApplyQueryToken: 0, processDialogVisible: false, saveProcessLoading: false, @@ -2100,6 +2137,181 @@ export default { isBlankValue (value) { return value == null || String(value).trim() === '' }, + normalizeProjectNo (projectNo) { + if (this.isBlankValue(projectNo)) { + return '' + } + return String(projectNo).trim() + }, + queryApplyOptionsByProjectNo (projectNo) { + const normalizedProjectNo = this.normalizeProjectNo(projectNo) + if (!normalizedProjectNo) { + return Promise.resolve([]) + } + return searchExpApplyList({ + projectNo: normalizedProjectNo, + page: 1, + limit: 500 + }).then(({ data }) => { + if (!(data && data.code === 0)) { + throw new Error((data && data.msg) || '查询试验单失败') + } + const pageList = (data.page && data.page.list) || [] + const matchedProjectNo = normalizedProjectNo.toUpperCase() + const optionMap = {} + const optionRows = [] + pageList.forEach(item => { + if (!item || this.isBlankValue(item.applyNo)) { + return + } + const applyStatus = this.isBlankValue(item.status) ? '' : String(item.status).trim() + // 业务要求:已完成的试验单不允许继续作为 tracking 打样单号使用。 + if (applyStatus === '草稿' || applyStatus === '已完成') { + return + } + const rowProjectNo = this.normalizeProjectNo(item.projectNo).toUpperCase() + // searchExpApplyList 按模糊 project_no 查询,这里再次做等值过滤,确保与 tracking 项目编码一一对应。 + if (rowProjectNo !== matchedProjectNo) { + return + } + const applyNo = String(item.applyNo).trim() + if (optionMap[applyNo]) { + return + } + optionMap[applyNo] = true + optionRows.push({ + applyNo: applyNo, + expectedFinishDate: this.formatDate(item.expectedFinishDate) + }) + }) + return optionRows + }) + }, + handleOneKeyProjectNoBlur () { + const projectNo = this.normalizeProjectNo(this.oneKeyForm.projectNo) + if (!projectNo) { + this.oneKeyProofingApplyQueryToken += 1 + this.oneKeyProofingApplyLoading = false + this.oneKeyProofingApplyOptions = [] + this.oneKeyForm.proofingNo = '' + this.oneKeyForm.requiredDeliveryDate = '' + return + } + this.loadOneKeyProofingApplyOptions(projectNo, { keepCurrentIfMissing: false }) + }, + handleOneKeyProofingNoChange (proofingNo) { + const selectedNo = this.isBlankValue(proofingNo) ? '' : String(proofingNo).trim() + if (!selectedNo) { + this.oneKeyForm.requiredDeliveryDate = '' + return + } + const matched = this.oneKeyProofingApplyOptions.find(item => item && item.applyNo === selectedNo) + if (!matched) { + return + } + this.oneKeyForm.proofingNo = matched.applyNo + this.oneKeyForm.requiredDeliveryDate = matched.expectedFinishDate || '' + }, + loadOneKeyProofingApplyOptions (projectNo, options) { + const queryOptions = options || {} + const normalizedProjectNo = this.normalizeProjectNo(projectNo) + const currentProofingNo = this.isBlankValue(this.oneKeyForm.proofingNo) + ? '' + : String(this.oneKeyForm.proofingNo).trim() + const queryToken = this.oneKeyProofingApplyQueryToken + 1 + this.oneKeyProofingApplyQueryToken = queryToken + if (!normalizedProjectNo) { + this.oneKeyProofingApplyLoading = false + this.oneKeyProofingApplyOptions = [] + return Promise.resolve([]) + } + this.oneKeyProofingApplyLoading = true + return this.queryApplyOptionsByProjectNo(normalizedProjectNo).then(optionRows => { + if (queryToken !== this.oneKeyProofingApplyQueryToken) { + return optionRows + } + const nextOptions = optionRows.slice() + const keepCurrentIfMissing = !!queryOptions.keepCurrentIfMissing + if (currentProofingNo) { + const hasCurrent = nextOptions.some(item => item && item.applyNo === currentProofingNo) + if (!hasCurrent && keepCurrentIfMissing) { + // 历史记录可能早于 ERF 规范化,保留原打样单号避免编辑场景被强制清空。 + nextOptions.unshift({ + applyNo: currentProofingNo, + expectedFinishDate: this.formatDate(this.oneKeyForm.requiredDeliveryDate) + }) + } + if (!hasCurrent && !keepCurrentIfMissing) { + this.oneKeyForm.proofingNo = '' + this.oneKeyForm.requiredDeliveryDate = '' + } + } + this.oneKeyProofingApplyOptions = nextOptions + if (currentProofingNo) { + this.handleOneKeyProofingNoChange(currentProofingNo) + } + return nextOptions + }).catch((e) => { + if (queryToken === this.oneKeyProofingApplyQueryToken) { + this.oneKeyProofingApplyOptions = [] + this.$message.error((e && e.message) || '查询试验单异常') + } + return [] + }).finally(() => { + if (queryToken === this.oneKeyProofingApplyQueryToken) { + this.oneKeyProofingApplyLoading = false + } + }) + }, + handleProofDialogProofingNoChange (proofingNo) { + const selectedNo = this.isBlankValue(proofingNo) ? '' : String(proofingNo).trim() + if (!selectedNo) { + this.proofDialogData.requiredDeliveryDate = '' + return + } + const matched = this.proofDialogApplyOptions.find(item => item && item.applyNo === selectedNo) + if (!matched) { + return + } + this.proofDialogData.proofingNo = matched.applyNo + this.proofDialogData.requiredDeliveryDate = matched.expectedFinishDate || '' + }, + loadProofDialogApplyOptions (projectNo) { + const normalizedProjectNo = this.normalizeProjectNo(projectNo) + const queryToken = this.proofDialogApplyQueryToken + 1 + this.proofDialogApplyQueryToken = queryToken + if (!normalizedProjectNo) { + this.proofDialogApplyLoading = false + this.proofDialogApplyOptions = [] + this.proofDialogData.proofingNo = '' + this.proofDialogData.requiredDeliveryDate = '' + return Promise.resolve([]) + } + this.proofDialogApplyLoading = true + return this.queryApplyOptionsByProjectNo(normalizedProjectNo).then(optionRows => { + if (queryToken !== this.proofDialogApplyQueryToken) { + return optionRows + } + this.proofDialogApplyOptions = optionRows + const currentProofingNo = this.isBlankValue(this.proofDialogData.proofingNo) + ? '' + : String(this.proofDialogData.proofingNo).trim() + if (currentProofingNo) { + this.handleProofDialogProofingNoChange(currentProofingNo) + } + return optionRows + }).catch((e) => { + if (queryToken === this.proofDialogApplyQueryToken) { + this.proofDialogApplyOptions = [] + this.$message.error((e && e.message) || '查询试验单异常') + } + return [] + }).finally(() => { + if (queryToken === this.proofDialogApplyQueryToken) { + this.proofDialogApplyLoading = false + } + }) + }, getBuOptionValue (site, buNo) { const rawBuNo = buNo == null ? '' : String(buNo).trim() if (!rawBuNo) { @@ -2276,6 +2488,9 @@ export default { const dialogMode = mode === 'edit' ? 'edit' : 'create' this.oneKeyDialogMode = dialogMode if (dialogMode !== 'edit') { + this.oneKeyProofingApplyQueryToken += 1 + this.oneKeyProofingApplyLoading = false + this.oneKeyProofingApplyOptions = [] this.oneKeyForm = this.getEmptyOneKeyForm() if (this.userBuList.length > 0) { this.oneKeyForm.buNo = this.userBuList[0].buNo || '' @@ -2331,7 +2546,11 @@ export default { throw new Error('未找到对应的项目物料信息,无法修改') } this.oneKeyForm = this.buildOneKeyEditForm(current, projectRows[0], partRows[0]) + this.oneKeyProofingApplyQueryToken += 1 + this.oneKeyProofingApplyLoading = false + this.oneKeyProofingApplyOptions = [] this.oneKeyDialogVisible = true + this.loadOneKeyProofingApplyOptions(this.oneKeyForm.projectNo, { keepCurrentIfMissing: true }) }).catch((e) => { this.$message.error((e && e.message) || '加载项目/物料/打样信息异常') this.oneKeyDialogMode = 'create' @@ -2392,6 +2611,9 @@ export default { this.currentRow = current const projectPartId = this.getTrackingProjectPartId(current) || current.id const projectCategory = this.getProjectCategoryValue(current) + this.proofDialogApplyQueryToken += 1 + this.proofDialogApplyLoading = false + this.proofDialogApplyOptions = [] this.proofDialogData = Object.assign(this.getDefaultProofDialogData(), { trackingId: null, site: current.site || this.$store.state.user.site, @@ -2424,6 +2646,7 @@ export default { this.$message.warning('未获取到项目分类,请手动选择') } this.proofDialogVisible = true + this.loadProofDialogApplyOptions(this.proofDialogData.projectNo) }, validateSyncToNpiRow (row) { const projectPartId = this.getTrackingProjectPartId(row)