index.js
13.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
// tabWorkOrder/pages/index/index.js
import api from '../../api'
import order_mixins from '../order_mixins.js'
Page({
/**
* 页面的初始数据
*/
data: {
...order_mixins.data,
orderObj: [
{
label: '销售顾问',
arr: ['merchantName', 'employeeName']
},
{
label: '转化人员',
arr: ['sellerMerchantName', 'sellerName']
},
{
label: '工单编号',
key: 'orderCode'
},
{
label: '工单时间',
key: 'orderTime'
}
],
searchObj: {},
pageNum: 1,
keyword: '',
list: [],
tabIndex: 0,
tabList: ['全部', '待跟进', '已升级', '战败'],
tabListTemplate: ['全部', '待跟进', '已升级', '战败']
},
navbarReady(e) {
// console.log(e)
let navBarHeight = e.detail.height
console.log('123', navBarHeight)
this.setData({
navBarHeight
})
},
tabClick(e) {
let { searchObj } = this.data
delete searchObj.statusList
this.setData({
tabIndex: e.detail,
searchObj
})
this.search()
},
input(e) {
let { value } = e.detail
this.setData({
keyword: value
})
},
clear() {
this.setData({
keyword: ''
})
this.search()
},
back() {
this.setData({
show_confirm: false
})
wx.showTabBar()
},
showConfirm() {
this.setData({
show_confirm: true
})
wx.hideTabBar()
},
jump(e) {
// 订单状态 1 待跟进, 2 不升级, 3 待支付,4 已支付,6 已评价 ,9 已撤销 , 10 已关闭 , 11 已失效
// constructionFlag 施工标识(Y:已施工;N||null:未施工)
// failureFlag 订单失效状态(Y:已失效,N:未失效)
// console.log(e.currentTarget.dataset)
// return
let { item, name } = e.currentTarget.dataset
// console.log(item, name)
// wx.$router.go('constructionOrderDetail', item)
let {
userInfo,
userInfo: { userType }
} = this.data
// console.log(status)
// console.log(item.constructionFlag)
// return
console.log(item)
if (name == 'createOrder') {
if (userInfo.merchantType && !userInfo.isSuper) {
// 是微信支付直接跳转确认页面
if (userType == 2 && item?.selectPayType == 1) {
wx.$router.go('confirmOrder', item)
} else if (userType == 2) {
wx.$router.go(name, item)
} else {
wx.$util.showNoAccess()
}
} else {
wx.$util.showNoAccess()
}
// 已支付加已施工
} else if (item.constructionFlag == 'Y' && item.status != 10) {
wx.$router.go('constructionOrderDetail', item)
} else {
// console.log(item)
wx.$router.go(name, item)
}
},
scan() {
wx.scanCode({
success(res) {
let { result } = res
console.log(result)
wx.$router.go('tabWorkOrder.createOrder', {
scene: result
})
},
fail(err) {
console.log(err)
}
})
},
delBtn(e) {
let _this = this
// let { list } = this.data
// index, ind
let {
item: { orderCode }
} = e.currentTarget.dataset
wx.showModal({
title: '',
content: '是否取撤销该工单?',
confirmText: '是',
confirmColor: '#347BFF',
cancelText: '否',
success(res) {
if (res.confirm) {
_this.showLoading('取消中...')
_this.repeal(orderCode)
}
}
})
// list[index][ind]['confirmIndex'] = true
// this.setData({
// list
// })
},
// 撤销该工单
repeal(orderCode) {
let _this = this
api
.revokeOrder({
orderCode
})
.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)
item.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)
},
init(userInfo) {},
search() {
wx.$refresh = false
this.setData({
list: [],
pageNum: 1,
flag: false,
nothing: false
})
this.getWorkList()
this.getStatByStatus()
},
getWorkList() {
//
// console.log('getWorkList', this.showLoading)
// this.showLoading('加载中...')
// 解决loading只能有一个的兼容问题
this.showLoading && this.showLoading('加载中...')
let { searchObj, pageNum, keyword, tabIndex, userInfo, status } = this.data
let obj = {
keyword,
pageNum,
...searchObj
}
// 待跟进状态需要特殊处理避免带出已关闭
if ([2, 3].includes(tabIndex)) {
let target = {
1: 'R',
2: 'Y',
3: 'N'
}
obj.upgradeFinishFlag = target[tabIndex]
} else if (tabIndex == 1) {
obj.statusList = [1]
}
// console.log(obj.sourceList && obj.statusList[0] == 'Y')
if ((obj.statusList && obj.statusList[0] == 'Y') || (obj.statusList && obj.statusList[0] == 'N')) {
obj.constructionFlag = obj.statusList[0]
delete obj.statusList
}
api.getWorkList(obj).then(res => {
wx.$util.hideLoading()
// console.log('工单', obj, res)
let { code, data, errId, message } = res
let total = 0
let list = []
if (code == 0) {
// 这个是用来判断哪些用户可以撤销的
let userType = !userInfo.isSuper && userInfo.merchantType
// let userType = true
data.list.map(e => {
if (e.orderTime) e.orderTime = new Date(e.orderTime).format('yyyy-MM-dd hh:mm:ss')
e.subOrderList.map(i => {
i.totalPrice = Number(wx.$util.decimal(i.totalPrice, 2)).toFixed(2)
})
e.total_price = e.totalPrice
e.totalPrice = Number(wx.$util.decimal(e.totalPrice, 2)).toFixed(2)
// e.selectPayType != 3 && e.selectPayType != 1
let orderType = userInfo.userType == 1 && e.status != 9 && e.status != 1 && ![1,3,4].includes(e.selectPayType)
e.repeal = userType && orderType
// 处理subOrderList 商品为空的情况
e.subOrderList = e.subOrderList.filter(item => item.merchantGoodsId)
// e.subOrderList = e.subOrderList.filter(item => item.id)
// 处理显示订单右上角文字
// console.log(status[e.status])
// console.log(' status[e.status]', status[e.status])
let text = status[e.status].text
let color = status[e.status].color
let background = status[e.status].background
// 不是订单失效状态优先显示已施工
if (![9, 11, 12].includes(e.status) && e.constructionFlag == 'Y') {
text = '已施工'
color = '#347BFF'
background = '#F3F7FC'
}
e.statusText = text
e.statuscolor = color
e.statusbackground = background
})
list = data.list
total = data.total
} else {
if (errId != '-5003') wx.$util.showToast(message)
}
if (total != 0) {
this.setData({
[`list[${pageNum - 1}]`]: list
})
}
this.setData({
total,
flag: true,
triggered: false
})
})
},
getStatByStatus() {
let { searchObj, keyword, tabList, tabListTemplate } = this.data
api
.statByStatus({
...searchObj,
keyword
})
.then(result => {
console.log(result)
let { data, code } = result
if (code == 0) {
const labelList = ['totalCount', 'waitUpgradeCount', 'upgradedCount', 'notUpgradeCount']
// tabList: ['全部', '待跟进', '已升级', '战败']
labelList.map((item, index) => {
tabList[index] = tabListTemplate[index] + ` (${data[item] ? data[item] : 0})`
})
this.setData({
tabList
})
}
})
.catch(err => {
console.log(err)
})
},
// test() {
// console.log('test')
// // debugger
// let orderCode = deleteList.splice(0, 1).join('')
// orderCode &&
// api
// .revokeOrder({
// orderCode
// })
// .then(_res_ => {
// let { code } = _res_
// console.log(_res_)
// if (code == 0) {
// // wx.$util.showToast('操作成功')
// wx.showToast({
// title: '操作成功',
// icon: 'success'
// })
// this.test()
// } else {
// wx.setStorageSync('errorCode', orderCode)
// wx.setStorageSync('waitCode', list)
// }
// })
// .catch(error => {
// console.log(error)
// wx.setStorageSync('errorCode', orderCode)
// wx.setStorageSync('waitCode', list)
// })
// },
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// this.test()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
if (wx.$refresh) this.search()
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {},
scrollonReachBottom() {
let { total, pageNum } = this.data
wx.$util.onReachBottom(
{
total,
pageNum
},
res => {
this.getWorkList()
this.getStatByStatus()
}
)
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {}
})