Browse Source

修改下單

wangfei 6 years ago
parent
commit
095fb6f4d1

+ 2
- 2
src/components/calcMenu/index.vue View File

12
             <ul>
12
             <ul>
13
               <li class="flex-h" v-for="(item,index) in data" :key="index">
13
               <li class="flex-h" v-for="(item,index) in data" :key="index">
14
                 <span>{{item.name}}</span>
14
                 <span>{{item.name}}</span>
15
-                <span v-if="item.specName !== null">({{item.specName}})</span>
15
+                <span v-if="item.specname !== null && item.specname!=''">({{item.specname}})</span>
16
                 <div class="flex-item">
16
                 <div class="flex-item">
17
                   <div>
17
                   <div>
18
-                    <span>x{{item.defaultNum === null ? item.num : item.defaultNum}}</span>
18
+                    <span>x{{item.num}}</span>
19
                   </div>
19
                   </div>
20
                 </div>
20
                 </div>
21
               </li>
21
               </li>

+ 37
- 32
src/components/orderPopup/index.vue View File

18
       <div class="bottom flex-h">
18
       <div class="bottom flex-h">
19
         <div class="flex-item">
19
         <div class="flex-item">
20
           <div>
20
           <div>
21
-            <span>¥{{price * num}}</span>
21
+            <span>¥{{data.spec[activeIndex].price}}</span>
22
           </div>
22
           </div>
23
         </div>
23
         </div>
24
         <i class="iconfont icon-jian" @click="subtract"></i>
24
         <i class="iconfont icon-jian" @click="subtract"></i>
38
   props: ['show', 'data'],
38
   props: ['show', 'data'],
39
   data () {
39
   data () {
40
     return {
40
     return {
41
-      activeIndex: '',
42
-      price: 0,
43
-      num: 1,
44
-      specId: '',
45
-      specName: '',
41
+      activeIndex: 0,
42
+      // price: 0,
43
+      // num: 0,
44
+      // specId: '',
45
+      // specName: '',
46
     }
46
     }
47
   },
47
   },
48
   computed: {
48
   computed: {
49
-
49
+    num: {
50
+      get () {
51
+        return this.data.spec[this.activeIndex].num
52
+      },
53
+      set (val) {
54
+        console.log(this.data)
55
+        this.data.spec[this.activeIndex].num = val
56
+        this.$emit('returnData', {
57
+          id: this.data.id,
58
+          name: this.data.name,
59
+          spec: this.data.spec[this.activeIndex].id,
60
+          specname: this.data.spec[this.activeIndex].value,
61
+          defaultNum: val,
62
+          defaultPrice: this.data.spec[this.activeIndex].price,
63
+        })
64
+      }
65
+    },
50
   },
66
   },
51
   components: {
67
   components: {
52
 
68
 
56
   },
72
   },
57
   methods: {
73
   methods: {
58
     sure () { // 确定
74
     sure () { // 确定
59
-      if (this.activeIndex === '' || this.price === 0 || this.num < 1) {
60
-        return false
61
-      }
62
-      this.$emit('returnData', {
63
-        name: this.data.name,
64
-        id: this.data.id,
65
-        specId: this.specId,
66
-        specName: this.specName,
67
-        num: this.num,
68
-        defaultNum: null,
69
-        price: this.price,
70
-        defaultPrice: null,
71
-      })
75
+      // this.$emit('returnData', this.data)
72
       this.close()
76
       this.close()
73
     },
77
     },
74
     subtract () { // 减
78
     subtract () { // 减
75
-      if (this.num > 1) {
79
+      if (this.num > 0) {
76
         this.num -= 1
80
         this.num -= 1
77
       }
81
       }
78
     },
82
     },
80
       this.num += 1
84
       this.num += 1
81
     },
85
     },
82
     selectItem (item, index) { // 选择规格
86
     selectItem (item, index) { // 选择规格
87
+      console.log(item)
83
       if (item.status === 1) {
88
       if (item.status === 1) {
84
-        if (this.activeIndex === index) {
85
-          this.activeIndex = ''
86
-          this.price = 0
87
-          this.specId = ''
88
-          this.specName = ''
89
-        } else {
90
-          this.activeIndex = index
91
-          this.price = item.price
92
-          this.specId = item.id
93
-          this.specName = item.value
94
-        }
89
+        // if (this.activeIndex === index) {
90
+        //   this.activeIndex = ''
91
+        //   this.price = 0
92
+        //   this.specId = ''
93
+        //   this.specName = ''
94
+        // } else {
95
+        this.activeIndex = index
96
+          // this.price = item.price
97
+          // this.specId = item.id
98
+          // this.specName = item.value
99
+        // }
95
       }
100
       }
96
     },
101
     },
