|
@@ -59,7 +59,7 @@
|
|
|
|
|
|
|
|
// API接口导入
|
|
// API接口导入
|
|
|
import { addForecast, updateForecast, getForecastDetail } from '@/api/forecast'
|
|
import { addForecast, updateForecast, getForecastDetail } from '@/api/forecast'
|
|
|
-import { addSalesForecastMain, updateSalesForecastMain, getSalesForecastSummaryByMonth, exportSalesForecastTemplate } from '@/api/forecast/forecast-summary'
|
|
|
|
|
|
|
+import { addSalesForecastMain, updateSalesForecastMain, getSalesForecastSummaryByMonth, exportSalesForecastTemplate, exportSalesForecastSummaryByYearMonth } from '@/api/forecast/forecast-summary'
|
|
|
import { getUserLinkGoods } from '@/api/order/sales-order'
|
|
import { getUserLinkGoods } from '@/api/order/sales-order'
|
|
|
|
|
|
|
|
// 常量和枚举导入
|
|
// 常量和枚举导入
|
|
@@ -214,6 +214,8 @@ export default {
|
|
|
|
|
|
|
|
/** 模板下载加载状态 */
|
|
/** 模板下载加载状态 */
|
|
|
templateLoading: false,
|
|
templateLoading: false,
|
|
|
|
|
+ /** 数据下载加载状态 */
|
|
|
|
|
+ dataExportLoading: false,
|
|
|
|
|
|
|
|
/** 客户选项列表
|
|
/** 客户选项列表
|
|
|
* @type {Array<CustomerOption>}
|
|
* @type {Array<CustomerOption>}
|
|
@@ -1358,6 +1360,50 @@ export default {
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * 下载销售预测数据(按年月)
|
|
|
|
|
+ * @returns {Promise<void>}
|
|
|
|
|
+ * @this {ForecastFormMixinComponent & Vue}
|
|
|
|
|
+ */
|
|
|
|
|
+ async handleDownloadData() {
|
|
|
|
|
+ const year = typeof this.formData.year === 'string' ? parseInt(this.formData.year, 10) : Number(this.formData.year)
|
|
|
|
|
+ const month = Number(this.formData.month)
|
|
|
|
|
+ if (!year || !month) {
|
|
|
|
|
+ this.$message && this.$message.warning('请先选择年份和月份')
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ this.dataExportLoading = true
|
|
|
|
|
+ const res = await exportSalesForecastSummaryByYearMonth(year, month)
|
|
|
|
|
+
|
|
|
|
|
+ const disposition = res?.headers?.['content-disposition'] || res?.headers?.['Content-Disposition']
|
|
|
|
|
+ const defaultMonth = String(month).padStart(2, '0')
|
|
|
|
|
+ let filename = `销售预测汇总_${year}-${defaultMonth}.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.dataExportLoading = false
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* 导入所选物料到下方表格
|
|
* 导入所选物料到下方表格
|
|
|
* @description 仅在点击"导入物料"按钮后,将选择的物料行添加到表格,默认预测数量为 1
|
|
* @description 仅在点击"导入物料"按钮后,将选择的物料行添加到表格,默认预测数量为 1
|
|
|
* @returns {void}
|
|
* @returns {void}
|