移动系统liao
2025-02-17 557c2711a3e103ebc3d0492344eca9730d5e92b2
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
<template>
    <view>
        <u-toast ref="uToast" /><u-no-network></u-no-network>
        <u-navbar title="提交订单" safeAreaInsetTop fixed placeholder>
            <view class="coreshop-navbar-left-slot" slot="left">
                <u-icon name="arrow-left" size="19" @click="goNavigateBack"></u-icon>
                <u-line direction="column" :hairline="false" length="16" margin="0 8px"></u-line>
                <u-icon name="home" size="22" @click="goHome"></u-icon>
            </view>
            <view slot="right">
            </view>
        </u-navbar>
        <view class="content">
 
            <view class="coreshop-margin-left-10 coreshop-margin-right-10 coreshop-margin-top-10">
                <u-alert :title="title" type="warning" effect="dark" :description="description"></u-alert>
            </view>
 
            <view class="coreshop-margin-left-10 coreshop-margin-right-10 coreshop-margin-top-10">
                <u-subsection :list="typeItems" mode="subsection" :current="typeCurrent" @change="onTypeItem" bg-color="#ffffff" active-color="#e54d42" v-if="typeItems.length > 0" style="border-radius:0;"></u-subsection>
            </view>
            <view class="content">
                <view v-show="OrderDistributionModelCurrent === 'isOpenHomeDelivery' || OrderDistributionModelCurrent === 'isOpenMailing'">
                    <!-- 收货地址信息 -->
                    <view class="coreshop-margin-top-10 coreshop-margin-bottom-10 coreshop-common-view-box" v-if="userShip && userShip.id" @click="showAddressList">
                        <view class="coreshop-bg-white coreshop-card address-view">
                            <view class="coreshop-list menu-avatar">
                                <view class="coreshop-list-item">
                                    <view class="icon-view">
                                        <u-icon name="map" size="18"></u-icon>
                                    </view>
                                    <view class="content">
                                        <view class="coreshop-text-black">
                                            <text>收货人:{{ userShip.name || '' }}</text>
                                            <text class="coreshop-margin-left-10">{{ userShip.mobile || ''}}</text>
                                        </view>
                                        <view class="coreshop-text-gray coreshop-font-sm flex">
                                            <view class="u-line-2">{{ userShip.areaName || ''}} {{userShip.street || ''}} {{userShip.address || ''}}</view>
                                        </view>
                                    </view>
                                    <view class="action coreshop-text-gray">
                                        <u-icon name="arrow-right" @click="goAddress()"></u-icon>
                                    </view>
                                </view>
                            </view>
                            <view class="address-line" />
                        </view>
                    </view>
                    <view class="coreshop-margin-top-10 coreshop-margin-bottom-10 coreshop-common-view-box" v-else>
                        <view class="coreshop-bg-white coreshop-card address-view coreshop-text-center coreshop-padding-bottom-30 coreshop-flex coreshop-justify-center">
                            <view class="coreshop-width-fit-content">
                                <u-button type="error" size="mini" @click="goAddress()">添加收货地址</u-button>
                            </view>
                            <view class="address-line" />
                        </view>
                    </view>
                </view>
                <view v-show="OrderDistributionModelCurrent === 'isOpenSelfDelivery'">
                    <!-- 门店信息 -->
                    <view class="coreshop-margin-top-10 coreshop-margin-bottom-10 coreshop-common-view-box" v-if="store && store.id" @click="goStorelist()">
                        <view class="coreshop-bg-white coreshop-card address-view">
                            <view class="coreshop-list menu-avatar">
                                <view class="coreshop-list-item">
                                    <view class="icon-view">
                                        <u-icon name="map" size="18"></u-icon>
                                    </view>
                                    <view class="content">
                                        <view class="coreshop-text-black">
                                            <text>{{store.name|| ''}}</text>
                                            <text class="coreshop-margin-left-10">{{store.mobile|| ''}}</text>
                                        </view>
                                        <view class="coreshop-text-gray coreshop-font-sm flex">
                                            <view class="u-line-2">{{store.address|| ''}}</view>
                                        </view>
                                    </view>
                                    <view class="action coreshop-text-gray">
                                        <u-icon name="arrow-right" @click="goStorelist()"></u-icon>
                                    </view>
                                </view>
                            </view>
                            <view class="address-line" />
                        </view>
                    </view>
                    <view v-else class='coreshop-margin-top-10 coreshop-margin-bottom-10 coreshop-common-view-box' @click="goStorelist()">
                        <view class="coreshop-bg-white coreshop-card address-view">
                            <view class='coreshop-padding-10 coreshop-text-center'>暂无门店</view>
                            <view class="address-line" />
                        </view>
                    </view>
                </view>
            </view>
            <view class='coreshop-margin-top-10 coreshop-margin-bottom-10 coreshop-common-view-box' v-if="storeSwitch == 1 && OrderDistributionModelCurrent === 'isOpenSelfDelivery'">
                <view class="coreshop-form-group">
                    <view class="title">姓名</view>
                    <input class='coreshop-cell-bd-input' placeholder='请输入提货人姓名' v-model="storePick.name" style="width: 100%;"></input>
                </view>
                <view class="coreshop-form-group">
                    <view class="title">电话</view>
                    <input class='coreshop-cell-bd-input' placeholder='请输入提货人电话' v-model="storePick.mobile" style="width: 100%;"></input>
                </view>
            </view>
            <!-- 商品列表信息 -->
            <!--商品信息-->
            <view class="coreshop-margin-top-10 coreshop-margin-bottom-10 coreshop-common-view-box">
                <view class="coreshop-bg-white coreshop-card goods-view">
                    <view class="goods-info-view-box coreshop-solid-bottom" v-if="item.isSelect == true" v-for="(item, index) in products" :key="index">
                        <view class="coreshop-avatar radius lg" :style="[{backgroundImage:'url('+ item.products.images+'?x-oss-process=image/resize,m_lfit,h_200,w_200' +')'}]" />
                        <view class="goods-info-view">
                            <view class="coreshop-text-black u-line-2">{{ item.products.name || ''}}</view>
                            <view class="coreshop-font-sm coreshop-text-gray" v-if="item.products.spesDesc !== null">{{ item.products.spesDesc || ''}}</view>
                            <view class="coreshop-tag-view" v-if="item.products.promotionList">
                                <u-tag :text="v.name" mode="light" size="mini" v-for="(v, k) in item.products.promotionList" :key="k" />
                            </view>
                            <view class="goods-price-view">
                                <view class="coreshop-flex coreshop-flex-direction-row">
                                    <text class="coreshop-text-price coreshop-text-red coreshop-font-lg">{{ item.products.price || '0'}}</text>
                                    <view class="coreshop-flex coreshop-flex-direction-row coreshop-font-10 coreshop-align-center" v-if="pointSwitch==1 && pointExchangeModel==2 && pointShowExchangePrice==1 && item.products.pointsDeduction > 0  && orderType== $globalConstVars.paymentType.common">
                                        <view>
                                            ({{ pointShowName}}兑换价:
                                        </view>
                                        <view class="coreshop-text-red">
                                            {{pointDiscountedProportion * item.products.pointsDeduction }}{{ pointShowName}}+{{ parseFloat(item.products.price - item.products.pointsDeduction).toFixed(2)}}元
                                        </view>
                                        )
                                    </view>
                                </view>
                                <view class='coreshop-text-right goods-num'>× {{ item.nums || ''}}</view>
                            </view>
                        </view>
 
                        <view class="coreshop-flex coreshop-flex-direction-row coreshop-font-13 coreshop-margin-top-10" v-if="pointSwitch==1 && pointExchangeModel==2 && pointShowExchangePrice==1 && item.products.pointsDeduction > 0  && orderType== $globalConstVars.paymentType.common">
                            <view>
                                {{ pointShowName}}兑换价合计:
                            </view>
                            <view class="coreshop-text-red">
                                {{pointDiscountedProportion * item.products.pointsDeduction * item.nums }}{{ pointShowName}}+{{parseFloat((item.products.price - item.products.pointsDeduction)*item.nums).toFixed(2) }}元
                            </view>
                        </view>
                        <view class="coreshop-flex coreshop-flex-direction-row coreshop-font-13 coreshop-margin-top-10" v-if="pointSwitch==1 && pointGetModel==2 && pointShowPoint==1 && item.products.points > 0">
                            <view>
                                购买将赠送:
                            </view>
                            <view class="coreshop-text-red">
                                {{item.products.points * item.nums }}{{ pointShowName}}
                            </view>
                        </view>
 
                    </view>
                </view>
            </view>
 
            <!--优惠券-->
            <view class="coreshop-margin-top-10 coreshop-margin-bottom-10 coreshop-common-view-box" v-if="userCoupons.length>0 && orderType== $globalConstVars.paymentType.common && isShowCoupon">
                <view class="coreshop-bg-white coreshop-card goods-view">
                    <view class="coreshop-text-black coreshop-gift-list">
                        <view class="u-line-1 title">优惠券</view>
                        <view @click="notUseCoupon()" v-if="usedCoupons.length>0" class="closeTag">
                            <u-tag class="coreshop-text-right" text="取消选择" closeable type="error" shape="circle" mode="dark" size="mini" />
                        </view>
                    </view>
                    <!--滑动列表-->
                    <view class="coupon-scroll-box">
                        <scroll-view class="coupon-scroll" scroll-x>
                            <block v-for="(item, index) in userCoupons" :key="index">
                                <view :id="['scroll' + (index + 1 )]" class="coupon-scroll-item coreshop-margin-top-10 flex coreshop-service-view couponBox" @click="couponHandle(index)">
                                    <view class="flex-sub bg-page coreshop-padding-10 coreshop-margin-10 radius ">
                                        <view class="coreshop-text-black u-line-1">{{ item.couponName || ''}}</view>
                                        <view class="coreshop-text-gray coreshop-font-sm u-line-1"> {{ item.expression2 }}</view>
                                        <view class="coreshop-text-black">
                                            <text class="line-red coreshop-font-10 radius">有效期:{{ item.stime + ' 至 ' + item.etime }}</text>
                                        </view>
                                        <view v-if="!item.checked && item.disabled">
                                            <view class="coreshop-corner-mark" />
                                            <view class="check-icon">
                                                <u-icon name="checkmark" color="#fff"></u-icon>
                                            </view>
                                        </view>
                                        <view v-else-if="item.checked && item.disabled">
                                            <view class="coreshop-corner-mark check" />
                                            <view class="check-icon check">
                                                <u-icon name="checkmark" color="#fff"></u-icon>
                                            </view>
                                        </view>
                                    </view>
                                </view>
                            </block>
                        </scroll-view>
                    </view>
                </view>
            </view>
            <!--支付方式-->
            <view class="coreshop-margin-top-10 coreshop-margin-bottom-10 coreshop-common-view-box">
                <view class="coreshop-bg-white coreshop-card pay-view">
                    <view class="coreshop-list menu">
                        <!-- 商户开启积分 并且用户有积分情况下 -->
                        <view class="coreshop-list-item" v-if="isOpenPoint === 1 && userPointNums > 0 && orderType== $globalConstVars.paymentType.common">
                            <!--<view class="coreshop-list-item arrow">-->
                            <view class="content">
                                <text class="coreshop-text-black">{{ pointShowName}}抵扣</text>
                                <view class="coreshop-text-gray coreshop-font-xs flex">
                                    <text class="u-line-1">
                                        可用{{ canUsePoint}}{{ pointShowName}},可抵扣{{ pointMoney}}元,共有{{ userPointNums}}{{ pointShowName}}
                                    </text>
                                </view>
                            </view>
                            <view class="action" @click="changePointHandle">
                                <view class="coreshop-text-gray fr">
                                    <switch :class="isUsePoint?'checked':''" :checked="isUsePoint"></switch>
                                </view>
                            </view>
                        </view>
                        <view class="coreshop-list-item" v-if="invoiceSwitch == 1" @click="goInvoice()">
                            <view class="content">
                                <text class="coreshop-text-black">发票</text>
                            </view>
                            <view class="coreshop-flex coreshop-flex-direction-row coreshop-justify-between">
                                <text class="coreshop-text-gray">{{invoice.name|| '无'}}</text>
                                <u-icon name="arrow-right"></u-icon>
                            </view>
                        </view>
                    </view>
                </view>
            </view>
            <!--商品价格计算-->
            <view class="coreshop-margin-top-10 coreshop-margin-bottom-10 coreshop-common-view-box">
                <view class="coreshop-bg-white coreshop-card coreshop-price-view">
                    <view class="coreshop-text-black item-view">
                        <view class="u-line-1 title">商品总额</view>
                        <text class="coreshop-text-red coreshop-text-price coreshop-text-right">{{ cartData.goodsAmount }}</text>
                    </view>
                    <view class="coreshop-text-black item-view">
                        <view class="u-line-1 title">商品优惠</view>
                        <text class="coreshop-text-right">- {{ cartData.goodsPromotionMoney || '0'}}</text>
                    </view>
                    <view class="coreshop-text-black item-view">
                        <view class="u-line-1 title">订单优惠</view>
                        <text class="coreshop-text-right">- {{ cartData.orderPromotionMoney || '0' }}</text>
                    </view>
                    <view class="coreshop-text-black item-view">
                        <view class="u-line-1 title">优惠券抵扣</view>
                        <text class="coreshop-text-right">- {{ cartData.couponPromotionMoney  || '0'}}</text>
                    </view>
                    <view class="coreshop-text-black item-view" v-if="isOpenPoint === 1 && userPointNums > 0 && orderType== $globalConstVars.paymentType.common">
                        <view class="u-line-1 title">{{ pointShowName}}抵扣</view>
                        <text class="coreshop-text-right">- {{ cartData.pointExchangeMoney || '0'}}</text>
                    </view>
                    <view class="coreshop-text-black item-view">
                        <view class="u-line-1 title">
                            <text class="coreshop-margin-right-10">运费</text>
                            <text class="cuIcon-question icon" />
                        </view>
                        <text class="coreshop-text-right">{{ cartData.costFreight || '0'}}</text>
                    </view>
                </view>
            </view>
            <!--买家留言-->
            <view class="coreshop-margin-top-10 coreshop-margin-bottom-10 coreshop-common-view-box">
                <view class="coreshop-bg-white coreshop-card coreshop-price-view">
                    <view class="title">买家留言</view>
                    <view class="coreshop-padding-10">
                        <textarea class="memoBox" maxlength="50" @input="memoChange" placeholder="50字以内(选填)"></textarea>
                    </view>
                </view>
            </view>
            <!--占位底部距离-->
            <view class="coreshop-tabbar-height" />
            <!--底部操作-->
            <view class="coreshop-bg-white coreshop-footer-fixed coreshop-foot-padding-bottom">
                <view class="coreshop-flex coreshop-flex-nowrap coreshop-justify-between  coreshop-padding-10 coreshop-percent-100">
                    <view class="coreshop-text-black coreshop-text-bold price-view coreshop-basis-6 coreshop-flex coreshop-align-center">
                        <text class="coreshop-margin-right-10">共 {{ productNums}} 件商品</text>
                        <text>合计<text class="coreshop-text-price coreshop-text-red coreshop-font-lg coreshop-margin-left-10"> {{ cartData.amount}}</text></text>
                    </view>
                    <view class="coreshop-basis-4">
                        <u-button size="normal" type="error" @click="toPay" :disabled='submitStatus' :loading='submitStatus'>确认下单</u-button>
                    </view>
                </view>
            </view>
        </view>
        <!-- 登录提示 -->
        <coreshop-login-modal></coreshop-login-modal>
    </view>
