CreateOrder.vue
41.2 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
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
<template>
<view class="order">
<view class="common-title">{{ orderCreateType == 'createWithPay' ? '新建工单' : '补录订单' }}</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"
>
<template slot="frontGear">
<Product
v-if="orderObj.frontGear"
@changeTotalPrice="changeTotalPrice"
:list="orderObj.frontGear"
:positionTypeList="positionTypeList"
:baseConfigData="baseConfigData"
></Product>
</template>
<template slot="frontWindow">
<Product
v-if="orderObj.frontWindow"
@changeTotalPrice="changeTotalPrice"
:list="orderObj.frontWindow"
:positionTypeList="positionTypeList"
:baseConfigData="baseConfigData"
></Product>
</template>
<template slot="rearWindow">
<Product
v-if="orderObj.rearWindow"
@changeTotalPrice="changeTotalPrice"
:list="orderObj.rearWindow"
:positionTypeList="positionTypeList"
:baseConfigData="baseConfigData"
></Product>
</template>
<template slot="rearGear">
<Product
v-if="orderObj.rearGear"
@changeTotalPrice="changeTotalPrice"
:list="orderObj.rearGear"
:positionTypeList="positionTypeList"
:baseConfigData="baseConfigData"
></Product>
</template>
<template slot="sunRoof">
<Product
v-if="orderObj.sunRoof"
@changeTotalPrice="changeTotalPrice"
:list="orderObj.sunRoof"
:positionTypeList="positionTypeList"
:baseConfigData="baseConfigData"
></Product>
</template>
<template slot="package">
<Package
v-if="orderObj.package"
@changeTotalPrice="changeTotalPrice"
:list="orderObj.package"
:positionTypeList="positionTypeList"
></Package>
</template>
<template slot="skuGoods">
<SkuGoods
v-if="orderObj.skuGoods"
:list="orderObj.skuGoods"
@changeTotalPrice="changeTotalPrice"
:positionTypeList="positionTypeList"
:baseConfigData="baseConfigData"
></SkuGoods>
<view
class="total"
v-if="totalPrice > 0"
>
<view class="total-left">总价</view>
<view class="total-right">¥{{ totalPrice }}</view>
</view>
</template>
<template slot="otherPay">
<view
v-if="showPayTips"
class="pay-tips"
>其他收款:当客户已向嘀加付款但无法使用流水补录时,新建工单应选择收款方为「嘀加收款」且支付方为「其他收款」。</view>
</template>
</GlCell>
</view>
<view
@click="submit"
class="btn"
>直接下单</view>
</scroll-view>
</view>
<!-- 弹窗 -->
<order-popup
ref="orderPopup"
:data="orderObj"
:dataKey="valueKey"
@onConfirm="onConfirm"
:externalData="externalData"
:popupType="popupType"
/>
</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, payTypeList } from '../contant'
import { interceptionMixin } from '@/mixin/index'
import { validateVin, formatVinInput } from '@/utils/vinVaildate'
export default {
name: 'CreateOrder',
mixins: [interceptionMixin],
components: {
GlCell,
OrderPopup,
Product,
Package,
SkuGoods
},
props: {
transmissionOfData: {
type: Object,
default: () => null
}
},
watch: {
transmissionOfData: {
handler (newVal) {
if (newVal) {
// 处理交易数据
const handleTransactionData = newVal => {
console.log('接收到的交易数据:', newVal)
this.orderCreateType = newVal.type
if (this.orderCreateType === 'supplementOrder') {
// 补录订单处理
const { outTradeNo, tradeNo } = newVal.selectedItems.reduce(
(acc, item) => ({
outTradeNo: [...(acc.outTradeNo || []), item.outTradeNo],
tradeNo: [...(acc.tradeNo || []), item.tradeNo]
}),
{}
)
Object.assign(this.orderObj, {
outTradeNo: outTradeNo.join(','),
tradeNo: tradeNo.join(',')
})
return
}
// 编辑和修改订单进入这里
// 新增订单处理
const {
paramsData: { customer, customerCoupon, ...rest }
} = newVal
// 基础字段映射
const baseFields = ['id', 'orderCode', 'userId', 'employeeName', 'deliveryEmployeeName', 'deliveryUserId', 'subShopMerchantName', 'subShopMerchantId', 'sellerName', 'sellerUserId', 'sellerMerchantName', 'sellerMerchantId', 'merchantId', 'merchantName', 'customerCouponId', 'selectPayType']
Object.assign(this.orderObj, Object.fromEntries(baseFields.map(field => [field, rest[field]])))
// 设置支付类型
this.orderObj.payeeType = rest.selectPayType == '2' ? '1' : '0'
// 客户信息映射
const customerFields = ['customerName', 'customerSex', 'customerPhone', 'salesType', 'standNo', 'plateNumber', 'experienceFlag']
Object.assign(this.orderObj, Object.fromEntries(customerFields.map(field => [field, customer[field]])))
// 优惠券信息
const { couponName, customerCouponCode } = customerCoupon
Object.assign(this.orderObj, {
couponName,
customerCouponCode,
couponInfo: couponName + customerCouponCode
})
// 车辆信息
this.orderObj.customer = {
carBrand: customer.carBrand,
carBrandId: customer.carBrandId,
carChildsBrandId: customer.carChildsBrandId,
carChildsBrandName: customer.carChildsBrandName,
carSeriesId: customer.carSeriesId,
carSeriesName: customer.carSeriesName,
customerPhone: customer.customerPhone,
standNo: customer.standNo,
plateNumber: customer.plateNumber,
customerSex: customer.customerSex,
experienceFlag: customer.experienceFlag,
salesType: customer.salesType,
customerName: customer.customerName
}
this.orderObj.carBrand = customer.carBrandId ? `${customer.carBrand}-${customer.carChildsBrandName}-${customer.carSeriesName}` : ''
// 更新表单状态
const updateFormCell = (formIndex, fieldName, value) => {
const cell = this.formList[formIndex].find(item => item.value === fieldName)
if (cell) cell.current = value
}
const formUpdates = [
[1, 'salesType', customer.salesType],
[1, 'customerSex', customer.customerSex],
[1, 'experienceFlag', customer.experienceFlag],
[2, 'selectPayType', this.orderObj.selectPayType],
[2, 'payeeType', this.orderObj.payeeType]
]
formUpdates.forEach(([index, field, value]) => updateFormCell(index, field, value))
// 商品回显,在获取商品列表之后
this.subOrderList = rest.subOrderList
}
console.log(this.orderObj, 'orderObj')
handleTransactionData(newVal)
} else {
this.userInfo = uni.$storage.get('userInfo') || {}
this.baseConfigData = uni.$storage.get('mock_data') || {}
this.orderCreateType = 'createWithPay'
this.orderObj = {
customer: {},
customerSex: '1',
experienceFlag: 'Y',
payeeType: 1,
salesType: '0',
frontGear: null, // 1 ,回显upgradeGoodsPosition == 1
frontWindow: null, // 2
rearWindow: null, // 3
rearGear: null, // 4
sunRoof: null, // 5, 6,7
package: null,
skuGoods: null // upgradeGoodsPosition 为空,则是其他精品单商品
}
this.initData()
}
},
immediate: true
}
},
data () {
return {
orderCreateType: 'createWithPay', // supplementOrder(补录订单) createWithPay(新增)
formList: utils.deepClone(FORM_LIST),
userInfo: {},
baseConfigData: {},
requiredList: [], // 录单设置的必填项
orderObj: {
customer: {},
customerSex: '1',
experienceFlag: 'Y',
payeeType: 1,
salesType: '0',
frontGear: null, // 1 ,回显upgradeGoodsPosition == 1
frontWindow: null, // 2
rearWindow: null, // 3
rearGear: null, // 4
sunRoof: null, // 5, 6,7
package: null,
skuGoods: null // upgradeGoodsPosition 为空,则是其他精品单商品
}, // 弹窗传入的数据},
popupType: 0,
popupTypeEnum,
externalData: [], //弹窗接口数据
subShopMerchantList: [], // 二级流量方列表
employeeList: [],
djPayList: [], // 嘀加收款方对应支付方式
merchantPayList: [], // 门店收款方对应支付方式
configPayTypeList: [], // 园区店配置支持的支付方式
payTypeList,
goodsList: [],
subOrderList: [],
otherProduct: [],
positionTypeList: [],
valueKey: '',
totalPrice: 0,
validateState: true,
// 产品槽位配置,用于循环渲染产品组件
productSlots: {
frontGear: true,
frontWindow: true,
rearGear: true,
rearWindow: true,
sunRoof: true
}
}
},
computed: {
showPayTips () {
if (this.orderObj.payeeType == 0 && this.orderObj.selectPayType == 7) return true
else return false
}
},
mounted () {
console.log('mounted', this.orderCreateType)
this.userInfo = uni.$storage.get('userInfo') || {}
this.baseConfigData = uni.$storage.get('mock_data') || {}
this.initData()
},
methods: {
initData () {
console.log('initData', this.orderCreateType, this.orderObj.id)
// 埋点
if (this.orderCreateType == 'createWithPay' && !this.orderObj.id) {
uni.$track.add({ eventCode: 'app_create_order' })
} else if (this.orderCreateType == 'supplementOrder') {
uni.$track.add({ eventCode: 'app_supplement_order' })
}
const { userInfo } = this
if (!this.orderObj.id) {
// 在原有的 orderObj 对象上新增这些属性
Object.assign(this.orderObj, {
sellerMerchantName: userInfo.merchantName,
sellerName: userInfo.name,
sellerMerchantId: userInfo.merchantId,
sellerUserId: userInfo.uuid,
merchantId: userInfo.shopMerchantId,
merchantName: userInfo.shopMerchantName
})
}
this.getShopMerchantPointConfig(this.orderObj.merchantId)
this.getSubShopMerchantList(this.orderObj.merchantId)
this.getSetting()
// 补录订单默认为嘀加收款,不需要获取园区店支付方式
if (this.orderCreateType == 'supplementOrder') {
this.orderObj.payeeType = 0
const cell = this.formList[2].find(item => item.value == 'payeeType')
if (cell) {
cell.current = 0
cell.radioList[1].disabled = true // 禁用4s店收款
}
this.djPayList = [
{
value: '5',
name: '嘀加收款'
}
]
this.changePayee()
} else {
// 防止从补录进来4s店收款为禁用
const cell = this.formList[2].find(item => item.value == 'payeeType')
if (cell) {
// 编辑订单时,使用已有的payeeType值,新建订单时使用默认值1
if (!this.orderObj.id) {
cell.current = 1
} else {
cell.current = this.orderObj.payeeType
}
cell.radioList[1].disabled = false
}
this.getConfig()
}
// this.getEmployeeList()
this.getSelectOrderGoodsList()
this.getPositionList()
if (this.orderCreateType == 'createWithPay' && !this.orderObj.id) this.getLastUserOrderInfo() // 补录订单和有id的情况,不需要设置默认值
},
// 选择行事件
handleCell (val) {
console.log(val, this.orderObj)
// 获取当前选中的popupType
this.popupType = Object.keys(this.popupTypeEnum).find(key => this.popupTypeEnum[key].key === val.value) * 1
// 获取对应的list字段
const popupConfig = this.popupTypeEnum[this.popupType]
if (popupConfig && popupConfig.list) {
this.externalData = this[popupConfig.list] || []
} else {
this.externalData = []
}
// 定义产品相关字段数组
const productFields = ['frontGear', 'frontWindow', 'rearGear', 'rearWindow', 'sunRoof', 'package', 'skuGoods']
if (productFields.includes(val.value)) {
this.valueKey = val.value
this.externalData = utils.deepClone(this.goodsList)
}
console.log(this.popupType, this.externalData, '-------------')
this.$refs.orderPopup.open()
},
// 单选框change事件
radioChange (e, val) {
console.log(e, val)
this.$set(this.orderObj, val.value, e.detail.value)
if (val.value == 'payeeType') {
this.changePayee()
}
},
// 弹窗确认回调
onConfirm (val, flag) {
console.log(val, flag, 'onConfirm')
this.externalData = []
// const { chooseContent } = val
const chooseContent = utils.deepClone(val.chooseContent)
// 根据popupTypeEnum优化处理
const _typeValue = this.popupTypeEnum[this.popupType]
console.log(_typeValue)
// 定义产品相关字段数组
const productFields = ['frontGear', 'frontWindow', 'rearGear', 'rearWindow', 'sunRoof', 'package', 'skuGoods']
if (_typeValue.key == 'carBrand') {
// 车型
this.$set(this.orderObj, _typeValue.key, `${chooseContent.carBrand}-${chooseContent.carChildsBrandName}-${chooseContent.carSeriesName}`)
this.orderObj.customer = {
...(this.orderObj.customer || {}),
...chooseContent
}
} else if (_typeValue.key == 'couponInfo') {
// 礼券
const { couponName, merchantCouponId, customerCouponCode } = chooseContent
Object.assign(this.orderObj, {
couponName: couponName,
merchantCouponId: merchantCouponId,
customerCouponCode: customerCouponCode
})
this.$set(this.orderObj, 'couponInfo', couponName + customerCouponCode)
} else if (productFields.includes(_typeValue.key)) {
if (_typeValue.key == 'skuGoods') {
if (!this.orderObj[_typeValue.key]) {
// 其他精品第一次赋值
this.$set(this.orderObj, _typeValue.key, 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 === 1) : chooseContent.filter(item => item.goodsFlag === 1)
const moreGoods = chooseContent
.filter(item => item.goodsFlag === 2)
.filter(item => {
return !selectedGoods.some(selectedItem => selectedItem.multipleSpecificationsGoods.goods.goodsId === item.multipleSpecificationsGoods.goods.goodsId)
})
// 合并已选的goodFlag为2的对象
this.orderObj[_typeValue.key] = [...singleGoods, ...moreGoods, ...selectedGoods]
}
} else {
this.$set(this.orderObj, _typeValue.key, chooseContent)
console.log(this.orderObj, 'this.orderObj')
}
// 商品类,需计算总价
setTimeout(() => {
this.changeTotalPrice()
}, 0)
} else if (_typeValue.key) {
this.orderObj[_typeValue.targetIdKey] = chooseContent[_typeValue.sourceIdKey]
this.$set(this.orderObj, _typeValue.targetNameKey, chooseContent[_typeValue.sourceNameKey])
}
},
// 输入框失去焦点事件
inputBlur (e, val) {
console.log(e, val)
this.orderObj.customer[val.value] = this.orderObj[val.value]
// VIN车架号动态校验:车架号字段,动态转换为大写
let standNoVal = this.orderObj.standNo
if (val.value === 'standNo' && standNoVal) {
this.orderObj.standNo = formatVinInput(standNoVal)
validateVin(this.orderObj.standNo)
.then(result => {
console.log('validateVin', result)
let { valid } = result.data
this.validateState = valid
// 校验成功,所有提示已在公共方法中处理
console.log('车架号校验成功:', result)
})
.catch(err => {
console.log('validateVinErr', result)
})
}
},
// 校验必填等规则
checkRequired () {
const phoneRex = /^[1]([3-9])[0-9]{9}$/
// 把formList中所有required为true的对象放到一个数组中
const requiredArr = []
const onlyLabelItem = []
this.formList.forEach(group => {
group.forEach(item => {
if (item.required === true && item.hidden !== true) {
if (item.onlyLabel === true) {
onlyLabelItem.push(item)
} else {
requiredArr.push(item)
}
}
})
})
// 遍历requiredArr,检查orderObj中是否有对应的值
for (let i = 0; i < requiredArr.length; i++) {
const item = requiredArr[i]
// 兼容嵌套customer对象的情况
let value
if (item.value === 'customerName' || item.value === 'customerPhone' || item.value === 'standNo' || item.value === 'plateNumber') {
value = this.orderObj.customer ? this.orderObj.customer[item.value] : undefined
} else {
value = this.orderObj[item.value]
}
// 0、false、'0'等视为有效,null/undefined/空字符串视为无效
if (value === undefined || value === null || value === '') {
uni.showToast({
title: `${item.label}不能为空`,
icon: 'none'
})
return false
}
// 如果是customerPhone,添加phoneRex校验
if (item.value === 'customerPhone' && !phoneRex.test(value)) {
uni.showToast({
title: `请输入正确的${item.label}`,
icon: 'none'
})
return false
}
}
// if (this.orderObj.standNo) {
// if (!utils.validateVIN(this.orderObj.standNo)) throw '车架号校验不匹配,请核对后重新输入'
// }
// 处理onlyLabel为true的特殊校验
if (onlyLabelItem.length > 0) {
// 检查frontGear、frontWindow、rearGear、rearWindow、sunRoof和couponInfo字段中是否至少有一个不为空
const labelFields = ['frontGear', 'frontWindow', 'rearGear', 'rearWindow', 'sunRoof', 'package', 'skuGoods']
const hasValue = labelFields.some(field => {
console.log(field, this.orderObj[field])
const value = this.orderObj[field]
return value !== undefined && value !== null && (Array.isArray(value) ? value.length > 0 : value !== '')
})
console.log(hasValue, hasValue)
if (!hasValue) {
uni.showToast({
title: '商品不能为空',
icon: 'none'
})
return false
}
}
return true
},
// 提交
async submit () {
// VIN车架号-动态校验
const carVin = this.orderObj.standNo
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
}
}
if (!(await this.checkDailyReport())) {
const { orderCreateType } = this
const obj = utils.deepClone(this.orderObj)
const otherCustomer = ['standNo', 'plateNumber', 'customerSex', 'experienceFlag', 'salesType']
obj.customer = {
...obj.customer,
...otherCustomer.reduce((acc, key) => {
if (obj[key] !== undefined) {
acc[key] = obj[key]
delete obj[key]
}
return acc
}, {})
}
// 将 frontGear、frontWindow、rearGear、rearWindow、sunRoof 字段合并到 goodsList 中
const labelFields = ['frontGear', 'frontWindow', 'rearGear', 'rearWindow', 'sunRoof', 'package', 'skuGoods']
let goodsList = []
let subGoodsList = []
labelFields.forEach(field => {
if (Array.isArray(obj[field]) && obj[field].length > 0) {
goodsList = goodsList.concat(obj[field])
}
delete obj[field]
})
if (goodsList.length > 0) {
goodsList.map(e => {
if (e.goodsFlag == 1) {
// 单商品
subGoodsList.push({
totalPrice: e.goods.sellPrice,
number: e.goods.number,
merchantGoodsId: e.goods.merchantGoodsId
})
}
// 套餐
if (e.goodsFlag == 3) {
e.packageGoods.goodsList.forEach(g => {
subGoodsList.push({
packageCode: e.packageGoods.packageCode,
packageName: e.packageGoods.packageName,
totalPrice: g.sellPrice,
number: e.packageGoods.number,
merchantGoodsId: g.merchantGoodsId,
upgradePrice: g.oldPrice
})
})
}
// 多规格
if (e.goodsFlag == 2) {
subGoodsList.push({
baseGoodsId: e.multipleSpecificationsGoods.goods.baseGoodsId,
totalPrice: Number(e.multipleSpecificationsGoods.goods.sellPrice),
number: e.multipleSpecificationsGoods.number,
merchantGoodsId: e.multipleSpecificationsGoods.goods.id || e.multipleSpecificationsGoods.goods.merchantGoodsId
})
}
})
obj.subOrderList = subGoodsList
}
delete obj.carBrand
delete obj.couponInfo
console.log(obj, 'rucan')
uni.showLoading({
title: '提交中...',
mask: true
})
const res = await uni.$api.boutiqueApi[orderCreateType](obj).finally(() => {
uni.hideLoading()
})
if (res) {
uni.showToast({
title: '保存成功',
icon: 'success'
})
if (this.orderCreateType == 'createWithPay' && !this.orderObj.id) {
uni.$track.add({ eventCode: 'app_submit_create_order' })
} else if (this.orderCreateType == 'supplementOrder') {
uni.$track.add({ eventCode: 'app_submit_supplement_order' })
}
this.$emit('jump', orderCreateType == 'supplementOrder' ? 'OrderDetail' : 'ConfirmOrder', res)
}
}
},
// 计算所有产品的总价
changeTotalPrice () {
let total = 0
// 遍历所有商品
const productFields = ['frontGear', 'frontWindow', 'rearGear', 'rearWindow', 'sunRoof', 'package', '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 += parseFloat(item.goods.sellPrice) * parseInt(item.goods.number)
} else if (item.packageGoods && item.packageGoods.upgradePrice && item.packageGoods.number) {
console.log(item.packageGoods, '套餐')
// if (item.packageGoods.price) {
// total += parseFloat(item.packageGoods.price) * parseInt(item.packageGoods.number)
// } else {
// total += parseFloat(item.packageGoods.upgradePrice) * parseInt(item.packageGoods.number)
// }
item.packageGoods.goodsList.forEach(i => {
total += parseFloat(i.sellPrice) * parseInt(item.packageGoods.number)
})
} else if (item.multipleSpecificationsGoods && item.multipleSpecificationsGoods.goods && item.multipleSpecificationsGoods.goods.sellPrice) {
console.log(item.multipleSpecificationsGoods, '多规格')
total += parseFloat(item.multipleSpecificationsGoods.goods.sellPrice) * parseInt(item.multipleSpecificationsGoods.number || 1)
}
})
}
})
console.log(total, 'total')
// 更新总价
this.totalPrice = total.toFixed(2)
},
// 获取上一个订单的销售顾问信息 并且不是再次下单
async getLastUserOrderInfo () {
const res = await uni.$api.boutiqueApi.getLastUserOrderInfo({
sellerUserId: this.userInfo.subLoginUser.uuid
})
console.log(this.orderObj.merchantId)
if (this.orderObj.merchantId == res.merchantId) {
this.$set(this.orderObj, 'employeeName', res.employeeName)
this.orderObj.userId = res.userId
console.log(res, '上一个订单的销售顾问信息')
} else {
this.getEmployeeList()
}
},
async getShopMerchantPointConfig (merchantId) {
const res = await uni.$api.boutiqueApi.getShopMerchantPointConfig({ merchantId })
if (res.pointsMultiRole == 'Y') {
const employeeCell = this.formList[0].find(item => item.label === '销售顾问')
if (employeeCell) employeeCell.label = '销售顾问/录单员'
// 找到formList中label为"交付专员"的对象,添加hidden: true
const deliveryCell = this.formList[0].find(item => item.label === '交付专员')
if (deliveryCell) {
deliveryCell.hidden = false
}
}
},
// 判断二级流量方
async getSubShopMerchantList (merchantId) {
const res = await uni.$api.boutiqueApi.getSubShopMerchantList({ merchantId })
if (res && res.length) {
this.subShopMerchantList = res
const cell = this.formList[0].find(item => item.label === '二级流量方')
if (cell) {
cell.hidden = false
}
}
},
// 动态获取 车型 车架 车牌 是否必填
getYQorderInfo () {
return new Promise(async (resolve, reject) => {
const YQorderSetting = uni.$storage.get('boutique_YQorderSetting')
if (YQorderSetting) return resolve(YQorderSetting)
else {
const { userInfo } = this
let { shopMerchantId, merchantId } = userInfo
const data = await uni.$api.boutiqueApi.getMerchantRecordingSettings({
scene: 1,
merchantId: shopMerchantId,
})
if (data) {
let YQorderSetting = {}
const keyMap = {
carBrand: 'carTypeRequiredFlag',
carNo: 'standNoRequiredFlag',
plateNo: 'plateNumRequiredFlag',
notUpgradeExperience: 'foEfRequiredFlag',
notUpgradeRejectionReason: 'foRrRequiredFlag'
}
; (data.orderFieldSettingList || []).forEach(e => {
const key = keyMap[e.fieldKey] || e.fieldKey
YQorderSetting[key] = e.isRequired ? 'Y' : 'N'
})
YQorderSetting.shopMerchantId = userInfo.shopMerchantId
// 过滤园区店是否需要屏蔽手机号选项
let filterYqPhoneConfig = JSON.parse(data.yqPhoneConfig)
YQorderSetting.yqPhoneConfig =
filterYqPhoneConfig?.find(item => item.yqMerchantId == merchantId)
console.log(YQorderSetting)
uni.$storage.set('boutique_YQorderSetting', YQorderSetting)
resolve(YQorderSetting)
}
}
})
},
// 获取车型、车架号、车牌号必填规则
async getSetting () {
const res = await this.getYQorderInfo()
const dictionaryObj = {
carTypeRequiredFlag: 'carBrand',
standNoRequiredFlag: 'standNo',
plateNumRequiredFlag: 'plateNumber'
}
for (const key in dictionaryObj) {
const cell = this.formList[1].find(item => item.value === dictionaryObj[key])
if (cell) cell.required = res[key] == 'Y'
}
},
// 获取园区店支付方式
async getConfig () {
const res = await uni.$api.boutiqueApi.getYqStoreConfig({
yqMerchantId: this.orderObj.sellerMerchantId
})
let m = res.supportPayTypes || []
let n = this.payTypeList
let list = n.filter(k => {
let idx = m.find(j => j == k.value)
return idx >= 0
})
// this.configPayTypeList = list
this.djPayList = [
...list?.filter(v => ![2, 5].includes(Number(v.value))),
{
name: '对公转账',
value: '6'
},
{
name: '其它收款',
value: '7'
}
]
this.merchantPayList = [...list?.filter(v => v.value == 2)]
this.changePayee()
console.log(this.djPayList, this.merchantPayList, 'list')
},
changePayee () {
const cell = this.formList[2].find(item => item.value === 'selectPayType')
if (cell) {
cell.radioList = this.orderObj.payeeType == 1 ? this.merchantPayList : this.djPayList
if (!this.orderObj.id && cell.radioList && cell.radioList.length > 0) {
cell.current = cell.radioList[0].value
// 使用 $set 确保响应式更新
this.$set(this.orderObj, 'selectPayType', cell.radioList[0].value)
}
}
},
// 获取 销售顾问列表
async getEmployeeList () {
const { userInfo, orderObj } = this
const { shopMerchantId, sceneType, merchantId } = userInfo,
data = await uni.$api.popupApi.getEmployeeList({
merchantId: orderObj.idKey == 'sellerUserId' ? merchantId : shopMerchantId,
sceneList: orderObj.idKey == 'sellerUserId' ? '' : [sceneType]
})
if (data && data.length) {
this.employeeList = data
this.$set(this.orderObj, 'employeeName', data[0].staffName)
this.orderObj.userId = data[0].uuid
}
},
async getPositionList () {
const res = await uni.$api.boutiqueApi.getPositionList({})
this.positionTypeList = res
},
// 商品列表
async getSelectOrderGoodsList () {
const { userInfo } = this
const res = await uni.$api.boutiqueApi.getSelectOrderGoodsList({
merchantId: userInfo.shopMerchantId,
sceneType: userInfo.sceneType
})
this.goodsList = res
// 分类映射
const posMap = {
frontGear: [1],
frontWindow: [2],
rearGear: [3],
rearWindow: [4],
sunRoof: [5, 6, 7]
}
// 初始化各类商品数组
const arrMap = {
frontGear: [],
frontWindow: [],
rearGear: [],
rearWindow: [],
sunRoof: []
}
res.forEach(val => {
if (val.goodsFlag == 1) {
let subVal = val.goods
subVal.positionStr = subVal.position
subVal.upgradePrice = subVal.sellPrice
subVal.price = subVal.sellPrice
subVal.goodsId = subVal.merchantGoodsId
Object.keys(posMap).forEach(key => {
if (posMap[key].includes(subVal.merchantGoodsPosition)) {
arrMap[key].push(val)
}
})
}
//商品多规格
if (val.goodsFlag == 2) {
val.multipleSpecificationsGoods.specificationList.forEach(item => {
item.specificationSelectValueList = []
item.specificationValueList.forEach(second => {
if (second.show) {
item.specificationSelectValueList.push(second.specificationValue)
}
})
})
this.otherProduct.push(val)
}
})
console.log(arrMap, 'arrMap')
// 批量设置 hidden 属性
Object.keys(arrMap).forEach(key => {
const cell = this.formList[2].find(item => item.value === key)
if (cell) cell.hidden = arrMap[key].length === 0
})
console.log('this.formList', this.formList)
const subOrderList = this.subOrderList || []
console.log('subOrderList', subOrderList)
let chooseList = []
subOrderList.map(e => {
// 普通商品
if (e && !e.packageName) {
if (e.specificationData.indexOf(';~;') == -1) {
// 修复取值字段名字错误问题
if (!e.price) {
e.price = utils.decimal(Number(e.totalPrice / e.number), 2)
//最低价
}
e.sellPrice = e.price
e.goodsId = e.merchantGoodsId
if (!e.minSellPrice) e.minSellPrice = e.upgradeShopMinPrice
e.goodsInfo = {
goodsName: e.upgradeGoodsAlias || e.upgradeGoodsName
}
e.merchantGoodsId = e.merchantGoodsId || e.id
chooseList.push({
goodsFlag: 1,
goods: e,
number: e.number,
active: true
})
}
// 多规格商品
if (e.specificationData.indexOf(';~;') > -1) {
// 修复取值字段名字错误问题
if (!e.price) {
e.price = utils.decimal(Number(e.totalPrice / e.number), 2)
//最低价
e.sellPrice = e.price
}
e.goodsId = e.merchantGoodsId
if (!e.minSellPrice) e.minSellPrice = e.upgradeShopMinPrice
e.goodsInfo = {
goodsName: e.upgradeGoodsAlias || e.upgradeGoodsName
}
e.count = e.number
e.merchantGoodsId = e.merchantGoodsId || e.id
let specificdata = this.handleSpecificationsEcho(e)
console.log(specificdata, 'specificdata')
chooseList = chooseList.concat(specificdata)
}
}
// 套餐
if (e && e.packageName) {
e.packageGoodsOrderList.forEach(g => {
g.oldPrice = g.sellPrice || g.upgradePrice
// g.sellPrice = g.sellPrice || g.upgradePrice;
g.price = g.totalPrice ? Number(g.totalPrice) / Number(g.number) : g.sellPrice
g.sellPrice = g.price
})
e.goodsList = e.packageGoodsOrderList
e.upgradePrice = e.goodsList.reduce((prev, cur) => {
console.log(prev, cur)
return prev + cur.sellPrice
}, 0)
e.number = e.goodsList.length ? e.goodsList[0].number : 1
e.price = e.goodsList.reduce((prev, cur) => {
return prev + Number(cur.totalPrice) / Number(cur.number)
}, 0)
chooseList.push({
isType: 'meal',
active: true,
goodsFlag: 3,
packageGoods: e,
number: e.number,
totalPrice: e.price
})
}
})
console.log(chooseList, 'chooseList')
const _singleGoods = chooseList.filter(item => item.goodsFlag == 1)
const _packageGoods = chooseList.filter(item => item.goodsFlag == 3)
const _skuGoods = chooseList.filter(item => item.goodsFlag == 2) || []
console.log(_singleGoods, 'singleGoods')
if (_singleGoods) {
// 回显upgradeGoodsPosition 1:前挡 2:前窗 3:后窗 4:后挡 5、6、7:天窗。 为空则是其他精品
this.$set(
this.orderObj,
'frontGear',
_singleGoods.filter(item => item.goods.upgradeGoodsPosition == 1)
)
this.$set(
this.orderObj,
'frontWindow',
_singleGoods.filter(item => item.goods.upgradeGoodsPosition == 2)
)
this.$set(
this.orderObj,
'rearWindow',
_singleGoods.filter(item => item.goods.upgradeGoodsPosition == 3)
)
this.$set(
this.orderObj,
'rearGear',
_singleGoods.filter(item => item.goods.upgradeGoodsPosition == 4)
)
this.$set(
this.orderObj,
'sunRoof',
_singleGoods.filter(item => item.goods.upgradeGoodsPosition == 5 || item.goods.upgradeGoodsPosition == 6 || item.goods.upgradeGoodsPosition == 7)
)
// 将没有upgradeGoodsPosition的商品添加到_skuGoods中
const noPositionGoods = _singleGoods.filter(item => !item.goods.upgradeGoodsPosition)
if (noPositionGoods.length > 0) {
_skuGoods.push(...noPositionGoods)
}
}
if (_packageGoods) {
this.$set(this.orderObj, 'package', _packageGoods)
}
console.log(_skuGoods, '_skuGoods')
if (_skuGoods && _skuGoods.length) {
this.$set(this.orderObj, 'skuGoods', _skuGoods)
}
console.log(this.orderObj, 'this.orderObj')
this.changeTotalPrice()
},
handleSpecificationsEcho (item) {
let skuArr = []
const { otherProduct } = this,
arr = item.specificationData.split('/'),
str = arr.join(';~;'),
obj = {
count: item.count,
goodsFlag: 2,
goods: null,
active: true,
isFlag: true //初始化进来不显示标识
}
otherProduct.forEach(data => {
if (data.goodsFlag == 2) {
let tempData = data.multipleSpecificationsGoods.specificationGoodsMap[str]
if (tempData) {
tempData.forEach(temp => {
if (temp.merchantGoodsId == item.goodsId) {
obj.multipleSpecificationsGoods = {
...data.multipleSpecificationsGoods,
baseGoodsName: item.goodsName || item.upgradeGoodsName,
goods: {
...temp,
price: item.price,
sellPrice: item.price,
goodsId: item.goodsId,
specificationStr: item.specificationData.replace(/;~;/g, '/')
}
}
skuArr.push(obj)
}
})
}
}
})
console.log(skuArr)
return skuArr
}
}
}
</script>
<style scoped lang="scss">
.order {
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: #f45001;
font-weight: 500;
}
}
.pay-tips {
padding: toRpx(24) toRpx(24) toRpx(24) 0;
font-size: toRpx(24);
color: #999;
}
.btn {
display: flex;
align-items: center;
justify-content: center;
margin: toRpx(88) auto 0;
width: toRpx(1130);
height: toRpx(80);
color: #fff;
border-radius: toRpx(48);
background: linear-gradient(0deg, #2c66f7 0%, #48a6ff 100%);
}
</style>