orderSignature.js
22.1 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
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
// tabWorkOrder/pages/orderSignature/orderSignature.js
import {
uploadImg
} from '~/api/api'
import api from '../../api.js'
import order_mixins from '../order_mixins.js'
import { getPositionList, getServiceFilmRollSetting, setConfigInfo } from '~/store/index'
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/miniProgram/'
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
IMG_URL,
...order_mixins.data,
showTips: true,
isYqdSuper: app.globalData.isYqdSuper,
isStaff: app.globalData.isStaff,
isShowPhone: app.globalData.YQorderSetting?.yqPhoneConfig,
ctx: '',
hasDraw: false,
canvasWidth: 0,
canvasHeight: 0,
startPoint: {
x: 0,
y: 0
},
selectColor: 'black',
lineColor: '#282829', // 颜色
lineSize: 3, // 笔记倍数
radius: 1.5, //画圆的半径
showPlaceHoder: true,
signImage: '',
constructionImgList: [],
rating: 5,
formData: {},
tags: [{
name: '服务态度好',
value: 1,
checked: true
},
{
name: '性价比高',
value: 2,
checked: false
},
{
name: '价格便宜',
value: 3,
checked: false
},
{
name: '一般',
value: 4,
checked: false
}
],
selectFilmNumberIndex: 0,
filmRollNoList: [],
isUseFilmRoll: false,
filmRollNoPopup: false,
filmSelectedItem: '',
baseConfigData: {}
},
setSignture(url) {
this.setData({
signImage: url,
hasDraw: true
})
},
chooseTag(e) {
let {
index
} = e.currentTarget.dataset
let {
tags
} = this.data
const name = `tags[${index}].checked`
// console.log(name, 'name')
// console.log(!tags[index].checked)
// console.log(tags[index])
this.setData({
[name]: !tags[index].checked
})
// customerComment = `${customerComment || ''}${tags[index]}`
// this.setData({
// customerComment
// })
},
setStar(e) {
let {
index
} = e.currentTarget.dataset
this.setData({
rating: ++index
})
},
// 删除图片
handleDelete(e) {
let {
index
} = e.currentTarget.dataset
let {
constructionImgList
} = this.data
constructionImgList.splice(index, 1)
this.setData({
constructionImgList
})
},
// 放大图片
handlePreviewImg(e) {
let {
item
} = e.currentTarget.dataset
console.log(item)
wx.$util.previewImage({
urls: [item]
})
},
handleUpload(e) {
let that = this
let {
constructionImgList
} = this.data
wx.chooseImage({
count: 1,
success(res) {
let [tempFiles] = res.tempFilePaths
let tempFilesList = tempFiles.split('.')
let imgType = tempFilesList[tempFilesList.length - 1]
let type = imgType == 'unknown' ? 'jpg' : imgType
wx.getFileSystemManager().readFile({
filePath: tempFiles, //选择图片返回的相对路径
encoding: 'base64', //编码格式
success(_res) {
wx.$util.showLoading('上传中...')
uploadImg({
file: `${type}@${_res.data}`
}).then(img => {
wx.$util.hideLoading()
let {
code,
data,
message
} = img
if (code == 0) {
constructionImgList.push(data)
that.setData({
constructionImgList
})
} else {
wx.$util.showToast(message)
}
})
}
})
}
})
},
checkPhoneShow(config) {
// 有就屏蔽手机号的显示
if (config) {
let {
customerObj
} = this.data
delete customerObj[2]
this.setData({
customerObj
})
}
},
async getOrderDetail(orderCode) {
// console.log(orderCode)
let _this = this
let { baseConfigData, isUseFilmRoll } = _this.data
let userInfo = wx.$util.getUserInfo()
wx.$util.showLoading('加载中...')
const positionTypeList = await getPositionList() || []
api
.getPackageGoodsDetail({
orderCode
})
.then(async res => {
let {
code,
message,
data,
isUseFilmRoll
} = res
if (code == 0) {
wx.$util.hideLoading()
let couponName = data.customerCoupon ? data.customerCoupon.couponName : ''
let total_price = 0
let warrantyCardList = []
// 服务商是否使用膜卷号配置
// 服务商是否使用膜卷号配置
if (!userInfo?.isSuper && userInfo.userType == 2 && data.status != 10) {
isUseFilmRoll = await getServiceFilmRollSetting(data?.sellerMerchantId)
this.setData({
isUseFilmRoll
})
}
for (var i = 0; i < data?.subOrderList?.length; i++) {
let e = data?.subOrderList[i]
total_price += e.totalPrice
e.price = Number(wx.$util.decimal(Number(e.totalPrice / e.number), 2)).toFixed(2)
e.positionStr = positionTypeList.filter(v => v.positionValue == e.upgradeGoodsPosition)[0]?.positionName || ''
if ((e.upgradeWarrantyPeriod || e.upgradeWarrantyPeriod > 0) && data.selectPayType != 0) {
warrantyCardList.push({
warrantyPeriod: e.upgradeWarrantyPeriod,
goodsName: e.upgradeGoodsAlias || e.upgradeGoodsName,
cardCode: e.cardCode
})
}
// 膜类商品 并且服务商开通了使用膜卷号配置
if (baseConfigData?.membraneTypeList?.includes(e?.upgradeGoodsType) && isUseFilmRoll) {
let result = await api.getfilmRollNoByGoods({upgradeGoodsId: e.upgradeGoodsId, yqMerchantId: data?.sellerMerchantId, merchantId: data?.merchantId})
e.filmNumberData = result?.data || []
// 仅配置一个膜卷号 自动选中
if (!e.filmRollNo && e.filmNumberData?.length == 1) e.filmRollNo = e.filmNumberData[0]
}
}
if(data.packageGoodsList){
data.packageGoodsList.forEach(item => {
item.packageGoodsOrderList.forEach(g=>{
g.price= g.totalPrice?Number(g.totalPrice) / Number(g.number):g.upgradePrice
})
item.goodsList=item.packageGoodsOrderList
item.price = item.goodsList.reduce((prev, cur) => {
return prev + Number(cur.totalPrice) / Number(cur.number)
}, 0)
item.count = item.goodsList.length ? item.goodsList[0].number : 1
let total = item.price * item.count
item.totalPrice = wx.$util.decimal(total, 2)
item.packageGoodsOrderList.forEach(g => {
g.positionStr = positionTypeList.filter(v => v.positionValue == g.upgradeGoodsPosition)[0]?.positionName || ''
})
total_price += item.totalPrice
})
}
data = {
...data.customer,
...data.payOrder,
...data,
packageGoodsList: data.packageGoodsList,
couponName,
total_price: data.selectPayType == 0 ? 0 : Number(wx.$util.decimal(total_price, 2)).toFixed(2)
}
if (data.customerCoupon) {
data.customerCoupon.customerCouponCode = data.customerCoupon.customerCouponCode.split('-')[0]
}
if (data.orderTime) data.time = new Date(data.orderTime).format('yyyy-MM-dd hh:mm:ss')
if (data.customer && data.customer.carSeriesName) {
data.carType = `${data.customer.carBrand || ''}-${data.customer.carChildsBrandName || ''}-${data.customer.carSeriesName || ''}`
}
this.setData({
orderInfo: data,
// flag: true,
warrantyCardList
})
// 条形码
// warrantyCardList.length && this.getBarCode()
// this.getServiceBaseInfo(data.merchantId)
// 校验是否显示二级流量方
// if (data.subShopMerchantName) {
// let { customerObj } = this.data
// if (customerObj.findIndex(val => val.key == 'subShopMerchantName') < 0) {
// customerObj[customerObj.length - 2] = {
// label: '二级流量方',
// key: 'subShopMerchantName'
// }
// }
// this.setData({
// customerObj
// })
// }
// 门店是否配置技师
// if (data?.technicianConfigDTOList?.length > 0) {
// this.isArtificer(data)
// }
// 获取园区店技师配置数据 wx.$util.getStorageSync('dj_boutique_user_info')?.merchantId
api.getQYTechnicianList({yqMerchantId: wx.$util.getStorageSync('dj_boutique_user_info')?.merchantId}).then(respone => {
if (respone?.code == 0) {
if (respone?.data.length > 0) this.isArtificer(respone.data)
}
})
} else {
wx.showModal({
title: '温馨提示',
content: message,
showCancel: false,
confirmText: '刷新',
confirmColor: '#347BFF',
success(res) {
if (res.confirm) {
_this.getOrderDetail(orderCode)
}
}
})
}
})
},
async getPackageGoodsDetail(orderCode) {
try {
let params = {
orderCode
}
let {total_price}=this.data.orderInfo;
const positionTypeList = await getPositionList() || []
api.getPackageGoodsDetail(params).then(res => {
res.data.packageGoodsList.forEach(item => {
item.packageGoodsOrderList.forEach(g=>{
g.price= g.totalPrice?Number(g.totalPrice) / Number(g.number):g.upgradePrice
})
item.goodsList=item.packageGoodsOrderList
item.price = item.goodsList.reduce((prev, cur) => {
return prev + Number(cur.totalPrice) / Number(cur.number)
}, 0)
item.count = item.goodsList.length ? item.goodsList[0].number : 1
let total = item.price * item.count
item.totalPrice = wx.$util.decimal(total, 2)
item.packageGoodsOrderList.forEach(g => {
g.positionStr = positionTypeList.filter(v => v.positionValue == g.upgradeGoodsPosition)[0]?.positionName || ''
})
total_price = Number(total_price)+Number(item.totalPrice)
})
if (res.code == 0) {
this.setData({
packageGoodsList: res.data.packageGoodsList,
'orderInfo.total_price': Number(wx.$util.decimal(total_price, 2)).toFixed(2)
})
}
})
} catch (err) {
}
},
isArtificer(data) {
let { customerObj, orderInfo } = this.data
orderInfo.isOpenArtificer = true
orderInfo.technicianList = data || [] // 技师数据
this.setData({
artificerList: data,
customerObj,
orderInfo
})
},
// 选择技师确认
changeArtificer(e) {
let value = e?.detail || {}
let { orderInfo } = this.data
orderInfo?.subOrderList?.forEach(val => {
if (val.subOrderCode == value?.subOrderCode) {
val.technicianName = value.technicianName
val.technicianUuid = value.technicianUuid
val.technicianId = value.technicianId
}
})
let params ={
orderCode: orderInfo?.orderCode,
subOrderCode: value?.subOrderCode,
technicianName: value?.technicianName,
technicianUuid: value?.technicianUuid,
technicianId: value?.technicianId
}
api.updateTechnicianInfo(params).then(res => {
let { code, message } = res
if (code == 0) {
this.setData({
artificerSelectPopup: false,
artificerSelectObj: value,
orderInfo
})
} else {
wx.$util.showToast(message)
}
})
},
// 选择膜卷号
selectfilmRollNo(e) {
let { item, index } = e.currentTarget.dataset
this.setData({
filmRollNoList: item?.filmNumberData,
selectFilmNumberIndex: index,
filmSelectedItem: item?.filmNo,
filmRollNoPopup: true
})
},
// 选择膜卷号确认
changefilmRollNo(e) {
let { selectFilmNumberIndex } = this.data
let prop = `orderInfo.subOrderList[${selectFilmNumberIndex}].filmRollNo`
this.setData({
[prop]: e?.detail,
filmRollNoPopup: false
})
},
// 选择技师
selectArtificer(e) {
let { item } = e.currentTarget.dataset
this.setData({
artificerSelectPopup: true,
artificerSelectObj: item
})
},
keepGoing(type) {
let {
orderInfo
} = this.data
orderInfo.orderSource = type
delete orderInfo.orderCode
wx.$router.redirectTo('createOrder', orderInfo)
},
previewImage(e) {
let {
url
} = e.currentTarget.dataset
// if (url.includes('http')) {
wx.previewImage({
urls: [url],
current: url
})
},
toFullPage() {
let {
id,
orderId
} = this.data
wx.$router.go('fullSignture', {
id,
orderId
})
},
// 上传图片
toUploadImage(tempFilePaths) {
let _this = this
const tempFiles = tempFilePaths
let imgType = tempFiles.split('.')[1]
let type = imgType == 'unknown' ? 'jpg' : imgType
return new Promise((resolve, reject) => {
wx.getFileSystemManager().readFile({
filePath: tempFiles, //选择图片返回的相对路径
encoding: 'base64', //编码格式
success(_res) {
wx.$util.showLoading('上传中...')
uploadImg({
file: `${type}@${_res.data}`
}).then(res => {
wx.$util.hideLoading()
let {
data
} = res
resolve(data)
// _this.saveToHttp(data)
// 更新报价单状态
// _this.changeOrderStatus(data)
})
},
fail(err) {
reject(err)
wx.$util.hideLoading()
}
})
})
},
validForm() {
let {
hasDraw,
constructionImgList,
tags
} = this.data
let that = this
if (!hasDraw) {
wx.showToast({
title: '还未签字哟!',
icon: 'none',
mask: true
})
return
}
if (constructionImgList.length == 0) {
wx.showToast({
title: '请上传客户合照或车辆照片',
icon: 'none',
mask: true
})
return
}
const flags = tags.some(item => item.checked)
if (!flags) {
wx.showToast({
title: '请至少选择一个评价标签',
icon: 'none'
})
return
}
return true
},
async confirmConstruction() {
let {
constructionImgList: customerPhotos,
tags,
rating,
orderCode,
orderInfo,
signImage,
isUseFilmRoll
} = this.data
let that = this
// 校验表单
let valid = this.validForm()
console.log(valid);
// return
if (!valid) return
// 获取签名图片 有全屏的就取全屏的 没有就当前页面的
if (!signImage) {
const imgPatch = await this.getSignatureImg()
signImage = await this.toUploadImage(imgPatch)
}
const evaluationList = tags.reduce((list, item, index) => {
if (item.checked) {
list.push(index + 1)
}
return list
}, [])
customerPhotos = customerPhotos.map(item => {
return {
customerPhoto: item
}
})
let params = {
orderCode,
customerPhotos,
electronicSignature:signImage,
rating,
merchantId: orderInfo.merchantId,
sceneType: 1,
// tags,
evaluationList
}
// return
// 使用膜卷号
if (isUseFilmRoll) {
let flag = false
for (var i = 0; i < orderInfo?.subOrderList?.length; i++) {
let val = orderInfo?.subOrderList[i]
if (val?.filmNumberData?.length) {
if (!val.filmRollNo) return wx.$util.showToast(`请配置膜卷号`)
flag = true
}
}
if (flag) {
let arr = []
orderInfo?.subOrderList?.forEach(val => {
if (val?.filmNumberData?.length && val.filmRollNo) arr.push({ subOrderCode: val.subOrderCode, filmRollNo: val.filmRollNo })
})
api.setfilmRollNo({subOrderList: arr}).then(res => {
let { code, message } = res
if (code == 0) {
this.confirmEvent(params, orderInfo)
} else {
wx.$util.showToast(message)
}
}).catch(err => {
wx.$util.hideLoading()
})
} else {
this.confirmEvent(params, orderInfo)
}
} else {
this.confirmEvent(params, orderInfo)
}
},
confirmEvent(params, orderInfo) {
api
.customerConfirmationSignature(params)
.then(result => {
let {
code,
message
} = result
if (code == 0) {
// wx.$router.redirectTo('')
wx.$util.showToast({
title: '确认评价成功',
icon: 'success'
})
wx.$util.refreshPageData()
wx.$router.redirectTo('constructionOrderDetail', orderInfo)
} else {
wx.$util.showToast(message)
}
})
.catch(err => {})
},
getSignatureImg() {
let {
canvasHeight,
canvasWidth
} = this.data
let that = this
return new Promise((resolve, reject) => {
wx.canvasToTempFilePath({
x: 0,
y: 0,
width: canvasWidth,
height: canvasHeight,
canvasId: 'signature',
// fileType:'jpg',
success(res) {
if (res.tempFilePath) {
// that.toUploadImage(res.tempFilePath)
resolve(res.tempFilePath)
}
},
fail(err) {
console.log(err)
reject(err)
}
},
that
)
})
},
scaleStart(event) {
if (event.type != 'touchstart') return false
let currentPoint = {
x: event.touches[0].x,
y: event.touches[0].y
}
this.drawCircle(currentPoint)
this.setData({
startPoint: currentPoint,
hasDraw: true,
showPlaceHoder: false
})
},
scaleMove(event) {
if (event.type != 'touchmove') return false
let {
startPoint
} = this.data
let currentPoint = {
x: event.touches[0].x,
y: event.touches[0].y
}
this.drawLine(startPoint, currentPoint)
this.setData({
startPoint: currentPoint
})
},
scaleEnd(e) {
this.setData({
isStart: true
})
},
drawCircle(point) {
//这里负责点
let ctx = this.canvasCtx
ctx.beginPath()
// ctx.fillStyle = this.data.lineColor;
ctx.setFillStyle(this.data.lineColor)
//笔迹粗细由圆的大小决定
ctx.arc(point.x, point.y, this.data.radius, 0, 2 * Math.PI)
ctx.fill()
ctx.closePath()
ctx.draw(true)
},
drawLine(sourcePoint, targetPoint) {
let ctx = this.canvasCtx
this.drawCircle(targetPoint)
ctx.beginPath()
// ctx.strokeStyle = this.data.lineColor;
ctx.setStrokeStyle(this.data.lineColor)
// ctx.lineWidth = this.data.radius * 2; //这里乘2是因为线条的粗细要和圆的直径相等
ctx.setLineWidth(this.data.radius * 2)
ctx.moveTo(sourcePoint.x, sourcePoint.y)
ctx.lineTo(targetPoint.x, targetPoint.y)
ctx.stroke()
ctx.closePath()
},
clearCanvas() {
//清空画布
let ctx = this.canvasCtx
ctx.clearRect(0, 0, this.data.canvasWidth, this.data.canvasHeight)
ctx.fillStyle = 'rgba(0, 0, 0, .1)'
ctx.draw()
this.setData({
hasDraw: false, //未签字
showPlaceHoder: true,
signImage: ''
})
},
initCanvas() {
let that = this
let query = wx.createSelectorQuery().in(this) //获取自定义组件的SelectQuery对象
this.canvasCtx = wx.createCanvasContext('signature', that)
// 设置线的样式
this.canvasCtx.setFillStyle('white')
this.canvasCtx.fillRect(0, 0, 600, 600)
this.canvasCtx.setLineCap('round')
this.canvasCtx.setLineJoin('round')
// 初始化颜色
this.canvasCtx.setStrokeStyle(that.data.selectColor)
query
.select('.modal-canvas')
.boundingClientRect(rect => {
console.log(rect, 'rect')
this.setData({
canvasWidth: rect.width,
canvasHeight: rect.height
})
})
.exec()
},
async onRoute(options) {
// console.log(options)
// 调试用
// options.orderCode = '230427135616113'
if (options.orderCode) {
// 获取配置服务数据
let baseConfigData = await setConfigInfo(app.globalData)
this.setData({baseConfigData})
this.setData({
orderCode: options.orderCode
})
this.getOrderDetail(options.orderCode)
// this.getGrass(options.orderCode)
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: async function (options) {
if (options.orderCode) {
// 获取配置服务数据
let baseConfigData = await setConfigInfo(app.globalData)
this.setData({baseConfigData})
this.getOrderDetail(options.orderCode)
this.setData({
orderCode: options.orderCode
})
}
let o = wx.$util.getStorageSync('dj_boutique_user_info')
this.checkPhoneShow(app.globalData.YQorderSetting?.yqPhoneConfig)
this.setData({
isYqdSuper: app.globalData.isYqdSuper,
isStaff: app.globalData.isStaff,
userInfo: o
})
this.initCanvas() // 初始化画布
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {},
/**
* 生命周期函数--监听页面显示
*/
onShow: function (options) {
// console.log(this.data)
// let code = this.data.orderCode || ''
// this.getGrass(code)
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {}
})