CreateOrder.vue
37.3 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
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
<template>
<view class="order">
<view
:class="['order-box',{hide:showUpload}]"
:key="formKey"
>
<view class="common-title">车险信息</view>
<view class="box">
<scroll-view
class="scroll-view"
scroll-y="true"
>
<view class="box-content">
<GlCell
:formList="formList"
:formData="orderObj"
@radioChange="radioChange"
@inputBlur="inputBlur"
@handleCell="handleCell"
:titleList="titleList"
>
<template slot="customer">
<view class="customer-title flex">
客户信息
<view
class="customer-file flex"
@click="handleCell({
key:'customer'
})"
>
<view class="sprite-icon icon-customer-list"></view>
客户档案
</view>
</view>
</template>
<template slot="skuGoods">
<template v-if="orderObj.skuGoods.length">
<SkuGoods
:list="orderObj.skuGoods"
@changeTotalPrice="changeTotalPrice"
:positionTypeList="positionTypeList"
:baseConfigData="baseConfigData"
></SkuGoods>
</template>
<template v-if="orderObj.total > 0">
<view class="total">
<view class="total-left">总价</view>
<view class="total-right">¥{{ orderObj.total }}</view>
</view>
</template>
</template>
<template slot="otherPay">
<view
v-if="showPayTips"
class="pay-tips"
>其他收款:当客户已向嘀加付款但无法使用流水补录时,新建工单应选择收款方为「嘀加收款」且支付方为「其他收款」。</view>
</template>
</GlCell>
</view>
<view class="btns flex">
<view
class="btn save"
@click="handleEditSave"
>存草稿</view>
<view
@click="submit"
class="btn"
>{{confirmText}}</view>
</view>
</scroll-view>
</view>
</view>
<!-- 弹窗 -->
<order-popup
ref="orderPopup"
:data="orderObj"
:dataKey="valueKey"
@onConfirm="onConfirm"
:externalData="externalData"
:popupType="popupType"
:popupTitle="popupTitle"
/>
<template v-if="showUpload">
<view class="upload-box">
<upload-proof-of-payment
@back="clearPayMentDocList"
@confirm="uploadConfirm"
/>
</view>
</template>
<!-- 支付弹框 -->
<OrderPay
ref="OrderPay"
@closePopup="closePopup"
@jumpSuccess="jumpSuccess"
/>
</view>
</template>
<script>
import utils from '@/utils/utils'
import OrderPopup from '@/components/OrderPopup/index.vue'
import GlCell from '../../../../components/Form/GlCell.vue'
import Product from './Product.vue'
import Package from './Package.vue'
import SkuGoods from './SkuGoods.vue'
import { FORM_LIST, popupTypeEnum, titleList } from '../contant'
import { interceptionMixin } from '@/mixin/index'
import UploadProofOfPayment from './UploadProofOfPayment.vue'
import dayjs from 'dayjs'
import OrderPay from './OrderPay.vue'
import NP from 'number-precision'
import { validateVin, formatVinInput } from '@/utils/vinVaildate'
export default {
name: 'CreateOrder',
mixins: [interceptionMixin],
components: {
GlCell,
OrderPopup,
Product,
Package,
SkuGoods,
UploadProofOfPayment,
OrderPay
},
props: {
transmissionOfData: {
type: Object,
default: () => null
}
},
watch: {
'orderObj.payee': {
handler (val) {
this.formList[4].map(e => {
if (e.value == 'pay2Time') e.label = {
0: '嘀加收款时间',
1: '4S店收款时间'
}[val]
})
},
immediate: true,
deep: true
},
'orderObj.payType': {
handler (val) {
this.formList[4].map(e => {
if (e.value == 'notes') e.required = val == 7
if (e.value == 'pay2Time') e.hidden = ![2, 5, 6, 7].includes(+val)
})
},
immediate: true,
deep: true
},
transmissionOfData: {
handler (val) {
const paramsData = val?.paramsData || {}
if (paramsData && paramsData.id) this.paramsData = paramsData
},
deep: true,
immediate: true
}
},
data () {
return {
paramsData: {},
saveStatus: false,
showUpload: false,
titleList,
formList: utils.deepClone(FORM_LIST),
baseConfigData: {},
orderObj: {
mode: 1,
payee: 0, // 收款方式
payType: 1, // 支付方式
insurancePrice: '',
skuGoods: [], //商品列表
referrerId: '', //销售顾问id
referrer: '',//销售顾问名称
deliveryId: '',//交付专员id
deliveryName: '',//交付专员名称
total: '',//总价
notes: '',//备注
carSeriesId: '', //车系id
seat: '5',//座位数
ownerGender: '男',
salesType: '0',
carInfo: {},
price: ''
}, // 弹窗传入的数据},
popupType: 0,
popupTypeEnum,
externalData: [], //弹窗接口数据
djPayList: [], // 嘀加收款方对应支付方式
merchantPayList: [], // 门店收款方对应支付方式
configPayTypeList: [], // 园区店配置支持的支付方式
goodsList: [],
subOrderList: [],
otherProduct: [],
positionTypeList: [],
valueKey: '',
popupTitle: '',
pointsMultiRole: 'Y',
formKey: Date.now(),
validateState: true
}
},
computed: {
showPayTips () {
return this.orderObj.payee == 0 && this.orderObj.payType == 7
},
confirmText () {
return [1, 3].includes(+this.orderObj.payType) ? '下一步·去支付' : '下一步·上传凭证'
},
userInfo () {
return uni.$storage.get('userInfo') || {}
}
},
mounted () {
this.baseConfigData = uni.$storage.get('mock_data') || {}
this.initData()
},
methods: {
async getQuotationInfoById (id) {
try {
let { goodsList: quotationGoodsList } = this, data = await uni.$api.equityApi.getQuotationInfoById({ id }),
{ orderObj } = this,
{ owner, insurancePrice, quotedPriceUpdate } = data
uni.hideLoading()
orderObj.price = this.divideByHundred(owner.price)
orderObj.insurancePrice = this.divideByHundred(insurancePrice)
orderObj.quotedPriceUpdate = this.divideByHundred(quotedPriceUpdate)
if (!data.vdQuotationGoodsList) data.vdQuotationGoodsList = []
orderObj.vdQuotationGoodsList = data.vdQuotationGoodsList.map(
item => {
item.price = this.divideByHundred(item.goodsPrice)
return item
}
)
if (!owner.ownerGender) owner.ownerGender = '男'
if (owner.carSeriesId) {
orderObj.carInfo = {
carBrand: owner.carBrand,
carBrandId: owner.carBrandId,
carChildsBrandId: owner.carChildsBrandId,
carChildsBrandName: owner.carChildsBrandName,
carSeriesId: owner.carSeriesId,
carSeriesName: owner.carSeriesName,
}
orderObj.carBrandText = `${owner.carBrand}-${owner.carChildsBrandName}-${owner.carSeriesName}`
}
if (owner.city) {
let [provinceText, cityText] = owner.city.split('-')
if (cityText) {
orderObj.provinceText = provinceText
orderObj.cityText = cityText
} else {
orderObj.provinceText = owner.city
orderObj.cityText = owner.city
}
}
this.formList[1].map(e => {
if (e.value == 'salesType') e.current = owner.salesType
if (e.value == 'ownerGender') e.current = owner.ownerGender
})
orderObj.skuGoods = data.vdQuotationGoodsList.reduce((pre, item) => {
// 是普通商品
if (!item.packageName && !item.specificationsValue) {
console.log(item)
let obj = {
...item,
goodsInfo: item,
upgradeGoodsId: item.goodsId,
merchantGoodsId: item.goodsId,
sellPrice: this.divideByHundred(item.goodsPrice),
minSellPrice: quotationGoodsList?.find(
val => val?.goods?.merchantGoodsId == item.goodsId
)?.goods?.minSellPrice, // 按商品数据对比补充详情商品最低价
validMinSellPrice: quotationGoodsList?.find(
val => val?.goods?.merchantGoodsId == item.goodsId
)?.goods?.validMinSellPrice // 按商品数据对比补充详情商品校验最低价字段
}
pre.push({
goodsFlag: 1,
goods: obj,
packageGoods: null
})
}
//套餐
if (item.packageName) {
let obj = {
...item,
merchantGoodsId: item.goodsId,
upgradeGoodsId: item.goodsId,
sellPrice: this.divideByHundred(item.goodsPrice),
number: 1,
minSellPrice: quotationGoodsList
?.find(
val =>
val.packageGoods?.goodsList?.length &&
val.packageGoods?.packageCode == item?.packageId
)
?.packageGoods?.goodsList?.find(
subV => subV.merchantGoodsId == item.goodsId
)?.minSellPrice, // 按商品数据对比补充详情商品最低价
validMinSellPrice: quotationGoodsList
?.find(
val =>
val.packageGoods?.goodsList?.length &&
val.packageGoods?.packageCode == item?.packageId
)
?.packageGoods?.goodsList?.find(
subV => subV.merchantGoodsId == item.goodsId
)?.validMinSellPrice // 按商品数据对比补充详情商品校验最低价字段
}
let index = pre.findIndex(ele => {
if (ele.packageGoods) {
return ele.packageGoods.packageId == item.packageId
}
})
if (index != -1) {
pre[index].packageGoods.goodsList.push(obj)
pre[index].price = NP.plus(pre[index].price, obj.price)
} else {
pre.push({
goods: null,
goodsFlag: 3,
price: item.price,
packageGoods: {
...item,
packageCode: item.packageId,
goodsList: [{
...obj
}]
}
})
}
}
//多规格商品
if (!item.packageName && item.specificationsValue) {
let specificdata = this.handleSpecificationsEcho(item)
pre = pre.concat(specificdata)
}
return pre
}, [])
let keyList = ['mode', 'payee', 'payType', 'referrerId', 'referrer',
'deliveryId', 'deliveryName', 'notes', 'id', 'orderId'
], customerKeyList = ['owner', 'phone', 'certificateNo', 'carVin', 'seat', ,
'ownerGender', 'ageRange', 'hobby', 'companion', 'carColor', 'salesType', 'city']
keyList.map(key => {
if (data[key] != null) orderObj[key] = data[key]
})
customerKeyList.map(key => {
if (owner[key] != null) orderObj[key] = owner[key]
})
if (owner.id) orderObj.ownerId = owner.id
let payeeCell = this.formList[4].find(item => item.value === 'payee')
if (payeeCell) payeeCell.current = orderObj.payee
this.orderObj = orderObj
this.getConfig()
setTimeout(() => {
this.changeTotalPrice()
}, 0)
} catch (error) {
console.log(error)
uni.hideLoading()
if (error) uni.showToast({
title: error,
icon: 'none',
})
}
},
initData () {
// 埋点
// uni.$track.add({ eventCode: 'app_create_order' })
const { paramsData } = this
this.getSelectOrderGoodsList()
if (!paramsData.id) this.getConfig()
this.getShopMerchantPointConfig()
this.orderSettingList()
},
async orderSettingList () {
const { shopMerchantId } = this.userInfo,
params = {
scene: 0,
isRequired: 1,
merchantId: shopMerchantId
},
data = await uni.$api.equityApi.orderSettingList(params)
if (data) {
let required = data.reduce((pre, item) => {
if (item.isRequired) {
pre.push(item.fieldKey)
}
return pre
}, [])
if (required.includes('carBrand')) this.formList[2].map(e => {
if (e.value == 'carBrandText') e.required = true
})
if (required.includes('carNo')) this.formList[2].map(e => {
if (e.value == 'carVin') e.required = true
})
if (required.includes('idNumber')) this.formList[1].map(e => {
if (e.value == 'certificateNo') e.required = true
})
}
},
async getShopMerchantPointConfig () {
const { shopMerchantId: merchantId } = this.userInfo,
{ pointsMultiRole } = await uni.$api.equityApi.getShopMerchantPointConfig({
merchantId
})
this.pointsMultiRole = pointsMultiRole
if (pointsMultiRole != 'Y') this.formList[0].map(e => {
if (e.value == 'deliveryName') e.hidden = true
if (e.value == 'referrer') e.label = '推荐人'
})
},
// 选择行事件
handleCell (val) {
let { payType } = this.orderObj,
{ pointsMultiRole } = this
this.popupTitle = ''
// 获取当前选中的popupType
this.popupType = Object.keys(this.popupTypeEnum).find(key => this.popupTypeEnum[key].key === val.key) * 1
// 获取对应的list字段
const popupConfig = this.popupTypeEnum[this.popupType]
if (popupConfig && popupConfig.list) {
this.externalData = this[popupConfig.list] || []
} else {
this.externalData = []
}
// 定义产品相关字段数组
const productFields = ['skuGoods']
if (productFields.includes(val.value)) {
this.valueKey = val.value
this.externalData = utils.deepClone(this.goodsList)
}
this.popupTitle = {
0: pointsMultiRole == 'Y' ? '销售顾问/录单员' : '推荐人',
4: '车型',
13: payType == 2 ? '4S店收款时间' : '嘀加收款时间'
}[this.popupType]
this.$refs.orderPopup.open()
},
// 单选框change事件
radioChange (e, val) {
this.$set(this.orderObj, val.value, e.detail.value)
if (val.value == 'payee') this.changePayee()
},
// 弹窗确认回调
onConfirm (val, flag) {
console.log(JSON.parse(JSON.stringify(val)), 'onConfirm')
this.externalData = []
// // const { chooseContent } = val
const chooseContent = utils.deepClone(val.chooseContent)
// 根据popupTypeEnum优化处理
const _typeValue = this.popupTypeEnum[this.popupType]
console.log(_typeValue)
// 定义产品相关字段数组
if (val.popupType == 19) return this.setCustomerInfo(chooseContent)
const productFields = ['skuGoods']
if (_typeValue.key == 'carBrand') {
// 车型
this.$set(this.orderObj, 'carBrandText', `${chooseContent.carBrand}-${chooseContent.carChildsBrandName}-${chooseContent.carSeriesName}`)
Object.assign(this.orderObj, {
carInfo: chooseContent
})
}
else if (productFields.includes(_typeValue.key)) {
if (_typeValue.key == 'skuGoods') {
if (!this.orderObj.skuGoods) {
// 其他精品第一次赋值
this.$set(this.orderObj, 'skuGoods', chooseContent)
} else {
// 过滤出已选的goodFlag为2的对象
const selectedGoods = this.orderObj[_typeValue.key].filter(item => item.goodsFlag === 2)
const singleGoods = flag ? this.orderObj[_typeValue.key].filter(item => item.goodsFlag != 2) : chooseContent.filter(item => item.goodsFlag != 2)
const moreGoods = chooseContent
.filter(item => item.goodsFlag === 2)
.filter(item => {
return !selectedGoods.some(selectedItem => selectedItem.multipleSpecificationsGoods.goods.goodsId === item.multipleSpecificationsGoods.goods.goodsId)
})
console.log(singleGoods, '===')
// 合并已选的goodFlag为2的对象
this.orderObj.skuGoods = [...singleGoods, ...moreGoods, ...selectedGoods]
}
}
setTimeout(() => {
this.changeTotalPrice()
}, 0)
}
else {
if (_typeValue.key == 'city') {
this.$set(this.orderObj, 'provinceText', chooseContent.province)
this.$set(this.orderObj, 'cityText', chooseContent.city)
this.$set(this.orderObj, 'city', chooseContent.city == chooseContent.province ? chooseContent.city : `${chooseContent.province}-${chooseContent.city}`)
} else if (_typeValue.key == 'todayShow') {
this.$set(this.orderObj, 'pay2Time', chooseContent)
} else if (_typeValue.list == 'employeeList') {
this.$set(this.orderObj, _typeValue.targetIdKey, chooseContent[_typeValue.sourceIdKey])
this.$set(this.orderObj, _typeValue.targetNameKey, chooseContent[_typeValue.sourceNameKey])
} else this.$set(this.orderObj, _typeValue.key, chooseContent)
console.log(this.orderObj, 'this.orderObj')
}
console.log(this.orderObj)
},
// 输入框失去焦点事件
inputBlur (e, val) {
console.log(e, val)
if (val.value == 'price') {
this.orderObj[val.value] = parseFloat(this.orderObj[val.value]) > 2000000 ? 2000000 : this.orderObj[val.value]
return
}
this.orderObj[val.value] = this.orderObj[val.value]
// VIN车架号动态校验:车架号字段,动态转换为大写
if (val.value === 'carVin') this.validateVin()
},
validateVin () {
let carVinVal = this.orderObj.carVin;
if (carVinVal) {
this.orderObj.carVin = formatVinInput(carVinVal)
validateVin(this.orderObj.carVin).then(result => {
console.log("validateVin", result);
let { valid } = result.data;
this.validateState = valid
// 校验成功,所有提示已在公共方法中处理
console.log('车架号校验成功:', result)
}).catch(err => {
console.log("validateVinErr", result);
})
}
},
// 校验必填等规则
checkRequired () {
try {
const phoneRex = /^[1]([3-9])[0-9]{9}$/,
requiredArr = [],
onlyLabelItem = [],
{ orderObj } = this
this.formList.forEach(group => {
group.forEach(item => {
if (item.required === true && item.hidden !== true) {
if (item.isArray) onlyLabelItem.push(item)
else requiredArr.push(item)
}
})
})
// VIN车架号-动态校验
const carVin = this.orderObj.carVin
console.log("validateState", this.validateState);
if (carVin) {
// 前置判断
if (carVin.length !== 17) {
uni.showToast({ title: '请输入 17 位有效字符(支持大写 A-H/J-N/P-Z、0-9)', icon: 'none' })
return false
}
// 根据接口校验结果判断
if (carVin.length === 17 && !this.validateState) {
uni.showToast({ title: '车架号校验不匹配,请核对后重新输入', icon: 'none' })
return false
}
}
// 遍历requiredArr,检查orderObj中是否有对应的值
for (let i = 0; i < requiredArr.length; i++) {
const item = requiredArr[i]
// 兼容嵌套customer对象的情况
let value = orderObj[item.value]
if (value === undefined || value === null || value === '') throw `${item.label}不能为空`
// 如果是customerPhone,添加phoneRex校验
if (item.value === 'phone' && !phoneRex.test(value)) throw `请输入正确的${item.label}`
}
// if (orderObj.carVin) {
// if (!utils.validateVIN(orderObj.carVin)) throw '车架号校验不匹配,请核对后重新输入'
// }
if (onlyLabelItem.length) {
const labelFields = ['skuGoods']
const hasValue = labelFields.some(field => {
const value = orderObj[field]
return value !== undefined && value !== null && (Array.isArray(value) ? value.length > 0 : value !== '')
})
if (!hasValue) throw '请选择增值车损险商品'
}
if (orderObj.certificateNo && orderObj.certificateNo.length != 18) throw '请输入正确的18位证件号'
return true
} catch (error) {
if (error) uni.showToast({
title: error,
icon: 'none'
})
return false
}
},
// 提交
async submit () {
if (!this.checkRequired() || await this.checkDailyReport()) return
this.handleSecondConfirmCheck(true)
},
async handleSecondConfirmCheck (check) {
try {
let orderInfo = this.getInsurance(),
{ payType } = orderInfo
if (check &&
([2, 5, 6, 7].includes(+payType)) &&
!(orderInfo.transactionNo && orderInfo.paymentDocList.length)
) return this.showUpload = true
if (orderInfo.pay2Time && ![1, 3].includes(+payType)) orderInfo.pay2Time = dayjs(orderInfo.pay2Time).format('YYYY-MM-DD HH:mm:ss')
else delete orderInfo.pay2Time
uni.showLoading({
title: `${check ? '报价' : '保存'}中...`,
mask: true
})
orderInfo.check = check
let apiName = orderInfo.id ? 'updateQuotation' : 'quotationAdd'
const data = await uni.$api.equityApi[apiName](orderInfo)
this.saveStatus = false
if (data) {
this.showUpload = false
wx.hideLoading()
if (check) {
if ([2, 5, 6, 7].includes(+payType)) return this.$emit('jump', 'OrderManagement')
let status = await this.createWithPay(data)
if (status) this.$refs.OrderPay.open(data)
else throw false
} else this.$emit('jump', 'OrderManagement')
} else throw false
} catch (error) {
console.log(error)
this.saveStatus = false
uni.hideLoading()
uni.showToast({
title: '提交失败',
icon: 'none'
})
}
},
createWithPay (id) {
return new Promise((resolve, reject) => {
let para = {
id,
customerNameUrl: '',
orderStatus: 2
}
uni.$api.equityApi.quotationUpgrade(para).then(res => {
resolve(res)
})
})
},
getInsurance () {
let {
orderObj,
userInfo
} = this,
orderInfo = utils.deepClone(orderObj),
{
default4SStoreInfo
} = userInfo,
params = {
owner: {
...orderInfo.carInfo
}
}
if (orderInfo.id) params.id = orderInfo.id
params.merchantId4s = default4SStoreInfo?.merchantId
params.merchantName4s = default4SStoreInfo?.merchantName
orderInfo.price = this.multipliedByHundred(orderInfo.price)
params.insurancePrice = this.multipliedByHundred(
orderInfo.insurancePrice
)
params.quotedPriceUpdate = this.multipliedByHundred(
orderInfo.quotedPriceUpdate
)
params.minEquityPrice = this.multipliedByHundred(
orderInfo.minEquityPrice
)
params.vdQuotationGoodsList = orderInfo.skuGoods.reduce(
(pre, item) => {
if (item.goods) {
item = item.goods
const obj = {
goodsId: item.merchantGoodsId,
goodsName: item.goodsName,
goodsNameAlias: item.goodsAlias || item.goodsNameAlias,
specificationsName: item.specificationNameSequence,
specificationsValue: item.specificationData ?
item.specificationData.replace(/;~;/g, '/') : '',
goodsPrice: this.multipliedByHundred(item.sellPrice)
}
pre.push(obj)
}
if (item.packageGoods) {
item = item.packageGoods
item.goodsList.map(ele => {
let obj = {
packageId: item.packageCode,
packageName: item.packageName,
packageNameAlias: item.packageAlias || item.packageNameAlias,
goodsId: ele.merchantGoodsId || ele.upgradeGoodsId,
goodsName: ele.upgradeGoodsName || ele.goodsName,
goodsNameAlias: ele.goodsAlias || ele.goodsNameAlias,
specificationsName: ele.specificationNameSequence,
specificationsValue: ele.specificationData ?
ele.specificationData.replace(/;~;/g, '/') : '',
// specificationsValue: item.specificationData ? item.specificationData.replace(reg, ' ') : '',
goodsPrice: this.multipliedByHundred(ele.sellPrice)
}
pre.push(obj)
})
}
if (item.multipleSpecificationsGoods) {
if (item.multipleSpecificationsGoods.goods) {
item = item.multipleSpecificationsGoods.goods
const obj = {
goodsId: item.merchantGoodsId,
goodsName: item.upgradeGoodsName || item.goodsName,
goodsNameAlias: item.goodsAlias || item.goodsNameAlias,
specificationsName: item.specificationNameSequence,
specificationsValue: item.specificationData ?
item.specificationData.replace(/;~;/g, '/') : '',
goodsPrice: this.multipliedByHundred(item.sellPrice)
}
pre.push(obj)
}
}
return pre
},
[]
)
let keyList = ['mode', 'payee', 'payType', 'referrerId', 'referrer',
'deliveryId', 'deliveryName', 'total', 'notes', 'tradeNo',
'transactionNo', 'paymentDocList', 'id', 'orderId', 'pay2Time'
],
customerKeyList = [
'owner', 'phone', 'certificateNo', 'carVin', 'seat', 'price',
'ownerGender', 'city', 'ageRange', 'hobby', 'companion', 'carColor', 'salesType'
]
keyList.map(key => {
if (orderInfo[key] != null) params[key] = orderInfo[key]
})
customerKeyList.map(key => {
if (orderInfo[key] != null) params.owner[key] = orderInfo[key]
})
if (orderInfo.ownerId) params.owner.id = orderInfo.ownerId
return params
},
// 乘以100保留两位小数点
multipliedByHundred (str) {
let floatVal = parseFloat(str)
if (isNaN(floatVal)) {
return 0
}
floatVal = Math.round(str * 10000) / 100
let strVal = floatVal.toString()
let searchVal = strVal.indexOf('.')
if (searchVal < 0) {
searchVal = strVal.length
strVal += '.'
}
while (strVal.length <= searchVal + 2) {
strVal += '0'
}
return parseFloat(strVal)
},
// 计算所有产品的总价
changeTotalPrice () {
let total = 0
// 遍历所有商品
const productFields = ['skuGoods']
productFields.forEach(slotName => {
const productList = this.orderObj[slotName]
if (Array.isArray(productList) && productList.length > 0) {
// 计算每个产品的价格 * 数量,并累加到总价
productList.forEach(item => {
if (item.goods && item.goods.sellPrice && item.goods.number) {
console.log(item.goods, '---单商品')
total = NP.plus(total, NP.times(item.goods.sellPrice, item.goods.number))
} else if (item.packageGoods && item.packageGoods.totalPrice) {
console.log(item.packageGoods, '套餐')
item.packageGoods.goodsList.map(i => {
total = NP.plus(total, i.sellPrice * i.number)
})
} else if (item.multipleSpecificationsGoods && item.multipleSpecificationsGoods.goods && item.multipleSpecificationsGoods.goods.sellPrice) {
console.log(item.multipleSpecificationsGoods, '多规格')
total = NP.plus(total, NP.times(item.multipleSpecificationsGoods.goods.sellPrice, item.multipleSpecificationsGoods.number || 1))
}
})
}
})
console.log(total, 'total')
// 更新总价
this.orderObj.total = total.toFixed(2)
},
// 获取园区店支付方式
async getConfig () {
this.djPayList = [
{
value: '1',
name: '微信支付'
},
{
name: '对公转账',
value: '6'
},
{
name: '其它收款',
value: '7'
},
]
this.merchantPayList = [{
value: '2',
name: '门店收款'
},]
this.changePayee()
},
changePayee () {
const cell = this.formList[4].find(item => item.value === 'payType'),
{ payType } = this.orderObj
if (cell) {
cell.radioList = this.orderObj.payee == 1 ? this.merchantPayList : this.djPayList
let index = cell.radioList.findIndex(i => i.value == payType)
if (index == -1) index = 0
if (cell.radioList && cell.radioList.length > 0) {
cell.current = cell.radioList[index].value
// 使用 $set 确保响应式更新
this.$set(this.orderObj, 'payType', cell.radioList[index].value)
}
}
},
// 商品列表
async getSelectOrderGoodsList () {
const { userInfo, paramsData } = this
if (paramsData.id) uni.showLoading({
title: '加载中...',
mask: true
})
const res = await uni.$api.boutiqueApi.getSelectOrderGoodsList({
merchantId: userInfo.shopMerchantId,
sceneType: userInfo.sceneType
})
this.goodsList = res
this.changeTotalPrice()
if (paramsData.id) this.getQuotationInfoById(paramsData.id)
},
handleSpecificationsEcho (item) {
console.log('item', item)
let {
goodsList: quotationGoodsList
} = this, skuArr = [],
arr = item.specificationsValue.split('/'),
str = arr.join(';~;');
quotationGoodsList.forEach(data => {
if (data.goodsFlag == 2) {
let tempData = data.multipleSpecificationsGoods.specificationGoodsMap[str]
if (tempData) {
tempData.forEach(temp => {
if (temp.merchantGoodsId == item.goodsId) {
let obj = {
goodsFlag: 2,
goods: null,
}
obj.multipleSpecificationsGoods = {
goods: temp,
baseGoodsName: item.goodsName
}
temp.price = this.divideByHundred(item.goodsPrice)
temp.goodsId = item.goodsId
temp.specificationStr = item.specificationsValue
console.log('🚀', obj)
skuArr.push(obj)
}
})
}
}
})
return skuArr
},
uploadConfirm ({
payVoucherList,
outTradeNo
}) {
let paymentDocList = []
payVoucherList.map(e => {
paymentDocList.push({
paymentDocUrl: e,
type: 1
})
})
this.orderObj.transactionNo = outTradeNo
this.orderObj.tradeNo = outTradeNo
this.orderObj.paymentDocList = paymentDocList
this.submit()
},
setCustomerInfo (customerInfo) {
const { orderObj } = this,
ownerGender = customerInfo.customerSex != 2 ? '男' : '女',
salesType = customerInfo.salesType || '0',
city = customerInfo.customerCity
Object.assign(orderObj, {
customerId: customerInfo.id,
owner: customerInfo.customerName,
phone: customerInfo.customerPhone,
ownerGender,
seat: customerInfo.carSeat || 5,
ageRange: customerInfo.customerAgeRange,
hobby: customerInfo.customerHobby,
companion: customerInfo.customerCompanion,
certificateNo: customerInfo.customerCertificateNo || '',
salesType,
carVin: customerInfo.carVin || '',
carColor: customerInfo.carColor || '',
})
this.formList[1].map(e => {
if (e.value == 'salesType') e.current = salesType
if (e.value == 'ownerGender') e.current = ownerGender
})
if (city) {
let [provinceText, cityText] = city.split('-')
if (cityText) {
orderObj.provinceText = provinceText
orderObj.cityText = cityText
} else {
orderObj.provinceText = city
orderObj.cityText = city
}
orderObj.city = city
}
if (customerInfo.carPrice) orderObj.price = this.divideByHundred(customerInfo.carPrice)
if (customerInfo.salesUuid) {
orderObj.referrerId = customerInfo.salesUuid
orderObj.referrer = customerInfo.salesName
}
if (customerInfo.carSeriesName) {
orderObj.carInfo = {
carBrand: customerInfo.carBrand,
carBrandId: customerInfo.carBrandId,
carChildsBrandId: customerInfo.carChildsBrandId,
carChildsBrandName: customerInfo.carChildsBrandName,
carSeriesId: customerInfo.carSeriesId,
carSeriesName: customerInfo.carSeriesName,
}
orderObj.carBrandText = `${customerInfo.carBrand}-${customerInfo.carChildsBrandName}-${customerInfo.carSeriesName}`
}
this.orderObj = orderObj
this.formKey = Date.now()
this.validateVin()
console.log(this.orderObj)
},
jumpSuccess (params) {
this.$emit('jump', 'OrderDetail', params)
},
async handleEditSave () {
let {
saveStatus
} = this
if (saveStatus) return false
this.saveStatus = true
this.handleSecondConfirmCheck(false)
},
divideByHundred: str => {
let floatVal = parseFloat(str)
if (isNaN(floatVal)) {
return 0
}
floatVal = Math.round(str * 100) / 10000
let strVal = floatVal.toString()
let searchVal = strVal.indexOf('.')
if (searchVal < 0) {
searchVal = strVal.length
strVal += '.'
}
while (strVal.length <= searchVal + 2) {
strVal += '0'
}
return parseFloat(strVal)
},
closePopup () {
this.$emit('jump', 'OrderManagement')
},
clearPayMentDocList () {
this.showUpload = false
this.orderObj.paymentDocList = []
this.orderObj.transactionNo = ''
}
}
}
</script>
<style scoped lang="scss">
.order {
height: 100%;
position: relative;
&-box {
visibility: visible;
height: 100%;
}
.hide {
opacity: 0;
visibility: hidden;
}
.upload-box {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
}
.box {
height: calc(100% - #{toRpx(120)});
padding-bottom: toRpx(24);
.scroll-view {
height: 100%;
}
}
.box-content {
padding: 0 toRpx(48);
}
.total {
display: flex;
justify-content: space-between;
align-items: center;
padding: toRpx(24) toRpx(32) toRpx(24) 0;
font-size: toRpx(28);
border-bottom: toRpx(2) solid #f7f7f6;
&-left {
color: #333;
font-weight: 500;
}
&-right {
color: #f24724;
font-weight: 500;
}
}
.pay-tips {
padding: toRpx(24) toRpx(24) toRpx(24) 0;
font-size: toRpx(24);
color: #999;
}
.btns {
padding: toRpx(24) toRpx(128);
gap: toRpx(32);
.save {
background: #3b73ff1a;
color: #4673ff;
font-size: toRpx(28);
font-weight: 500;
}
}
.btn {
display: flex;
align-items: center;
justify-content: center;
width: toRpx(1130);
height: toRpx(80);
color: #fff;
border-radius: toRpx(48);
background: linear-gradient(0deg, #2c66f7 0%, #48a6ff 100%);
}
.customer-title {
.customer-file {
margin-left: toRpx(20);
color: #347bff;
font-size: toRpx(24);
.sprite-icon {
margin-right: toRpx(4);
}
}
}
</style>