|
|
@@ -22,7 +22,7 @@ import {
|
|
|
MaterialDetailDataSource
|
|
|
} from '@/constants/order'
|
|
|
import { MATERIAL_DETAIL_EVENTS, DIALOG_EVENTS } from './events'
|
|
|
-import { getMaterialFullList } from '@/api/order/sales-order'
|
|
|
+import { getMaterialFullList, downloadSalesOrderTemplate } from '@/api/order/sales-order'
|
|
|
import { getBrandStockList } from '@/api/forecast/brand-stock'
|
|
|
import {
|
|
|
formatAmount,
|
|
|
@@ -180,7 +180,13 @@ export default {
|
|
|
* 选中的行数据 - 用于批量操作
|
|
|
* @type {MaterialDetailRecord[]}
|
|
|
*/
|
|
|
- selectedRows: []
|
|
|
+ selectedRows: [],
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 模板下载加载状态
|
|
|
+ * @type {boolean}
|
|
|
+ */
|
|
|
+ templateLoading: false
|
|
|
}
|
|
|
},
|
|
|
|
|
|
@@ -575,6 +581,43 @@ export default {
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
+ * 下载销售订单模板
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ * @this {MaterialDetailTableComponent & Vue}
|
|
|
+ */
|
|
|
+ async handleDownloadTemplate() {
|
|
|
+ try {
|
|
|
+ this.templateLoading = true
|
|
|
+
|
|
|
+ const res = await downloadSalesOrderTemplate()
|
|
|
+
|
|
|
+ const disposition = res?.headers?.['content-disposition'] || res?.headers?.['Content-Disposition']
|
|
|
+ let filename = '销售订单模板.xlsx'
|
|
|
+ if (disposition) {
|
|
|
+ const utf8Match = /filename\*=UTF-8''([^;\n]+)/i.exec(disposition)
|
|
|
+ const plainMatch = /filename="?([^;\n"]+)"?/i.exec(disposition)
|
|
|
+ const raw = utf8Match ? decodeURIComponent(utf8Match[1]) : (plainMatch ? plainMatch[1] : '')
|
|
|
+ if (raw) filename = raw
|
|
|
+ }
|
|
|
+
|
|
|
+ const blob = new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' })
|
|
|
+ const url = window.URL.createObjectURL(blob)
|
|
|
+ const a = document.createElement('a')
|
|
|
+ a.href = url
|
|
|
+ a.download = filename
|
|
|
+ document.body.appendChild(a)
|
|
|
+ a.click()
|
|
|
+ document.body.removeChild(a)
|
|
|
+ window.URL.revokeObjectURL(url)
|
|
|
+ } catch (e) {
|
|
|
+ console.error('下载模板失败:', e)
|
|
|
+ this.$message && this.$message.error('下载模板失败,请稍后重试')
|
|
|
+ } finally {
|
|
|
+ this.templateLoading = false
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
* 准备物料明细数据
|
|
|
* @description 将选中的物料数据转换为物料明细表所需的格式
|
|
|
* @param {import('./types').MaterialOption} material - 物料数据(来自getMaterialFullList API)
|