businessCell.js
16.6 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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
// tabOperating/pages/index/component/business/business.js
import api from '../../../../api'
const app = getApp()
Component({
/**
* 组件的属性列表
*/
properties: {
dataDateStr: {
type: String,
observer: function (n) {
// console.log(n)
this.getUserDayReport(n)
}
}, // 查询日期
canRemark: {
type: Boolean
},
today: {
type: String
}
// refresh: {
// // 刷新列表
// type: Boolean,
// observer: function (n) {
// console.log()
// let {hidden} = this.data
// // 如果在当前页面
// if (!hidden) {
// }
// // this.getUserDayReport(n)
// // this.getUserInfo()
// }
// },
// hidden: {
// // 刷新列表
// type: Boolean,
// observer: function (n) {
// console.log(this.data)
// console.log(n)
// if (n) {
// }
// }
// }
},
/**
* 组件的初始数据
*/
data: {
scrollTop: 0,
tipsShow: false,
startX: 0, //开始坐标
startY: 0,
page: 1,
list: [
// {
// id: 0,
// title: '标题1',
// create_time: '2019-09-06'
// },
// {
// id: 1,
// title: '标题2',
// create_time: '2019-09-06'
// },
// {
// id: 2,
// title: '标题3',
// create_time: '2019-09-06'
// }
],
remarkObj: {
// showRemark: false,
remarkValue: '',
type: false, // true 新增字段 false 修改字段值
id: '',
placeholderAdd: '请输入完整的字段名,最多10个字',
placeholderUpdate: '新数值会覆盖旧数值'
},
businessObj: {},
listItem: [
{
label: '今日贴膜台次',
prop: 'currentDayFilmToShopTotal',
week: 'currentWeekFilmToShopTotal',
month: 'currentMonthFilmToShopTotal',
diffWeek: 'filmToShopTotalWeekRate'
},
{
label: '今日升级太阳膜台次',
prop: 'currentDayFilmUpgradeTotal',
week: 'currentWeekFilmUpgradeTotal',
month: 'currentMonthFilmUpgradeTotal',
diffWeek: 'filmUpgradeTotalWeekRate'
},
{
label: '今日贴膜升级率',
update: 'currentDayFilmUpgradeTotal',
total: 'currentDayFilmToShopTotal',
prop: 'currentDayFilmUpgradeRate',
diffWeek: 'filmUpgradeRateWeekRate',
different: '今日升级率'
},
{
label: '今日累计太阳膜营业额',
prop: 'currentDayFilmOrderMoneyTotal',
week: 'currentWeekFilmOrderMoneyTotal',
month: 'currentMonthFilmOrderMoneyTotal',
diffWeek: 'filmOrderMoneyTotalWeekRate'
},
{
label: '今日太阳膜均客单价',
prop: 'currentDayFilmCustomerUnitMoney',
month: 'currentMonthFilmCustomerUnitMoney',
diffWeek: 'filmCustomerUnitMoneyWeekRate',
different: '本月进店均客单价'
},
{
label: '累计剩余未到店贴膜台次',
prop: 'notComeToFilmTotal',
different: '已领券未到店核销的客户量'
}
]
// userInfo: wx.$util.getUserInfo()
// userInfo:
},
// 生命周期
lifetimes: {
attached: function () {
// 在组件实例进入页面节点树时执行
this.getUserInfo()
// let userInfo =wx.$util.getUserInfo()
// console.log()
// let { userInfo } = this.data
// let thisPage = wx.$router.getPageInstance()
// console.log(userInfo)
// console.log(thisPage.data.activeTab)
// let { userInfo } = thisPage.data
// console.log(userInfo)
// console.log(thisPage.data['userInfo'])
}
},
/**
* 组件的方法列表
*/
methods: {
inputFocus(e) {
// this.setTimeout(() => {
// wx.hideKeyboard()
// }, 1000)
// let thisPage = wx.$router.getPageInstance()
// // console.log(thisPage.data)
// let { statusBarHeight } = thisPage.data
// console.log(e, '键盘弹起', statusBarHeight)
// this.setData({
// scrollTop: 1000
// })
// wx.pageScrollTo({
// scrollTop: 271,
// duration: 300
// })
// var inputHeight = 0
// setTimeout(() => {
// thisPage.setData({
// statusBarHeight: -271
// })
// }, 1000)
// console.log(e.detail.height)
// thisPage.setData({
// statusBarHeight: -271
// })
// if (e.detail.height) {
// inputHeight = e.detail.height
// thisPage.setData({
// statusBarHeight: -parseInt(inputHeight)
// })
// }
},
// inputBlur(e) {
// // let statusBarHeight = app.globalData.statusBarHeight + 43
// // let thisPage = wx.$router.getPageInstance()
// // thisPage.setData({
// // statusBarHeight
// // })
// // console.log('confirm')
// // console.log(statusBarHeight)
// let { index } = e.currentTarget.dataset
// let { list, dataDateStr } = this.data
// if (!list[index].value) return
// console.log(list[index])
// // 改字段值
// let params = {
// dataDateStr: dataDateStr,
// fieldValue: list[index].value,
// fieldId: list[index].fieldId
// }
// api
// .customizeDayReport(params)
// .then(result => {
// console.log(result)
// if (result.code == 0) {
// wx.$util.showToast('字段值修改成功!')
// this.getUserDayReport()
// } else {
// wx.$util.showToast(result.message)
// }
// })
// .catch(err => {
// console.log(err)
// })
// },
input(e) {
let { value } = e.detail
console.log(e.currentTarget.dataset)
let { index } = e.currentTarget.dataset
let { list } = this.data
// let {index} =
// console.log(e.detail)
console.log(index)
console.log(value)
value = value.replace(/[^\d.]/g, '') //清除“数字”和“.”以外的字符
value = value.replace(/\.{2,}/g, '.') //只保留第一个. 清除多余的
value = value.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')
value = value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3') //只能输入两个小数
list[index]['value'] = value
this.setData({
list
})
console.log(value)
// if (value.indexOf('.') < 0 && value != '') {
// //以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额
// value = parseFloat(value)
// }
},
getUserInfo() {
this.setData({
userInfo: wx.$util.getUserInfo()
})
},
refreshList() {
this.getUserDayReport()
},
getUserDayReport(date) {
let dataDateStr = date || this.data.dataDateStr
// wx.$util.showLoading()
api
.userDayReport({ dataDateStr })
.then(result => {
// wx.hideLoading()
let { code, data } = result
if (code == '0') {
// let showTips
let thisPage = wx.$router.getPageInstance()
this.setData({
businessObj: data,
list: data.list.length ? data.list : [],
triggered: false
})
thisPage.setData({
showTips: Boolean(data.list.length)
})
}
console.log(result)
})
.catch(err => {
console.log(err)
})
},
remarkConfirm(e) {
// 判断自定义字段是新增还是修改数值 做对应处理
let value = e.detail
let { dataDateStr, remarkObj } = this.data
// let apiPost = remarkObj.type == 'add'? :api.customizeDayReport
let thisPage = wx.$router.getPageInstance()
// 新增字段
if (remarkObj.type == 'add') {
// console.log(thisPage)
let params = {
fieldName: value,
merchantId: thisPage.data.userInfo.merchantId
}
// console.log(thisPage.data)
api
.customizeDayReportFieldAdd(params)
.then(result => {
// console.log(result)
if (result.code == '0') {
wx.$util.showToast('新增字段成功!')
thisPage.setData({
showRemark: false
})
this.getUserDayReport()
} else {
wx.$util.showToast('新增字段失败')
}
})
.catch(err => {
console.log(err)
})
} else {
// 改字段值
let params = {
dataDateStr: dataDateStr,
fieldValue: value,
fieldId: remarkObj.id
}
api
.customizeDayReport(params)
.then(result => {
console.log(result)
if (result.code == 0) {
thisPage.setData({
showRemark: false
})
// wx.$util.showToast('字段值修改成功!')
wx.$util.showToast({
title: '成功!',
icon: 'success'
})
this.getUserDayReport()
}
})
.catch(err => {
console.log(err)
})
}
},
tipsShowPop() {
// console.log('tips')
let thisPage = wx.$router.getPageInstance()
thisPage.setData({
businessTipsShow: true
})
},
// closePop() {
// // console.log('closePop')
// let { remarkObj } = this.data
// remarkObj.showRemark = false
// this.setData({
// remarkObj
// })
// },
remarkShow(e) {
console.log(e)
let { list } = this.data
// console.log(listItem)
// e.currentTarget.dataset
// console.log(e.currentTarget.dataset)
let { id, type, value } = e.currentTarget.dataset
if (type == 'add') {
if (list.length >= 10) {
return wx.$util.showToast('自定义字段最多10个')
}
}
const typeList = {
// create: {
// placeholder: '请输入数字',
// title: '新增数据'
// },
add: {
placeholder: '请输入完整的字段名,最多10个字',
title: '新增字段'
},
update: {
placeholder: '新数值会覆盖旧数值',
title: '核准数据'
}
}
let label
if (type == 'update' && !value) {
label = { placeholder: '请输入数字', title: '新增数据' }
} else {
label = typeList[type]
}
// if (condition) {
// }
// let obj =
let thisPage = wx.$router.getPageInstance()
console.log(typeList[type])
thisPage.setData({
remarkObj: {
// showRemark: true,
remarkValue: type == 'add' ? '' : value,
type, // add 新增字段 update 修改字段值
id,
...label
// ...typeList[type]
// title:
// placeholderAdd: '请输入完整的字段名,最多10个字',
// placeholderUpdate: '新数值会覆盖旧数值'
},
showRemark: true
})
this.setData({
remarkObj: {
// showRemark: true,
remarkValue: type == 'add' ? '' : value,
type, // add 新增字段 update 修改字段值
id,
...typeList[type]
// placeholderAdd: '请输入完整的字段名,最多10个字',
// placeholderUpdate: '新数值会覆盖旧数值'
}
})
},
delBtn(e) {
let { id, index } = e.currentTarget.dataset
let { list } = this.data
list[index]['confirmIndex'] = true
this.setData({
list
})
// let _this = this
console.log(id)
// wx.showModal({
// content: '确认删除自定义字段?',
// confirmText: '确认删除',
// cancelText: '返回',
// confirmColor: '#347BFF',
// success(res) {
// if (res.confirm) {
// console.log(id)
// console.log('用户点击确定')
// api
// .customizeDayReportFieldDelete({
// fieldId: id
// })
// .then(_res_ => {
// let { code, message } = _res_
// if (code == 0) {
// wx.$util.showToast('操作成功')
// _this.getUserDayReport()
// } else {
// wx.$util.showToast(message)
// }
// })
// }
// }
// })
},
confirmDelBtn(e) {
let { id } = e.currentTarget.dataset
api
.customizeDayReportFieldDelete({
fieldId: id
})
.then(_res_ => {
let { code, message } = _res_
if (code == 0) {
wx.$util.showToast('操作成功')
this.getUserDayReport()
} else {
wx.$util.showToast(message)
}
})
},
touchE: function (e) {
// console.log(e);
var that = this
if (e.changedTouches.length == 1) {
//手指移动结束后触摸点位置的X坐标
var endX = e.changedTouches[0].clientX
//触摸开始与结束,手指移动的距离
var disX = that.data.startX - endX
console.log(that.data.delBtnWidth)
var delBtnWidth = that.data.delBtnWidth
//如果距离小于删除按钮的1/2,不显示删除按钮
var txtStyle = disX > delBtnWidth / 2 ? 'left:-' + delBtnWidth + 'rpx' : 'left:0'
//获取手指触摸的是哪一项
var index = e.currentTarget.dataset.index
var list = that.data.list
list[index].txtStyle = txtStyle
//更新列表的状态
that.setData({
list: list
})
}
},
//手指触摸动作开始 记录起点X坐标
touchstart: function (e) {
// 权限控制 员工不能删除 和没选具体门店的管理员也不能
// canRemark 处理不是员工并且只有一个店的情况
let { userInfo, canRemark, dataDateStr, today } = this.data
// (userInfo.userType != 2 || userInfo.isSuper) && (userInfo.subLoginUser.merchantId != userInfo.merchantId || canRemark)
let canDelete = userInfo.subLoginUser.merchantId != userInfo.merchantId || canRemark
// userInfo.userType != 2 || canDelete
if (!((userInfo.userType != 2 || userInfo.isSuper) && canDelete)) {
return
}
// let today = new Date().format('yyyy-MM-dd').toString()
// console.log(today);
// let isToday = today==dataDateStr
// debugger
// console.log(this.data.today != this.data.dataDateStr)
// if (this.data.today != this.data.dataDateStr ) {
// return
// }
//开始触摸时 重置所有删除
this.data.list.forEach(function (v, i) {
if (v.isTouchMove)
//只操作为true的
v.isTouchMove = false
v.confirmIndex = false
})
this.setData({
startX: e.changedTouches[0].clientX,
startY: e.changedTouches[0].clientY,
list: this.data.list
})
},
//滑动事件处理
touchmove: function (e) {
//不是当天的不可以删除
let { today, dataDateStr } = this.data
if (today != dataDateStr) {
return
}
var that = this,
index = e.currentTarget.dataset.index, //当前索引
startX = that.data.startX, //开始X坐标
startY = that.data.startY, //开始Y坐标
touchMoveX = e.changedTouches[0].clientX, //滑动变化坐标
touchMoveY = e.changedTouches[0].clientY, //滑动变化坐标
//获取滑动角度
angle = that.angle(
{
X: startX,
Y: startY
},
{
X: touchMoveX,
Y: touchMoveY
}
)
that.data.list.forEach(function (v, i) {
v.isTouchMove = false
//滑动超过30度角 return
if (Math.abs(angle) > 30) return
if (i == index) {
if (touchMoveX > startX)
//右滑
v.isTouchMove = false
//左滑
else v.isTouchMove = true
}
})
//更新数据
that.setData({
list: that.data.list
})
},
/**
* 计算滑动角度
* @param {Object} start 起点坐标
* @param {Object} end 终点坐标
*/
angle: function (start, end) {
var _X = end.X - start.X,
_Y = end.Y - start.Y
//返回角度 /Math.atan()返回数字的反正切值
return (360 * Math.atan(_Y / _X)) / (2 * Math.PI)
}
}
})