From a4c16fbf8630a2a8f08c771647c442e9f7352434 Mon Sep 17 00:00:00 2001 From: qiankanghui Date: Wed, 25 Nov 2026 17:31:53 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=A2=E5=B9=B4=E7=AE=A1=E7=90=86=EF=BC=8C?= =?UTF-8?q?=E4=BA=A7=E5=93=81=E8=B5=84=E6=96=99=E9=AB=98=E7=BA=A7=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=E4=BC=98=E5=8C=96=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=8F=91?= =?UTF-8?q?=E8=B5=B7=E5=B9=B6=E5=AE=A1=E6=A0=B8=E6=8C=89=E9=92=AE=EF=BC=8C?= =?UTF-8?q?npc-iqc=E4=BC=98=E5=8C=96=E5=AF=BC=E5=85=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/baseInformation/srmInventoryPeriod.js | 10 + src/api/order/srmSavingsReport.js | 3 + src/views/modules/npcIqc/npcIqcList.vue | 471 +++++++++++++---- .../order/com_poOrder_CustomerPicker.vue | 9 +- .../modules/order/srmSavingsReportImport.vue | 243 ++++++++- .../srmBaseInformation/srmInventoryPeriod.vue | 490 ++++++++++++++++++ .../srmPart/PartAdvancedCopyDialog.vue | 121 ++++- src/views/modules/srmPart/partInfoList.vue | 352 +++++++++++-- 8 files changed, 1532 insertions(+), 167 deletions(-) create mode 100644 src/api/baseInformation/srmInventoryPeriod.js create mode 100644 src/views/modules/srmBaseInformation/srmInventoryPeriod.vue diff --git a/src/api/baseInformation/srmInventoryPeriod.js b/src/api/baseInformation/srmInventoryPeriod.js new file mode 100644 index 0000000..13cf8e2 --- /dev/null +++ b/src/api/baseInformation/srmInventoryPeriod.js @@ -0,0 +1,10 @@ +import { createAPI } from '@/utils/httpRequest.js' + +// 财年管理接口(CompanyID 使用系统 customer) +export const getInventoryPeriodPage = (params) => createAPI('/srmInventoryPeriod/page', 'POST', params) + +export const saveInventoryPeriod = (params) => createAPI('/srmInventoryPeriod/save', 'POST', params) + +export const updateInventoryPeriod = (params) => createAPI('/srmInventoryPeriod/update', 'POST', params) + +export const deleteInventoryPeriod = (params) => createAPI('/srmInventoryPeriod/delete', 'POST', params) diff --git a/src/api/order/srmSavingsReport.js b/src/api/order/srmSavingsReport.js index 10f0cd1..b7850cf 100644 --- a/src/api/order/srmSavingsReport.js +++ b/src/api/order/srmSavingsReport.js @@ -9,6 +9,9 @@ import { createAPI } from '@/utils/httpRequest.js' // 主页面分页查询 export const searchSavingsReportPage = data => createAPI('/srm/srmSavingsReport/page', 'POST', data) +// ExtAmount 汇总:过滤条件与列表一致,months 支持多选 +export const summarySavingsReport = data => createAPI('/srm/srmSavingsReport/summary', 'POST', data) + // 下载 Savings 导入模板(固定 11 列表头,与 CNREPORT.xlsx 一致) export const downloadSavingsTemplate = () => http({ url: http.adornUrl('/srm/srmSavingsReport/template'), diff --git a/src/views/modules/npcIqc/npcIqcList.vue b/src/views/modules/npcIqc/npcIqcList.vue index 4d47fc5..ead7851 100644 --- a/src/views/modules/npcIqc/npcIqcList.vue +++ b/src/views/modules/npcIqc/npcIqcList.vue @@ -34,10 +34,8 @@ - - - - + + @@ -92,6 +90,7 @@ + @@ -129,65 +128,83 @@ - - - -
- 请选择文件 - - - 选择文件 + + +
+ + 下载导入模板 + + + + 选择导入文件 + - 上传 - - 下载模板 + + 导出校验结果 + {{ uploadFileName || '未选择文件' }} + 存在校验失败行,请修正后重新选择文件 + + 已读取 {{ uploadPreviewList.length }} 行,表格显示前{{ previewDisplayLimit }}行,其中 {{ invalidPreviewCount }} 行校验失败 +
- - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + -
- 保存 - 关闭 + row && row.valid === false).length + } + }, mounted () { this.$nextTick(() => { // 计算表格高度和详情页高度,保持一致 @@ -348,82 +408,242 @@ export default { this.uploadPreviewList = [] }, - // 文件选择变化 + // 选择文件后立即自动预览并校验,与期初导入页面交互一致 handleFileChange (file) { - this.uploadFile = file.raw - this.uploadFileName = file.name + if (this.importBusy) { + return + } + const rawFile = file && file.raw + if (!rawFile) { + return + } + this.uploadFileName = file.name || '' + this.uploadFile = rawFile + this.uploadPreviewList = [] + this.previewUploadData() }, - // 预览上传数据 - previewUploadData () { - if (!this.uploadFile) { - this.$message.warning('请先选择文件') + // 重复选择文件时替换旧文件后重新预览 + handleFileExceed (files) { + if (this.importBusy || !files || !files.length) { return } + this.clearSelectedFile() + this.handleFileChange({ raw: files[0], name: files[0].name }) + }, + + clearSelectedFile () { + this.uploadFileName = '' + this.uploadFile = null + if (this.$refs.npcIqcUpload) { + this.$refs.npcIqcUpload.clearFiles() + } + }, - const formData = new FormData() - formData.append('file', this.uploadFile) + handleUploadDialogClosed () { + this.clearSelectedFile() + this.uploadPreviewList = [] + }, - // 调用后端预览接口 + // 预览上传数据(后端同步逐行做供应商名称存在性校验,失败行黄标) + previewUploadData () { + this.previewLoading = true previewUpload(this.uploadFile).then(({ data }) => { if (data && data.code === 0) { this.uploadPreviewList = data.data || [] - this.$message.success('文件解析成功,请确认数据后点击保存') + if (this.invalidPreviewCount) { + this.$message.warning(`Excel共${this.uploadPreviewList.length}行,${this.invalidPreviewCount}行校验未通过,请查看黄色行错误信息或导出校验结果`) + } else { + this.$message.success(`Excel读取成功,共${this.uploadPreviewList.length}行,请确认数据后点击保存`) + } } else { - this.$message.error(data.msg || '文件解析失败') + this.showUploadError((data && data.msg) || '文件解析失败') } }).catch((error) => { console.error('文件解析失败:', error) const errorMsg = (error.response && error.response.data && error.response.data.msg) || error.message || '未知错误' - this.$message.error('文件解析失败: ' + errorMsg) + this.showUploadError(errorMsg) + }).finally(() => { + this.previewLoading = false }) }, + // 整体解析失败提示:保留确认框方便看清逐行信息,同时清空预览 + showUploadError (msg) { + this.uploadPreviewList = [] + this.$alert(msg, '导入文件读取失败', { + confirmButtonText: '确定', + type: 'error', + customClass: 'npc-import-error-alert' + }).catch(() => {}) + }, + + // 失败行黄标,与期初导入页面一致 + previewRowClassName ({ row }) { + return row && row.valid === false ? 'npc-import-warning-row' : '' + }, + + // 预览表纠正措施请求列:Excel 原始值转是/否 + caRequestFormatter (row) { + const value = row ? row.caRequest : '' + return (value === true || value === 'true' || value === 1 || value === '1') ? '是' : '否' + }, + // 确认上传 confirmUpload () { + if (this.importBusy) { + return + } if (this.uploadPreviewList.length === 0) { this.$message.warning('没有可保存的数据') return } + if (this.invalidPreviewCount) { + this.$message.warning(`有${this.invalidPreviewCount}行校验未通过,请修正Excel后重新选择文件`) + return + } + this.saving = true + // 调用后端保存接口 + batchSave(this.uploadFile).then(({ data }) => { + if (data && data.code === 0) { + this.$message.success('数据保存成功') + this.uploadDialogVisible = false + this.getMainData() + } else { + this.showUploadSaveError(data.msg || '数据保存失败') + } + }).catch((error) => { + console.error('数据保存失败:', error) + const errorMsg = (error.response && error.response.data && error.response.data.msg) || error.message || '未知错误' + this.showUploadSaveError(errorMsg) + }).finally(() => { + this.saving = false + }) + }, - this.$confirm(`确认保存 ${this.uploadPreviewList.length} 条数据吗?`, '提示', { + // 保存失败弹确认框,点确定后才关闭,避免提示几秒后自动消失看不清 + showUploadSaveError (message) { + this.$alert(message || '保存失败', '导入保存失败', { confirmButtonText: '确定', - cancelButtonText: '取消', - type: 'warning' - }).then(() => { - // 调用后端保存接口 - batchSave(this.uploadFile).then(({ data }) => { - if (data && data.code === 0) { - this.$message.success('数据保存成功') - this.uploadDialogVisible = false - this.getMainData() - } else { - this.$message.error(data.msg || '数据保存失败') - } - }).catch((error) => { - console.error('数据保存失败:', error) - const errorMsg = (error.response && error.response.data && error.response.data.msg) || error.message || '未知错误' - this.$message.error('数据保存失败: ' + errorMsg) - }) + type: 'error', + customClass: 'npc-import-error-alert' }).catch(() => {}) }, + // 导出当前预览数据及校验结果:失败行整行标黄,首列为错误信息 + handleExportPreview () { + if (this.importBusy) { + return + } + if (!this.uploadPreviewList.length) { + this.$message.warning('请先选择导入文件并完成预览') + return + } + this.exporting = true + try { + const columns = [{ prop: 'validationMessage', label: '错误信息', width: 280 }].concat(this.previewColumns) + const xml = this.buildPreviewExportXml(columns, this.uploadPreviewList) + const blob = new Blob(['\ufeff' + xml], { type: 'application/vnd.ms-excel;charset=utf-8' }) + const url = window.URL.createObjectURL(blob) + const link = document.createElement('a') + link.href = url + link.download = this.resolvePreviewExportFileName() + document.body.appendChild(link) + link.click() + document.body.removeChild(link) + window.URL.revokeObjectURL(url) + this.$message.success('校验结果已导出') + } catch (error) { + this.$message.error((error && error.message) || '导出失败,请稍后重试') + } finally { + this.exporting = false + } + }, + + resolvePreviewExportFileName () { + const now = new Date() + const pad = val => String(val).padStart(2, '0') + return `NPC_IQC导入校验结果_${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}.xls` + }, + + /** + * 生成带行底色的 SpreadsheetML,Excel 打开后失败行仍为黄色 + */ + buildPreviewExportXml (columns, rows) { + const headerCells = columns.map(column => { + const width = column.prop === 'validationMessage' ? 280 : 80 + return `` + }).join('') + const headerRow = '' + columns.map(column => { + return `${this.escapeExcelXml(column.label)}` + }).join('') + '' + const dataRows = (rows || []).map(row => { + const styleAttr = row && row.valid === false ? ' ss:StyleID="Warn"' : '' + const cells = columns.map(column => { + const value = this.formatExportCellValue(row, column.prop) + return `${this.escapeExcelXml(value)}` + }).join('') + return `${cells}` + }).join('') + return ` + + + + + + + + + ${headerCells}${headerRow}${dataRows}
+
+
` + }, + + // 导出单元格文本:空值输出空串,避免 Excel 出现 undefined;纠正措施请求列转是/否 + formatExportCellValue (row, prop) { + if (!row || !prop) { + return '' + } + if (prop === 'caRequest') { + return this.caRequestFormatter(row) + } + const value = row[prop] + if (value == null || value === '') { + return '' + } + return String(value) + }, + + // SpreadsheetML 特殊字符转义,防止错误信息里的符号破坏 XML + escapeExcelXml (value) { + return String(value == null ? '' : value) + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + }, + // 下载模板 downloadTemplateFile () { - const loading = this.$loading({ - lock: true, - text: '正在下载模板...', - spinner: 'el-icon-loading', - background: 'rgba(0, 0, 0, 0.7)' - }) - + if (this.importBusy) { + return + } + this.templateDownloading = true this.$http({ url: this.$http.adornUrl('/npcIqc/downloadTemplate'), method: 'post', responseType: 'blob' }).then(response => { - loading.close() - // 创建下载文件 const blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' @@ -442,9 +662,10 @@ export default { this.$message.success('模板下载成功') }).catch(error => { - loading.close() console.error('模板下载失败:', error) this.$message.error('模板下载失败,请联系管理员') + }).finally(() => { + this.templateDownloading = false }) }, @@ -646,7 +867,61 @@ export default { /deep/ .el-table__body td { padding: 4px 0; } -.npc-iqc-container /deep/ .el-dialog .el-table__header th { - text-align: center; - } +/* 导入弹窗:布局对齐期初导入页面 */ +.dialog-toolbar { + display: flex; + align-items: center; + flex-wrap: wrap; + min-height: 40px; + margin-bottom: 12px; + gap: 10px; +} + +.file-name { + display: inline-block; + max-width: 360px; + overflow: hidden; + color: #606266; + text-overflow: ellipsis; + white-space: nowrap; +} + +.invalid-hint { + color: #e6a23c; + font-size: 13px; +} + +.preview-count { + margin-left: auto; + color: #606266; + font-variant-numeric: tabular-nums; +} + +.npc-import-preview { + width: 100%; +} + +.npc-import-preview /deep/ .npc-import-warning-row > td { + background-color: #fff7d6 !important; +} + +.npc-import-preview /deep/ .npc-import-warning-row:hover > td { + background-color: #fff0b3 !important; +} + +.dialog-footer { + text-align: right; +} + + + diff --git a/src/views/modules/order/com_poOrder_CustomerPicker.vue b/src/views/modules/order/com_poOrder_CustomerPicker.vue index d042eea..7d3a88f 100644 --- a/src/views/modules/order/com_poOrder_CustomerPicker.vue +++ b/src/views/modules/order/com_poOrder_CustomerPicker.vue @@ -8,8 +8,9 @@ - - - + + + + + 至 + + @@ -20,9 +34,31 @@ 查询 导入 + + {{ "导出" }} + + +
+ ExtAmount 汇总 + 金额合计:{{ formatAmount(summaryData.extAmountTotal) }} + 记录数:{{ summaryData.rowCount || 0 }} + {{ summaryScopeTip }} +
+ row && row.valid === false).length }, @@ -226,7 +306,8 @@ export default { }, mounted () { this.$nextTick(() => { - this.height = window.innerHeight - 200 + // 预留汇总条高度,避免页面出现多余滚动 + this.height = window.innerHeight - 250 }) }, methods: { @@ -235,14 +316,39 @@ export default { this.pageIndex = 1 this.getDataList() }, + // 列表/汇总/导出共用查询条件,避免直接修改 searchData + buildQueryParams (extra) { + return Object.assign({ + year: this.searchData.year || '', + months: this.buildMonthList(), + poNumber: this.searchData.poNumber || '', + vendorName: this.searchData.vendorName || '' + }, extra || {}) + }, + // 月份区间展开为后端已有的 months 闭区间集合,只填一端时向该端放开 + buildMonthList () { + const { monthStart, monthEnd } = this.searchData + if (!monthStart && !monthEnd) { + return [] + } + const from = monthStart || 1 + const to = monthEnd || 12 + const months = [] + for (let month = from; month <= to; month++) { + months.push(month) + } + return months + }, + // 兜底:清空一端或外部赋值导致区间倒挂时,把另一端对齐,避免出现空结果 + normalizeMonthRange () { + const { monthStart, monthEnd } = this.searchData + if (monthStart && monthEnd && monthStart > monthEnd) { + this.searchData.monthEnd = monthStart + } + }, getDataList () { this.dataListLoading = true - const params = { - ...this.searchData, - page: this.pageIndex, - limit: this.pageSize - } - searchSavingsReportPage(params).then(({ data }) => { + searchSavingsReportPage(this.buildQueryParams({ page: this.pageIndex, limit: this.pageSize })).then(({ data }) => { if (data && data.code === 0) { const pageData = data.page this.dataList = pageData && pageData.list ? pageData.list : [] @@ -257,6 +363,79 @@ export default { }).finally(() => { this.dataListLoading = false }) + this.getSummary() + }, + // ExtAmount 汇总:后端按同过滤条件聚合全部匹配数据,不受分页影响 + getSummary () { + this.summaryLoading = true + summarySavingsReport(this.buildQueryParams()).then(({ data }) => { + if (data && data.code === 0) { + this.summaryData = { + rowCount: data.rowCount || 0, + extAmountTotal: data.extAmountTotal || 0 + } + } else { + this.summaryData = { rowCount: 0, extAmountTotal: 0 } + } + }).catch(() => { + this.summaryData = { rowCount: 0, extAmountTotal: 0 } + }).finally(() => { + this.summaryLoading = false + }) + }, + // 金额显示:千分位 + 保留2位小数 + formatAmount (value) { + const num = Number(value) + if (!isFinite(num)) { + return '0.00' + } + return num.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) + }, + // ==================== 导出 ==================== + async createExportData () { + this.exportList = [] + await searchSavingsReportPage(this.buildQueryParams({ page: 1, limit: 999999 })).then(({ data }) => { + if (data && data.code === 0) { + const pageData = data.page + const rows = pageData && pageData.list ? pageData.list : [] + this.exportList = Array.isArray(rows) ? rows : [] + // 汇总行随导出一起输出(vue-json-excel 的 footer 每项占一个合并单元格行,因此传文本) + const total = this.exportList.reduce((sum, row) => sum + (Number(row.extAmount) || 0), 0) + this.exportFooter = [`ExtAmount 合计:${this.formatAmount(total)}(记录数 ${this.exportList.length})`] + } else { + this.$message.error((data && data.msg) || '导出失败') + } + }).catch(() => { + this.$message.error('导出失败') + }) + this.exportName = 'Savings报表' + dayjs().format('YYYYMMDDHHmmss') + return this.exportList + }, + startDownload () { + this.dataListLoading = true + }, + finishDownload () { + this.dataListLoading = false + }, + fields () { + return { + '年份': 'year', + '月份': 'month', + 'PONumber': 'poNumber', + 'VendorName': 'vendorName', + '供应商编码': 'supplierNo', + 'Issued_Date': 'issuedDate', + 'ItemCode': 'itemCode', + 'UnitPrice': 'unitPrice', + 'Received_Date': 'receivedDate', + 'need_by_date': 'needByDate', + 'Qty': 'qty', + 'OldPrice': 'oldPrice', + 'Variance': 'variance', + 'ExtAmount': 'extAmount', + '导入人': 'createBy', + '导入时间': 'createDate' + } }, sizeChangeHandle (val) { this.pageSize = val @@ -271,7 +450,8 @@ export default { openImportDialog () { this.dialogVisible = true this.importYear = this.searchData.year || new Date().getFullYear() - this.importMonth = this.searchData.month || (new Date().getMonth() + 1) + // 导入仍为单月,区间选择时默认取开始月份 + this.importMonth = this.searchData.monthStart || (new Date().getMonth() + 1) this.previewRows = [] this.clearSelectedFile() }, @@ -477,6 +657,43 @@ export default { line-height: 1.5; } +/* 月份区间分隔符 */ +.range-separator { + padding: 0 6px; + color: #909399; +} + +/* ExtAmount 汇总条 */ +.summary-bar { + display: flex; + align-items: center; + flex-wrap: wrap; + gap: 18px; + padding: 8px 12px; + margin-bottom: 10px; + font-size: 13px; + color: #606266; + background-color: #f5f7fa; + border: 1px solid #ebeef5; + border-left: 3px solid #409eff; + border-radius: 2px; +} + +.summary-label { + font-weight: 600; + color: #303133; +} + +.summary-value { + color: #409eff; + font-variant-numeric: tabular-nums; +} + +.summary-tip { + margin-left: auto; + color: #909399; +} + .dialog-toolbar { display: flex; align-items: center; diff --git a/src/views/modules/srmBaseInformation/srmInventoryPeriod.vue b/src/views/modules/srmBaseInformation/srmInventoryPeriod.vue new file mode 100644 index 0000000..ab66309 --- /dev/null +++ b/src/views/modules/srmBaseInformation/srmInventoryPeriod.vue @@ -0,0 +1,490 @@ + + + + + diff --git a/src/views/modules/srmPart/PartAdvancedCopyDialog.vue b/src/views/modules/srmPart/PartAdvancedCopyDialog.vue index bb3b240..d033644 100644 --- a/src/views/modules/srmPart/PartAdvancedCopyDialog.vue +++ b/src/views/modules/srmPart/PartAdvancedCopyDialog.vue @@ -1,4 +1,5 @@