97
     close () { // 关闭弹窗
102
     close () { // 关闭弹窗

+ 73
- 33
src/pages/user/placeOrder/index.vue View File

59
       <div class="flex-item">
59
       <div class="flex-item">
60
         <div>
60
         <div>
61
           <span>总计</span>
61
           <span>总计</span>
62
-          <span>{{totalNum}}</span>
62
+          <span>{{sumNum}}</span>
63
           <span>杯</span>
63
           <span>杯</span>
64
           <span>共</span>
64
           <span>共</span>
65
-          <span>{{totalPrice}}</span>
65
+          <span>{{sumPrice}}</span>
66
           <span>元</span>
66
           <span>元</span>
67
           <i class="iconfont" :class="{'icon-jiantou-up': !showCalcMenu,'icon-jiantou-down': showCalcMenu}" @click="showCalcMenu = true"></i>
67
           <i class="iconfont" :class="{'icon-jiantou-up': !showCalcMenu,'icon-jiantou-down': showCalcMenu}" @click="showCalcMenu = true"></i>
68
         </div>
68
         </div>
71
       <a @click="toPlaceOrder">下单</a>
71
       <a @click="toPlaceOrder">下单</a>
72
     </div>
72
     </div>
73
     <orderPopup :show="showPopup" :data="currentSpec" @closePopup="closePopup" @returnData="calcMenus"></orderPopup>
73
     <orderPopup :show="showPopup" :data="currentSpec" @closePopup="closePopup" @returnData="calcMenus"></orderPopup>
74
-    <calcMenu :show="showCalcMenu" :totalNum="totalCupNum" :data="settlementList" @returnData="calcMenus" @emptyMenus="emptyMenus" @closeCalcMenu="closeCalcMenu" @placeOrder="placeOrder"></calcMenu>
74
+    <calcMenu :show="showCalcMenu" :totalNum="sumNum" :data="selGoods" @returnData="calcMenus" @emptyMenus="emptyMenus" @closeCalcMenu="closeCalcMenu" @placeOrder="placeOrder"></calcMenu>
75
   </div>
75
   </div>
76
 </template>
76
 </template>
77
 
77
 
122
         freeMode: true,
122
         freeMode: true,
123
         freeModeMomentumVelocityRatio: 2,
123
         freeModeMomentumVelocityRatio: 2,
124
       },
124
       },
125
+      selGoods: [],
125
     }
126
     }
126
   },
127
   },
127
   computed: {
128
   computed: {
136
     MySubSwiper () {
137
     MySubSwiper () {
137
       return this.$refs.mySubSwiper.swiper
138
       return this.$refs.mySubSwiper.swiper
138
     },
139
     },
140
+    sumNum () {
141
+      let num = 0
142
+      this.selGoods.map(x => {
143
+        num += x.num
144
+      })
145
+      return num
146
+    },
147
+    sumPrice () {
148
+      let price = 0
149
+      this.selGoods.map(x => {
150
+        price += x.price*x.num - 0
151
+      })
152
+      return price
153
+    }
139
   },
154
   },
140
   components: {
155
   components: {
141
     swiper,
156
     swiper,
163
       'getGoodsList',
178
       'getGoodsList',
164
     ]),
179
     ]),
165
     toPlaceOrder () { // 下单 
180
     toPlaceOrder () { // 下单 
166
-      if(this.settlementList.length){
167
-        this.$router.push({name: 'placeOrderDetail', query: {info: JSON.stringify(this.settlementList), caseid: encodeURI(this.caseId), areaid: encodeURI(this.areaId), areaname: encodeURI(this.areaName), areaid: encodeURI(this.areaId), tableid: encodeURI(this.tableId), tableno: encodeURI(this.tableNo)}})
181
+      if(this.selGoods.length){
182
+        this.$router.push({name: 'placeOrderDetail', query: {info: JSON.stringify(this.selGoods), caseid: encodeURI(this.caseId), areaid: encodeURI(this.areaId), areaname: encodeURI(this.areaName), areaid: encodeURI(this.areaId), tableid: encodeURI(this.tableId), tableno: encodeURI(this.tableNo)}})
168
       }else{
183
       }else{
169
         this.$toast('您还没有选择商品哦~')
184
         this.$toast('您还没有选择商品哦~')
170
       }
185
       }
210
           }
225
           }
