diff --git a/src/views/modules/oss/ossComponents.vue b/src/views/modules/oss/ossComponents.vue index e13f31a..f9f0668 100644 --- a/src/views/modules/oss/ossComponents.vue +++ b/src/views/modules/oss/ossComponents.vue @@ -83,6 +83,26 @@ export default { singleUpload: { type: Boolean, default: false + }, + queryOrderRef3List: { + type: Array, + default: () => [] + }, + showOrderRef3Filter: { + type: Boolean, + default: false + }, + orderRef3FilterOptions: { + type: Array, + default: () => [] + }, + orderRef3FilterQueryMap: { + type: Object, + default: () => ({}) + }, + orderRef3LabelMap: { + type: Object, + default: () => ({}) } }, data(){ @@ -111,7 +131,8 @@ export default { currentRev:null, newRev:null, fileRemark:'' - } + }, + orderRef3FilterValue:'' } }, methods:{ @@ -154,38 +175,143 @@ export default { this.$refs.table.setCurrentRow() } }, - handleQuery(){ + resolveOrderRef3Label(orderRef3){ + const key = String(orderRef3 || '').trim() + if (!key) { + return '' + } + if (this.orderRef3LabelMap && this.orderRef3LabelMap[key]) { + return this.orderRef3LabelMap[key] + } + const option = (this.orderRef3FilterOptions || []).find(item => String(item.value || '').trim() === key) + if (option) { + return option.label || key + } + return key + }, + resolveFilterQueryOrderRef3(value){ + const key = String(value || '').trim() + if (!key) { + return [] + } + const mapping = this.orderRef3FilterQueryMap || {} + const mapped = mapping[key] + if (Array.isArray(mapped) && mapped.length > 0) { + return mapped + } + return [key] + }, + buildQueryOrderRef3List(){ + let list = [] + if (this.showOrderRef3Filter && this.orderRef3FilterValue) { + list = this.resolveFilterQueryOrderRef3(this.orderRef3FilterValue) + } else if (Array.isArray(this.queryOrderRef3List) && this.queryOrderRef3List.length > 0) { + list = this.queryOrderRef3List + } else { + list = [this.orderRef3] + } + const cache = new Set() + return list + .map(item => String(item || '').trim()) + .filter(item => { + if (cache.has(item)) { + return false + } + cache.add(item) + return true + }) + }, + sortQueryRows(rows){ + const sourceList = Array.isArray(rows) ? rows : [] + return sourceList.sort((a, b) => { + const dateA = a && a.createDate ? new Date(a.createDate).getTime() : 0 + const dateB = b && b.createDate ? new Date(b.createDate).getTime() : 0 + if (dateA !== dateB) { + return dateB - dateA + } + const idA = a && a.id ? Number(a.id) : 0 + const idB = b && b.id ? Number(b.id) : 0 + return idB - idA + }) + }, + async handleQuery(){ if (!this.params.orderRef1 && !this.params.orderRef2){ return; } - let params = { - ...this.params, - } this.queryLoading = true; - queryOss(params).then(({data})=>{ - if (data && data.code === 0){ - this.dataList = data.rows; - if (this.rowClickSelect && this.currentSelectedRowId) { - const selectedRow = (this.dataList || []).find(item => item.id === this.currentSelectedRowId) - if (selectedRow) { - this.selectionDataList = [selectedRow] - this.$nextTick(() => { - if (this.$refs.table) { - this.$refs.table.setCurrentRow(selectedRow) - } - }) - } else { - this.resetRowSelection() + const ref3List = this.buildQueryOrderRef3List() + const finalRef3List = ref3List.length > 0 ? ref3List : [''] + try { + const requestList = finalRef3List.map(orderRef3 => { + const params = { + ...this.params, + orderRef3: orderRef3 + } + return queryOss(params).then(({data}) => { + if (data && data.code === 0) { + return Array.isArray(data.rows) ? data.rows : [] } + this.$message.warning((data && data.msg) || '附件查询失败') + return [] + }) + }) + const rowsGroup = await Promise.all(requestList) + const mergedRows = [] + const rowMap = new Map() + rowsGroup.forEach(rows => { + ;(rows || []).forEach(row => { + if (!row) { + return + } + const key = String(row.id || '') + if (key && rowMap.has(key)) { + return + } + const normalizedRow = { + ...row, + orderRef3Label: this.resolveOrderRef3Label(row.orderRef3) + } + mergedRows.push(normalizedRow) + if (key) { + rowMap.set(key, true) + } + }) + }) + this.dataList = this.sortQueryRows(mergedRows) + if (this.rowClickSelect && this.currentSelectedRowId) { + const selectedRow = (this.dataList || []).find(item => item.id === this.currentSelectedRowId) + if (selectedRow) { + this.selectionDataList = [selectedRow] + this.$nextTick(() => { + if (this.$refs.table) { + this.$refs.table.setCurrentRow(selectedRow) + } + }) + } else { + this.resetRowSelection() } - }else { - this.$message.warning(data.msg); } - this.queryLoading = false; - }).catch((error)=>{ + } catch (error){ this.$message.error(error); + } finally { this.queryLoading = false; - }) + } + }, + resolveUploadOrderRef3(){ + if (this.showOrderRef3Filter && Array.isArray(this.orderRef3FilterOptions) && this.orderRef3FilterOptions.length > 0) { + const selectedType = String(this.orderRef3FilterValue || '').trim() + if (!selectedType) { + this.$message.warning('请先选择附件类型') + return '' + } + const queryList = this.resolveFilterQueryOrderRef3(selectedType) + return queryList.length > 0 ? queryList[0] : selectedType + } + const queryList = this.buildQueryOrderRef3List() + if ((!this.orderRef3 || !String(this.orderRef3).trim()) && queryList.length > 0) { + return queryList[0] + } + return this.orderRef3 }, handleUpload(){ this.$nextTick(()=>{ @@ -249,7 +375,11 @@ export default { } formData.append('orderRef1', this.orderRef1); formData.append('orderRef2', this.ossForm.orderRef2); - formData.append('orderRef3', this.orderRef3); + const uploadOrderRef3 = this.resolveUploadOrderRef3() + if (!uploadOrderRef3) { + return + } + formData.append('orderRef3', uploadOrderRef3); formData.append('fileRemark', this.ossForm.remark); if (this.requireFileNoRev){ formData.append('fileNo', this.ossForm.fileNo); @@ -423,29 +553,42 @@ export default { } }); }, - handleDownload(){ - if (this.selectionDataList.length === 0){ + async handleDownload(){ + const selectedRows = Array.isArray(this.selectionDataList) ? [...this.selectionDataList] : [] + if (selectedRows.length === 0){ this.$message.warning('请选择要下载的附件'); return; } - for (let i = 0; i < this.selectionDataList.length; i++) { - let params = { - id:this.selectionDataList[i].id, + const failNames = [] + const taskList = selectedRows.map(row => { + const params = { + id: row.id } - previewOssFileById(params).then((response) => { - const blob = new Blob([response.data], { type: response.headers['content-type'] }); - const link = document.createElement('a'); - link.href = URL.createObjectURL(blob); - link.setAttribute('download', this.selectionDataList[i].fileName); - link.target = '_blank'; // 打开新窗口预览 - link.click(); - URL.revokeObjectURL(link.href); - if (this.rowClickSelect) { - this.resetRowSelection(); - } else if (this.$refs.table) { - this.$refs.table.clearSelection(); - } - }); + const fileName = row.fileName || '附件' + return previewOssFileById(params).then((response) => { + const blob = new Blob([response.data], { type: response.headers['content-type'] }) + const link = document.createElement('a') + link.href = URL.createObjectURL(blob) + link.setAttribute('download', fileName) + link.click() + URL.revokeObjectURL(link.href) + return true + }).catch(() => { + failNames.push(fileName) + return false + }) + }) + const resultList = await Promise.all(taskList) + const successCount = resultList.filter(item => item).length + if (failNames.length > 0) { + this.$message.warning('部分文件下载失败:' + failNames.join(',')) + } else if (successCount > 0) { + this.$message.success('已下载 ' + successCount + ' 个附件') + } + if (this.rowClickSelect) { + this.resetRowSelection() + } else if (this.$refs.table) { + this.$refs.table.clearSelection() } } }, @@ -474,6 +617,10 @@ export default { this.handleQuery(); } }, + orderRef3FilterValue(){ + this.resetRowSelection() + this.handleQuery() + }, orderRef2(newVal) { this.ossForm.orderRef2 = newVal; }, @@ -494,6 +641,17 @@ export default { + diff --git a/src/views/modules/rohs/rohsRecord.vue b/src/views/modules/rohs/rohsRecord.vue index 8705204..7540bf1 100644 --- a/src/views/modules/rohs/rohsRecord.vue +++ b/src/views/modules/rohs/rohsRecord.vue @@ -162,12 +162,12 @@ :title="modalTitle" :visible.sync="modalFlag" width="1012px" - top="4vh" + top="3.8vh" v-drag :close-on-click-modal="false" :showClose="false"> - +
@@ -526,7 +526,7 @@ :data="modalData.materialList" @selection-change="materialSelectionChange" :header-cell-style="materialDialogHeaderCellStyle" - :height="705" + :height="715" style="width: 100%"> @@ -538,23 +538,87 @@ -
- - +
+ + + + + + + + + + + + + + + + + + + + + + + +
@@ -1019,13 +1083,17 @@ :remove-visible="authFileRemove" :preview-visible="authFilePreview" :disabled="currentRow.status === '已完成'" + :show-order-ref3-filter="true" + :order-ref3-filter-options="rohsAttachmentTypeOptionList" + :query-order-ref3-list="rohsAttachmentQueryOrderRef3List" + :order-ref3-filter-query-map="rohsAttachmentTypeFilterQueryMap" + :order-ref3-label-map="rohsAttachmentTypeLabelMap" label="序列号" :height="secondHeight - 25" style="margin-top: 2px" - :columns="fileColumnList" + :columns="rohsAttachmentSummaryColumnList" :order-ref1="currentRow.site" - :order-ref2="currentRow.referenceNo" - order-ref3="rohsAttachment"> + :order-ref2="currentRow.referenceNo"> @@ -1151,6 +1219,94 @@ export default { columnWidth: 120 } ], + rohsAttachmentTypeOptionList: [ + { value: 'rohsAttachmentTds', label: 'TDS' }, + { value: 'rohsAttachmentMsds', label: 'MSDS' }, + { value: 'rohsAttachmentTestReport', label: '测试报告' }, + { value: 'rohsAttachmentOther', label: 'Other' } + ], + rohsAttachmentTypeLabelMap: { + rohsAttachmentTds: 'TDS', + rohsAttachmentMsds: 'MSDS', + rohsAttachmentTestReport: '测试报告', + rohsAttachmentOther: 'Other', + rohsAttachment: 'Other' + }, + rohsAttachmentQueryOrderRef3List: [ + 'rohsAttachmentTds', + 'rohsAttachmentMsds', + 'rohsAttachmentTestReport', + 'rohsAttachmentOther', + 'rohsAttachment' + ], + rohsAttachmentTypeFilterQueryMap: { + rohsAttachmentTds: ['rohsAttachmentTds'], + rohsAttachmentMsds: ['rohsAttachmentMsds'], + rohsAttachmentTestReport: ['rohsAttachmentTestReport'], + rohsAttachmentOther: ['rohsAttachmentOther', 'rohsAttachment'] + }, + rohsAttachmentSummaryColumnList: [ + { + columnProp: 'orderRef3Label', + headerAlign: 'center', + align: 'center', + columnLabel: '类型', + columnHidden: false, + columnImage: false, + columnSortable: false, + status: true, + fixed: '', + columnWidth: 120 + }, + { + columnProp: 'fileName', + headerAlign: 'center', + align: 'center', + columnLabel: '文件名称', + columnHidden: false, + columnImage: false, + columnSortable: false, + status: true, + fixed: '', + columnWidth: 160 + }, + { + columnProp: 'fileRemark', + headerAlign: 'center', + align: 'center', + columnLabel: '备注', + columnHidden: false, + columnImage: false, + columnSortable: false, + status: true, + fixed: '', + columnWidth: 220 + }, + { + columnProp: 'createDate', + headerAlign: 'center', + align: 'center', + columnLabel: '上传时间', + columnHidden: false, + columnImage: false, + columnSortable: false, + status: true, + fixed: '', + columnWidth: 160 + }, + { + columnProp: 'createBy', + headerAlign: 'center', + align: 'center', + columnLabel: '上传人', + columnHidden: false, + columnImage: false, + columnSortable: false, + status: true, + fixed: '', + columnWidth: 120 + } + ], tdsFileColumnList: [ { columnProp: 'fileNo', @@ -1389,7 +1545,10 @@ export default { if (val === 'attachmentInfo' || val === 'npdInfo') { this.$nextTick(() => { if (val === 'attachmentInfo') { - this.refreshOssRef('modalAttachmentOss') + this.refreshOssRef('modalAttachmentTdsOss') + this.refreshOssRef('modalAttachmentMsdsOss') + this.refreshOssRef('modalAttachmentTestReportOss') + this.refreshOssRef('modalAttachmentOtherOss') } if (val === 'npdInfo') { this.refreshOssRef('modalTdsOss') @@ -2290,7 +2449,10 @@ export default { }) }, refreshAttachmentPanels () { - this.refreshOssRef('modalAttachmentOss') + this.refreshOssRef('modalAttachmentTdsOss') + this.refreshOssRef('modalAttachmentMsdsOss') + this.refreshOssRef('modalAttachmentTestReportOss') + this.refreshOssRef('modalAttachmentOtherOss') this.refreshOssRef('modalTdsOss') this.refreshOssRef('bottomAttachmentOss') this.refreshOssRef('bottomTdsOss')