Parcourir la source

feat: 选择优惠券

listKer il y a 2 ans
Parent
commit
1e43a5e0c4
2 fichiers modifiés avec 21417 ajouts et 52 suppressions
  1. 21167 37
      package-lock.json
  2. 250 15
      src/pages/confirmOrder/details/index.vue

Fichier diff supprimé car celui-ci est trop grand
+ 21167 - 37
package-lock.json


+ 250 - 15
src/pages/confirmOrder/details/index.vue

@@ -131,17 +131,37 @@
131 131
             </div>
132 132
             <div class="on-icon">></div>
133 133
           </div>
134
-          <div v-if="order_data.coupon_list&&order_data.coupon_list.length>0">
134
+
135
+
136
+          <!-- <div v-if="order_data.coupon_list&&order_data.coupon_list.length>0">
135 137
             <div class="coupon-ps"
136 138
                  v-for="item,index in order_data.coupon_list"
137 139
                  :key="index">
138 140
               <div>{{item.coupon_name}}</div>
139 141
               <div class="cou-price">-¥{{price}}</div>
140 142
             </div>
143
+          </div> -->
144
+
145
+          <div v-if="1==1">
146
+            <div class="coupon-ps"
147
+                 v-for="item,index in isSelectCoup"
148
+                 :key="index">
149
+              <div>{{item.coupon_name}}</div>
150
+      <div class="cou-price" v-if="item.type==4?true:false">抵扣{{item.projectName}}</div>
151
+      <div class="cou-price" v-if="item.type==3?true:false">抵扣全部项目(除升级包)</div>
152
+      <div class="cou-price" v-if="item.type==2?true:false">¥{{item.price}}</div>
153
+      <div class="cou-price" v-if="item.type==1?true:false">¥{{item.price}}</div>
154
+                    <!-- <div class="cou-price">-¥{{price}}</div> -->
155
+            </div>
141 156
           </div>
157
+
158
+
159
+
160
+
161
+
142 162
         </div>
143 163
         <div class="over-price">
144
-          合计: <span class="price-num"><span class="min-size">¥</span>399<span class="min-size">.00</span></span>
164
+          合计: <span class="price-num"><span class="min-size">¥</span>{{showMoney}}<span class="min-size"></span></span>
145 165
         </div>
146 166
       </div>
147 167
       <div class="payment"
@@ -158,9 +178,13 @@
158 178
           <li class="coupon-info"
159 179
               v-for="item,index in couponList"
160 180
               :key="index">
161
-            <div class="coupon-tips-text">{{item.type==1?'无条件抵扣券':item.type==2?'满减券':item.type==3?'全额券':'项目全减券'}}</div>
181
+  <!-- 1: '抵扣券',
182
+      2: '满减券',
183
+      3: '全额减免券',
184
+      4: '项目卡券' -->
185
+            <div class="coupon-tips-text">{{item.type==1?'抵扣券':item.type==2?'满减券':item.type==3?'全额减免券':'项目卡券'}}</div>
162 186
             <div class="top">
163
-              <div v-if="item.type!=2"
187
+              <div v-if="item.type==3"
164 188
                    class="discount-over">全免</div>
165 189
               <div v-else
166 190
                    class="discount">
@@ -172,7 +196,7 @@
172 196
                 <div class="tips-ts">有效期至{{item.ex_time}}</div>
173 197
               </div>
174 198
               <div class="choice-icon"
175
-                   @click="selectPupop(item,index)"><img :src="item.Select?select:unSelect"></div>
199
+                   @click="selectPupop(item,index)"><img :src="item.isSelect?select:unSelect"></div>
176 200
             </div>
177 201
             <div class="bottom">
178 202
               <div class="coupon-notes"
@@ -382,7 +406,19 @@ export default {
382 406
       isChange: false,//项目是否有改变
383 407
       isEditProject: false,//是否编辑项目
384 408
       page: 1,
385
-      limit: 20,
409
+      limit: 200,
410
+
411
+
412
+
413
+
414
+    needSelect: false,
415
+    coupSelectType: '',
416
+    productDiscount: '',
417
+    isSelectCoup: [], // 选择的优惠券
418
+    // 下面是支付的数据
419
+    showMoney: 0, // 价值总额
420
+    // showRuleText: 10086,
421
+
386 422
     };
387 423
   },
388 424
   computed: {
@@ -398,6 +434,7 @@ export default {
398 434
         this.remarks = res.data.remark
399 435
         this.programmeList = res.data.scheme_list
400 436
         this.order_data = res.data.order_data
437
+        this.showMoney=res.data.order_data.price
401 438
         this.poreList = res.data.detail_list
402 439
         this.calculationPrice()
403 440
       })
@@ -579,6 +616,12 @@ export default {
579 616
     },
580 617
     //获取订单优惠券
