index.js
12.7 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
// tabDate/pages/index/index.js
import api from '../../api'
const app = getApp()
const TABLIST = ['全部', '已预约', '待预约']
Page({
/**
* 页面的初始数据
*/
data: {
tabIndex: 0,
activeIndex:0,
phoneShow: false,
inviteObj: {
dayInvited: 0,
overdue: 0,
weekInvited: 0
},
tabList: ['全部', '已预约', '待预约'],
orderObj: [
{
label: '销售顾问',
arr: ['merchantName', 'employeeName']
},
{
label: '礼券名称',
c_key: 'couponName',
key: 'customerCoupon',
e_key: 'employeeName'
},
{
label: '领券时间',
c_key: 'time',
key: 'customerCoupon'
},
{
label: '转化人员',
arr: ['yqMerchantName', 'userName']
}
],
// 邀约状态(1待邀约;2已邀约;3取消预约)
status: {
1: {
text: '待预约',
color: '#FF7D12'
},
2: {
text: '已预约',
color: '#347BFF'
},
3: {
text: '取消预约',
color: '#FF7D12'
},
5: {
text: '超时未到店',
color: '#FF7D12'
},
6: {
text: '已撤销',
color: '#FF7D12'
},
4: {
text: '已施工',
color: '#347BFF'
},
7: {
text: '已支付',
color: '#14CC68'
}
},
searchObj: {},
pageNum: 1,
keyword: '',
list: []
},
delBtn(e) {
let _this = this
// let { list } = this.data
// index, ind
let {
item: { id, customerCouponId }
} = e.currentTarget.dataset
wx.showModal({
title: '',
content: '是否取撤销该工单?',
confirmText: '是',
confirmColor: '#347BFF',
cancelText: '否',
success(res) {
if (res.confirm) {
_this.showLoading('取消中...')
_this.repeal(customerCouponId)
}
}
})
// list[index][ind]['confirmIndex'] = true
// this.setData({
// list
// })
},
// 撤销该工单
repeal(id) {
let _this = this
api
.updateInviteRecordrStatus({
id
})
.then(_res_ => {
let { code, message } = _res_
if (code == 0) {
// wx.$util.showToast('操作成功')
wx.showToast({
title: '操作成功',
icon: 'success'
})
setTimeout(() => {
_this.search()
}, 500)
} else {
wx.$util.showToast(message)
}
})
},
touchE: function (e) {
// console.log(e)
var that = this
// console.log(e.changedTouches.length)
// debugger
let { item: li } = e.currentTarget.dataset
// console.log(!li.repeal)
if (!li.repeal) return
if (e.changedTouches.length == 1) {
//手指移动结束后触摸点位置的X坐标
var endX = e.changedTouches[0].clientX
//触摸开始与结束,手指移动的距离
var disX = that.data.startX - endX
// console.log(disX)
var delBtnWidth = that.data.delBtnWidth
//如果距离小于删除按钮的1/2,不显示删除按钮
var txtStyle = disX > delBtnWidth / 2 ? 'left:-' + delBtnWidth + 'rpx' : 'left:0'
//获取手指触摸的是哪一项
var index = e.currentTarget.dataset.index
var ind = e.currentTarget.dataset.ind
var list = that.data.list
list[index][ind].txtStyle = txtStyle
// console.log(list)
//更新列表的状态
that.setData({
list: list
})
}
},
//手指触摸动作开始 记录起点X坐标
touchstart: function (e) {
// console.log(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
//开始触摸时 重置所有删除
// this.data.list.forEach(item => {
// console.log(item)
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) {
// console.log(e)
// if (condition) {
// }
// let { userInfo } = this.data
let { item: li } = e.currentTarget.dataset
// console.log(!li.repeal)
if (!li.repeal) return
// let userType = !userInfo.isSuper && userInfo.merchantType
// let orderType = userInfo.userType == 1 && li.status != 9 && li.status != 1 && li.selectPayType != 3 && li.selectPayType != 1
// // 权限检验
// // console.log(!userType || !orderType)
// if (!userType || !orderType) return
var that = this,
index = e.currentTarget.dataset.index, //当前索引
ind = e.currentTarget.dataset.ind, //当前索引
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
}
)
// console.log(that.data.list[index])
that.data.list[index].forEach(function (v, i) {
v.isTouchMove = false
//滑动超过30度角 return
if (Math.abs(angle) > 30) return
if (i == ind) {
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)
},
navbarReady(e) {
let navBarHeight = e.detail.height
this.setData({
navBarHeight
})
},
tabClick(e) {
console.log('tabClick',e.detail);
let { searchObj } = this.data
delete searchObj.inviteStatus
this.setData({
tabIndex: e.detail,
searchObj
})
this.search()
},
input(e) {
let { value } = e.detail
this.setData({
keyword: value
})
},
clear() {
this.setData({
keyword: ''
})
this.search()
},
phoneCall(e) {
let { phone } = e.currentTarget.dataset
wx.makePhoneCall({
phoneNumber: phone
})
},
back() {
let { show_confirm } = this.data
if (show_confirm)
this.setData({
show_confirm: false
})
wx.showTabBar()
// else wx.$router.back()
},
showConfirm() {
this.setData({
show_confirm: true
})
wx.hideTabBar()
},
jump(e) {
// console.log(e)
// return
let { item, name,recorderid } = e.currentTarget.dataset
wx.$router.go(name, item)
wx.$util.pointRecord(recorderid)
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
phoneShow: app.globalData.YQorderSetting?.yqPhoneConfig
})
// this.getStatByPeriod()
// this.getiIviteRecord()
},
getiIviteRecord() {
// let params = {}
let { searchObj, keyword } = this.data
let params = {
...searchObj
}
if (keyword) params.keyword = keyword
api.getiIviteRecord(params).then(res => {
let { data } = res
this.setData({
['tabList[0]']: TABLIST[0] + '(' + (data.inviteCount || 0) + ')',
['tabList[1]']: TABLIST[1] + '(' + (data.hadInvitedCount || 0) + ')',
['tabList[2]']: TABLIST[2] + '(' + (data.notInvitedCount || 0) + ')'
})
})
},
getStatByPeriod() {
let { searchObj, keyword } = this.data
let params = {
date: new Date().format('yyyy-MM-dd'),
...searchObj
}
if (keyword) params.keyword = keyword
api.getStatByPeriod(params).then(res => {
let { data } = res
this.setData({
inviteObj: data
})
})
},
init() {
let now = Math.round(new Date())
this.setData({
now
})
},
search() {
wx.$refresh = false
this.setData({
list: [],
pageNum: 1,
flag: false,
nothing: false
})
this.getInviteList()
this.getiIviteRecord()
// this.getStatByPeriod()
},
getInviteList() {
this.showLoading && this.showLoading('加载中...')
// console.log(this.showLoading)
let { searchObj, pageNum, keyword, tabIndex, userInfo } = this.data
let obj = {
currentPage: pageNum,
...searchObj
}
if (keyword) obj.keyword = keyword
if (tabIndex != 0) obj.inviteStatusList = tabIndex == 1 ? [2] : [1, 3]
console.log(tabIndex,obj);
// debugger
api.getInviteList(obj).then(res => {
wx.hideLoading()
console.log(obj, res)
let { code, data, message } = res
let total = 0
let list = []
if (code == 0) {
data.list.map(e => {
if (e.inviteDate) e.time = new Date(e.inviteDate).format('yyyy-MM-dd hh:mm:ss')
if (e.customerCoupon) {
if (e.customerCoupon.createdDate) e.customerCoupon.time = new Date(e.customerCoupon.createdDate).format('yyyy-MM-dd hh:mm:ss')
}
if (e.customer) {
if (e.customerCoupon.employeeName) e.employeeName = e.customerCoupon.employeeName
e.merchantName = e.customer.merchantName
e.yqMerchantName = e.customer.yqMerchantName
}
})
console.log(data.list, 'list')
const userType = !userInfo?.isSuper && userInfo?.merchantType && userInfo.userType == 1
list = data.list.map(item => {
item.repeal = userType && [1, 2].includes(item.inviteStatus)
return item
})
total = data.total
} else {
this.showToast(message)
}
if (total != 0) {
this.setData({
[`list[${pageNum - 1}]`]: list
})
}
this.setData({
total,
flag: true,
triggered: false
})
})
},
showDateBox(e) {
console.log(e)
let { item } = e.currentTarget.dataset
this.setData({
dateItem: item,
showDate: true
})
this.getStatByPeriod()
this.getiIviteRecord()
},
setInviteDate() {
let { dateItem, inviteDateStr } = this.data
api
.setInviteDate({
id: dateItem.id,
inviteType: dateItem.customerCoupon.couponType,
inviteDateStr,
remark: dateItem.remark || ''
})
.then(res => {
wx.hideLoading()
console.log(res)
let { code, message } = res
if (code == 0) {
this.setData({
showDate: false
})
this.search()
} else {
this.showToast(message)
}
})
},
onRoute (options) {
// console.log('activeIndex' in options);
if ('activeIndex' in options) {
// let { searchObj } = this.data
// delete searchObj.inviteStatus
this.setData({
activeIndex:options.activeIndex,
// searchObj.inviteStatusList
})
}
if (wx.$refresh ) {
this.search()
// this.getStatByPeriod()
// this.getiIviteRecord()
}
console.log(options,'options');
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
// if (wx.$refresh) {
// this.search()
// // this.getStatByPeriod()
// // this.getiIviteRecord()
// }
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {},
scrollonReachBottom() {
let { total, pageNum } = this.data
wx.$util.onReachBottom(
{
total,
pageNum
},
res => {
this.getInviteList()
}
)
},
/**
* 监听 TabBar 切换点击
*/
onTabItemTap(item) {
console.log(item, 'item')
wx.$util.pointRecord(10)
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {}
})