4sOverview.js
13.8 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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
import { IMG_URL } from '../../../utils/imageBase.js'
// tabOperating/pages/operatingShow/operatingShow.js
import api from '../../api.js'
import { getYQInfo } from '~/store/index'
import { getSystemInfoSync } from '~/utils/systemInfo'
// import WXMLCanvas from '../../wxml-canvas/index'
//设计稿宽度,一般为750
const UI_Width = 750
//同步获取设备系统信息
const info = getSystemInfoSync()
//设备像素密度
const dpr = info.pixelRatio
//计算比例
const scale = info.screenWidth / UI_Width
//计算canvas实际渲染尺寸
let width = parseInt(scale * 710)
let height = parseInt(scale * 740)
//计算canvas画布尺寸
let canvasWidth = width * dpr
let canvasHeight = height * dpr
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
IMG_URL,
statusBarHeight: app.globalData.statusBarHeight + 43,
size: { width: 0, height: 0 },
canvasWidth,
canvasHeight,
dpr,
tableList: [],
currentPage: 1,
pageSize: 10,
total: 0,
// pageSize: 20,
pages: 1,
shareModal: false,
dateObj: {
// beginDateStr: ''
},
ShopStatisticsLabel: ['到店贴膜量', '体验量', '成交量', '成交金额'],
shopStatisticsTotalLabel: ['引流体验率', '体验转化率', '升级客单价'],
copyMerchantObj: {
merchantName: '四川华信恒驰汽车销售服务有限公司',
customerTotal: '322', // 客户数
customerShareRate: '78%', // 客占率
filmTimesTotalDay: '3', // 到店贴膜量
experienceTotalDay: '2', // 体验量
upgradeTotalDay: '1', // 成交量
orderMoneyTotalDay: '100', // 成交金额
// merchantId integer($int32) // 商户号
fileTimesTotalMonth: '56', // 当月到店贴膜量
experienceTotalMonth: '33', // 当月体验量
upgradeTotalMonth: '19', // 当月成交量
orderMoneyTotalMonth: '9999', // 当月成交金额
attractExperienceRate: '99%', // 引流体验率
experienceUpgradeRate: '78%', // 体验转化率
upgradeAveragePrice: '99999' // 升级客单价
}
},
navbarReady(e) {
let navBarHeight = e.detail.height
this.setData({
navBarHeight
})
},
jump() {
wx.$router.back()
},
/**设置日期 */
setTimeList(dateNum) {
// console.log('time')
let maxDate = new Date().format('yyyy-MM-dd')
const curDate = new Date()
let today = dateNum || new Date(curDate.getTime() - 24 * 60 * 60 * 1000).format('yyyy-MM-dd')
// console.log(new Date(today).getTime())
// console.log(today)
/**
* 根据日期字符串获取星期几
* @param dateString 日期字符串(如:2020-05-02)
* @returns {String}
*/
var dateArray = today.split('-')
let date = new Date(dateArray[0], parseInt(dateArray[1] - 1), dateArray[2])
// console.log(date)
let todayShow = ' 周' + '日一二三四五六'.charAt(date.getDay())
let toadyforList = dateArray[0] + '年' + dateArray[1] + '月' + dateArray[2] + '日 '
todayShow = toadyforList + todayShow
this.setData({
dateObj: {
today,
maxDate,
todayShow,
toadyforList
}
})
},
changePicker(e) {
let { value } = e.detail
let { merchantId } = this.data.merchantRange[value]
// 修改对应下标显示
app.globalData.yqdInfo.subIndex = value
let obj = {}
if (merchantId) obj.merchantId = merchantId
wx.$util.showLoading('加载中...')
console.log(wx.$util.showLoading)
api.swtichSubLoginInfo(obj).then(res => {
// console.log(res)
let { code, data, message } = res
wx.hideLoading()
if (code == 0) {
wx.$util.setUserInfo(data)
this.init(data)
// this.refresh()
this.setTimeList()
this.getAccumulateList()
} else {
this.showToast(message)
}
})
this.tapPicker()
},
// 切换园区
tapPicker() {
this.setData({
moveArrow: !this.data.moveArrow
})
},
// 切换日历
tapCalendar() {
console.log(this.data.whiteArrow)
this.setData({
whiteArrow: !this.data.whiteArrow
})
},
init(userInfo) {
// app .
getYQInfo(userInfo)
.then(result => {
console.log(result)
this.setData({
...result
})
})
.catch(err => {})
},
// 获取选中天数
rangeSelect(e) {
// console.log(e.detail)
let { date } = e.detail
console.log(date)
this.setTimeList(date)
this.setData({
currentPage: 1
})
this.getAccumulateList()
},
scrollonReachBottom() {
console.log('scrollonReachBottom')
let { pages, currentPage } = this.data
// 判断当前页是否是末页
if (pages == currentPage) return wx.$util.showToast('列表已到底')
this.setData({
currentPage: currentPage + 1
})
this.getAccumulateList()
},
restPageNum() {
console.log('restPageNum')
this.setData({
currentPage: 1
})
this.getAccumulateList()
},
// 请求4s日报列表
getAccumulateList() {
// console.log('getAccumulateList')
// wx.$util.showLoading()
wx.$util.showLoading('加载中...')
let {
dateObj: { today: endDateStr },
currentPage,
pageSize,
tableList
} = this.data
// let params = JSON.parse(JSON.stringify(dateObj))
let params = {
endDateStr,
currentPage,
pageSize
}
api
.orderdayreportMerchant(params)
.then(result => {
wx.hideLoading()
console.log(result)
let { code, data } = result
if (code == '0') {
// 处理某些字段百分比回显问题
let objNameList = ['customerShareRate', 'attractExperienceRate', 'experienceUpgradeRate']
data.list.forEach(element => {
objNameList.forEach(name => {
//如果有值并且不等于0
if (element[name]) {
element[name] = element[name] + '%'
}
})
})
this.setData({
// tableList: currentPage == 1 ? data.list : [...tableList, ...data.list],
tableList: data.list,
// tableObj:data,
triggered: false,
pages: data.pages,
total: data.total
})
}
})
.catch(err => {
console.log(err)
})
},
showShareModel(e) {
// console.log(e)
let { item } = e.currentTarget.dataset
console.log(item)
this.setData({
copyMerchantObj: item
})
this.createNewImg()
},
//将canvas转换为图片保存到本地,然后将图片路径传给image图片的src
createNewImg() {
var that = this
let { copyMerchantObj, dateObj } = this.data
var context = wx.createCanvasContext('mycanvas')
//根据像素密度缩放
// context.scale(this.data.dpr, this.data.dpr)
// context.beginPath()
context.setFillStyle('#fff')
context.fillRect(0, 0, 355, 370)
context.setFillStyle('#EFF5FE')
context.fillRect(0, 0, 355, 50)
this.setCanvasText(context, copyMerchantObj.merchantName, 355 / 2, 25, 14, '#347BFF', 'bold', true)
this.setCanvasText(context, copyMerchantObj.customerTotal, 105, 90, 22, '#333', 'bold')
this.setCanvasText(context, '客户数', 105, 112, 12, '#333', 'normal')
this.setCanvasText(context, copyMerchantObj.customerShareRate, 260, 90, 22, '#333', 'bold')
this.setCanvasText(context, '客占率', 260, 112, 12, '#333', 'normal')
context.setFillStyle('#ECF4FF')
context.fillRect(5, 140, 345, 30)
this.setCanvasText(context, '到店贴膜量', 105, 155, 12, '#7F7F7F', 'normal')
this.setCanvasText(context, '体验量', 185, 155, 12, '#7F7F7F', 'normal')
this.setCanvasText(context, '成交量', 245, 155, 12, '#7F7F7F', 'normal')
this.setCanvasText(context, '成交金额', 315, 155, 12, '#7F7F7F', 'normal')
context.setFillStyle('#F9FCFF')
context.fillRect(5, 170, 345, 80)
this.setCanvasText(context, '单天', 40, 195, 14, '#333333', 'normal')
this.setCanvasText(context, copyMerchantObj.filmTimesTotalDay, 105, 195, 14, '#333333', 'bold')
this.setCanvasText(context, copyMerchantObj.experienceTotalDay, 185, 195, 14, '#333333', 'bold')
this.setCanvasText(context, copyMerchantObj.upgradeTotalDay, 245, 195, 14, '#333333', 'bold')
this.setCanvasText(context, copyMerchantObj.orderMoneyTotalDay, 315, 195, 14, '#333333', 'bold')
this.setCanvasText(context, '本月', 40, 230, 14, '#333333', 'normal')
this.setCanvasText(context, copyMerchantObj.fileTimesTotalMonth, 105, 230, 14, '#333333', 'bold')
this.setCanvasText(context, copyMerchantObj.experienceTotalMonth, 185, 230, 14, '#333333', 'bold')
this.setCanvasText(context, copyMerchantObj.upgradeTotalMonth, 245, 230, 14, '#333333', 'bold')
this.setCanvasText(context, copyMerchantObj.orderMoneyTotalMonth, 315, 230, 14, '#333333', 'bold')
context.setFillStyle('#ECF4FF')
context.fillRect(5, 260, 345, 30)
this.setCanvasText(context, '引流体验率', 105, 275, 12, '#7F7F7F', 'normal')
this.setCanvasText(context, '体验转化率', 205, 275, 12, '#7F7F7F', 'normal')
this.setCanvasText(context, '升级客单价', 310, 275, 12, '#7F7F7F', 'normal')
context.setFillStyle('#F9FCFF')
context.fillRect(5, 290, 345, 40)
this.setCanvasText(context, '总指标', 40, 310, 14, '#333333', 'normal')
this.setCanvasText(context, copyMerchantObj.attractExperienceRate, 105, 310, 14, '#333333', 'normal')
this.setCanvasText(context, copyMerchantObj.experienceUpgradeRate, 205, 310, 14, '#333333', 'normal')
this.setCanvasText(context, copyMerchantObj.upgradeAveragePrice, 310, 310, 14, '#333333', 'normal')
this.setCanvasText(context, `数据统计日期:${dateObj.toadyforList}`, 280, 350, 10, '#666666', 'normal')
const dpr = getSystemInfoSync().pixelRatio
// context.width = 710 * dpr
// context.height = 700 * dpr
// context.scale(dpr, dpr)
// context.fillRect(0, 0, 100, 100)
context.draw()
//将生成好的图片保存到本地
setTimeout(function () {
wx.canvasToTempFilePath({
canvasId: 'mycanvas',
x: 0,
y: 0,
width: 710,
height: 700,
destWidth: 710 * dpr, // width*屏幕像素密度
destHeight: 700 * dpr, // height*屏幕像素密度
fileType: 'jpg',
quality: 1, //图片的质量,目前仅对 jpg 有效。取值范围为 (0, 1],不在范围内时当作 1.0 处理。
success: function (res) {
var tempFilePath = res.tempFilePath
that.setData({
imagePath: tempFilePath
})
wx.$modal(that, {
show: true,
title: '',
tabTitleShow: false,
success: res => {},
error: () => {}
})
},
fail: function (res) {
console.log(res)
}
})
}, 200)
},
setCanvasText(context, text, x, y, font, color, bold = 'normal', center) {
context.font = `normal ${bold} ${font}px PingFangSC-Semibold`
context.setFillStyle(color)
context.setTextBaseline('middle')
center && context.setTextAlign('center')
context.fillText(text, x, y)
context.stroke()
},
shareBtn(e) {
let that = this
let type = e.detail
// console.log(e)
// console.log(e.detail)
if (type == 'wx' && wx.showShareImageMenu) {
wx.showShareImageMenu({
path: this.data.imagePath,
success: () => {
that.setData({
shareModal: false
})
},
fail: res => {
console.log(res)
that.setData({
shareModal: false
})
if (res.errMsg.indexOf('deny') != -1 || res.errMsg.indexOf('denied') != -1) {
wx.showToast({
title: '保存相册失败,请设置权限!',
icon: 'none',
duration: 2000
})
} else {
wx.showToast({
title: '保存相册失败,请重试!',
icon: 'none',
duration: 2000
})
}
}
})
} else {
// 保存图片
this.savimg()
}
},
savimg() {
// 保存图片
let that = this
wx.saveImageToPhotosAlbum({
filePath: this.data.imagePath,
success: res => {
that.setData({
shareModal: false
})
wx.showToast({
title: '保存相册成功!',
icon: 'none',
duration: 3000
})
},
fail: res => {
that.setData({
shareModal: false
})
console.log(res)
if (res.errMsg.indexOf('deny') != -1 || res.errMsg.indexOf('denied') != -1) {
wx.showToast({
title: '保存相册失败,请设置权限!',
icon: 'none',
duration: 2000
})
} else {
wx.showToast({
title: '保存相册失败,请重试!',
icon: 'none',
duration: 2000
})
}
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// 获取当期日期的前前一天
this.setTimeList()
// 请求4s日报列表
this.getAccumulateList()
this.setData({
flag: true
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
// this.createNewImg()
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {}
})