CCL_QMS检验
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1317 lines
44 KiB

<template>
<el-dialog
class="eds-batch-entry-dialog"
:close-on-click-modal="false"
:visible.sync="dialogVisible"
:fullscreen="isFullscreen"
append-to-body
top="4vh"
width="1380px"
@opened="onOpened"
@closed="onClosed">
<div slot="title" class="eds-dialog-title">
<span>{{ $t('qc.iqcPage.edsBatchEntryTitle') }}</span>
<div class="eds-dialog-actions">
<el-button size="mini" @click="isFullscreen = !isFullscreen">
{{ $t(isFullscreen ? 'qc.iqcPage.edsExitFullscreen' : 'qc.iqcPage.edsFullscreen') }}
</el-button>
<el-button
size="mini"
type="warning"
:loading="syncEdsLoading || saving"
:disabled="readonly || loading || tagChecking"
@click="handleSyncEds">
{{ $t('qc.iqcPage.syncEds') }}
</el-button>
</div>
</div>
<div v-loading="loading" class="eds-batch-body">
<!-- 实测值序号:扫入 / 移除标签号 -->
<div class="tag-bind-section">
<div class="section-title">
<i class="el-icon-price-tag"></i>
{{ $t('qc.iqcPage.edsMeasuredSeqArea') }}
<span class="section-hint">{{ $t('qc.iqcPage.edsTagBindHint') }}</span>
</div>
<div v-if="!itemGroups.length" class="tag-empty">{{ $t('qc.iqcPage.edsNoInspectionItem') }}</div>
<div v-else class="tag-input-grid">
<div class="tag-input-item">
<label>{{ $t('qc.iqcPage.edsTagScanIn') }}</label>
<el-input
ref="scanInInput"
v-model="scanInRollNo"
clearable
:disabled="readonly"
:readonly="tagChecking"
:placeholder="$t('qc.iqcPage.edsTagScanInPlaceholder')"
@keyup.enter.native="onScanInEnter" />
</div>
<div class="tag-input-item">
<label>{{ $t('qc.iqcPage.edsTagRemove') }}</label>
<el-input
ref="removeInput"
v-model="removeRollNo"
clearable
:disabled="readonly"
:readonly="tagChecking"
:placeholder="$t('qc.iqcPage.edsTagRemovePlaceholder')"
@keyup.enter.native="onRemoveEnter" />
</div>
</div>
</div>
<div class="toolbar">
<!--
<el-button
type="primary"
size="mini"
icon="el-icon-more"
:disabled="readonly || !itemGroups.length"
@click="openBatchAdd">
{{ $t('qc.iqcPage.batchAdd') }}
</el-button>
-->
<el-button
v-if="!isAllExpanded"
type="text"
icon="el-icon-arrow-down"
@click="expandAll">
{{ $t('qc.iqcPage.batchExpand') }}
</el-button>
<el-button
v-else
type="text"
icon="el-icon-arrow-up"
@click="collapseAll">
{{ $t('qc.iqcPage.batchCollapse') }}
</el-button>
</div>
<el-collapse v-model="activeNames" class="item-collapse">
<el-collapse-item
v-for="group in itemGroups"
:key="group.itemNo"
:name="group.itemNo">
<template slot="title">
<div class="item-header">
<span class="item-code">{{ group.itemNo }}</span>
<span class="item-sep">·</span>
<span class="item-name" :title="group.itemDesc || ''">{{ group.itemDesc || '-' }}</span>
<span class="item-spec">
<span class="spec-card">{{ $t('qc.table.standardValue') }}:{{ displayMetaValue(group, 'defaultValue') }}</span>
<span class="spec-card">{{ $t('qc.table.upperValue') }}:{{ displayMetaValue(group, 'maxValue') }}</span>
<span class="spec-card">{{ $t('qc.table.lowerValue') }}:{{ displayMetaValue(group, 'minValue') }}</span>
</span>
<span class="item-sep">·</span>
<span
class="spec-card item-progress"
:class="enteredCount(group) >= group.rows.length && group.rows.length ? 'is-success' : 'is-warning'">
{{ enteredCount(group) }}/{{ group.rows.length }}
</span>
<!--
<el-button
type="primary"
size="mini"
:disabled="readonly"
@click.stop="addRowToGroup(group)">
{{ $t('qc.common.add') }}
</el-button>
-->
</div>
</template>
<el-table
:data="group.rows"
border
class="eds-item-table"
:header-cell-style="{ background: '#f5f7fa', color: '#606266', fontWeight: '500' }">
<el-table-column prop="num" :label="$t('qc.iqcPage.serialNumber')" width="60" align="center" />
<el-table-column prop="isQualified" :label="$t('qc.iqcPage.isQualified')" width="110" align="center">
<template slot-scope="{ row }">
<el-select
v-model="row.isQualified"
size="mini"
clearable
:disabled="readonly || isRowLocked(row)"
@change="onQualifiedChange(row, $event)"
:class="{
greenElSelect: String(row.isQualified || '').toUpperCase() === 'Y',
redElSelect: String(row.isQualified || '').toUpperCase() === 'N'
}"
:placeholder="$t('qc.iqcPage.isQualified')"
style="width: 100%">
<el-option :label="$t('qc.iqcPage.qualified')" value="Y" style="color: #67C23A" />
<el-option :label="$t('qc.iqcPage.unqualified')" value="N" style="color: #F56C6C" />
</el-select>
</template>
</el-table-column>
<el-table-column prop="rollNo" :label="$t('qc.iqcPage.tagNo')" min-width="160" align="center">
<template slot-scope="{ row }">
<el-input
:value="row.rollNo"
readonly
:disabled="readonly || isRowLocked(row) || tagChecking"
:placeholder="$t('qc.iqcPage.edsTagPlaceholder')" />
</template>
</el-table-column>
<el-table-column prop="productQuantity" :label="$t('qc.iqcPage.productQuantity')" min-width="100" align="center" />
<el-table-column prop="defectQty" :label="$t('qc.iqcPage.edsDefectQty')" min-width="100" align="center">
<template slot-scope="{ row }">
<el-input-number
v-model="row.defectQty"
:min="0"
:max="2147483647"
:precision="0"
:controls="false"
:disabled="readonly || isRowLocked(row)"
@change="(val, oldVal) => onDefectQtyChange(row, val, oldVal)"
style="width: 100%" />
</template>
</el-table-column>
<el-table-column prop="samplingLocation" :label="$t('qc.iqcPage.samplingPosA')" min-width="120" align="center">
<template slot-scope="{ row }">
<el-input
v-model="row.samplingLocation"
:disabled="readonly || isRowLocked(row)"
:placeholder="$t('qc.iqcPage.enterSamplingPosA')" />
</template>
</el-table-column>
<el-table-column prop="samplingLocationB" :label="$t('qc.iqcPage.samplingPosB')" min-width="120" align="center">
<template slot-scope="{ row }">
<el-input
v-model="row.samplingLocationB"
:disabled="readonly || isRowLocked(row)"
:placeholder="$t('qc.iqcPage.enterSamplingPosB')" />
</template>
</el-table-column>
<el-table-column prop="subDetailValue" :label="$t('qc.iqcPage.measuredA')" min-width="120" align="center">
<template slot-scope="{ row }">
<el-input
v-model="row.subDetailValue"
:disabled="readonly || isRowLocked(row)"
:placeholder="$t('qc.iqcPage.enterMeasuredA')" />
</template>
</el-table-column>
<el-table-column prop="subDetailValueB" :label="$t('qc.iqcPage.measuredB')" min-width="120" align="center">
<template slot-scope="{ row }">
<el-input
v-model="row.subDetailValueB"
:disabled="readonly || isRowLocked(row)"
:placeholder="$t('qc.iqcPage.enterMeasuredB')" />
</template>
</el-table-column>
<el-table-column prop="isTransfer" :label="$t('qc.iqcPage.isTransfer')" width="90" align="center">
<template slot-scope="{ row }">
<span>{{ formatQcYesNoFlag(displayTransferFlag(row)) }}</span>
</template>
</el-table-column>
<el-table-column :label="$t('qc.common.operation')" width="70" align="center">
<template slot-scope="{ row, $index }">
<el-button
v-if="!readonly && !isRowLocked(row) && !isRowTransferred(row)"
type="text"
size="mini"
style="color:#F56C6C"
@click="removeRow(group, $index)">
{{ $t('qc.common.delete') }}
</el-button>
</template>
</el-table-column>
</el-table>
</el-collapse-item>
</el-collapse>
</div>
<div slot="footer" class="dialog-footer">
<el-button
type="primary"
size="small"
:loading="saving"
:disabled="readonly || !itemGroups.length"
icon="el-icon-check"
@click="handleSave">
{{ $t('qc.iqcPage.saveCurrentRoll') }}
</el-button>
<el-button size="small" @click="dialogVisible = false">{{ $t('qc.common.close') }}</el-button>
</div>
<sync-eds-dialog
:visible.sync="syncEdsDialogVisible"
:preview-list="syncEdsPreviewList"
:loading="syncEdsLoading"
@confirm="confirmSyncEds" />
<!-- 批量新增行 -->
<el-dialog
:title="$t('qc.iqcPage.batchAdd')"
:close-on-click-modal="false"
:visible.sync="batchAddVisible"
append-to-body
width="510px">
<el-form :inline="true" label-position="top">
<el-form-item :label="$t('qc.iqcPage.defaultSamplingPosA')">
<el-input v-model="batchAddData.samplingLocation" style="width: 150px" />
</el-form-item>
<el-form-item :label="$t('qc.iqcPage.defaultSamplingPosB')">
<el-input v-model="batchAddData.samplingLocationB" style="width: 150px" />
</el-form-item>
<el-form-item :label="$t('qc.iqcPage.sampleQty')">
<el-input v-model="batchAddData.samplingNumber" type="number" style="width: 150px" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" size="small" @click="confirmBatchAdd">{{ $t('qc.common.save') }}</el-button>
<el-button size="small" @click="batchAddVisible = false">{{ $t('qc.common.close') }}</el-button>
</div>
</el-dialog>
</el-dialog>
</template>
<script>
import {
listSubDetailedRecordForEds,
saveEdsBatchSubDetailed,
checkEdsRollInspection,
syncEdsInspectionResults
} from '@/api/qc/qc'
import { formatQcYesNoFlag, normalizeQcValueTypeDb } from '@/utils/qcValueTypeDisplay'
import SyncEdsDialog from './SyncEdsDialog.vue'
const TRACK_FIELDS = [
'rollNo',
'productQuantity',
'defectQty',
'samplingLocation',
'samplingLocationB',
'subDetailValue',
'subDetailValueB',
'subDetailValueC',
'subDetailValueD',
'subDetailValueE',
'isQualified'
]
export default {
name: 'EdsBatchEntryDialog',
components: {
SyncEdsDialog
},
props: {
visible: {
type: Boolean,
default: false
},
detailData: {
type: Object,
default: () => ({})
},
detailList: {
type: Array,
default: () => []
},
inspectionType: {
type: String,
default: 'IQC'
}
},
data () {
return {
isFullscreen: false,
loading: false,
saving: false,
scanInRollNo: '',
removeRollNo: '',
itemGroups: [],
activeNames: [],
/** 打开时快照:key = itemNo__num,用于对比仅保存变更行 */
originalRowMap: {},
batchAddVisible: false,
batchAddData: {
samplingLocation: '',
samplingLocationB: '',
samplingNumber: ''
},
/** 扫描卷号校验中,防止重复提交 */
tagChecking: false,
syncEdsDialogVisible: false,
syncEdsLoading: false,
syncEdsPreviewList: [],
syncEdsAllRows: [],
/** 各卷最新 EDS 传输结论:rollNo -> PASS/FAIL */
syncEdsLatestTransferMap: {}
}
},
computed: {
dialogVisible: {
get () {
return this.visible
},
set (val) {
this.$emit('update:visible', val)
}
},
readonly () {
return this.detailData && this.detailData.submitFlag === 'Y'
},
isAllExpanded () {
const total = (this.itemGroups || []).length
return total > 0 && (this.activeNames || []).length >= total
},
itemMetaMap () {
const map = {}
;(this.detailList || []).forEach((item) => {
if (item && item.itemNo != null) {
map[item.itemNo] = item
}
})
return map
}
},
watch: {
visible (val) {
if (val) {
this.isFullscreen = false
// 打开即清空上方扫入/移除输入,避免闪现上次内容
this.scanInRollNo = ''
this.removeRollNo = ''
this.loadData()
}
}
},
methods: {
formatQcYesNoFlag (value) {
return formatQcYesNoFlag(value, this.$t.bind(this))
},
onOpened () {
this.$nextTick(() => {
this.focusScanInInput()
})
},
onClosed () {
this.scanInRollNo = ''
this.removeRollNo = ''
this.itemGroups = []
this.activeNames = []
this.originalRowMap = {}
this.batchAddVisible = false
this.tagChecking = false
this.batchAddData = {
samplingLocation: '',
samplingLocationB: '',
samplingNumber: ''
}
this.syncEdsDialogVisible = false
this.syncEdsPreviewList = []
this.syncEdsAllRows = []
this.syncEdsLatestTransferMap = {}
this.syncEdsLoading = false
},
fetchSubDetailRows () {
const detail = this.detailData || {}
const payload = {
site: detail.site,
buNo: detail.buNo,
inspectionNo: detail.inspectionNo,
inspectionType: String(this.inspectionType || 'IQC').toUpperCase()
}
return listSubDetailedRecordForEds(payload).then(({ data }) => {
if (!(data && data.code === 0)) {
return Promise.reject(new Error((data && (data.msg || data.message)) || this.$t('qc.iqcPage.edsLoadFail')))
}
this.syncEdsLatestTransferMap = data.latestTransferMap || {}
return Array.isArray(data.rows) ? data.rows : []
})
},
loadData () {
const detail = this.detailData || {}
if (!detail.site || !detail.buNo || !detail.inspectionNo) {
this.$message.warning(this.$t('qc.iqcPage.edsNoSubDetail'))
return
}
this.loading = true
this.fetchSubDetailRows().then((rows) => {
this.buildGroups(rows)
this.$nextTick(() => this.focusScanInInput())
}).catch((err) => {
this.$message.error((err && err.message) || this.$t('qc.iqcPage.edsLoadFail'))
}).finally(() => {
this.loading = false
})
},
buildGroups (rows) {
const groupMap = {}
// 先按 detailList 顺序建组,保证检验项全部展示
;(this.detailList || []).forEach((item) => {
if (!item || item.itemNo == null) return
groupMap[item.itemNo] = {
itemNo: item.itemNo,
itemDesc: item.itemDesc || item.itemName || '',
meta: item,
rows: []
}
})
rows.forEach((row) => {
if (!row) return
const itemNo = row.itemNo
if (itemNo == null) return
if (!groupMap[itemNo]) {
groupMap[itemNo] = {
itemNo,
itemDesc: (this.itemMetaMap[itemNo] && (this.itemMetaMap[itemNo].itemDesc || this.itemMetaMap[itemNo].itemName)) || '',
meta: this.itemMetaMap[itemNo] || {},
rows: []
}
}
const cloned = { ...row }
// 保证标签号字段可编辑,并补齐 itemNo 便于变更对比
if (cloned.rollNo == null) cloned.rollNo = ''
if (cloned.productQuantity == null) cloned.productQuantity = null
if (cloned.defectQty == null) cloned.defectQty = 0
if (cloned.itemNo == null) cloned.itemNo = itemNo
groupMap[itemNo].rows.push(cloned)
})
Object.keys(groupMap).forEach((key) => {
groupMap[key].rows.sort((a, b) => (Number(a.num) || 0) - (Number(b.num) || 0))
})
const orderKeys = (this.detailList || []).map((i) => i.itemNo).filter((k) => k != null && groupMap[k])
Object.keys(groupMap).forEach((k) => {
if (!orderKeys.includes(k)) orderKeys.push(k)
})
this.itemGroups = orderKeys.map((k) => groupMap[k])
this.activeNames = this.itemGroups.slice(0, 3).map((g) => g.itemNo)
this.captureOriginalSnapshot()
},
rowKey (itemNo, num) {
return `${itemNo}__${num}`
},
normalizeField (val) {
if (val == null) return ''
return String(val).trim()
},
snapshotRow (row) {
const snap = {}
TRACK_FIELDS.forEach((f) => {
snap[f] = this.normalizeField(row[f])
})
// 非变更比对字段:用于保存时拦截已传输行的删除
snap.isTransfer = this.normalizeField(row.isTransfer)
return snap
},
captureOriginalSnapshot () {
const map = {}
;(this.itemGroups || []).forEach((group) => {
;(group.rows || []).forEach((row) => {
if (!row || row.itemNo == null || row.num == null) return
// 加载行可能未带 itemNo(来自子明细表查询已含),兜底用 group.itemNo
const itemNo = row.itemNo != null ? row.itemNo : group.itemNo
map[this.rowKey(itemNo, row.num)] = this.snapshotRow({ ...row, itemNo })
})
})
this.originalRowMap = map
},
isRowChanged (row, itemNo) {
const key = this.rowKey(itemNo, row.num)
const original = this.originalRowMap[key]
if (!original) return true
return TRACK_FIELDS.some((f) => this.normalizeField(row[f]) !== original[f])
},
resetTransferOnEdit () {
return ['IPQC', 'FQC', 'OQC'].includes(this.normalizeField(this.inspectionType).toUpperCase())
},
displayTransferFlag (row) {
return this.resetTransferOnEdit() && this.isRowChanged(row, row.itemNo) ? 'N' : row.isTransfer
},
buildChangePayload () {
const detail = this.detailData || {}
const resetTransfer = this.resetTransferOnEdit()
const updatedRows = []
const insertedRows = []
const deletedRows = []
const currentKeys = new Set()
const affectedItemNos = new Set()
;(this.itemGroups || []).forEach((group) => {
const itemNo = group.itemNo
;(group.rows || []).forEach((row, idx) => {
if (!row) return
const num = row.num != null ? row.num : (idx + 1)
const key = this.rowKey(itemNo, num)
currentKeys.add(key)
const payloadRow = {
site: detail.site,
buNo: detail.buNo,
inspectionNo: detail.inspectionNo,
itemNo,
num,
rollNo: row.rollNo != null ? String(row.rollNo).trim() : '',
productQuantity: row.productQuantity,
samplingLocation: row.samplingLocation,
samplingLocationB: row.samplingLocationB,
subDetailValue: row.subDetailValue,
subDetailValueB: row.subDetailValueB,
subDetailValueC: row.subDetailValueC,
subDetailValueD: row.subDetailValueD,
subDetailValueE: row.subDetailValueE,
fileName: row.fileName,
isTransfer: resetTransfer ? 'N' : row.isTransfer,
isQualified: resetTransfer && Number(row.defectQty) > 0 ? 'N' : row.isQualified,
defectQty: row.defectQty == null ? 0 : row.defectQty
}
if (!this.originalRowMap[key]) {
insertedRows.push(payloadRow)
affectedItemNos.add(itemNo)
} else if (this.isRowChanged(row, itemNo)) {
updatedRows.push(payloadRow)
affectedItemNos.add(itemNo)
}
})
})
Object.keys(this.originalRowMap || {}).forEach((key) => {
if (currentKeys.has(key)) return
const original = this.originalRowMap[key] || {}
// 已传输行不允许删除(前后端双重拦截)
if (String(original.isTransfer || '').toUpperCase() === 'Y') {
return
}
const parts = key.split('__')
if (parts.length < 2) return
const itemNo = parts[0]
const num = Number(parts[1])
deletedRows.push({ itemNo, num })
affectedItemNos.add(itemNo)
})
const itemSpecs = []
;(this.itemGroups || []).forEach((group) => {
if (!affectedItemNos.has(group.itemNo)) return
const meta = group.meta || {}
itemSpecs.push({
itemNo: group.itemNo,
// 归一化为 T/N,避免 valueTypeDb 为空或中文时后端按数字逻辑重算结论
valueTypeDb: normalizeQcValueTypeDb(meta) || meta.valueTypeDb || '',
minValue: meta.minValue,
maxValue: meta.maxValue
})
})
return {
site: detail.site,
buNo: detail.buNo,
inspectionNo: detail.inspectionNo,
inspectionType: String(this.inspectionType || 'IQC').toUpperCase(),
updatedRows,
insertedRows,
deletedRows,
itemSpecs
}
},
/**
* 调用 EDS/TT 校验卷号;success=true 才通过
* @returns {Promise<Object|boolean>} 校验成功时返回扫描信息(含产品数)
*/
validateEdsRollNo (serialNo) {
const detail = this.detailData || {}
const inspectionNo = detail.inspectionNo
const sn = serialNo != null ? String(serialNo).trim() : ''
if (!inspectionNo || !sn) {
return Promise.resolve(false)
}
return checkEdsRollInspection({
inspectionNo,
serialNo: sn
}).then(({ data }) => {
// 后端 R.ok(map) 会把校验结果及 productQuantity 合并到顶层
if (data && data.code === 0 && data.success === true) {
return data
}
const tip = (data && (data.message || data.msg)) || this.$t('qc.iqcPage.edsRollCheckFail')
this.$message.error(tip)
return false
}).catch((err) => {
this.$message.error((err && err.message) || this.$t('qc.iqcPage.edsRollCheckFail'))
return false
})
},
hasRollNoInGroups (serialNo) {
const sn = serialNo != null ? String(serialNo).trim() : ''
if (!sn) return false
return (this.itemGroups || []).some((group) =>
(group.rows || []).some((row) => row && String(row.rollNo || '').trim() === sn)
)
},
nextNumForGroup (group) {
let groupMax = 0
;(group.rows || []).forEach((r) => {
const num = Number(r.num)
if (!Number.isNaN(num) && num > groupMax) groupMax = num
})
return groupMax + 1
},
/** 扫入:TT 校验通过后,每个检验项新增一行该卷号 */
onScanInEnter () {
if (this.readonly || this.tagChecking) return
if (!this.itemGroups.length) {
this.$message.warning(this.$t('qc.iqcPage.edsNoInspectionItem'))
return
}
const serialNo = this.scanInRollNo != null ? String(this.scanInRollNo).trim() : ''
if (!serialNo) return
if (this.hasRollNoInGroups(serialNo)) {
this.$message.warning(this.$t('qc.iqcPage.edsTagAlreadyExists', { rollNo: serialNo }))
this.scanInRollNo = ''
return
}
this.tagChecking = true
this.validateEdsRollNo(serialNo).then((result) => {
if (!result) return
this.itemGroups.forEach((group) => {
const row = this.createEmptyRow(this.nextNumForGroup(group))
row.itemNo = group.itemNo
row.rollNo = serialNo
row.productQuantity = result.productQuantity == null || result.productQuantity === '' ? null : result.productQuantity
row.isQualified = 'Y'
group.rows.push(row)
})
this.$message.success(this.$t('qc.iqcPage.edsTagScanInSuccess', { rollNo: serialNo }))
}).finally(() => {
this.scanInRollNo = ''
this.tagChecking = false
})
},
/** 移除:删除每个检验项中对应卷号的行 */
onRemoveEnter () {
if (this.readonly || this.tagChecking) return
if (!this.itemGroups.length) {
this.$message.warning(this.$t('qc.iqcPage.edsNoInspectionItem'))
return
}
const serialNo = this.removeRollNo != null ? String(this.removeRollNo).trim() : ''
if (!serialNo) return
let matched = 0
let blocked = 0
this.itemGroups.forEach((group) => {
if (!group || !group.rows) return
for (let i = group.rows.length - 1; i >= 0; i--) {
const row = group.rows[i]
if (!row || String(row.rollNo || '').trim() !== serialNo) continue
matched += 1
if (this.isRowTransferred(row) || this.isRowLocked(row)) {
blocked += 1
continue
}
group.rows.splice(i, 1)
}
})
this.removeRollNo = ''
if (!matched) {
this.$message.warning(this.$t('qc.iqcPage.edsTagRemoveNotFound', { rollNo: serialNo }))
} else if (blocked > 0) {
this.$message.warning(this.$t('qc.iqcPage.edsTagRemoveBlocked', { rollNo: serialNo }))
} else {
this.$message.success(this.$t('qc.iqcPage.edsTagRemoveSuccess', { rollNo: serialNo }))
}
this.$nextTick(() => this.focusRemoveInput())
},
/** 行内标签号回车:校验通过才保留,失败则清空 */
onRowRollNoEnter (row) {
if (!row || this.readonly || this.isRowLocked(row) || this.isRowTransferred(row) || this.tagChecking) {
return
}
const serialNo = row.rollNo != null ? String(row.rollNo).trim() : ''
if (!serialNo) return
this.tagChecking = true
this.validateEdsRollNo(serialNo).then((result) => {
if (!result) {
row.rollNo = ''
row.productQuantity = null
} else {
row.productQuantity = result.productQuantity == null || result.productQuantity === '' ? null : result.productQuantity
if (!String(row.isQualified || '').trim()) {
row.isQualified = Number(row.defectQty) > 0 ? 'N' : 'Y'
}
}
}).finally(() => {
this.tagChecking = false
})
},
isRowTransferred (row) {
return row && String(row.isTransfer || '').toUpperCase() === 'Y'
},
onQualifiedChange (row, value) {
if (!this.resetTransferOnEdit()) return
if (value === 'Y') {
row.defectQty = 0
} else if (Number(row.defectQty) > 0) {
row.isQualified = 'N'
}
},
onDefectQtyChange (row, newVal, oldVal) {
if (!row) return
if (row.defectQty == null) row.defectQty = 0
if (this.readonly || this.isRowLocked(row)) return
const next = Number(newVal != null ? newVal : row.defectQty)
const prev = oldVal == null || oldVal === '' ? null : Number(oldVal)
if (!(next > 0)) return
if (!this.resetTransferOnEdit() && prev === next) return
row.isQualified = 'N'
},
focusScanInInput () {
const ref = this.$refs.scanInInput
const el = Array.isArray(ref) ? ref[0] : ref
if (el && el.focus) {
el.focus()
}
},
focusRemoveInput () {
const ref = this.$refs.removeInput
const el = Array.isArray(ref) ? ref[0] : ref
if (el && el.focus) {
el.focus()
}
},
expandAll () {
this.activeNames = this.itemGroups.map((g) => g.itemNo)
},
collapseAll () {
this.activeNames = []
},
displayMetaValue (group, field) {
const meta = (group && group.meta) || {}
const val = meta[field]
if (val == null || String(val).trim() === '') return '-'
return val
},
enteredCount (group) {
return (group.rows || []).filter((r) => r && r.subDetailValue != null && String(r.subDetailValue).trim() !== '').length
},
isRowLocked (row) {
return row && String(row.isSubmit || '').toUpperCase() === 'Y'
},
createEmptyRow (num, defaults = {}) {
return {
num,
rollNo: '',
productQuantity: null,
defectQty: 0,
samplingLocation: defaults.samplingLocation || '',
samplingLocationB: defaults.samplingLocationB || '',
subDetailValue: '',
subDetailValueB: '',
subDetailValueC: '',
subDetailValueD: '',
subDetailValueE: '',
isQualified: '',
isTransfer: '',
isSubmit: 'N'
}
},
/** 单个检验项新增一行,便于手动维护标签号 */
addRowToGroup (group) {
if (this.readonly || !group) return
const row = this.createEmptyRow(this.nextNumForGroup(group))
row.itemNo = group.itemNo
group.rows.push(row)
if (this.activeNames.indexOf(group.itemNo) === -1) {
this.activeNames = this.activeNames.concat([group.itemNo])
}
},
openBatchAdd () {
if (this.readonly || !this.itemGroups.length) return
this.batchAddData = {
samplingLocation: '',
samplingLocationB: '',
samplingNumber: ''
}
this.batchAddVisible = true
},
confirmBatchAdd () {
const count = Number(this.batchAddData.samplingNumber)
if (!count || count < 1 || !Number.isInteger(count)) {
this.$message.warning(this.$t('qc.iqcPage.sampleQty'))
return
}
this.itemGroups.forEach((group) => {
let groupMax = this.nextNumForGroup(group) - 1
for (let i = 0; i < count; i++) {
const row = this.createEmptyRow(groupMax + i + 1, this.batchAddData)
row.itemNo = group.itemNo
group.rows.push(row)
}
})
this.expandAll()
this.batchAddVisible = false
this.$nextTick(() => this.focusScanInInput())
},
removeRow (group, index) {
if (!group || !group.rows) return
const row = group.rows[index]
if (this.isRowTransferred(row)) {
this.$message.warning(this.$t('qc.iqcPage.edsTransferredNoDelete'))
return
}
if (this.isRowLocked(row) || this.readonly) {
return
}
group.rows.splice(index, 1)
},
/**
* 保存当前变更。
* @param {Object} options
* @param {boolean} options.closeOnSuccess 成功后是否关闭弹框
* @param {boolean} options.silentIfNoChange 无变更时是否静默跳过
* @returns {Promise<{saved:boolean, skipped:boolean}>}
*/
persistCurrentChanges (options = {}) {
const closeOnSuccess = !!options.closeOnSuccess
const silentIfNoChange = !!options.silentIfNoChange
const detail = this.detailData || {}
if (!detail.site || !detail.buNo || !detail.inspectionNo) {
this.$message.warning(this.$t('qc.iqcPage.edsNoSubDetail'))
return Promise.reject(new Error('missing detail'))
}
if (this.readonly) {
return Promise.resolve({ saved: false, skipped: true })
}
const payload = this.buildChangePayload()
const changeCount = (payload.updatedRows.length || 0)
+ (payload.insertedRows.length || 0)
+ (payload.deletedRows.length || 0)
const refreshMasterQuantities = this.resetTransferOnEdit()
if (!changeCount && !refreshMasterQuantities) {
if (!silentIfNoChange) {
this.$message.warning(this.$t('qc.iqcPage.edsNoChangeToSave'))
}
return Promise.resolve({ saved: false, skipped: true })
}
this.saving = true
return saveEdsBatchSubDetailed(payload).then(({ data }) => {
if (data && data.code === 0) {
this.$message.success(this.$t('qc.iqcPage.edsSaveSuccess'))
this.$emit('saved', data.quantitySummary)
if (closeOnSuccess) {
this.dialogVisible = false
} else {
if (refreshMasterQuantities) {
const savedRows = new Map([...payload.updatedRows, ...payload.insertedRows]
.map(row => [this.rowKey(row.itemNo, row.num), row]))
this.itemGroups.forEach(group => {
group.rows.forEach(row => {
const saved = savedRows.get(this.rowKey(group.itemNo, row.num))
if (saved) {
row.isTransfer = saved.isTransfer
row.isQualified = saved.isQualified
}
})
})
}
this.captureOriginalSnapshot()
}
return { saved: true, skipped: false }
}
return Promise.reject(new Error((data && (data.msg || data.message)) || this.$t('qc.iqcPage.edsSaveFail')))
}).catch((err) => {
this.$message.error((err && err.message) || this.$t('qc.iqcPage.edsSaveFail'))
return Promise.reject(err)
}).finally(() => {
this.saving = false
})
},
handleSave () {
if (this.readonly || this.saving || this.syncEdsLoading || this.tagChecking) return
this.persistCurrentChanges({ closeOnSuccess: true, silentIfNoChange: false }).catch(() => {})
},
/** 同步 EDS:先保存当前数据,再打开与检验单一致的同步预览 */
handleSyncEds () {
if (this.readonly || this.saving || this.syncEdsLoading || this.loading || this.tagChecking) return
this.persistCurrentChanges({ closeOnSuccess: false, silentIfNoChange: true }).then(() => {
return this.openSyncEdsPreview()
}).catch(() => {})
},
/**
* 本次是否传输:无履历=首次传;结论不变=不传;最新 FAIL 且当前 PASS=重传
*/
needEdsTransferThisTime (latestResult, currentIsFail) {
const latest = latestResult != null ? String(latestResult).trim().toUpperCase() : ''
const current = currentIsFail ? 'FAIL' : 'PASS'
if (!latest) return true
if (latest === current) return false
return latest === 'FAIL' && current === 'PASS'
},
buildSyncEdsPreviewList (rows, latestTransferMap) {
const source = Array.isArray(rows) ? rows : []
const historyMap = latestTransferMap && typeof latestTransferMap === 'object'
? latestTransferMap
: (this.syncEdsLatestTransferMap || {})
// 检验单中的检验项目数量(各卷相同)
const itemCount = Array.isArray(this.detailList) ? this.detailList.length : 0
const isIpqcFqcOqc = ['IPQC', 'FQC', 'OQC'].includes(String(this.inspectionType || '').trim().toUpperCase())
const groupMap = {}
source.forEach((row) => {
if (!row) return
const rollNo = row.rollNo != null ? String(row.rollNo).trim() : ''
const key = rollNo || '__EMPTY__'
if (!groupMap[key]) {
groupMap[key] = {
rollNo,
defectQty: 0,
theoreticalCount: 0,
enteredCount: 0,
hasAbnormal: false
}
}
const group = groupMap[key]
const defectQty = Number(row.defectQty) || 0
group.defectQty = isIpqcFqcOqc ? group.defectQty + defectQty : Math.max(group.defectQty, defectQty)
group.theoreticalCount += 1
if (String(row.isTransfer || '').trim().toUpperCase() === 'Y') {
group.enteredCount += 1
}
if (String(row.isQualified || '').trim().toUpperCase() === 'N') {
group.hasAbnormal = true
}
})
return Object.keys(groupMap).map((key) => {
const g = groupMap[key]
const needTransfer = isIpqcFqcOqc
? g.enteredCount < g.theoreticalCount
: this.needEdsTransferThisTime(historyMap[g.rollNo], g.hasAbnormal)
return {
rollNo: g.rollNo,
defectQty: g.defectQty,
itemCount,
theoreticalCount: g.theoreticalCount,
enteredCount: g.enteredCount,
isAbnormal: g.hasAbnormal,
isAbnormalText: g.hasAbnormal ? this.$t('qc.common.yes') : this.$t('qc.common.no'),
conclusion: g.hasAbnormal
? this.$t('qc.iqcPage.unqualified')
: this.$t('qc.iqcPage.qualified'),
needTransfer,
needTransferText: needTransfer ? this.$t('qc.common.yes') : this.$t('qc.common.no')
}
})
},
openSyncEdsPreview () {
this.syncEdsLoading = true
return this.fetchSubDetailRows().then((rows) => {
this.syncEdsAllRows = rows
const keepActive = (this.activeNames || []).slice()
this.buildGroups(rows)
this.activeNames = keepActive.filter((name) => this.itemGroups.some((g) => g.itemNo === name))
const preview = this.buildSyncEdsPreviewList(rows, this.syncEdsLatestTransferMap)
if (!preview.length) {
this.$message.warning(this.$t('qc.iqcPage.syncEdsNoData'))
return
}
this.syncEdsPreviewList = preview
this.syncEdsDialogVisible = true
}).catch(() => {
this.$message.error(this.$t('qc.iqcPage.syncEdsFail'))
}).finally(() => {
this.syncEdsLoading = false
})
},
confirmSyncEds () {
if (this.syncEdsLoading) return
const preview = Array.isArray(this.syncEdsPreviewList) ? this.syncEdsPreviewList : []
const needTransferCount = preview.filter((row) => row && row.needTransfer).length
const missingRoll = preview.some((row) => {
if (!row || !row.needTransfer) return false
return !(row.rollNo != null && String(row.rollNo).trim())
})
if (missingRoll) {
this.$message.warning(this.$t('qc.iqcPage.syncEdsMissingRollNo'))
return
}
const detail = this.detailData || {}
this.syncEdsLoading = true
const payload = {
site: detail.site,
buNo: detail.buNo,
inspectionNo: detail.inspectionNo,
inspectionType: String(this.inspectionType || 'IQC').toUpperCase()
}
syncEdsInspectionResults(payload).then(({ data }) => {
if (data && data.code === 0 && data.success !== false) {
if (needTransferCount === 0) {
this.$message.warning(this.$t('qc.iqcPage.syncEdsNoPending'))
} else {
this.$message.success(this.$t('qc.iqcPage.syncEdsSuccess'))
}
this.syncEdsDialogVisible = false
this.$emit('saved')
this.loadData()
} else {
this.$message.error((data && (data.msg || data.message)) || this.$t('qc.iqcPage.syncEdsFail'))
}
}).catch(() => {
this.$message.error(this.$t('qc.iqcPage.syncEdsFail'))
}).finally(() => {
this.syncEdsLoading = false
})
}
}
}
</script>
<style scoped>
.eds-dialog-title {
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 8px;
padding-right: 40px;
font-size: 16px;
font-weight: 600;
color: #303133;
}
.eds-dialog-actions {
margin-left: auto;
}
.eds-batch-body {
min-height: 420px;
}
.tag-bind-section {
border: 1px solid #e4e7ed;
border-radius: 4px;
background: #fafbfc;
padding: 10px 12px 12px;
margin-bottom: 8px;
}
.section-title {
font-size: 14px;
font-weight: 600;
color: #303133;
margin-bottom: 10px;
}
.section-title i {
margin-right: 4px;
color: #409eff;
}
.section-hint {
margin-left: 8px;
font-size: 12px;
font-weight: 400;
color: #909399;
}
.tag-empty {
color: #909399;
font-size: 13px;
padding: 8px 0;
}
.tag-input-grid {
display: flex;
flex-wrap: wrap;
gap: 10px 14px;
}
.tag-input-item {
width: 200px;
}
.tag-input-item label {
display: block;
font-size: 12px;
color: #606266;
margin-bottom: 4px;
line-height: 1.2;
}
.toolbar {
margin: 4px 0 8px;
}
.item-collapse {
border: none;
max-height: 480px;
overflow: auto;
}
.item-header {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 6px 8px;
width: 100%;
padding-right: 8px;
line-height: 1;
}
.item-code,
.item-name {
font-weight: 600;
color: #303133;
}
.item-name {
max-width: 220px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.item-sep {
color: #909399;
}
.item-spec {
display: inline-flex;
align-items: center;
flex-wrap: wrap;
gap: 4px 6px;
}
.spec-card {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0 8px;
height: 22px;
line-height: 1;
text-align: center;
border: 1px solid #dcdfe6;
border-radius: 3px;
background: #f5f7fa;
color: #303133;
font-size: 12px;
font-weight: 400;
box-sizing: border-box;
}
.item-progress {
font-weight: 600;
font-variant-numeric: tabular-nums;
}
.item-progress.is-success {
color: #67c23a;
border-color: #c2e7b0;
background: #f0f9eb;
}
.item-progress.is-warning {
color: #e6a23c;
border-color: #f5dab1;
background: #fdf6ec;
}
.item-header .el-button--mini {
display: inline-flex;
align-items: center;
justify-content: center;
height: 22px;
padding: 0 8px;
margin-left: 0;
line-height: 1;
}
.dialog-footer {
text-align: center;
}
</style>
<style>
.eds-batch-entry-dialog > .el-dialog {
max-width: calc(100% - 24px);
}
.eds-batch-entry-dialog > .el-dialog.is-fullscreen {
display: flex;
flex-direction: column;
max-width: 100%;
overflow: hidden;
}
.eds-batch-entry-dialog > .is-fullscreen > .el-dialog__header,
.eds-batch-entry-dialog > .is-fullscreen > .el-dialog__footer {
flex-shrink: 0;
}
.eds-batch-entry-dialog > .is-fullscreen > .el-dialog__body,
.eds-batch-entry-dialog > .is-fullscreen .eds-batch-body {
display: flex;
flex: 1;
flex-direction: column;
min-height: 0;
}
.eds-batch-entry-dialog > .is-fullscreen .tag-bind-section,
.eds-batch-entry-dialog > .is-fullscreen .toolbar {
flex-shrink: 0;
}
.eds-batch-entry-dialog > .is-fullscreen .item-collapse {
min-height: 0;
max-height: none;
}
.eds-batch-entry-dialog .el-dialog__body {
padding: 12px 16px 8px;
}
/* 展开箭头放到项目名称前面 */
.eds-batch-entry-dialog .el-collapse-item__header {
height: auto;
min-height: 42px;
line-height: normal;
padding-top: 10px;
padding-bottom: 10px;
display: flex;
align-items: center;
flex-direction: row;
}
.eds-batch-entry-dialog .el-collapse-item__arrow {
order: -1;
margin: 0 8px 0 0 !important;
line-height: 1 !important;
height: auto !important;
display: inline-flex;
align-items: center;
}
.eds-batch-entry-dialog .el-collapse-item__header > *:not(.el-collapse-item__arrow) {
order: 1;
}
.eds-batch-entry-dialog .el-collapse-item__content {
padding-bottom: 10px;
}
/* 与「点击输入」弹框一致:沿用全局 input.el-input__inner 高度,不做额外覆盖 */
.eds-batch-entry-dialog .tag-input-item .el-input,
.eds-batch-entry-dialog .eds-item-table .el-input {
width: 100%;
}
.eds-batch-entry-dialog .tag-input-item .el-input__suffix {
display: flex;
align-items: center;
height: 100%;
right: 2px;
}
.eds-batch-entry-dialog .tag-input-item .el-input__icon {
line-height: 20px;
width: 18px;
}
.eds-batch-entry-dialog .eds-item-table .el-table__body td,
.eds-batch-entry-dialog .eds-item-table .el-table__header th {
padding: 2px 0;
}
/* Override the global 14px cell height so editable controls are not clipped. */
.eds-batch-entry-dialog .eds-item-table .el-table__body td .cell {
height: 24px;
line-height: 24px;
}
.eds-batch-entry-dialog .eds-item-table .el-input {
height: 20px;
line-height: 20px;
vertical-align: middle;
}
.eds-batch-entry-dialog .eds-item-table .el-select {
width: 100%;
vertical-align: middle;
}
.eds-batch-entry-dialog .eds-item-table .el-select .el-input__inner {
height: 20px;
line-height: 20px;
}
.eds-batch-entry-dialog .eds-item-table .el-select .el-input__icon {
line-height: 20px;
}
.eds-batch-entry-dialog .eds-item-table .greenElSelect .el-input__inner {
color: #67C23A;
}
.eds-batch-entry-dialog .eds-item-table .redElSelect .el-input__inner {
color: #F56C6C;
}
.eds-batch-entry-dialog .eds-item-table .el-button--text {
height: 20px;
padding: 0;
line-height: 20px;
vertical-align: baseline;
}
</style>