optionMall.vue
11.9 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<template>
<div class="ipage-option-wrapper">
<ul class="condition-box">
<li class="condition-item">
<span class="condition-item-text">{{ ($Project == 'mall' ? $t('pholder.mallS') : $t('pholder.shopS')) + ':'}}</span>
<el-select v-model="mallVal" filterable :placeholder="$t('pholder.shopSelect')" class="mall-sel-box"
@change="mallChange">
<el-option v-for="item in mallData" :key="item.id" :label="item.name" :value="item.id">
</el-option>
</el-select>
</li>
<!-- 选择日期 S -->
<li class="condition-item">
<div class="condition-item-option">
<div class="time-wrapper newTime">
<el-radio-group v-model="dateType" size="small">
<el-radio-button v-for="item in analyasisTime" :key="item.value" :label="item.value" >{{i18nFormatter(item.label)}}</el-radio-button>
</el-radio-group>
</div>
</div>
</li>
<li class="condition-item">
<!-- <span class="condition-item-text">{{ $t('iPage.selectdate') }}:</span> -->
<div class="condition-item-option">
<el-date-picker class="date-input" v-show="dateType == 'day'" size="mini" v-model="dayTime"
value-format="yyyy-MM-dd" format="yyyy-MM-dd" align="right" type="date"
:placeholder="$t('pholder.date')" :picker-options="pickerOption"></el-date-picker>
<el-date-picker class="date-input analysis-date-input date-week-box" v-show="dateType === 'week'" v-model="weekTime" align="right" type="week" :format="datePickerFormatter('week')" size="mini" :placeholder="$t('pholder.week')" :picker-options="weekPickerOpt">
</el-date-picker>
<el-date-picker class="date-input" v-show="dateType == 'month'" size="mini" v-model="monthTime"
align="right" type="month" value-format="yyyy-MM" format="yyyy-MM"
:placeholder="$t('pholder.month')" :picker-options="pickerOption"></el-date-picker>
<el-date-picker class="date-input" v-show="dateType == 'year'" size="mini" v-model="yearTime"
align="right" type="year" value-format="yyyy" format="yyyy" :placeholder="$t('pholder.year')"
:picker-options="pickerOption"></el-date-picker>
<el-date-picker class="date-input analysis-date-input times-box" v-model="customTime" value-format="yyyy-MM-dd" align="right" type="daterange" size="mini" :picker-options="pickerOption" range-separator="-" v-show="dateType === 'custom'" :start-placeholder="$t('table.startTime')" :end-placeholder="$t('table.endTime')">
</el-date-picker>
</div>
</li>
<!-- 选择日期 E -->
<!-- 操作按钮区域 S -->
<li class="condition-item">
<el-button type="primary" class="primary-btn" size="small"
:disabled="(dateType == 'day' && !dayTime) || (dateType == 'week' && !weekTime) || (dateType == 'month' && !monthTime) || (dateType == 'year' && !yearTime)|| (dateType == 'custom' && !customTime)"
@click="confirmCondition(true)">{{ $t('button.confirm') }}</el-button>
<!-- <el-button class="reset-btn" size="small" @click="resetRefresh">{{ $t('button.reset') }}</el-button> -->
</li>
<!-- 操作按钮区域 E -->
</ul>
<!-- 统计方式区域 S -->
<ul class="condition-box">
<el-button style="margin-left:10px;" class="reset-btn collapse-btn" size="small" icon="el-icon-download"
:loading="downloadStatus" @click="download"></el-button>
</ul>
<!-- 统计方式区域 E -->
</div>
</template>
<script>
let hasInit = false; //是否完成初始化绘图
let optionData;
import _ from 'underscore';
import { mixin } from './download'
import html2canvas from "html2canvas";
import jsPDF from "jspdf";
const analyasisTime = ['day', "week","month", "year", 'custom'].map(item => ({
label: item,
value: item
}))
export default {
mixin: [mixin],
// props: {
// pVal: {
// type: String,
// required: true,
// },
// },
data() {
return {
downloadStatus: false,
accountVal: "",
mallVal: "",
analyasisTime,
mallData: [],
orgType: "mall", //当前页面所属的层级【'account','mall','floor',...】
dateType: "day", //报告类型【'day','month',...】
radioVal: "", //单选【统计、画像】
params: {},
dayTime: "", //日-期
weekTime:'',//周
monthTime: "", //月
yearTime: "", //年
customTime: '',//自定义
pickerOption: {
disabledDate(time) {
return time.getTime() > Date.now();
},
},
weekPickerOpt: {
firstDayOfWeek: window._vionConfig.firstDayOfWeek ? window._vionConfig.firstDayOfWeek : 1
},
};
},
watch: {
radioVal(val) {
// this.confirmCondition();
},
dayTime(val) {
this.sessionDate("dayDate", val);
},
weekTime(val) {
this.sessionDate("weekDate", val);
},
monthTime(val) {
this.sessionDate("monthDate", val);
},
yearTime(val) {
this.sessionDate("yearDate", val);
},
customTime(val) {
this.sessionDate('customDate', val);
}
},
mounted() {
hasInit = false;
let { dayDate, weekDate, monthDate, yearDate, customDate } = this.createDate();
this.dayTime = dayDate;
this.weekTime = weekDate;
this.monthTime = monthDate;
this.yearTime = yearDate;
this.customTime = customDate;
// this.initOption();
},
methods: {
download() {
this.downloadStatus = true;
let mparts = document.querySelector('.mparts');
let { width, height } = mparts.getBoundingClientRect();
const ops = {
scale: window.devicePixelRatio,
width,
height,
useCORS: true,
allowTaint: false,
}
let contentWidth = width;
let contentHeight = height;
html2canvas(mparts, ops).then(canvas => {
// jspdf.js 插件对单页面的最大宽高限制 为 14400
let limit = 14400;
let pdf;
let pageData = canvas.toDataURL("image/jpeg", 1.0); // 清晰度 0 - 1
if (contentHeight > limit) {
let contentScale = limit / contentHeight;
contentHeight = limit;
contentWidth = contentScale * contentWidth;
}
let orientation = "p";
// 在 jspdf 源码里,如果是 orientation = 'p' 且 width > height 时, 会把 width 和 height 值交换,
// 类似于 把 orientation 的值修改为 'l' , 反之亦同。
if (contentWidth > contentHeight) {
orientation = "l";
}
// orientation Possible values are "portrait" or "landscape" (or shortcuts "p" or "l")
pdf = new jsPDF(orientation, "pt", [contentWidth, contentHeight]); // 下载尺寸 a4 纸 比例
// pdf.addImage(pageData, 'JPEG', 左,上,宽度,高度)设置
pdf.addImage(pageData, "JPEG", 0, 0, contentWidth, contentHeight);
this.$emit('downloadSuccess', true);
let dateVal = this.dateType == "day" ? this.dayTime : this.dateType == "month" ? this.monthTime : this.dateType == "year" ? this.yearTime : "";
let timeObj = this.newDateFormat(this.dateType, new Date(dateVal));
let title2 = timeObj.startTime.slice(0, this.dateType == "day" ? 11 : this.dateType == "month" ? 7 : 4);
let title = this.$t(`asisTab.${this.orgType}`) + this.$t(`asisTab.${this.dateType + 'Report'}`);
pdf.save(title + '【' + title2 + '】' + '.pdf');
this.downloadStatus = false;
})
},
i18nFormatter(label) {
let langeLabel = 'asisTab.' + label;
return this.$t(langeLabel)
},
mallChange() {
this.initDraw();
this.$cookie.set('mallId', this.mallVal);
},
setOption(data) {
switch (data.orgType) {
case "mall":
this.mallVal = data.id;
this.radioVal = "count";
this.$cookie.set('mallId', data.id);
this.$router.push('/ipage/ipagemall' + this.dateType);
break;
}
},
initOption(objData,mallData) {
this.mallVal = objData.mallId;
this.mallData = mallData;
let emitData = {
mallIds: this.mallVal,
orgType: this.orgType,
dateType: this.dateType,
dateVal:
this.dateType == "day"
? this.dayTime
: this.dateType == "week"
? this.weekTime
: this.dateType == "month"
? this.monthTime
: this.dateType == "year"
? this.yearTime
: this.dateType == "custom"
? this.customTime
: "",
}
let timeObj = this.newDateFormat(
this.dateType,
new Date(emitData.dateVal)
);
emitData.startDate = timeObj.startTime;
emitData.endDate = timeObj.endTime;
this.$emit('initData', emitData);
},
confirmCondition(force) {
const emitData = {
mallIds: this.mallVal,
orgType: this.orgType,
dateType: this.dateType,
dateVal:
this.dateType == "day"
? this.dayTime
: this.dateType == "week"
? this.weekTime
: this.dateType == "month"
? this.monthTime
: this.dateType == "year"
? this.yearTime
: this.dateType == "custom"
? this.customTime
: "",
};
if(this.dateType == "custom"){
emitData.startDate = this.customTime[0];
emitData.endDate = this.customTime[1];
}else{
let timeObj = this.newDateFormat(
this.dateType,
new Date(emitData.dateVal)
);
emitData.startDate = timeObj.startTime;
emitData.endDate = timeObj.endTime;
}
this.$emit("reportData", emitData);
},
resetRefresh() {
this.dayTime = dateUnit.dateFormat(new Date(), "yyyy-MM-dd");
this.weekTime = new Date(); // 周时间
this.monthTime = new Date(); // 月时间
this.yearTime = new Date(); // 年时间
this.customTime = [this.dayReduce(new Date(), 15), dateUnit.dateFormat(new Date(), 'yyyy-MM-dd')];
},
initDraw() {
if (hasInit) return false;
hasInit = true;
this.confirmCondition();
},
},
};
</script>
<style scoped>
@import url(../css/public.css);
.newTime{
width: auto;
}
</style>