211
         }
226
         }
212
       }
227
       }
213
-      // console.log(JSON.stringify(this.menuList))
214
     },
228
     },
215
     reback () { // 返回桌位选择
229
     reback () { // 返回桌位选择
216
       this.$dialog.confirm({
230
       this.$dialog.confirm({
234
       this.currentSpec = null
248
       this.currentSpec = null
235
     },
249
     },
236
     selectSpec (val) { // 选规格
250
     selectSpec (val) { // 选规格
251
+      console.log(val)
237
       this.currentSpec = val
252
       this.currentSpec = val
238
       this.showPopup = true
253
       this.showPopup = true
239
     },
254
     },
241
       this.MySwiper.slideTo(index, 300)
256
       this.MySwiper.slideTo(index, 300)
242
     },
257
     },
243
     calcMenus (val) { // 计算清单
258
     calcMenus (val) { // 计算清单
244
-      var bool = true, arr = this.settlementList.slice()
245
-      if (val.specId === null) {
246
-        for (var n = 0; n < arr.length; n++) {
247
-          if (arr[n].id === val.id && arr[n].specId === null) {
248
-            bool = false
249
-            arr[n] = val
250
-          }
251
-        }
252
-        if (bool) {
253
-          arr.push(val)
254
-        }
255
-      } else {
256
-        for (var n = 0; n < arr.length; n++) {
257
-          if (arr[n].specId === val.specId) {
258
-            bool = false
259
-            arr[n] = val
260
-          }
261
-        }
262
-        if (bool) {
263
-          arr.push(val)
264
-        }
265
-      }
266
-      for (var n = 0; n < arr.length; n++) {
267
-        if (arr[n].num === 0 || arr[n].defaultNum === 0) {
268
-          arr.splice(n, 1)
259
+      var ishas = false
260
+      const _that = this
261
+      this.selGoods.map((goods,inx) => {
262
+        if(goods.id === val.id && goods.spec === (val.spec || '')){
263
+          ishas = true
264
+          _that.selGoods[inx].num = val.defaultNum
269
         }
265
         }
266
+      })
267
+      if (!ishas) {
268
+        this.selGoods.push({
269
+          id: val.id,
270
+          price: val.defaultPrice,
271
+          num: val.defaultNum,
272
+          name: val.name,
273
+          spec: (val.spec || ''),
274
+          specname: (val.specname || ''),
275
+        })
270
       }
276
       }
271
-      this.settlementList = arr
277
+      console.log(this.selGoods)
278
+      // var settlementList = this.settlementList
279
+      // val.spec.map(spec => {
280
+      //   settlementList.filter
281
+      // })
282
+
283
+
284
+      // var bool = true, arr = this.settlementList.slice()
285
+      // if (val.specId === null) {
286
+      //   for (var n = 0; n < arr.length; n++) {
287
+      //     if (arr[n].id === val.id && arr[n].specId === null) {
288
+      //       bool = false
289
+      //       arr[n] = val
290
+      //     }
291
+      //   }
292
+      //   if (bool) {
293
+      //     arr.push(val)
294
+      //   }
295
+      // } else {
296
+      //   for (var n = 0; n < arr.length; n++) {
297
+      //     if (arr[n].specId === val.specId) {
298
+      //       bool = false
299
+      //       arr[n] = val
300
+      //     }
301
+      //   }
302
+      //   if (bool) {
303
+      //     arr.push(val)
304
+      //   }
305
+      // }
306
+      // for (var n = 0; n < arr.length; n++) {
307
+      //   if (arr[n].num === 0 || arr[n].defaultNum === 0) {
308
+      //     arr.splice(n, 1)
309
+      //   }
310
+      // }
311
+      // this.settlementList = arr
272
       // console.log(JSON.stringify(this.settlementList))
312
       // console.log(JSON.stringify(this.settlementList))
273
-      this.calcTotalNum()
313
+      // this.calcTotalNum()
274
     },
314
     },
275
     calcTotalNum () { // 计算总数量、价格
315
     calcTotalNum () { // 计算总数量、价格
276
       var num = 0, price = 0
316
       var num = 0, price = 0

+ 15
- 9
src/pages/user/placeOrderDetail/index.vue View File

10
                 <div><span>{{item.name}}</span></div>
10
                 <div><span>{{item.name}}</span></div>
11
               </div>
11
               </div>
12
               <div class="flex-item">
12
               <div class="flex-item">
13
-                <div><span>{{item.specName}}</span></div>
13
+                <div><span>{{item.specname}}</span></div>
14
               </div>
14
               </div>
15
               <div class="flex-item">
15
               <div class="flex-item">
16
-                <div><span>x{{item.defaultNum === null ? item.num : item.defaultNum}}</span></div>
16
+                <div><span>x{{item.num}}</span></div>
17
               </div>
17
               </div>
18
               <div class="flex-item">
18
               <div class="flex-item">
19
-                <div><span>¥{{item.defaultPrice === null ? item.price : item.defaultPrice}}</span></div>
19
+                <div><span>¥{{item.price * item.num}}</span></div>
20
               </div>
20
               </div>
21
             </li>
21
             </li>
22
             <li class="flex-h">
22
             <li class="flex-h">
76
           AreaName: decodeURI(_self.$route.query.areaname),
76
           AreaName: decodeURI(_self.$route.query.areaname),
77
           TableId: decodeURI(_self.$route.query.tableid),
77
           TableId: decodeURI(_self.$route.query.tableid),
78
           TableNo: decodeURI(_self.$route.query.tableno),
78
           TableNo: decodeURI(_self.$route.query.tableno),
79
-          Amount: String(_self.returnAmount()[0]), // 订单金额
80
-          OrdersNum: Number(_self.returnAmount()[1]),
79
+          Amount: 0, // 订单金额
80
+          OrdersNum: 0,
81
           Remark: '',
81
           Remark: '',
82
         },
82
         },
83
         detail: [],
83
         detail: [],
150
       this.postData.info.PayType = this.postData.coupon.length ? 'coupon' : 'vip'
150
       this.postData.info.PayType = this.postData.coupon.length ? 'coupon' : 'vip'
151
       var orderInfo = JSON.parse(this.$route.query.info)
151
       var orderInfo = JSON.parse(this.$route.query.info)
152
       this.postData.detail = []
152
       this.postData.detail = []
153
+      var amount = 0
154
+      var num = 0
153
       for (var n = 0; n < orderInfo.length; n++) {
155
       for (var n = 0; n < orderInfo.length; n++) {
154
         this.postData.detail.push({
156
         this.postData.detail.push({
155
           GoodsId: orderInfo[n].id,
157
           GoodsId: orderInfo[n].id,
156
           GoodsName: orderInfo[n].name,
158
           GoodsName: orderInfo[n].name,
157
-          SpecId: orderInfo[n].specId,
158
-          SpecName: orderInfo[n].specName,
159
-          Number: orderInfo[n].defaultNum === null ? orderInfo[n].num - 0 : orderInfo[n].defaultNum - 0,
160
-          Price: orderInfo[n].defaultNum === null ? String(orderInfo[n].price) : String(orderInfo[n].defaultPrice),
159
+          SpecId: orderInfo[n].spec,
160
+          SpecName: orderInfo[n].specname,
161
+          Number: orderInfo[n].num - 0,
162
+          Price: String(orderInfo[n].price-0),
161
         })
163
         })
164
+        amount += (orderInfo[n].price-0) * orderInfo[n].num
165
+        num += orderInfo[n].num-0
162
       }
166
       }
167
+      this.postData.info.Amount = String(amount)
168
+      this.postData.info.OrdersNum = num
163
       console.log(JSON.stringify(this.postData))
169
       console.log(JSON.stringify(this.postData))
164
       this.toPay({
170
       this.toPay({
165
         info: JSON.stringify(this.postData.info),
171
         info: JSON.stringify(this.postData.info),