|
|
@@ -22,7 +22,7 @@ import {
|
|
|
MaterialDetailDataSource
|
|
|
} from '@/constants/order'
|
|
|
import { MATERIAL_DETAIL_EVENTS, DIALOG_EVENTS } from './events'
|
|
|
-import { getMaterialFullList, downloadSalesOrderTemplate } from '@/api/order/sales-order'
|
|
|
+import { getMaterialFullList, downloadSalesOrderTemplate, importSalesOrderById } from '@/api/order/sales-order'
|
|
|
import { getBrandStockList } from '@/api/forecast/brand-stock'
|
|
|
import {
|
|
|
formatAmount,
|
|
|
@@ -186,7 +186,13 @@ export default {
|
|
|
* 模板下载加载状态
|
|
|
* @type {boolean}
|
|
|
*/
|
|
|
- templateLoading: false
|
|
|
+ templateLoading: false,
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 模板上传加载状态
|
|
|
+ * @type {boolean}
|
|
|
+ */
|
|
|
+ uploadLoading: false
|
|
|
}
|
|
|
},
|
|
|
|
|
|
@@ -618,6 +624,79 @@ export default {
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
+ * 触发上传选择
|
|
|
+ * @returns {void}
|
|
|
+ * @this {MaterialDetailTableComponent & Vue}
|
|
|
+ */
|
|
|
+ handleUploadClick() {
|
|
|
+ if (this.uploadLoading) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const input = this.$refs.materialUploadInput
|
|
|
+ if (input && typeof input.click === 'function') {
|
|
|
+ input.click()
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理上传文件选择
|
|
|
+ * @param {Event} event - 文件选择事件
|
|
|
+ * @returns {void}
|
|
|
+ * @this {MaterialDetailTableComponent & Vue}
|
|
|
+ */
|
|
|
+ handleUploadFileChange(event) {
|
|
|
+ const input = event?.target
|
|
|
+ const file = input?.files?.[0]
|
|
|
+ if (!file) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.uploadSalesOrderFile(file).finally(() => {
|
|
|
+ if (input) {
|
|
|
+ input.value = ''
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传销售订单明细 Excel
|
|
|
+ * @param {File} file - Excel 文件
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ * @this {MaterialDetailTableComponent & Vue}
|
|
|
+ */
|
|
|
+ async uploadSalesOrderFile(file) {
|
|
|
+ if (!this.orderId) {
|
|
|
+ this.$message && this.$message.warning('请先保存订单获取订单ID后再上传')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const filename = file?.name || ''
|
|
|
+ if (!/\.(xls|xlsx)$/i.test(filename)) {
|
|
|
+ this.$message && this.$message.error('请上传 .xls 或 .xlsx 格式文件')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ this.uploadLoading = true
|
|
|
+ const response = await importSalesOrderById(this.orderId, file)
|
|
|
+ const success = response?.data?.success
|
|
|
+ const data = response?.data?.data
|
|
|
+ const message = response?.data?.msg || response?.data?.message
|
|
|
+ if (success && Array.isArray(data)) {
|
|
|
+ this.$emit(MATERIAL_DETAIL_EVENTS.MATERIAL_IMPORT, data)
|
|
|
+ this.$emit(MATERIAL_DETAIL_EVENTS.REFRESH)
|
|
|
+ this.$message && this.$message.success(message || `成功导入 ${data.length} 条物料明细`)
|
|
|
+ } else {
|
|
|
+ this.$message && this.$message.error(message || '上传失败,请检查模板内容')
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('上传模板失败:', error)
|
|
|
+ this.$message && this.$message.error('上传失败,请稍后重试')
|
|
|
+ } finally {
|
|
|
+ this.uploadLoading = false
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
* 准备物料明细数据
|
|
|
* @description 将选中的物料数据转换为物料明细表所需的格式
|
|
|
* @param {import('./types').MaterialOption} material - 物料数据(来自getMaterialFullList API)
|