diff --git a/src/views/modules/datacenter/customer-analysis/index.vue b/src/views/modules/datacenter/customer-analysis/index.vue index 335482e..6a47d14 100644 --- a/src/views/modules/datacenter/customer-analysis/index.vue +++ b/src/views/modules/datacenter/customer-analysis/index.vue @@ -7,12 +7,14 @@ style="margin-right: 20px" v-model="formInline.dateType" placeholder="请选择" + @change="handleDateTypeChange" > + + + + 查询 导出 @@ -139,13 +152,15 @@ import * as XLSX from "xlsx"; import { saveAs } from "file-saver"; import { mapState } from "vuex"; import * as echarts from "echarts"; +import dayjs from "dayjs"; export default { data() { return { value1: "", value: "", formInline: { - dateType: "1", + dateType: "7", + timeRange: [], }, analysis: {}, trend: [], @@ -162,16 +177,19 @@ export default { }); }, methods: { + handleDateTypeChange() { + this.formInline.timeRange = []; + }, getList() { - this.$api.dataCenter - .customerAnalysis({ dateType: this.formInline.dateType }) - .then((res) => { - this.analysis = res.data.data; - }); + let params = this.getParams(); + if (!params) return; + this.$api.dataCenter.customerAnalysis(params).then((res) => { + this.analysis = res.data.data; + }); const elementTypes = ["1", "2", "3", "4"]; const chartPromises = elementTypes.map((type) => - this.$api.dataCenter.customerTrend({ ...this.formInline, elementType: type }) + this.$api.dataCenter.customerTrend({ ...params, elementType: type }) ); Promise.all(chartPromises).then((responses) => { @@ -179,6 +197,30 @@ export default { this.init(chartData); }); }, + getParams() { + let params = {}; + if (this.formInline.dateType === "custom") { + if ( + this.formInline.timeRange && + this.formInline.timeRange.length === 2 + ) { + params.startTime = this.formInline.timeRange[0]; + params.endTime = this.formInline.timeRange[1]; + } else { + this.$message.error("请选择时间范围"); + return null; + } + } else { + const end = dayjs().endOf("day").format("YYYY-MM-DD HH:mm:ss"); + const start = dayjs() + .subtract(this.formInline.dateType - 1, "day") + .startOf("day") + .format("YYYY-MM-DD HH:mm:ss"); + params.startTime = start; + params.endTime = end; + } + return params; + }, init(allData) { // 先销毁旧实例 this.charts.forEach((chart) => { diff --git a/src/views/modules/datacenter/product-analysis/index.vue b/src/views/modules/datacenter/product-analysis/index.vue index f56596c..968d999 100644 --- a/src/views/modules/datacenter/product-analysis/index.vue +++ b/src/views/modules/datacenter/product-analysis/index.vue @@ -7,13 +7,14 @@ style="margin-right: 20px" v-model="formInline.dateType" placeholder="请选择" + @change="handleDateTypeChange" > + + + + 查询 导出 @@ -318,11 +330,13 @@