</template>
<script>
 
    export default {
 
        data() {
            return {
                typeItems: [],
                //typeItems: ['快递物流', '同城配送', '门店自提'],
                typeCurrent: 0,
                cartData: {}, // 购物车商品详情
                products: [], // 货品信息
                promotions: [], // 促销信息
                userShip: {}, // 用户收货地址
                receiptType: 1, // 订单类型 1快递物流发货订单,2同城配送,3是门店自提订单
                params: {
                    ids: 0, // 传递过来的购物车id
                    userShipId: 0,
                    areaId: 0, // 收货地址id
                    couponCode: '', // 优惠券码列表(string)多张逗号分隔
                    point: 0,// 抵扣积分额
                    type: 1,//购物车类型
                    objectId: 0,//关联对象类型
                }, // 监听params参数信息 以重新请求接口
                // 发票信息
                invoice: {
                    type: 1,    // 类型 1不开发票 2个人发票 3公司发票
                    name: '',    // 发票抬头
                    code: ''    // 发票税号
                },
                memo: '', // 买家留言
                items: [
                    '选择优惠券',
                    '输入券码',
                ],
                orderType: 1, // 商品订单类型 1
                current: 0,
                isUsePoint: false,    // 是否勾选使用积分
                userPointNums: 0, // 用户的总积分
                canUsePoint: 0,    // 可以使用的积分
                pointMoney: 0, // 积分抵扣的金额
                userCoupons: [], // 用户的可用优惠券列表
                usedCoupons: {}, // 已经选择使用的优惠券
                inputCouponCode: '', // 输入的优惠券码
                optCoupon: '',// 当前选择使用的优惠券(暂存使用 如果接口返回不可用则剔除优惠券状态)
                store: {
                    id: 0,
                    name: '',
                    mobile: '',
                    address: ''
                },
                storePick: {
                    name: '',
                    mobile: ''
                },
                objectId: 0,//关联对象序列
                teamId: 0,//拼团订单分组序列
                submitStatus: false,
                isOpenHomeDelivery: true,
                isOpenMailing: true,
                isOpenSelfDelivery: true,
                OrderDistributionModels: [],
                OrderDistributionModelCurrent: '',
                requireOrder: 0,//自定义交易组件是否需要推单,1:需要,0:不需要
                requiredFundType: 0, //requireOrder = 1时生效,0,非二级商户号订单,1,二级商户号订单,2,两种方式皆可(后续只会存在1)
                traceId: '', //跟踪ID,有效期十分钟,会影响主播归因、分享员归因等,需创建订单前调用,调用生成订单 api 时需传入该参数
                title: '下单提醒',
                description: '选择【同城配送】下单将产生运费,由我们进行配送,选择【门店自提】下单,请前往门店提供订单手机号码或者核销码进行核销取货。'
            }
        },
        components: {},
        onLoad(options) {
            var _this = this;
            //下单前置检查,自定义交易组件检测场景是否需要推送订单到微信服务。
            // #ifdef APP-PLUS|APP-PLUS-NVUE
            _this.getOrderDistributionModel()
            // #endif
            // #ifdef MP
            uni.getSystemInfo({
                success: (res) => {
                    //console.log("所获取设备数据皆来自设备本身", res)
                    var systemInfo = res;
                    if (systemInfo.deviceType != 'pc') {
                        var values = systemInfo.version.split('.');
                        var v1 = parseInt(values[0]);
                        var v2 = parseInt(values[1]);
                        var v3 = parseInt(values[2]);
                        if (v1 >= 8 && v2 >= 0 && v3 >= 18) {
                            wx.checkBeforeAddOrder({
                                success(res) {
                                    if (res.errMsg == 'checkBeforeAddOrder:ok') {
                                        _this.requireOrder = res.data.requireOrder;
                                        _this.requiredFundType = res.data.requiredFundType;
                                        _this.traceId = res.data.traceId;
                                        // 获取不同类型营销下单支持的配送方式
                                        _this.getOrderDistributionModel()
                                    }
                                },
                                fail(res) {
                                    // 获取不同类型营销下单支持的配送方式
                                    _this.getOrderDistributionModel()
                                }
                            })
                        } else {
                            _this.getOrderDistributionModel();
                        }
 
                    } else {
                        _this.getOrderDistributionModel();
                    }
                },
                fail(res) {
                    _this.getOrderDistributionModel()
                }
            })
            // #endif
 
            let cartIds = options.cartIds;
            if (options.orderType) {
                this.orderType = options.orderType;
                this.params.type = options.orderType;
            }
            if (options.objectId) {
                this.objectId = options.objectId;
                this.params.objectId = options.objectId;
            }
            if (options.teamId) {
                this.teamId = options.teamId;
            }
            this.params.ids = JSON.parse(cartIds)
            if (!this.params.ids) {
                _this.$refs.uToast.show({
                    message: '获取失败', type: 'error', complete: function () {
                        uni.navigateBack({
                            delta: 1
                        });
                    }
                })
            }
 
            // 获取用户的默认收货地址信息
            this.userDefaultShip()
            // 获取用户的可用优惠券信息
            this.getUserCounpons()
            //获取默认门店信息
            this.getDefaultStore();
        },
        onShow() {
            // #ifdef MP-ALIPAY || MP-TOUTIAO
            let userShip = this.$db.get('addressUserShip', true);
            if (userShip) {
                this.userShip = userShip;
                this.params.userShipId = userShip.id;
                this.params.areaId = userShip.areaId;
                this.$db.del('addressUserShip', true);
            }
            let userInvoice = this.$db.get('userInvoice', true);
            if (userInvoice) {
                this.invoice = userInvoice;
                this.$db.del('userInvoice', true);
            }
            let userStore = this.$db.get('userStore', true);
            if (userStore) {
                this.store = userStore;
                this.$db.del('userStore', true);
            }
            // #endif
            // #ifdef APP-PLUS || APP-PLUS-NVUE
            let userShip = this.$store.state.userShip;
            if (userShip) {
                this.userShip = userShip;
                this.params.userShipId = userShip.id;
                this.params.areaId = userShip.areaId;
            }
            let userInvoice = this.$store.state.invoice;
            if (userInvoice) {
                this.invoice = userInvoice;
            }
            // #endif
        },
        methods: {
            // 切换门店
            onTypeItem(index) {
                if (this.typeCurrent !== index) {
                    this.typeCurrent = index;
                }
                let receiptType = 1;
 
                this.OrderDistributionModelCurrent = this.OrderDistributionModels[this.typeCurrent];
                if (this.OrderDistributionModelCurrent == 'isOpenMailing') {
                    receiptType = 1;
                } else if (this.OrderDistributionModelCurrent == 'isOpenHomeDelivery') {
                    receiptType = 2;
                } else if (this.OrderDistributionModelCurrent == 'isOpenSelfDelivery') {
                    receiptType = 3;
                }
                this.receiptType = receiptType;
                this.getCartList();
            },
            // 跳转到门店列表
            goStorelist() {
                //console.log("跳转到门店列表");
                this.$u.route('/pages/placeOrder/storeList/storeList')
            },
            // 没有收货地址时跳转
            goAddress() {
                //console.log("没有收货地址时跳转");
                this.$u.route('/pages/member/address/list/list?type=order')
            },
            // 获取不同类型营销下单支持的配送方式
            getOrderDistributionModel() {
                if (this.requireOrder == 1) {
                    let newTypeItems = [];
                    newTypeItems.push('快递物流');
                    this.OrderDistributionModels.push('isOpenMailing');
                    this.typeItems = newTypeItems;
                    this.OrderDistributionModelCurrent = this.OrderDistributionModels[0];
                } else {
                    let data = {
                        id: this.orderType
                    };
                    this.$u.api.getOrderDistributionModel(data).then(res => {
                        if (res.status) {
                            //物流快递
                            this.isOpenMailing = res.data.isOpenMailing;
                            //同城配送
                            this.isOpenHomeDelivery = res.data.isOpenHomeDelivery;
                            //上门自提
                            this.isOpenSelfDelivery = res.data.isOpenSelfDelivery;
 
                            if (this.requireOrder == 0) {
                                let newTypeItems = [];
                                if (this.isOpenMailing) {
                                    newTypeItems.push('快递物流');
                                    this.OrderDistributionModels.push('isOpenMailing');
                                }
                                if (this.isOpenHomeDelivery) {
                                    newTypeItems.push('同城配送');
                                    this.OrderDistributionModels.push('isOpenHomeDelivery');
                                }
                                if (this.isOpenSelfDelivery) {
                                    newTypeItems.push('门店自提');
                                    this.OrderDistributionModels.push('isOpenSelfDelivery');
                                }
                                this.typeItems = newTypeItems;
                            }
                            this.OrderDistributionModelCurrent = this.OrderDistributionModels[0];
                            if (this.OrderDistributionModelCurrent == 'isOpenMailing') {
                                this.receiptType = 1;
                            } else if (this.OrderDistributionModelCurrent == 'isOpenHomeDelivery') {
                                this.receiptType = 2;
                            } else if (this.OrderDistributionModelCurrent == 'isOpenSelfDelivery') {
                                this.receiptType = 3;
                            }
                        }
                    })
                }
            },
            // 获取用户的默认收货地址
            userDefaultShip() {
                this.$u.api.userDefaultShip().then(res => {
                    if (res.status && res.data && Object.keys(res.data).length) {
                        this.userShip = res.data
                        this.params.userShipId = this.userShip.id;
                        this.params.areaId = this.userShip.areaId
 
                        this.storePick.name = res.data.name;
                        this.storePick.mobile = res.data.mobile;
 
                    }
                })
            },
            // 获取购物车商品详情
            getCartList() {
                uni.showLoading({
                    title: '加载中'
                });
                let _that = this;
                let data = this.params
                data['receiptType'] = this.receiptType    // 区分订单类型  1快递物流,2同城配送,3上门自提订单
                this.$u.api.cartList(data).then(res => {
                    if (res.status) {
                        let data = res.data
                        // 判断是否开启积分抵扣 并且 没有勾选积分使用
                        if (this.isOpenPoint === 1 && !this.isUsePoint) {
                            let money = {
                                cartType: this.orderType,
                                ids: this.params.ids,
                                orderMoney: data.amount
                            }
                            this.$u.api.usablePoint(money).then(res => {
                                if (res.status) {
                                    this.userPointNums = res.data.point    // 用户总积分
                                    this.canUsePoint = res.data.availablePoint    // 可以使用的积分
                                    this.pointMoney = res.data.pointExchangeMoney    // 积分抵扣的总金额
                                }
                            })
                        }
                        // 所有价格转换
                        //data.amount = this.$common.formatMoney(data.amount);
                        //data.goodsAmount = this.$common.formatMoney(data.goodsAmount);
                        data.goodsPromotionMoneyOld = data.goodsPromotionMoney;
                        //data.goodsPromotionMoney = this.$common.formatMoney(data.goodsPromotionMoney);
                        //data.couponPromotionMoney = this.$common.formatMoney(data.couponPromotionMoney);
                        data.orderPromotionMoneyOld = data.orderPromotionMoney;
                        //data.orderPromotionMoney = this.$common.formatMoney(data.orderPromotionMoney);
                        //data.pointExchangeMoney = this.$common.formatMoney(data.pointExchangeMoney);
                        //data.costFreight = this.$common.formatMoney(data.costFreight);
                        // 购物车详情
                        this.cartData = data
                        // 商品详情
                        this.products = data.list
                        //判断是否有库存
                        let noStock = true;
                        for (let i = 0; i < data.list.length; i++) {
                            if (data.list[i].isSelect) {
                                noStock = false;
                            }
                        }
                        if (noStock) {
                            this.$u.toast("您所挑选的商品已售罄,请重新添加哦");
                        }
                        // 优惠信息
                        this.promotions = data.promotionList
                        // 使用的优惠券信息
                        this.usedCoupons = data.coupon
 
                        this.inputCouponCode = ''
                        this.optCoupon = ''
                        uni.hideLoading();
                    } else {
 
                        this.$refs.uToast.show({
                            message: res.msg, type: 'error', back: false, complete: function () {
                                // 优惠券不可用状态判断
                                // 优惠券号码不存在             15009
                                // 优惠券未开始                15010
                                // 优惠券已使用                15013
                                // 优惠券不符合使用规则        15014
                                // 优惠券不可使用多张            15015
                                // 优惠券已经过期            15011
                                let errStatus = [15009, 15010, 15011, 15013, 15014, 15015,]
                                if (errStatus.indexOf(res.data) !== -1) {
                                    //console.log('删除使用的优惠券号码');
                                    // 删除使用的优惠券号码
                                    if (_that.current === 1) {
                                        _that.removeCouponCode(_that.inputCouponCode, _that.current)
                                    } else {
                                        // 取消选择使用的状态
                                        //console.log(_that.optCoupon);
                                        if (_that.optCoupon) {
                                            _that.userCoupons.forEach(item => {
                                                if (item.couponCode === _that.optCoupon) {
                                                    item.checked = false
                                                }
                                            })
                                        }
                                        _that.removeCouponCode(_that.optCoupon, _that.current)
                                        //console.log(_that.optCoupon);
                                    }
                                } else {
                                    //console.log('未判断出内容');
                                }
                            }
                        })
                        uni.hideLoading();
                    }
                })
            },
            // 获取用户可用的优惠券信息
            getUserCounpons() {
                let data = {
                    display: 'no_used',
                    ids: this.params.ids
                }
                this.$u.api.getCartCoupon(data).then(res => {
                    if (res.status) {
                        let _list = res.data.list
                        let nowTime = Math.round(new Date().getTime() / 1000).toString()
                        _list.forEach(item => {
                            this.$set(item, 'checked', false)
                            // 判断优惠券是否有效(开始时间)
                            this.$set(item, 'disabled', item.startTime > nowTime ? true : false)
                            this.$set(item, 'cla', item.disabled ? 'cci-l bg-c' : 'cci-l')    // 绑定相应的class样式
                        })
                        this.userCoupons = _list
                    }
                })
            },
            // 点击使用/取消优惠券操作
            couponHandle(index) {
                // 更改使用/取消状态
                this.userCoupons[index].checked = !this.userCoupons[index].checked
                // 暂存当次选中使用的优惠券key
                this.optCoupon = this.userCoupons[index].couponCode
                let arr = []
                this.userCoupons.forEach(item => {
                    if (item.checked) {
                        arr.push(item.couponCode)
                    }
                })
                if (this.userCoupons[index].checked) {
                    // 使用
                    this.params.couponCode = arr.join()
                } else {
                    // 取消使用
                    let paramsCodes = this.params.couponCode.split(',')
                    let usedIndex = paramsCodes.indexOf(this.userCoupons[index].couponCode)
                    if (usedIndex !== -1) {
                        paramsCodes.splice(usedIndex, 1)
                        this.params.couponCode = paramsCodes.join()
                    }
                }
            },
            // 手输的优惠券码使用
            useInputCouponCode() {
                if (!this.inputCouponCode) {
                    this.$u.toast('请输入优惠券码')
                } else {
                    // 判断是否有使用的优惠券
                    if (this.params.couponCode.length > 0) {
                        this.params.couponCode += ',' + this.inputCouponCode
                    } else {
                        this.params.couponCode = this.inputCouponCode
                    }
                }
            },
            // 不使用优惠券
            notUseCoupon() {
                this.inputCouponCode = ''    // 清空手输的优惠券码
                this.userCoupons.forEach(item => {
                    item.checked = false
                }) // 取消所有选中的使用状态
                this.params.couponCode = ''    // 清空params优惠券码
            },
            // 移除/取消使用中的指定优惠券
            removeCouponCode(code, current) {
                let arr = this.params.couponCode.split(',')
                arr.splice(arr.indexOf(code), 1)
                current === 0 ? this.optCoupon = '' : this.inputCouponCode = ''
                this.params.couponCode = arr.join()
            },
            // 是否使用积分
            changePointHandle(e) {
                //this.switchA = e.detail.value
                if (this.userPointNums > 0) {
                    this.isUsePoint = !this.isUsePoint;
                    this.params.point = this.isUsePoint ? this.canUsePoint : 0;
                }
            },
            // 去支付
            toPay() {
                this.submitStatus = true;
                let receiptType = 1;
                if (this.OrderDistributionModelCurrent == 'isOpenMailing') {
                    receiptType = 1;
                } else if (this.OrderDistributionModelCurrent == 'isOpenHomeDelivery') {
                    receiptType = 2;
                } else if (this.OrderDistributionModelCurrent == 'isOpenSelfDelivery') {
                    receiptType = 3;
                }
                this.receiptType = receiptType;
                let data = {
                    cartIds: this.params.ids,
                    memo: this.memo,
                    couponCode: this.params.couponCode,
                    point: this.params.point,
                    receiptType: this.receiptType,
                    objectId: this.objectId,
                    teamId: this.teamId,
                    orderType: this.orderType, //订单类型
                    scene: this.$store.state.scene, //场景值(用于确定小程序是否来源直播和视频号)
                    requireOrder: this.requireOrder,
                    requiredFundType: this.requiredFundType,
                    traceId: this.traceId,
                }
 
                let delivery = {}
                // 判断是快递配送还是门店自提
                if (this.receiptType == 1 || this.receiptType == 2) {
                    if (!this.userShip.id || !this.params.areaId) {
                        this.$u.toast('请选择收货地址');
                        this.submitStatus = false;
                        return false;
                    }
                    // 快递配送
                    delivery = {
                        ushipId: this.userShip.id,
                        areaId: this.params.areaId
                    }
                }
                if (this.receiptType == 3) {
                    if (!this.store.id) {
                        this.$u.toast('请选择自提门店');
                        this.submitStatus = false;
                        return false;
                    }
                    if (!this.storePick.name) {
                        this.$u.toast('请输入提货人姓名');
                        this.submitStatus = false;
                        return false;
                    }
                    if (!this.storePick.mobile) {
                        this.$u.toast('请输入提货人电话');
                        this.submitStatus = false;
                        return false;
                    }
                    // 门店自提
                    delivery = {
                        storeId: this.store.id,
                        ladingName: this.storePick.name,
                        ladingMobile: this.storePick.mobile
                    }
                }
 
                // 发票信息
                data['taxType'] = this.invoice.type
                data['taxName'] = this.invoice.name
                data['taxCode'] = this.invoice.code
                // #ifdef MP-WEIXIN
                data['source'] = 3;
                // #endif
                // #ifdef MP-ALIPAY
                data['source'] = 4;
                // #endif
                // #ifdef APP-PLUS || APP-PLUS-NVUE
                data['source'] = 5;
                // #endif
                // #ifdef MP-TOUTIAO
                data['source'] = 6;
                // #endif
                data = Object.assign(data, delivery)
                this.$u.api.createOrder(data).then(res => {
                    this.submitStatus = false;
                    if (res.status) {
                        // 创建订单成功 去支付
                        // 判断是否为0元订单,如果是0元订单直接支付成功
                        if (res.data.payStatus == '2') {
                            this.$u.route({ type: 'redirectTo', url: '/pages/payment/result/result?orderId=' + res.data.orderId });
                        } else {
                            this.$u.route({ type: 'redirectTo', url: '/pages/payment/pay/pay?orderId=' + res.data.orderId + '&type=' + this.orderType });
                        }
                        //发起订阅
                        // #ifdef MP-WEIXIN
                        this.subscription();
                        // #endif
                    } else {
                        this.$u.toast(res.msg);
                    }
                });
            },
            //发起订阅
            subscription() {
                this.$u.api.getSubscriptionTmplIds(null).then(res => {
                    if (res.status) {
                        //console.log(res.data);
                        if (res.data.length > 0) {
                            wx.getSetting({
                                withSubscriptions: true,
                                success(resSetting) {
                                    //console.log('subscriptionsSetting', resSetting.subscriptionsSetting)
                                    if (wx.requestSubscribeMessage) {
                                        wx.requestSubscribeMessage({
                                            tmplIds: res.data,  //购买,发货,收货通知
                                            success: function (ress) {
                                                //console.log(ress);
                                            },
                                            fail: function (ress) {
                                                //console.log(ress);
                                            }
                                        })
                                    } else {
                                        wx.showToast({
                                            title: '请更新您微信版本,来获取订阅消息功能',
                                            icon: 'none'
                                        });
                                    }
 
                                }
                            });
                        }
                    } else {
                        this.$u.toast('消息订阅配置信息获取失败');
                    }
                });
            },
            // 跳转发票页面
            goInvoice() {
                this.$u.route('/pages/placeOrder/invoice/invoice')
            },
            // 跳转我的收货地址列表
            showAddressList() {
                this.$u.route('/pages/member/address/list/list?type=order')
            },
            // tab点击切换
            onClickItem(index) {
                if (this.current !== index) {
                    this.current = index;
                }
            },
            // 获取默认店铺
            getDefaultStore() {
                if (this.storeSwitch == 1) {
                    this.$u.api.defaultStore().then(res => {
                        if (res.status) {
                            if (res.data && res.data.id) {
                                let store = {
                                    id: res.data.id || 0,
                                    name: res.data.storeName || '',
                                    mobile: res.data.mobile || '',
                                    address: res.data.address || ''
                                }
                                this.store = store;
                            } else {
                                this.$u.toast('商家未配置默认自提店铺!');
                            }
                        }
                    });
                }
            },
            memoChange(e) {
                //console.log(e);
                this.memo = e.detail.value
            },
        },
        computed: {
            // 计算购物车商品数量
            productNums() {
                let nums = 0
                for (let i in this.cartData.list) {
                    if (this.cartData.list[i].isSelect) {
                        nums += this.cartData.list[i].nums;
                    }
                }
                return nums
            },
            // 判断商户是否开启积分抵扣 1开启 2未开启
            isOpenPoint() {
                return this.$store.state.config.pointSwitch
            },
            // 判断是否开启了我的优惠券 1开启 2未开启
            isShowCoupon() {
                return this.$store.state.config.showCoupon == 1;
            },
            // 获取使用的优惠券名称
            usedCouponsCompute() {
                var userCouponsCount = this.userCoupons.length;
 
                let name = userCouponsCount + '张可用'
                if (Object.keys(this.usedCoupons).length) {
                    let coupons = []
                    for (let i in this.usedCoupons) {
                        coupons.push(this.usedCoupons[i])
                    }
                    name = coupons.join()
                }
                return name
            },
            // 判断是否开启发票功能
            invoiceSwitch() {
                //console.log("发票功能:" + this.$store.state.config.invoiceSwitch);
                return this.$store.state.config.invoiceSwitch || 2;
            },
            // 判断店铺开关
            storeSwitch() {
                //var status = this.$store.state.config.storeSwitch || 2;
                //if (status == 2) {
                //    this.typeItem = ['快递物流', '同城配送']
                //}
                //console.log(status);
                return this.$store.state.config.storeSwitch || 2;
            },
            // 根据接口返回数据判断是否使用优惠券
            couponIsUsed() {
                //console.log(this.cartData.coupon);
                return this.cartData.coupon && this.cartData.coupon.length > 0;
            },
            pointSwitch() { return this.$store.state.config.pointSwitch },
            pointShowExchangePrice() { return this.$store.state.config.pointShowExchangePrice },
            pointDiscountedProportion() { return this.$store.state.config.pointDiscountedProportion },
            pointExchangeModel() { return this.$store.state.config.pointExchangeModel },
            pointShowName() { return this.$store.state.config.pointShowName },
            pointGetModel() { return this.$store.state.config.pointGetModel },
            pointShowPoint() { return this.$store.state.config.pointShowPoint },
        },
        watch: {
            // 监听数据状态(切换收货地址, 是否使用优惠券, 是否使用积分) 重新请求订单数据
            params: {
                handler() {
                    this.getCartList();
                },
                deep: true
            }
        }
    }
</script>
 
<style scoped lang="scss">
    @import 'index.scss';
</style>