许成详 6 jaren geleden
bovenliggende
commit
49f63d17de

+ 85
- 40
src/pages/user/placeOrderDetail/index.vue Bestand weergeven

@@ -23,8 +23,8 @@
23 23
               <div class="flex-item">
24 24
                 <div><span>选择商品券</span></div>
25 25
               </div>
26
-              <a class="active" @click="showSelect = true">
27
-                <span>{{postData.ticketName === '' ? '1张饮品券' : postData.ticketName}}</span>
26
+              <a class="active" v-if="getCouponOff && couponList.length" @click="showSelectCouponLayer = true">
27
+                <span>{{postData.customercouponid === '' ? '有' + couponList.length + '张优惠券可选' : '已选择优惠券'}}</span>
28 28
                 <i class="iconfont icon-jiantou-right"></i>
29 29
               </a>
30 30
             </li>
@@ -45,16 +45,24 @@
45 45
         <a @click="toPayer">确定</a>
46 46
       </div>
47 47
     </div>
48
-    <div class="selectLayer" :class="{'show': showSelect}">
49
-      <div>
50
-        <van-picker
51
-          show-toolbar
52
-          title="选择优惠券"
53
-          :columns="ticketList"
54
-          @cancel="showSelect = false"
55
-          @confirm="onConfirm"
56
-          value-key="value"
57
-        />
48
+    <div class="selectCouponLayer" :class="{'show': showSelectCouponLayer}">
49
+      <div class="flex-v">
50
+        <div>
51
+          <i class="iconfont icon-guanbi" @click="showSelectCouponLayer = false"></i>
52
+        </div>
53
+        <div class="flex-item">
54
+          <div class="flex-h">
55
+            <div class="flex-item" style="margin: 0 .2rem;">
56
+              <ul>
57
+                <li v-for="(item,index) in couponList" :key="index" @click="selectCouponItem(item)" :class="{'active':item.select}">
58
+                  <i class="iconfont icon-gouxuan"></i>
59
+                  <discounts :data="item"></discounts>
60
+                </li>
61
+              </ul>
62
+            </div>
63
+          </div>
64
+        </div>
65
+        <a @click="sureSelectCoupon">确定</a>
58 66
       </div>
59 67
     </div>
60 68
   </div>
@@ -63,12 +71,16 @@
63 71
 <script>
64 72
 import { mapState, createNamespacedHelpers } from 'vuex'
65 73
 const { mapActions: caseTableActions } = createNamespacedHelpers('placeOrderForCoffee')
74
+import discounts from '../../../components/discounts/discounts'
66 75
 
