wangfei il y a 6 ans
Parent
révision
095fb6f4d1

+ 2
- 2
src/components/calcMenu/index.vue Voir le fichier

@@ -12,10 +12,10 @@
12 12
             <ul>
13 13
               <li class="flex-h" v-for="(item,index) in data" :key="index">
14 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 16
                 <div class="flex-item">
17 17
                   <div>
18
-                    <span>x{{item.defaultNum === null ? item.num : item.defaultNum}}</span>
18
+                    <span>x{{item.num}}</span>
19 19
                   </div>
20 20
                 </div>
21 21
               </li>

+ 37
- 32
src/components/orderPopup/index.vue Voir le fichier

@@ -18,7 +18,7 @@
18 18
       <div class="bottom flex-h">
19 19
         <div class="flex-item">
20 20
           <div>
21
-            <span>¥{{price * num}}</span>
21
+            <span>¥{{data.spec[activeIndex].price}}</span>
22 22
           </div>
23 23
         </div>
24 24
         <i class="iconfont icon-jian" @click="subtract"></i>
@@ -38,15 +38,31 @@ export default {
38 38
   props: ['show', 'data'],
39 39
   data () {
40 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 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 67
   components: {
52 68
 
@@ -56,23 +72,11 @@ export default {
56 72
   },
57 73
   methods: {
58 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 76
       this.close()
73 77
     },
74 78
     subtract () { // 减
75
-      if (this.num > 1) {
79
+      if (this.num > 0) {
76 80
         this.num -= 1
77 81
       }
78 82
     },
@@ -80,18 +84,19 @@ export default {
80 84
       this.num += 1
81 85
     },
82 86
     selectItem (item, index) { // 选择规格
87
+      console.log(item)
83 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 102
     close () { // 关闭弹窗

+ 73
- 33
src/pages/user/placeOrder/index.vue Voir le fichier

@@ -59,10 +59,10 @@
59 59
       <div class="flex-item">
60 60
         <div>
61 61
           <span>总计</span>
62
-          <span>{{totalNum}}</span>
62
+          <span>{{sumNum}}</span>
63 63
           <span>杯</span>
64 64
           <span>共</span>
65
-          <span>{{totalPrice}}</span>
65
+          <span>{{sumPrice}}</span>
66 66
           <span>元</span>
67 67
           <i class="iconfont" :class="{'icon-jiantou-up': !showCalcMenu,'icon-jiantou-down': showCalcMenu}" @click="showCalcMenu = true"></i>
68 68
         </div>
@@ -71,7 +71,7 @@
71 71
       <a @click="toPlaceOrder">下单</a>
72 72
     </div>
73 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 75
   </div>
76 76
 </template>
77 77
 
@@ -122,6 +122,7 @@ export default {
122 122
         freeMode: true,
123 123
         freeModeMomentumVelocityRatio: 2,
124 124
       },
125
+      selGoods: [],
125 126
     }
126 127
   },
127 128
   computed: {
@@ -136,6 +137,20 @@ export default {
136 137
     MySubSwiper () {
137 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 155
   components: {
141 156
     swiper,
@@ -163,8 +178,8 @@ export default {
163 178
       'getGoodsList',
164 179
     ]),
165 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 183
       }else{
169 184
         this.$toast('您还没有选择商品哦~')
170 185
       }
@@ -210,7 +225,6 @@ export default {
210 225
           }
211 226
         }
212 227
       }
213
-      // console.log(JSON.stringify(this.menuList))
214 228
     },
215 229
     reback () { // 返回桌位选择
216 230
       this.$dialog.confirm({
@@ -234,6 +248,7 @@ export default {
234 248
       this.currentSpec = null
235 249
     },
236 250
     selectSpec (val) { // 选规格
251
+      console.log(val)
237 252
       this.currentSpec = val
238 253
       this.showPopup = true
239 254
     },
@@ -241,36 +256,61 @@ export default {
241 256
       this.MySwiper.slideTo(index, 300)
242 257
     },
243 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 312
       // console.log(JSON.stringify(this.settlementList))
273
-      this.calcTotalNum()
313
+      // this.calcTotalNum()
274 314
     },
275 315
     calcTotalNum () { // 计算总数量、价格
276 316
       var num = 0, price = 0

+ 15
- 9
src/pages/user/placeOrderDetail/index.vue Voir le fichier

@@ -10,13 +10,13 @@
10 10
                 <div><span>{{item.name}}</span></div>
11 11
               </div>
12 12
               <div class="flex-item">
13
-                <div><span>{{item.specName}}</span></div>
13
+                <div><span>{{item.specname}}</span></div>
14 14
               </div>
15 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 17
               </div>
18 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 20
               </div>
21 21
             </li>
22 22
             <li class="flex-h">
@@ -76,8 +76,8 @@ export default {
76 76
           AreaName: decodeURI(_self.$route.query.areaname),
77 77
           TableId: decodeURI(_self.$route.query.tableid),
78 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 81
           Remark: '',
82 82
         },
83 83
         detail: [],
@@ -150,16 +150,22 @@ export default {
150 150
       this.postData.info.PayType = this.postData.coupon.length ? 'coupon' : 'vip'
151 151
       var orderInfo = JSON.parse(this.$route.query.info)
152 152
       this.postData.detail = []
153
+      var amount = 0
154
+      var num = 0
153 155
       for (var n = 0; n < orderInfo.length; n++) {
154 156
         this.postData.detail.push({
155 157
           GoodsId: orderInfo[n].id,
156 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 169
       console.log(JSON.stringify(this.postData))
164 170
       this.toPay({
165 171
         info: JSON.stringify(this.postData.info),