|
|
|
@ -1,6 +1,6 @@ |
|
|
|
<script> |
|
|
|
import {searchCodeItemAllDefsSeq} from "../../../api/code/codeItemDef"; |
|
|
|
import {searchCodeGenerationItemValueList, searchCodeItemValueListItem} from "../../../api/code/codeItemValue"; |
|
|
|
import {searchCodeGenerationItemValueList as searchCodeGenerationItemValueApi, searchCodeItemValueListItem} from "../../../api/code/codeItemValue"; |
|
|
|
import {codeConditionDetailList} from "../../../api/code/codeConditionDetail"; |
|
|
|
import {codeNoGenerate, saveDrawing, searchDrawingDetailList, searchDrawingList} from "../../../api/code/codeDrawing"; |
|
|
|
import dayjs from "dayjs"; |
|
|
|
@ -36,9 +36,27 @@ export default { |
|
|
|
return itemValue |
|
|
|
}, |
|
|
|
showConditionName() { |
|
|
|
return (val) => { |
|
|
|
if (val && val.length > 0){ |
|
|
|
return val[0].conditionName |
|
|
|
return (item, index) => { |
|
|
|
const itemValues = (item && item.itemValues) ? item.itemValues : [] |
|
|
|
const selectedValue = this.codeItemValues[index] |
|
|
|
if (itemValues.length > 0) { |
|
|
|
if (selectedValue !== undefined && selectedValue !== null && selectedValue !== '') { |
|
|
|
const matched = itemValues.find(value => String(value.valueItemNo) === String(selectedValue)) |
|
|
|
if (matched && matched.conditionName) { |
|
|
|
return matched.conditionName |
|
|
|
} |
|
|
|
if (item && item.itemByCondition === 'Y') { |
|
|
|
return '暂无定义' |
|
|
|
} |
|
|
|
return '' |
|
|
|
} |
|
|
|
const firstWithName = itemValues.find(value => value.conditionName) |
|
|
|
if (firstWithName && firstWithName.conditionName) { |
|
|
|
return firstWithName.conditionName |
|
|
|
} |
|
|
|
} |
|
|
|
if (item && item.itemByCondition === 'Y' && selectedValue !== undefined && selectedValue !== null && selectedValue !== '') { |
|
|
|
return '暂无定义' |
|
|
|
} |
|
|
|
return '' |
|
|
|
}; |
|
|
|
@ -192,9 +210,7 @@ export default { |
|
|
|
detailRows = detailRes.data.rows || [] |
|
|
|
} |
|
|
|
} |
|
|
|
if (detailRows.length > 0) { |
|
|
|
await this.applyDrawingDetailToForm(detailRows, token) |
|
|
|
} |
|
|
|
await this.applyDrawingDetailToForm(detailRows, token) |
|
|
|
} catch (error) { |
|
|
|
this.$message.error(error) |
|
|
|
} |
|
|
|
@ -252,7 +268,7 @@ export default { |
|
|
|
} |
|
|
|
return result |
|
|
|
}, |
|
|
|
getDrawingDescValue(detail, itemDef, drawingDescMap) { |
|
|
|
getDrawingDescValue(detail, itemDef, drawingDescMap, itemValues = [], parentSelectedLabel = '') { |
|
|
|
if (!drawingDescMap || drawingDescMap.size === 0) { |
|
|
|
return '' |
|
|
|
} |
|
|
|
@ -260,7 +276,16 @@ export default { |
|
|
|
detail ? detail.itemName : '', |
|
|
|
detail ? detail.itemDesc : '', |
|
|
|
itemDef ? itemDef.itemDesc : '', |
|
|
|
parentSelectedLabel, |
|
|
|
] |
|
|
|
if (itemValues && itemValues.length > 0) { |
|
|
|
for (let i = 0; i < itemValues.length; i++) { |
|
|
|
const conditionName = String((itemValues[i] && itemValues[i].conditionName) || '').trim() |
|
|
|
if (conditionName) { |
|
|
|
candidates.push(conditionName) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
for (let i = 0; i < candidates.length; i++) { |
|
|
|
const key = String(candidates[i] || '').trim() |
|
|
|
if (key && drawingDescMap.has(key)) { |
|
|
|
@ -269,11 +294,31 @@ export default { |
|
|
|
} |
|
|
|
return '' |
|
|
|
}, |
|
|
|
getSelectedItemLabel(index) { |
|
|
|
if (index < 0) { |
|
|
|
return '' |
|
|
|
} |
|
|
|
const selectedValue = this.codeItemValues[index] |
|
|
|
if (selectedValue === undefined || selectedValue === null || selectedValue === '') { |
|
|
|
return '' |
|
|
|
} |
|
|
|
const itemDef = this.codeItemDefs[index] || {} |
|
|
|
const itemValues = itemDef.itemValues || [] |
|
|
|
const matched = itemValues.find(value => String(value.valueItemNo) === String(selectedValue)) |
|
|
|
return matched && matched.itemValue ? String(matched.itemValue).trim() : '' |
|
|
|
}, |
|
|
|
findMatchedSelectItem(itemValues, detailValue, tokenValue, descValue, detailLabel) { |
|
|
|
const list = itemValues || [] |
|
|
|
if (list.length === 0) { |
|
|
|
return null |
|
|
|
} |
|
|
|
const labelCandidates = [detailLabel, descValue].filter(value => String(value || '').trim() !== '') |
|
|
|
for (let i = 0; i < labelCandidates.length; i++) { |
|
|
|
const matchedByItemValue = list.find(value => this.isSameMatchValue(value.itemValue, labelCandidates[i])) |
|
|
|
if (matchedByItemValue) { |
|
|
|
return matchedByItemValue |
|
|
|
} |
|
|
|
} |
|
|
|
const valueCandidates = [detailValue, tokenValue].filter(value => String(value || '').trim() !== '') |
|
|
|
for (let i = 0; i < valueCandidates.length; i++) { |
|
|
|
const matchedByValueNo = list.find(value => this.isSameMatchValue(value.valueNo, valueCandidates[i])) |
|
|
|
@ -294,9 +339,9 @@ export default { |
|
|
|
return matchedByValueItemNo |
|
|
|
} |
|
|
|
} |
|
|
|
const labelCandidates = [detailLabel, descValue, detailValue].filter(value => String(value || '').trim() !== '') |
|
|
|
for (let i = 0; i < labelCandidates.length; i++) { |
|
|
|
const matchedByItemValue = list.find(value => this.isSameMatchValue(value.itemValue, labelCandidates[i])) |
|
|
|
const fallbackLabelCandidates = [detailValue].filter(value => String(value || '').trim() !== '') |
|
|
|
for (let i = 0; i < fallbackLabelCandidates.length; i++) { |
|
|
|
const matchedByItemValue = list.find(value => this.isSameMatchValue(value.itemValue, fallbackLabelCandidates[i])) |
|
|
|
if (matchedByItemValue) { |
|
|
|
return matchedByItemValue |
|
|
|
} |
|
|
|
@ -381,6 +426,37 @@ export default { |
|
|
|
} |
|
|
|
return [] |
|
|
|
}, |
|
|
|
buildGenerationValueQueryParams(index) { |
|
|
|
const params = [] |
|
|
|
for (let i = 0; i <= index; i++) { |
|
|
|
params.push({ |
|
|
|
...this.codeItemDefs[i], |
|
|
|
value: this.codeItemValues[i] |
|
|
|
}) |
|
|
|
} |
|
|
|
return params |
|
|
|
}, |
|
|
|
async queryConditionValuesForPrefill(index, token) { |
|
|
|
if (token !== this.dialogInitToken) { |
|
|
|
return [] |
|
|
|
} |
|
|
|
const itemDef = this.codeItemDefs[index] |
|
|
|
if (!itemDef || itemDef.itemByCondition !== 'Y' || index === 0) { |
|
|
|
return [] |
|
|
|
} |
|
|
|
try { |
|
|
|
const params = this.buildGenerationValueQueryParams(index) |
|
|
|
const {data} = await searchCodeGenerationItemValueApi(params) |
|
|
|
if (token !== this.dialogInitToken) { |
|
|
|
return [] |
|
|
|
} |
|
|
|
if (data && data.code === 0) { |
|
|
|
return data.rows || [] |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
} |
|
|
|
return [] |
|
|
|
}, |
|
|
|
async applyDrawingDetailToForm(detailRows, token) { |
|
|
|
const detailMap = new Map() |
|
|
|
detailRows.forEach(detail => { |
|
|
|
@ -397,7 +473,8 @@ export default { |
|
|
|
const isVirtualItem = itemDef.virtualItem === 'Y' |
|
|
|
const seqToken = isVirtualItem ? null : (seqTokens[seqTokenIndex++] || null) |
|
|
|
const detail = detailMap.get(String(itemDef.itemNo)) |
|
|
|
if (!detail && !seqToken) { |
|
|
|
const parentSelectedLabel = this.getSelectedItemLabel(i - 1) |
|
|
|
if (!detail && !seqToken && drawingDescMap.size === 0) { |
|
|
|
continue |
|
|
|
} |
|
|
|
const tokenType = seqToken && seqToken.type === 'pipe' ? '流水号' : null |
|
|
|
@ -408,15 +485,36 @@ export default { |
|
|
|
this.$set(this.codeItemTypes, i, this.resolveDefaultItemType(itemDef)) |
|
|
|
} |
|
|
|
if (this.codeItemTypes[i] === '选择') { |
|
|
|
const loadedItemValues = await this.ensureSelectItemValuesForPrefill(i, token) |
|
|
|
const allItemValues = await this.ensureSelectItemValuesForPrefill(i, token) |
|
|
|
if (token !== this.dialogInitToken) { |
|
|
|
return |
|
|
|
} |
|
|
|
let matchedItemValues = allItemValues |
|
|
|
const conditionItemValues = await this.queryConditionValuesForPrefill(i, token) |
|
|
|
if (token !== this.dialogInitToken) { |
|
|
|
return |
|
|
|
} |
|
|
|
if (conditionItemValues.length > 0) { |
|
|
|
matchedItemValues = conditionItemValues |
|
|
|
this.$set(this.codeItemDefs, i, { |
|
|
|
...this.codeItemDefs[i], |
|
|
|
itemValues: conditionItemValues |
|
|
|
}) |
|
|
|
} |
|
|
|
const detailValue = detail ? detail.itemValue : '' |
|
|
|
const detailLabel = detail ? detail.itemLabel : '' |
|
|
|
const tokenValue = seqToken ? seqToken.value : '' |
|
|
|
const descValue = this.getDrawingDescValue(detail, itemDef, drawingDescMap) |
|
|
|
const matchedItem = this.findMatchedSelectItem(loadedItemValues, detailValue, tokenValue, descValue, detailLabel) |
|
|
|
let descValue = this.getDrawingDescValue(detail, itemDef, drawingDescMap, matchedItemValues, parentSelectedLabel) |
|
|
|
let matchedItem = this.findMatchedSelectItem(matchedItemValues, detailValue, tokenValue, descValue, detailLabel) |
|
|
|
if (!matchedItem && matchedItemValues !== allItemValues) { |
|
|
|
matchedItemValues = allItemValues |
|
|
|
this.$set(this.codeItemDefs, i, { |
|
|
|
...this.codeItemDefs[i], |
|
|
|
itemValues: allItemValues |
|
|
|
}) |
|
|
|
descValue = this.getDrawingDescValue(detail, itemDef, drawingDescMap, matchedItemValues, parentSelectedLabel) |
|
|
|
matchedItem = this.findMatchedSelectItem(matchedItemValues, detailValue, tokenValue, descValue, detailLabel) |
|
|
|
} |
|
|
|
if (matchedItem) { |
|
|
|
this.$set(this.codeItemValues, i, matchedItem.valueItemNo) |
|
|
|
await this.backfillParentValuesByCondition(i, matchedItem, token) |
|
|
|
@ -427,7 +525,7 @@ export default { |
|
|
|
} else { |
|
|
|
const detailValue = detail ? detail.itemValue : undefined |
|
|
|
const tokenValue = seqToken ? seqToken.value : undefined |
|
|
|
const descValue = this.getDrawingDescValue(detail, itemDef, drawingDescMap) |
|
|
|
const descValue = this.getDrawingDescValue(detail, itemDef, drawingDescMap, [], parentSelectedLabel) |
|
|
|
const fillValue = (detailValue !== undefined && detailValue !== null && detailValue !== '') ? detailValue : |
|
|
|
(tokenValue !== undefined && tokenValue !== null && tokenValue !== '' ? tokenValue : descValue) |
|
|
|
if (fillValue !== undefined) { |
|
|
|
@ -562,7 +660,7 @@ export default { |
|
|
|
this.codeItemDefs[index].itemValues = [] |
|
|
|
this.$set(this.codeItemDefs, index, {...this.codeItemDefs[index]}) |
|
|
|
try { |
|
|
|
const {data} = await searchCodeGenerationItemValueList(arr) |
|
|
|
const {data} = await searchCodeGenerationItemValueApi(arr) |
|
|
|
if (data && data.code === 0){ |
|
|
|
let itemDefs = {...this.codeItemDefs[index], itemValues: data.rows} |
|
|
|
this.$set(this.codeItemDefs, index, itemDefs) |
|
|
|
@ -781,8 +879,8 @@ export default { |
|
|
|
<el-input v-if="codeItemTypes[index] === '手工'" placeholder="请输入" v-model="codeItemValues[index]"></el-input> |
|
|
|
<el-input v-if="codeItemTypes[index] === '流水号'" disabled v-model="codeItemValues[index]"></el-input> |
|
|
|
</div> |
|
|
|
<div style="display: inline-block" v-if="showConditionName(item.itemValues) !== ''"> |
|
|
|
<span v-if="">(</span><span>{{showConditionName(item.itemValues)}}</span><span>)</span> |
|
|
|
<div style="display: inline-block" v-if="showConditionName(item, index) !== ''"> |
|
|
|
<span v-if="">(</span><span>{{showConditionName(item, index)}}</span><span>)</span> |
|
|
|
</div> |
|
|
|
</el-form-item> |
|
|
|
</el-form> |
|
|
|
|