67 76
 export default {
68 77
   name: '',
69 78
   data () {
70 79
     var _self = this
71 80
     return {
81
+      showSelectCouponLayer: false,
82
+      getCouponOff: false,
83
+      couponList: [], // 优惠券列表
72 84
       postData: {
73 85
         info: {
74 86
           CaseId: decodeURI(_self.$route.query.caseid),
@@ -81,21 +93,7 @@ export default {
81 93
           Remark: '',
82 94
         },
83 95
         detail: [],
84
-        coupon: [
85
-          //   {
86
-          //   OrdersCouponId: '',
87
-          //   OrdersId: '',
88
-          //   OrdersNo: '',
89
-          //   CouponId: '',
90
-          //   CouponName: '',
91
-          //   OrgId: '',
92
-          //   GoodsId: '',
93
-          //   GoodsName: '',
94
-          //   UsedAmount: '',
95
-          //   Status: '',
96
-          //   CreateDate: '',
97
-          // }
98
-        ],
96
+        customercouponid: ''
99 97
       },
100 98
       ticketList: [{
101 99
         value: '优惠券1',
@@ -107,10 +105,12 @@ export default {
107 105
         value: '优惠券3',
108 106
         id: '3',
109 107
       }],
110
-      showSelect: false,
111 108
       orderInfo: JSON.parse(_self.$route.query.info) || []
112 109
     }
113 110
   },
111
+  components: {
112
+    discounts,
113
+  },
114 114
   computed: {
115 115
     ...mapState({
116 116
       userInfo: x => x.userCenter.userInfo,
@@ -118,13 +118,63 @@ export default {
118 118
     })
119 119
   },
120 120
   created () {
121
-    // console.log(this.$route.query.info)
122
-    // console.log(JSON.stringify(this.postData))
121
+    this.getCouponList().then((res) => {
122
+      // console.log(JSON.stringify(res))
123
+      var id = JSON.parse(this.$route.query.info)[0].id, arr = [], nowDate = Date.now()
124
+      for (var n = 0; n < res.length; n++) {
125
+        if (res[n].Coupon.CouponType === 'goods' && res[n].Status === 1) {
126
+          if (res[n].Coupon.IsAll) {
127
+            this.couponList.push(res[n])
128
+          } else {
129
+            for (var a = 0; a < res[n].Coupon.Targets.length; a++) {
130
+              if (res[n].Coupon.Targets[a].TargetId === id && nowDate >= new Date(res[n].StartDate).getTime() && nowDate < new Date(res[n].EndDate).getTime()) {
131
+                this.couponList.push({
132
+                  title: res[n].Coupon.CouponName,
133
+                  desc: res[n].Coupon.Share.UseInstruction,
134
+                  time: this.toolClass.dateFormat(res[n].EndDate),
135
+                  useType: '未使用',
136
+                  tag: '商品',
137
+                  id: res[n].CustomerCouponId,
138
+                  select: false,
139
+                })
140
+              }
141
+            }
142
+          }
143
+        }
144
+      }
145
+      this.getCouponOff = true
146
+      // console.log(JSON.stringify(this.couponList))
147
+    })
123 148
   },
124 149
   methods: {
125 150
     ...caseTableActions([
126 151
       'toPay',
152
+      'getCouponList',
127 153
     ]),
154
+    sureSelectCoupon () {
155
+      var bool = false
156
+      for (var n = 0; n < this.couponList.length; n++) {
157
+        if (this.couponList[n].select) {
158
+          bool = true
159
+          this.postData.customercouponid = this.couponList[n].id
160
+        }
161
+      }
162
+      if (!bool) {
163
+        this.postData.customercouponid = ''
164
+      }
165
+      this.showSelectCouponLayer = false
166
+    },
167
+    selectCouponItem (item) { // 选择优惠券
168
+      // item.select = !item.select
169
+      if (!item.select) {
170
+        for (var n = 0; n < this.couponList.length; n++) {
171
+          this.couponList[n].select = false
172
+        }
173
+        item.select = true
174
+      } else {
175
+        item.select = false
176
+      }
177
+    },
128 178
     returnAmount () { // 返回总金额  
129 179
       var amount = 0, num = 0, info = JSON.parse(this.$route.query.info)
130 180
       for (var n = 0; n < info.length; n++) {
@@ -138,16 +188,11 @@ export default {
138 188
       }
139 189
       return [amount, num]
140 190
     },
141
-    onConfirm (value, index) {
142
-      this.postData.coupon.CouponName = value.value
143
-      this.postData.coupon.CouponId = value.id
144
-      this.showSelect = false
145
-    },
146 191
     toPayer () { // 下单
147 192
       this.postData.info.OrgId = this.orgId
148 193
       this.postData.info.UserId = this.userInfo.CustomerId
149 194
       this.postData.info.UserName = this.userInfo.customer.CustomerName
150
-      this.postData.info.PayType = this.postData.coupon.length ? 'coupon' : 'vip'
195
+      this.postData.info.PayType = this.postData.customercouponid === '' ? 'coupon' : 'vip'
151 196
       var orderInfo = JSON.parse(this.$route.query.info)
152 197
       this.postData.detail = []
153 198
       var amount = 0
@@ -159,10 +204,10 @@ export default {
159 204
           SpecId: orderInfo[n].spec,
160 205
           SpecName: orderInfo[n].specname,
161 206
           Number: orderInfo[n].num - 0,
162
-          Price: String(orderInfo[n].price-0),
207
+          Price: String(orderInfo[n].price - 0),
163 208
         })
164
-        amount += (orderInfo[n].price-0) * orderInfo[n].num
165
-        num += orderInfo[n].num-0
209
+        amount += (orderInfo[n].price - 0) * orderInfo[n].num
210
+        num += orderInfo[n].num - 0
166 211
       }
167 212
       this.postData.info.Amount = String(amount)
168 213
       this.postData.info.OrdersNum = num
@@ -170,7 +215,7 @@ export default {
170 215
       this.toPay({
171 216
         info: JSON.stringify(this.postData.info),
172 217
         detail: JSON.stringify(this.postData.detail),
173
-        coupon: JSON.stringify(this.postData.coupon)
218
+        customercouponid: this.postData.customercouponid
174 219
       }).then((res) => {
175 220
         this.$dialog.alert({
176 221
           message: '下单成功!'

+ 132
- 0
src/pages/user/placeOrderDetail/page.scss Bestand weergeven

@@ -167,4 +167,136 @@
167 167
       overflow: hidden;
168 168
     }
169 169
   }
170
+  .selectCouponLayer{
171
+    width: 100%;
172
+    position: absolute;
173
+    left: 0;
174
+    top: 0;
175
+    bottom: 0;
176
+    z-index: 100;
177
+    background: rgba(0,0,0,.5);
178
+    display: none;
179
+    &.show{
180
+      display: block;
181
+    }
182
+    >div{
183
+      width: 100%;
184
+      height: 4rem;
185
+      position: absolute;
186
+      overflow: hidden;
187
+      left: 0;
188
+      bottom: 0;
189
+      background: #fff;
190
+      border-radius: .1rem .1rem 0 0;
191
+      >div{
192
+        width: 100%;
193
+        &:first-child{
194
+          text-align: right;
195
+          margin-top: .1rem;
196
+          >i{
197
+            margin-right: .1rem;
198
+            font-size: .2rem;
199
+            color: #666;
200
+          }
201
+        }
202
+        &.flex-item{
203
+          position: relative;
204
+          overflow: visible;
205
+          >div{
206
+            width: 100%;
207
+            position: absolute;
208
+            overflow: visible;
209
+            left: 0;
210
+            top: 0;
211
+            bottom: 0;
212
+            >div{
213
+              width: 100%;
214
+              overflow-y: scroll;
215
+              -webkit-overflow-scrolling: touch;
216
+              transform: translateZ(0);
217
+              -webkit-transform: translateZ(0);
218
+              overflow-x: visible;
219
+              ul{
220
+                width: 100%;
221
+                position: relative;
222
+                overflow: visible;
223
+                li{
224
+                  width: 100%;
225
+                  position: relative;
226
+                  overflow: visible;
227
+                  margin: .1rem auto 0;
228
+                  >i{
229
+                    display: none;
230
+                    font-size: .2rem;
231
+                    color: #fd684a;
232
+                    position: absolute;
233
+                    right: .1rem;
234
+                    top: .1rem;
235
+                    z-index: 110;
236
+                  }
237
+                  &.active{
238
+                    >i{
239
+                      display: block;
240
+                    }
241
+                  }
242
+                }
243
+              }
244
+            }
245
+          }
246
+        }
247
+      }
248
+      >a{
249
+        width: 100%;
250
+        display: block;
251
+        text-align: center;
252
+        font-size: .16rem;
253
+        color: #fff;
254
+        background: #fd684a;
255
+        line-height: .5rem;
256
+      }
257
+    }
258
+    // >div{
259
+    //   width: 100%;
260
+    //   max-height: 3rem;
261
+    //   overflow: hidden;
262
+    //   position: absolute;
263
+    //   left: 0;
264
+    //   bottom: 0;
265
+    //   background: #fff;
266
+    //   border-radius: .1rem .1rem 0 0;
267
+    //   >div{
268
+    //     width: 100%;
269
+    //     position: relative;
270
+    //     overflow: visible;
271
+    //     &:first-child{
272
+    //       text-align: right;
273
+    //     }
274
+    //     i{
275
+    //       font-size: .2rem;
276
+    //       color: #666;
277
+    //       margin-right: .1rem;
278
+    //     }
279
+    //     >ul{
280
+    //       position: relative;
281
+    //       overflow: visible;
282
+    //       margin: 0 .2rem;
283
+    //       >li{
284
+    //         width: 100%;
285
+    //         position: relative;
286
+    //         overflow: visible;
287
+    //         margin: .1rem auto 0;
288
+    //       }
289
+    //     }
290
+    //   }
291
+    //   >a{
292
+    //     width: 100%;
293
+    //     display: block;
294
+    //     text-align: center;
295
+    //     font-size: .16rem;
296
+    //     color: #fff;
297
+    //     background: #fd684a;
298
+    //     line-height: .5rem;
299
+    //   }
300
+    // }
301
+  }
170 302
 }

+ 11
- 2
src/store/placeOrderForCoffee/index.js Bestand weergeven

@@ -63,19 +63,28 @@ export default {
63 63
         })
64 64
       })
65 65
     },
66
-    toPay (context, { info, detail, coupon }) { // 下单
66
+    toPay (context, { info, detail, customercouponid }) { // 下单
67 67
       return new Promise((resolve) => {
68 68
         Ajax(api.caseForCoffee.placeGoodsOrder.url, {
69 69
           method: api.caseForCoffee.placeGoodsOrder.method,
70 70
           data: {
71 71
             info,
72 72
             detail,
73
-            coupon,
73
+            customercouponid,
74 74
           },
75 75
         }).then(res => {
76 76
           resolve(res)
77 77
         })
78 78
       })
79 79
     },
80
+    getCouponList (context) { // 获取优惠券列表
81
+      return new Promise((resolve) => {
82
+        Ajax(api.caseForCoffee.getCouponList.url, {
83
+          method: api.caseForCoffee.getCouponList.method,
84
+        }).then(res => {
85
+          resolve(res)
86
+        })
87
+      })
88
+    },
80 89
   }
81 90
 }

+ 5
- 1
src/util/api.js Bestand weergeven

@@ -47,7 +47,11 @@ const $api = {
47 47
     placeGoodsOrder: { // 商品下单
48 48
       method: 'post',
49 49
       url: `${baseUrl}${wechat}/order/goods`
50
-    }
50
+    },
51
+    getCouponList: { // 获取优惠券列表
52
+      method: 'get',
53
+      url: `${baseUrl}${wechat}/customer/coupon`
54
+    },
51 55
   },
52 56
   majorProjects: { // 项目专题
53 57
     getCourseList: { // 获取课程列表