581 618
     onCoupon () {
619
+
620
+      if(this.couponList.length>0){
621
+         this.isCoupun = true
622
+         return
623
+      }
624
+
582 625
       let params = {
583 626
         id: this.id,
584 627
         page: this.page,
@@ -587,29 +630,221 @@ export default {
587 630
       api.getOrderCoupon(params).then(res => {
588 631
         this.couponList = [...this.couponList, ...res.data.list]
589 632
         this.couponList.forEach(item => {
590
-          this.$set(item, 'Select', false)
633
+          this.$set(item, 'isSelect', false)
591 634
         })
592 635
         this.page++
593 636
         if (this.couponList.length < res.data.total) {
594 637
           this.onCoupon()
595 638
         }
596 639
       })
640
+      console.log(this.couponList)
597 641
       this.isCoupun = true
598 642
     },
643
+
644
+
599 645
     //数组包含关系
600 646
     includes (arr1, arr2) {
601 647
       return arr2.every(val => arr1.includes(val));
602 648
     },
603 649
     //选中优惠券
604
-    selectPupop (item, index) {
605
-      this.couponList[index].Select = !this.couponList[index].Select
606
-      this.selectCouponList = this.couponList.filter(res => {
607
-        return res.Select == true
608
-      })
609
-      this.selectCouponList.forEach(res => {
610
-      })
650
+    // selectPupop (item, index) {
651
+    //   this.couponList[index].Select = !this.couponList[index].Select
652
+    //   this.selectCouponList = this.couponList.filter(res => {
653
+    //     return res.Select == true
654
+    //   })
655
+    //   this.selectCouponList.forEach(res => {
656
+    //   })
657
+
658
+    // },
659
+
660
+
661
+// 不可以用的不显示,如果同时有项目劵、抵扣劵、满减劵,只能用一种类型,其他劵不显示
662
+// 1、针对单个项目,项目劵可以多选
663
+// 2、抵扣劵、满减劵针对的是整个订单,当用户已使用了单个项目劵时,抵扣劵、满减劵就不能使用
664
+// 3、优惠劵可以给多个项目抵扣,
665
+// 4、默认抵扣金额最高的
666
+// 5、优惠劵排序,到期时间倒叙
667
+
668
+
669
+/**
670
+   * 点击使用按钮、勾选按钮
671
+   */
672
+  selectPupop: function (item, index) {
673
+
674
+
675
+    let CouPonIndex = this.couponList
676
+
677
+    let selectIndex = index
678
+    let curreValue = !CouPonIndex[selectIndex].isSelect
679
+    let project_list = this.order_data.project_list //这里是项目列表
680
+
681
+    // 判断是否是不相同的项目券
682
+    if (this.couponList[selectIndex].type != 4) {
683
+      for (let i = 0; i < CouPonIndex.length; i++) {
684
+        CouPonIndex[i].isSelect = false
685
+      }
686
+      for (let i = 0; i < project_list.length; i++) {
687
+        project_list[i].cardId = ''
688
+      }
689
+
690
+    } else if (this.coupSelectType != 4) {
691
+      for (let i = 0; i < CouPonIndex.length; i++) {
692
+        CouPonIndex[i].isSelect = false
693
+      }
694
+      for (let i = 0; i < project_list.length; i++) {
695
+        project_list[i].cardId = ''
696
+      }
697
+    } else {
698
+      let numberSelect = 0
699
+      for (let i = 0; i < CouPonIndex.length; i++) {
700
+        if (CouPonIndex[i].isSelect) {
701
+          numberSelect = numberSelect + 1
702
+        }
703
+      }
704
+      console.log('numberSelect')
705
+      console.log(numberSelect)
706
+      if (numberSelect == this.order_data.project_list.length && curreValue) {
707
+            this.$message.error('最多选择' + this.order_data.project_list.length + '项目券!');
708
+        return
709
+      }
710
+    }
711
+    // 判断是否是取消选择项目券
712
+    CouPonIndex[selectIndex].isSelect = curreValue
713
+    if (!curreValue) {
714
+      for (let j = 0; j < project_list.length; j++) {
715
+        if (project_list[j].cardId && project_list[j].cardId == this.couponList[selectIndex].id) { // 如果是取消选择,那么也要取消绑定项目的id
716
+          project_list[j].cardId = ''
717
+        }
718
+      }
719
+      CouPonIndex[selectIndex].projectids = ''
720
+    }
721
+    let orderDetails1 = this.order_data
722
+    orderDetails1.project_list = project_list
723
+
724
+
725
+      this.order_data=orderDetails1
726
+      this.couponList=CouPonIndex
727
+      this.coupSelectType=this.couponList[selectIndex].type
728
+
729
+    console.log(this.order_data)
730
+    console.log(this.couponList)
731
+
732
+    this.selectCoup()
733
+
734
+  },
735
+
736
+// 选择项目进行绑定
737
+  selectCoup() {
738
+    let that = this
739
+    let isSelectCoups = []
740
+    for (let i = 0; i < this.couponList.length; i++) {
741
+      if (this.couponList[i].isSelect) {
742
+        let selectCoup = that.couponList[i]
743
+        isSelectCoups.push(selectCoup)
744
+      }
745
+    }
746
+      this.isSelectCoup=isSelectCoups
747
+    console.log(this.isSelectCoup)
748
+
749
+    // 抵扣顺序按照项目金额计算
750
+    that.theMoneyBest()
751
+  },
752
+
753
+  // 抵扣顺序按照项目金额计算
754
+  // 卡券,项目券数据包,id:订单项目ID,coupon_id:优惠券ID,如:[{"id":1220,coupon_id:199}]  
755
+  theMoneyBest() {
756
+    let that = this
757
+    let project_list = this.order_data.project_list //这里是项目列表
758
+    let isSelectCoup = this.isSelectCoup //这里选择了的卡券列表
759
+    let selectProjectList = [] // 适合的卡券列表
760
+    // let CouPonIndex = this.CouPonIndex // 卡券选择的Id
761
+    let productDiscount = this.couponList // 卡券列表
762
+    console.log(productDiscount)
763
+    // debugger
764
+    if (isSelectCoup[0].type == 4) {
765
+      for (let i = 0; i < isSelectCoup.length; i++) { // 首先遍历卡券
766
+        if (!isSelectCoup[i].projectids) { // 如果卡券没绑定项目
767
+          console.log('没绑定过!')
768
+
769
+          let selectIndexMoney = 0 // 初始值
770
+          let selectIndex = 111 // 初始金额
771
+          for (let j = 0; j < project_list.length; j++) { // 遍历项目
772
+            if (isSelectCoup[i].project_ids.indexOf(project_list[j].id) != -1 && !project_list[j].cardId) { // 如果卡券能够使用这个项目并且这个项目没有被绑定过
773
+              console.log('project_list[j].price')
774
+              console.log(project_list[j].price)
775
+              console.log(selectIndexMoney)
776
+              console.log(project_list[j].price > selectIndexMoney)
777
+              if (project_list[j].price * 1 > selectIndexMoney * 1) {
778
+                selectIndex = j
779
+                selectIndexMoney = project_list[j].price
780
+                console.log('--' + selectIndexMoney)
781
+              }
782
+              // selectProjectList.push(project_list[i])
783
+            }
784
+          }
785
+          if (selectIndex != 111) {
786
+            console.log('走了这里走了这里')
787
+            isSelectCoup[i].projectids = project_list[selectIndex].id
788
+            isSelectCoup[i].projectName = project_list[selectIndex].name
789
+            project_list[selectIndex].cardId = isSelectCoup[i].id
790
+          } else {
791
+            for (let k = 0; k < productDiscount.length; k++) {
792
+              if (productDiscount[k].id == isSelectCoup[i].id) {
793
+                // isSelectCoup.
794
+                productDiscount[k].isSelect = false
795
+                // isSelectCoup.splice(isSelectCoup.length-1,1);
796
+                this.$message.error('没有适合的项目!');
797
+              }
798
+            }
799
+          }
800
+
801
+        }
802
+      }
803
+      let orderDetails1 = this.order_data
804
+      orderDetails1.project_list = project_list
805
+        this.couponList= productDiscount
806
+        this.isSelectCoup= isSelectCoup
807
+        this.order_data= orderDetails1
808
+    }
809
+
810
+    this.calculateMoney() //计算总额
811
+  },
812
+
813
+  // 计算总额
814
+  calculateMoney() {
815
+    let that = this
816
+    let money = this.order_data.price
817
+    let isSelectCoup = this.isSelectCoup
818
+    let project_list = this.order_data.project_list //这里是项目列表
819
+
820
+    if (isSelectCoup.length == 0) {
821
+        this.showMoney=money.toFixed(2)
822
+      return
823
+    }
824
+
825
+    // 如果是项目
826
+    if (isSelectCoup[0].type == 4) {
827
+      for (let i = 0; i < project_list.length; i++) {
828
+        if (project_list[i].cardId) {
829
+          money = money - project_list[i].price
830
+        }
831
+      }
832
+        this.showMoney=money.toFixed(2)
833
+    } else if (isSelectCoup[0].type == 3) {
834
+      for (let i = 0; i < project_list.length; i++) {
835
+        money = money - project_list[i].price
836
+      }
837
+
838
+    } else {
839
+      money = money - isSelectCoup[0].price
840
+    }
841
+
842
+        this.showMoney=money.toFixed(2)
843
+
844
+
845
+  },
846
+
611 847
 
612
-    },
613 848
     changeActive (e) {
614 849
       this.active = e
615 850
     },