createArchives.js
16.5 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
583
584
585
586
587
588
589
590
591
592
593
// tabWorkOrder/pages/createArchives/createArchives.js
// tabWorkOrder/pages/createOrder/createOrder.js
// import deepClone from '~/utils/deepClone'
import api from '../../api'
import { getYQorderInfo } from '~/store/index'
const app = getApp()
let toastList = {
employeeName: '销售顾问不能为空',
subShopMerchantId: '二级流量方不能为空',
customerName: '车主姓名不能为空',
customerPhone: '手机号不能为空',
sellerUserId: '转化人员不能为空',
customerCouponCode: '精品礼券不能为空',
carBrand: '车型不能为空',
standNo: '车架号( VIN码 )不能为空',
plateNumber: '车牌不能为空'
}
const phoneRex = /^[1]([3-9])[0-9]{9}$/
Page({
/**
* 页面的初始数据
*/
data: {
scanIcon: 'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/ocr_icon.png',
name: 'createdOrder',
phoneShow: false,
orderObj: {
// selectPayType: 2,
// remark: ''
},
goodsData: [],
userInfo: {},
notUpgradeOrderList: [
{
customerName: '',
customerPhone: '',
customerSex: 1,
confirmIndex: false
}
// {
// customerName: '',
// customerPhone: '',
// standNo: '',
// customerSex: 1,
// confirmIndex: false
// }
],
dateObj: {
beforeDay: '',
today: '',
nextDay: '',
maxDate: '',
todayShow: ''
},
toView: '',
typeIndx: 0,
// isPlateNumber: false
isStandNo: false,
isShowSubShopMerchant: false,
requiredList: [],
tipsProps: {
tipsText: '本表单用于快速创建客户待跟进订单',
showTips: false,
type: 1
},
selectCustomIndex: 0
},
routerBack() {
wx.$router.back()
},
reWrite(type, data) {
let { notUpgradeOrderList, typeIndx } = this.data
notUpgradeOrderList[typeIndx][type] = data
this.setData({
notUpgradeOrderList
})
},
navOcr(e) {
// console.log('ocr')
let { type, index } = e.currentTarget.dataset
console.log(type)
// wx.$router.go('ocr', { type: 'test' })
this.setData({
typeIndx: index
})
wx.$router.go(`ocr?type=${type}`)
},
addUserItem() {
let customer = {
customerName: '',
customerPhone: '',
customerSex: 1
}
let { notUpgradeOrderList } = this.data
notUpgradeOrderList.push(customer)
this.setData({
notUpgradeOrderList
})
setTimeout(() => {
this.setData({
toView: 'addBtn'
})
}, 0)
},
chooseCar(e) {
let { selectCustomIndex, notUpgradeOrderList } = this.data
notUpgradeOrderList[selectCustomIndex] = {
...notUpgradeOrderList[selectCustomIndex],
...e.detail
}
this.setData({
notUpgradeOrderList
})
},
/**设置日期 */
setTimeList(dateNum) {
// console.log('time')
let maxDate = new Date().format('yyyy-MM-dd')
let today = dateNum || new Date().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())
todayShow = dateArray[0] + '年' + dateArray[1] + '月' + dateArray[2] + '日 ' + todayShow
this.setData({
dateObj: {
today,
maxDate,
todayShow
}
})
},
dateChange(e) {
// console.log(e.)
// console.log(type)
let { type } = e.currentTarget.dataset
console.log(type)
let { dateObj } = this.data
this.calendar = this.selectComponent('#calender')
if (type == 'before') {
this.setTimeList(dateObj.beforeDay)
} else {
this.setTimeList(dateObj.nextDay)
}
this.calendar.resetData(type == 'before' ? dateObj.beforeDay : dateObj.nextDay)
},
// 获取选中天数
rangeSelect(e) {
console.log(e.detail)
let { date } = e.detail
this.setTimeList(date)
},
delBtn(e) {
let ind = e.currentTarget.dataset.ind
let { notUpgradeOrderList } = this.data
notUpgradeOrderList.splice(ind, 1)
this.setData({
notUpgradeOrderList
})
},
touchE: function (e) {
// return
// 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(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 notUpgradeOrderList = that.data.notUpgradeOrderList
notUpgradeOrderList[index].txtStyle = txtStyle
// console.log(list)
//更新列表的状态
that.setData({
notUpgradeOrderList
})
}
},
//手指触摸动作开始 记录起点X坐标
touchstart: function (e) {
// return
// console.log(e)
//开始触摸时 重置所有删除
this.data.notUpgradeOrderList.forEach(item => {
item.isTouchMove = false
item.confirmIndex = false
})
this.setData({
startX: e.changedTouches[0].clientX,
startY: e.changedTouches[0].clientY,
notUpgradeOrderList: this.data.notUpgradeOrderList
})
},
//滑动事件处理
touchmove: function (e) {
let { notUpgradeOrderList } = this.data
// 为1就不能再删除了
if (notUpgradeOrderList.length == 1) 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])
notUpgradeOrderList.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({
notUpgradeOrderList
})
},
/**
* 计算滑动角度
* @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)
},
showPopup(e) {
let { showName, index } = e.currentTarget.dataset
this.setData({
[showName]: true,
selectCustomIndex: index
})
},
input(e) {
let { notUpgradeOrderList } = this.data
let { value } = e.detail
let { name, index } = e.currentTarget.dataset
console.log(name, index)
// [`notUpgradeOrderList.${index}.${name}`]:
notUpgradeOrderList[index][name] = value
this.setData({
notUpgradeOrderList
})
},
changeGender(e) {
let { notUpgradeOrderList } = this.data
let { gender, index } = e.currentTarget.dataset
wx.vibrateShort()
notUpgradeOrderList[index]['customerSex'] = gender
this.setData({
notUpgradeOrderList
// ['orderObj.customer.customerSex']: gender
})
},
staffDailyReportMerchantValid(userInfo) {
// let { userInfo } = this.data
return new Promise((resolve, reject) => {
// console.log(userInfo, 'userInfo')
api
.staffDailyReportMerchantValid({
// merchantId: userInfo.shopMerchantId
merchantId: userInfo.shopMerchantId,
yqMerchantId: userInfo.merchantId,
staffUuid: userInfo.uuid,
sceneType: 1
})
.then(res => {
if (res.data) {
// 获取当前日期
let currentDate = new Date()
// 获取上一天的日期
let previousDate = new Date(currentDate)
previousDate.setDate(currentDate.getDate() - 1)
// toISOString 方法会丢失时区 导致与北京时间差八小时
let hour = previousDate.getHours() + 8
previousDate.setHours(hour)
// 格式化日期为"yyyy-mm-dd"
let formattedDate = previousDate.toISOString().split('T')[0]
if (wx.__HAS_NOREPORT_MODAL || wx.__HAS_NOTLOGIN_MODAL) return false
wx.__HAS_NOREPORT_MODAL = true
wx.showModal({
title: '日报提醒',
content: '您有未填写的日报,请点击前往。',
showCancel: false,
// cancelText: '取消', // '取消
cancelColor: '#292D33',
confirmText: '前往填写',
confirmColor: '#347BFF',
success(res) {
if (res.confirm) {
wx.$router.go('tabWorkOrder.upgradeStaffDaily', {
// reportDate: hasNeedReport.date
reportDate: formattedDate
})
}
},
complete: () => {
// 这个延迟的目的是为了避免短时间内重复弹出
// 你要是没有这个需要也可以去掉,直接把标志位改成 false 就行
setTimeout(() => {
wx.__HAS_NOREPORT_MODAL = false
}, 2000)
}
})
// return false
resolve(res.data)
} else {
resolve(res.data)
}
})
.catch(err => {
console.log(err)
})
})
},
async submit(i) {
let userInfo = wx.$util.getUserInfo()
// 校验是否填写昨日日报
let staffCheck = await this.staffDailyReportMerchantValid(userInfo)
if (staffCheck) return false;
this.checkPhoneUseConfig()
let { type } = i.currentTarget.dataset
let { orderObj, notUpgradeOrderList, dateObj } = this.data
let key = this.checkRequired(orderObj)
// debugger
if (key) {
this.showToast(toastList[key])
wx.pageScrollTo({
selector: `.${key}`
})
return
}
for (let index = 0; index < notUpgradeOrderList.length; index++) {
if (!notUpgradeOrderList[index].customerName) {
return this.showToast(`请输入第${index + 1}位客户姓名`)
}
if (!phoneRex.test(notUpgradeOrderList[index].customerPhone)) {
this.showToast(`请输入第${index + 1}位客户正确的手机号`)
return
}
// if (isStandNo && !notUpgradeOrderList[index].standNo) {
// return this.showToast(`请输入第${index + 1}位客户车架号`)
// }
}
orderObj = {
...orderObj,
// notUpgradeOrderList,
createDate: dateObj.today
}
if (type == 'success') {
orderObj.preliminaryOrders = notUpgradeOrderList
} else {
orderObj.notUpgradeOrderList = notUpgradeOrderList
}
this.showLoading('提交中...')
// return
const apiName = type == 'success' ? 'createPrerecordedOrderBatch' : 'notUpgradeOrder'
// 选择车型会有数据干扰 删除参数
delete orderObj.customer
api[apiName](orderObj).then(res => {
wx.hideLoading()
// console.log(orderObj, res)
let { code, data, message } = res
if (code == 0) {
// 状态更新 需刷新工单列表和预约管理列表
wx.$util.refreshPageData()
this.showToast({
icon: 'success',
title: '提交成功'
})
// wx.$router.back()
// wx.$router.go('tabindex.index')
wx.$router.go('tabIndex.index')
// if (save) {
// wx.showModal({
// title: '温馨提示',
// content: '保存成功',
// showCancel: false,
// confirmText: '知道了',
// confirmColor: '#347BFF',
// success(_res_) {
// if (_res_.confirm) {
// wx.$router.back(page => {
// page.search && page.search()
// })
// }
// }
// })
// } else {
// wx.$refresh = true
// // wx.$router.redirectTo('confirmOrder', data)
// wx.$router.redirectTo('orderDetail', data)
// // 暂时保留跳转页面
// // wx.$router.go('confirmOrder', data)
// }
} else {
this.showToast(message)
}
})
},
checkRequired(obj) {
// 导入动态校验字段
// console.log(requiredList) ...requiredList,
let { requiredList } = this.data
let target = [...requiredList, 'employeeName']
try {
target.map(key => {
if (!obj[key]) {
throw key
}
})
} catch (error) {
return error
}
return false
},
checkPhoneUseConfig() {
let { phoneShow, orderObj, notUpgradeOrderList } = this.data
if (phoneShow && orderObj.merchantName && orderObj.employeeName) {
// && !orderObj.customer.customerPhone
// let list = phoneShow.shopMerchantPhoneList
let phoneConfig =
phoneShow.find(item => {
item.shopMerchantId == orderObj.merchantId
}) || phoneShow.pop()
console.log(phoneConfig)
notUpgradeOrderList.forEach(item => {
item.customerPhone = item.customerPhone || phoneConfig?.phoneNumber
})
this.setData({
notUpgradeOrderList
})
}
},
getSetting() {
// 动态获取 车型 车架 车牌 是否必填
let { isStandNo } = this.data
// app .
getYQorderInfo()
.then(merchantSettingInfo => {
console.log(merchantSettingInfo)
let dictionaryObj = {
// carTypeRequiredFlag: 'carBrand',
standNoRequiredFlag: 'standNo'
// plateNumRequiredFlag: 'plateNumber'
}
// dictionaryObj
// let requiredList = []
for (const key in dictionaryObj) {
if (merchantSettingInfo[key] == 'Y') {
// requiredList.push(dictionaryObj[key])
isStandNo = true
}
}
this.setData({
isStandNo,
// phoneShow: merchantSettingInfo.yqPhoneConfig
phoneShow: wx.$util.deepClone(merchantSettingInfo.yqPhoneConfig)
})
// this.setData({ merchantSettingInfo })
})
.catch(err => {
console.log(err)
})
},
init(userInfo) {
let { orderObj } = this.data
// console.log(userInfo)
// if (!orderObj.sellerMerchantName) {
orderObj.sellerMerchantName = userInfo.merchantName
orderObj.sellerMerchantId = userInfo.merchantId
orderObj.sellerName = userInfo.name
orderObj.sellerUserId = userInfo.uuid
this.setData({
orderObj
})
},
initOPtions(res) {
if (res.customerName) {
// if (query) {
// 解码
for (const key in res) {
res[key] = decodeURIComponent(res[key])
}
// options.query = query
// }
console.log(res, 'res');
let f = 'notUpgradeOrderList[' + 0 + '].customerName'
this.setData({
[f]: res.customerName
})
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (res) {
this.setTimeList()
console.log(res)
res && this.initOPtions(res)
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function (res) {
console.log(res)
// this.getConfig()
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function (res) {
console.log(res, 'onroute')
},
onRoute(res) {
console.log(res, 'onroute')
res && this.initOPtions(res)
// this.getSetting()
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () { },
onUnload: () => { },
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () { },
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () { },
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () { },
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () { }
})