mixin.js
6.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import echarts from '@/components/Echarts'
export default {
props: {
title: String,
icon: String,
ckey: String
},
inject: ['evtReport', 'getChartId', 'getChartName', 'getCardIds', 'getCardList', 'getChartList'],
data() {
return {
chartId: "",
chartData: {
},
loaded: false,
params: {} //顶部公用请求参数
}
},
mounted() {},
components: {
...echarts
},
methods: {
showLoading() {
let chart = this.$refs.chart;
if (chart && chart.chart) {
chart.chart.showLoading("default", {
text: "",
color: "#409eff"
});
chart.chart.loading = true;
}
},
hideLoading() {
let chart = this.$refs.chart;
if (chart && chart.chart) {
chart.chart.hideLoading();
chart.chart.loading = false;
}
},
loadModuleData(params, force = false) {
if (this.loaded && !force) return false;
this.loaded = true;
let org_name = params.orgType + 'Ids';
/****************************************************/
this.params = {
orgType: params.orgType,
orgIds: params[org_name] || params.mallIds,
dateType: params.dateType,
dataTypePlus: params.dataTypePlus?params.dataTypePlus:'',
mallIds: params.mallIds,
startDate: params.startDate,
endDate: params.endDate,
isStore:params.isStore,
groupIds:params.groupIds
};
params[org_name] && (this.params[org_name] = params[org_name]);
/*if(params.timeLevel){
this.params.timeLevel = params.timeLevel
}*/
this.setChartConfig(params);
this.loadChartData(this.params);
},
setChartConfig(params) {
let chartKeys = this.getChartsConfig && this.getChartsConfig(params);
if (!chartKeys || (!this.ckey && !chartKeys.default)) {
this.configObj = {};
} else if (!this.ckey && chartKeys.default) {
this.configObj = chartKeys.default;
} else {
this.configObj = chartKeys[this.ckey] || chartKeys.default;
this.configObj.otherConf || (this.configObj.otherConf = chartKeys.default.otherConf);
}
this.configObj && this.configObj.otherConf && (this.configObj.otherConf._color || (this.configObj.otherConf._color = this.getSeriesColor()));
},
resetLoaded() {
this.loaded = false;
this.chartData && (this.chartData.series = [])
},
bindIcon(icon) {
if (this.icon == 'empty') return '';
return require("@/assets/img/ipage/" + (this.icon || icon || 'shuju') + '.png');
},
/**
* 获取随机颜色
* */
getRandomColors(length) {
let colors = [],
temp = [];
while (colors.length < length) {
temp.push(getColor());
colors = [...new Set(temp)];
}
function getColor() {
return (
"#" +
("00000" + ((Math.random() * 0x1000000) << 0).toString(16)).slice(-6)
);
}
return colors;
},
/**
* 获取自定义颜色
* */
getSeriesColor() {
return ['#4a90ff', '#55d9a9', '#f7cf98', '#ff9fc2', '#91e7f8', '#fd7041', '#597ef4', '#f8f02d', '#fa2d2e', '#b05cdd', '#ff877e', '#939893'];
},
ajaxModuleData(params) {
if (!this.chartId) this.chartId = this.getChartId(this.ckey);
if (!this.chartId) {
console.error('无法获取' + this.ckey + '对应的chartId');
return
}
/*缓存请求参数S*/
if (Object.keys(this.params).length == 0 && params) {
this.params = params;
}
if (!params) {
params = this.params;
}
/*缓存请求参数E*/
params.chartIds = this.chartId;
this.tempParams = params;
this.showLoading();
return new Promise((resolve, reject) => {
this.$api.ipageReport.bodyReport(params).then(res => {
let { data } = res.data;
if (!String(this.chartId).includes(',')) {
resolve(data[this.ckey]);
} else {
resolve(data);
}
this.hideLoading();
}).catch(e => {
this.hideLoading();
resolve({});
})
});
},
/**
* 获取全部店铺
* */
getZoneList() {
return this.$api.base.zone({
mallId: this.params.mallIds,
status: 1,
sortName: '"floor".name, "zone".name',
// _t: Date.parse(new Date()) / 1000
})
},
/**
* 获取全部店铺
* */
getFloorList() {
return this.$api.base.floor({
mallId: this.params.mallIds,
accountId: this.$cookie.get("accountId"),
status: 1,
})
},
getFloorZone(floorId, params) {
return this.$api.base
.getFloorZone(floorId, params);
},
/**
* 获取全部业态
* */
getFormatList() {
return this.$api.base.formatlist({
//_t: Date.parse(new Date()) / 1000
})
},
getMallList() {
return this.$api.base.bases("/malls", { status: 1, accountId: this.$cookie.get('accountId') })
}
}
}