diff --git a/src/views/modules/yieldReport/com_separate_roll.vue b/src/views/modules/yieldReport/com_separate_roll.vue index ca71914..7a1038a 100644 --- a/src/views/modules/yieldReport/com_separate_roll.vue +++ b/src/views/modules/yieldReport/com_separate_roll.vue @@ -41,7 +41,7 @@ - + @@ -135,6 +135,11 @@ + + + @@ -146,6 +151,68 @@ + + +
+ 当前卷:第{{ currentRollDefectIndex }}卷 + 面损合计:{{ formatQty(getCurrentRollSurfaceLossQty()) }} + 已选不良合计:{{ formatQty(getCurrentRollDefectTotal()) }} +
+ + + 不良代码 + + + + + + + + + + + + + 添加 + + + + + + + + + + + + 确定 + +
+
@@ -311,6 +378,7 @@ 关闭 +
@@ -326,6 +394,7 @@ saveAbnormalRollData,/*保存异常截卷数据*/ } from '@/api/yieldReport/com_separate_roll.js'; import { fixedCarrierSave } from '@/api/fixedCarrier/fixedCarrier.js'; + import Chooselist from '@/views/modules/common/Chooselist'; /*打印标签专用的js*/ import { @@ -344,7 +413,6 @@ removerLanguage, saveSysLanguageList } from "@/api/sysLanguage.js"; - import { getPartLabelTemplateList, callUspPartLabelTemplate @@ -358,6 +426,9 @@ export default { name: "com_separate_roll", mixins: [labelPrintTemplates], + components: { + Chooselist + }, data() { return { titleCon: '创建分卷', @@ -411,6 +482,17 @@ export default { carrierNo: '' }, rowDataList: [], // 排数据列表 + // 分卷不良原因(前端暂存) + rollDefectDialogVisible: false, + currentRollDefectIndex: 1, + tagNo: '', + rollDefectForm: { + defectCode: '', + defectDesc: '', + defectQty: null + }, + rollDefectMap: {}, + currentRollDefectList: [], operatorData: { site: this.$store.state.user.site, username: this.$store.state.user.name, @@ -603,6 +685,8 @@ export default { this.hasCachedData = false; this.cachedDataCount = 0; this.cachedRowDataList = []; // 重置缓存的原始行数据 + // 重置分卷不良原因暂存 + this.resetRollDefectData(); // 清空行数据列表 this.rowDataList = []; //判断是否启用多语言 @@ -725,6 +809,22 @@ export default { this.pageData.rollCount = this.pageData.rowCount } this.initRowDataList() + this.resetRollDefectData() + }, + + // 卷数变化时校验并清理不良原因缓存 + handleRollCountChange() { + if (this.pageData.rollCount > this.pageData.rowCount) { + this.pageData.rollCount = this.pageData.rowCount + } + const hasDefectReason = Object.keys(this.rollDefectMap).some(key => { + const list = this.rollDefectMap[key] + return Array.isArray(list) && list.length > 0 + }) + if (hasDefectReason) { + this.$message.warning('卷数已变更,原不良原因已清空,请重新维护') + } + this.resetRollDefectData() }, // 数量变化时自动计算不良数、良率和总数 @@ -744,6 +844,206 @@ export default { } }, + resetRollDefectData() { + this.rollDefectDialogVisible = false + this.currentRollDefectIndex = 1 + this.rollDefectMap = {} + this.currentRollDefectList = [] + this.resetRollDefectForm() + }, + + resetRollDefectForm() { + this.rollDefectForm = { + defectCode: '', + defectDesc: '', + defectQty: null + } + }, + + normalizeRollDefectMap() { + const maxRollCount = Number(this.pageData.rollCount || 0) + Object.keys(this.rollDefectMap).forEach(key => { + if (Number(key) > maxRollCount) { + this.$delete(this.rollDefectMap, key) + } + }) + }, + + getRollSegments() { + const totalRows = Array.isArray(this.rowDataList) ? this.rowDataList.length : 0 + const rollCount = Number(this.pageData.rollCount || 0) + if (totalRows <= 0 || rollCount <= 0) { + return [] + } + const rowsPerRoll = Math.floor(totalRows / rollCount) + const remainingRows = totalRows % rollCount + const segments = [] + let startRow = 0 + for (let i = 0; i < rollCount; i++) { + const currentRollRows = rowsPerRoll + (i < remainingRows ? 1 : 0) + if (currentRollRows <= 0) { + continue + } + segments.push({ + rollIndex: i + 1, + startRow: startRow, + endRow: startRow + currentRollRows - 1, + rowCount: currentRollRows + }) + startRow += currentRollRows + } + return segments + }, + + getRollSegmentByRowIndex(rowIndex) { + const segments = this.getRollSegments() + return segments.find(item => rowIndex >= item.startRow && rowIndex <= item.endRow) || null + }, + + getRollSegmentByRollIndex(rollIndex) { + const segments = this.getRollSegments() + return segments.find(item => item.rollIndex === rollIndex) || null + }, + + ensureRollDefectList(rollIndex) { + const key = String(rollIndex) + if (!Array.isArray(this.rollDefectMap[key])) { + this.$set(this.rollDefectMap, key, []) + } + }, + + openRollDefectDialog(rowIndex) { + const segment = this.getRollSegmentByRowIndex(rowIndex) + if (!segment) { + this.$message.warning('当前卷信息无效,请先确认排数和卷数') + return + } + this.currentRollDefectIndex = segment.rollIndex + this.ensureRollDefectList(segment.rollIndex) + this.currentRollDefectList = this.rollDefectMap[String(segment.rollIndex)] + this.resetRollDefectForm() + this.rollDefectDialogVisible = true + }, + + getRollSurfaceLossQty(rollIndex) { + const segment = this.getRollSegmentByRollIndex(rollIndex) + if (!segment) { + return 0 + } + let total = 0 + for (let i = segment.startRow; i <= segment.endRow; i++) { + const row = this.rowDataList[i] + total += Number(row && row.surfaceLossQty ? row.surfaceLossQty : 0) + } + return total + }, + + getCurrentRollSurfaceLossQty() { + return this.getRollSurfaceLossQty(this.currentRollDefectIndex) + }, + + getRollDefectTotal(rollIndex) { + const list = this.rollDefectMap[String(rollIndex)] || [] + return list.reduce((sum, item) => sum + Number(item && item.defectQty ? item.defectQty : 0), 0) + }, + + getCurrentRollDefectTotal() { + return this.getRollDefectTotal(this.currentRollDefectIndex) + }, + + formatQty(value) { + const num = Number(value || 0) + return Number(num.toFixed(6)).toString() + }, + + async addRollDefectItem() { + if (!this.currentRollDefectList) { + return + } + this.rollDefectForm.defectCode = (this.rollDefectForm.defectCode || '').trim().toUpperCase() + if (!this.rollDefectForm.defectCode) { + this.$message.error('请先选择不良代码') + return + } + if (!this.rollDefectForm.defectDesc) { + this.$message.error('请选择有效的不良代码') + return + } + const defectQty = Number(this.rollDefectForm.defectQty) + if (!defectQty || defectQty <= 0) { + this.$message.error('不良数量必须大于0') + return + } + + const existing = this.currentRollDefectList.find(item => item.defectCode === this.rollDefectForm.defectCode) + if (existing) { + existing.defectQty = Number(existing.defectQty || 0) + defectQty + existing.defectDesc = this.rollDefectForm.defectDesc + } else { + this.currentRollDefectList.push({ + defectCode: this.rollDefectForm.defectCode, + defectDesc: this.rollDefectForm.defectDesc, + defectQty: defectQty + }) + } + this.resetRollDefectForm() + }, + + removeRollDefectItem(index) { + if (!this.currentRollDefectList) { + return + } + this.currentRollDefectList.splice(index, 1) + }, + + getBaseData(val) { + if (this.tagNo === 89) { + this.rollDefectForm.defectCode = val.DefectCode || '' + this.rollDefectForm.defectDesc = val.DefectDesc || '' + } + }, + + getBaseList(val) { + this.tagNo = val + this.$nextTick(() => { + let strVal = '' + if (val === 89) { + strVal = this.rollDefectForm.defectCode || '' + } + this.$refs.baseList.init(val, strVal) + }) + }, + + getRollDefectDetails(rollIndex) { + const list = this.rollDefectMap[String(rollIndex)] || [] + return list + .map(item => ({ + defectCode: item.defectCode, + defectDesc: item.defectDesc || '', + defectQty: Number(item.defectQty || 0) + })) + .filter(item => item.defectCode && item.defectQty > 0) + }, + + // 校验每卷不良原因合计必须等于该卷面损合计 + validateRollDefectQtyBySurfaceLoss() { + const segments = this.getRollSegments() + if (!segments.length) { + return true + } + this.normalizeRollDefectMap() + for (let i = 0; i < segments.length; i++) { + const rollIndex = segments[i].rollIndex + const surfaceLossQty = this.getRollSurfaceLossQty(rollIndex) + const defectReasonQty = this.getRollDefectTotal(rollIndex) + if (Math.abs(surfaceLossQty - defectReasonQty) > 0.000001) { + this.$message.error(`第${rollIndex}卷不良原因数量合计(${this.formatQty(defectReasonQty)})必须等于该卷面损数合计(${this.formatQty(surfaceLossQty)})`) + return false + } + } + return true + }, + // 验证排数据 validateRowData() { if (this.pageData.rowCount <= 0) { @@ -784,13 +1084,26 @@ export default { return true } - for (let i = 0; i < this.rowDataList.length; i++) { - const row = this.rowDataList[i] - const packingList = row && row.packingList !== undefined && row.packingList !== null - ? String(row.packingList).trim() - : '' - if (!packingList) { - this.$message.error(`Packing List不能为空`) + const segments = this.getRollSegments() + if (!segments.length) { + return true + } + + for (let i = 0; i < segments.length; i++) { + const segment = segments[i] + let hasPackingList = false + for (let rowIndex = segment.startRow; rowIndex <= segment.endRow; rowIndex++) { + const row = this.rowDataList[rowIndex] + const packingList = row && row.packingList !== undefined && row.packingList !== null + ? String(row.packingList).trim() + : '' + if (packingList) { + hasPackingList = true + break + } + } + if (!hasPackingList) { + this.$message.error(`第${segment.rollIndex}卷的Packing List不能为空`) return false } } @@ -899,6 +1212,11 @@ export default { return false; } + // 校验每卷不良原因数量是否等于该卷面损数量 + if (!this.validateRollDefectQtyBySurfaceLoss()) { + return false; + } + // 确认框 try { await this.$confirm('确定执行异常截卷操作吗?该操作将执行产量报告。', '提示', { @@ -978,6 +1296,7 @@ export default { rollNums: 1, totalDefectQty: totalDefectQty, rollRows: rollRows, + rollDefectDetails: this.getRollDefectDetails(rollIndex + 1), packingList: rollPackingList, remark: rollRemark }; @@ -1062,40 +1381,21 @@ export default { // 表格合并行方法(备注列根据卷数合并) objectSpanMethod({ row, column, rowIndex, columnIndex }) { - // 对备注和Packing List列进行按卷合并 - if (column.label === '备注' || column.label === 'Packing List') { - // 计算每卷的排数 - const rowsPerRoll = Math.floor(this.pageData.rowCount / this.pageData.rollCount) - const remainingRows = this.pageData.rowCount % this.pageData.rollCount - - // 计算当前行属于第几卷 - let currentRollIndex = 0 - let accumulatedRows = 0 - - for (let i = 0; i < this.pageData.rollCount; i++) { - const currentRollRows = rowsPerRoll + (i < remainingRows ? 1 : 0) - if (rowIndex < accumulatedRows + currentRollRows) { - currentRollIndex = i - break - } - accumulatedRows += currentRollRows + // 对备注、Packing List和操作列进行按卷合并 + if (column.label === '备注' || column.label === 'Packing List' || column.label === '操作') { + const segment = this.getRollSegmentByRowIndex(rowIndex) + if (!segment) { + return } - - // 计算当前卷的排数 - const currentRollRows = rowsPerRoll + (currentRollIndex < remainingRows ? 1 : 0) - - // 如果是当前卷的第一行,显示合并的单元格 - if (rowIndex === accumulatedRows) { + if (rowIndex === segment.startRow) { return { - rowspan: currentRollRows, + rowspan: segment.rowCount, colspan: 1 } - } else { - // 其他行不显示 - return { - rowspan: 0, - colspan: 0 - } + } + return { + rowspan: 0, + colspan: 0 } } }, @@ -1105,26 +1405,11 @@ export default { if (this.pageData.rowCount <= 0 || this.pageData.rollCount <= 0) { return {} } - - // 计算每卷的排数 - const rowsPerRoll = Math.floor(this.pageData.rowCount / this.pageData.rollCount) - const remainingRows = this.pageData.rowCount % this.pageData.rollCount - - // 计算当前行属于第几卷 - let currentRollIndex = 0 - let accumulatedRows = 0 - - for (let i = 0; i < this.pageData.rollCount; i++) { - const currentRollRows = rowsPerRoll + (i < remainingRows ? 1 : 0) - if (rowIndex < accumulatedRows + currentRollRows) { - currentRollIndex = i - break - } - accumulatedRows += currentRollRows + const segment = this.getRollSegmentByRowIndex(rowIndex) + if (!segment) { + return {} } - - // 计算当前卷的排数 - const currentRollRows = rowsPerRoll + (currentRollIndex < remainingRows ? 1 : 0) + const currentRollRows = segment.rowCount // 每行高度约为32px const rowHeight = 32 @@ -1432,6 +1717,12 @@ export default { return false } + // 校验每卷不良原因数量是否等于该卷面损数量 + if (!this.validateRollDefectQtyBySurfaceLoss()) { + this.yieldReportLoading = false; + return false + } + try { // 计算分卷 const rowsPerRoll = Math.floor(this.pageData.rowCount / this.pageData.rollCount) @@ -1484,6 +1775,7 @@ export default { rollNums: 1, // 固定为1 defectQty: totalDefectQty, // 该卷的不良总数 rollRows: rollRows, // 该卷包含的排数据 + rollDefectDetails: this.getRollDefectDetails(rollIndex + 1), packingList: rollPackingList, // 该卷的Packing List remark: rollRemark // 该卷的备注 } @@ -1797,7 +2089,6 @@ export default { } /* 备注列单元格样式 - 使用绝对定位填满 */ -.customer-dialog >>> .el-table td:last-child, .customer-dialog >>> .el-table td.remark-column, .customer-dialog >>> .el-table td.packing-list-column { padding: 0 !important; @@ -1805,7 +2096,6 @@ export default { overflow: hidden !important; } -.customer-dialog /deep/ .el-table td:last-child, .customer-dialog /deep/ .el-table td.remark-column, .customer-dialog /deep/ .el-table td.packing-list-column { padding: 0 !important; @@ -1869,6 +2159,33 @@ export default { overflow-y: auto !important; } +/* 分卷不良原因对话框 */ +.roll-defect-summary { + display: flex; + justify-content: space-between; + align-items: center; + margin-bottom: 12px; + padding: 8px 12px; + background: #f5f7fa; + border-radius: 4px; + color: #606266; +} + +.roll-defect-form /deep/ .el-form-item { + margin-right: 12px; +} + +.roll-defect-form .defect-code-label a { + color: #409EFF; + font-weight: 600; + cursor: pointer; +} + +.roll-defect-form /deep/ .defect-code-input .el-input__inner { + color: #409EFF; + font-weight: 600; +} +