Преглед изворни кода

feat(forecast-form): 添加导入功能支持

yz пре 1 месец
родитељ
комит
8d9eee892a

+ 71 - 1
src/components/forecast-form/forecast-form-mixin.js

@@ -59,7 +59,7 @@
 
 // API接口导入
 import { addForecast, updateForecast, getForecastDetail } from '@/api/forecast'
-import { addSalesForecastMain, updateSalesForecastMain, getSalesForecastSummaryByMonth, exportSalesForecastTemplate, exportSalesForecastSummaryByYearMonth } from '@/api/forecast/forecast-summary'
+import { addSalesForecastMain, updateSalesForecastMain, getSalesForecastSummaryByMonth, exportSalesForecastTemplate, exportSalesForecastSummaryByYearMonth, importSalesForecastSummaryById } from '@/api/forecast/forecast-summary'
 import { getUserLinkGoods } from '@/api/order/sales-order'
 
 // 常量和枚举导入
@@ -216,6 +216,8 @@ export default {
       templateLoading: false,
       /** 数据下载加载状态 */
       dataExportLoading: false,
+      /** 导入加载状态 */
+      importLoading: false,
 
       /** 客户选项列表
        * @type {Array<CustomerOption>}
@@ -1360,6 +1362,74 @@ export default {
     },
 
     /**
+     * 点击导入按钮
+     * @returns {void}
+     * @this {ForecastFormMixinComponent & Vue}
+     */
+    handleImportClick() {
+      if (!this.isEdit || !this.formData.id) {
+        this.$message && this.$message.warning('当前记录未保存,无法导入')
+        return
+      }
+      const input = this.$refs && this.$refs.importInput
+      if (input && input.click) {
+        input.value = ''
+        input.click()
+      }
+    },
+
+    /**
+     * 处理导入文件选择
+     * @param {Event} event
+     * @returns {Promise<void>}
+     * @this {ForecastFormMixinComponent & Vue}
+     */
+    async handleImportFile(event) {
+      const target = event && event.target
+      const file = target && target.files ? target.files[0] : null
+      if (!file) return
+      if (!this.formData.id) {
+        this.$message && this.$message.warning('未获取到当前记录ID')
+        return
+      }
+
+      try {
+        this.importLoading = true
+        const res = await importSalesForecastSummaryById(this.formData.id, file)
+        const list = res && res.data && res.data.data ? res.data.data : []
+        if (!Array.isArray(list)) {
+          this.$message && this.$message.warning('导入数据格式异常')
+          return
+        }
+
+        this.stockTableData = list.map(item => ({
+          id: item.id ? safeBigInt(item.id) : undefined,
+          goodsId: item.itemId ? safeBigInt(item.itemId) : undefined,
+          code: item.itemCode || '',
+          cname: item.itemName || '',
+          brandId: item.brandId ? safeBigInt(item.brandId) : undefined,
+          brandCode: item.brandCode || '',
+          brandName: item.brandName || '',
+          typeNo: item.specs || '',
+          productDescription: item.pattern || '',
+          brandItem: item.pattern || '',
+          storeInventory: undefined,
+          forecastQuantity: Number(item.forecastQuantity || 0)
+        }))
+
+        this.selectedRowKeys = []
+        this.updateStockSelectOptions && this.updateStockSelectOptions()
+        this.normalizePageAfterMutations && this.normalizePageAfterMutations()
+        this.$message && this.$message.success('导入成功')
+      } catch (e) {
+        console.error('导入失败:', e)
+        this.$message && this.$message.error('导入失败,请稍后重试')
+      } finally {
+        this.importLoading = false
+      }
+    },
+
+    /**
      * 下载销售预测数据(按年月)
      * @returns {Promise<void>}
      * @this {ForecastFormMixinComponent & Vue}

+ 15 - 16
src/components/forecast-form/index.vue

@@ -59,6 +59,14 @@
           <!-- 工具栏:下载模板 -->
           <div class="table-toolbar">
             <el-button
+              type="warning"
+              size="small"
+              icon="el-icon-upload2"
+              :loading="importLoading"
+              v-if="isEdit"
+              @click="handleImportClick"
+            >导入</el-button>
+            <el-button
               type="primary"
               size="small"
               icon="el-icon-download"
@@ -74,6 +82,13 @@
               v-if="isEdit"
               @click="handleDownloadData"
             >下载数据</el-button>
+            <input
+              ref="importInput"
+              type="file"
+              accept=".xls,.xlsx"
+              style="display: none;"
+              @change="handleImportFile"
+            />
           </div>
 
           <el-table
@@ -89,11 +104,6 @@
             <el-table-column prop="cname" label="物料名称" min-width="160" show-overflow-tooltip />
             <el-table-column prop="brandName" label="品牌名称" min-width="120" show-overflow-tooltip />
             <el-table-column prop="typeNo" label="规格" min-width="120" show-overflow-tooltip />
-            <el-table-column prop="storeInventory" label="库存数量" min-width="120">
-              <template #default="{ row }">
-                <span>{{ parseInt(row.storeInventory || 0) }}</span>
-              </template>
-            </el-table-column>
             <!-- Removed specs/description column: productDescription -->
             <el-table-column label="预测数量" min-width="140">
               <template #default="{ row }">
@@ -107,17 +117,6 @@
                 />
               </template>
             </el-table-column>
-            <!-- 操作列:删除按钮 -->
-            <el-table-column label="操作" fixed="right" width="120">
-              <template #default="{ row, $index }">
-                <el-button
-                  type="text"
-                  size="small"
-                  icon="el-icon-delete"
-                  @click="handleDelete(row, $index)"
-                >删除</el-button>
-              </template>
-            </el-table-column>
           </el-table>
 
           <!-- 分页控件(前端分页) -->

+ 6 - 0
src/components/forecast-form/types.d.ts

@@ -150,6 +150,8 @@ export interface ForecastFormMixinData {
   templateLoading: boolean;
   /** 数据下载加载状态 */
   dataExportLoading: boolean;
+  /** 导入加载状态 */
+  importLoading: boolean;
   /** 客户选项列表 */
   customerOptions: Array<CustomerOption>;
   /** 客户选项加载状态 */
@@ -296,6 +298,10 @@ export interface ForecastFormMethods {
   loadUserLinkGoods(): Promise<void>;
   /** 下载销售预测模板 */
   handleDownloadTemplate(): Promise<void>;
+  /** 点击导入按钮 */
+  handleImportClick(): void;
+  /** 处理导入文件选择 */
+  handleImportFile(event: Event): Promise<void>;
   /** 下载销售预测数据(按年月) */
   handleDownloadData(): Promise<void>;
   /** 品牌变更处理 */