lrf 2 vuotta sitten
vanhempi
commit
ac167ade02
1 muutettua tiedostoa jossa 25 lisäystä ja 4 poistoa
  1. 25 4
      pages/market/index.vue

+ 25 - 4
pages/market/index.vue

@@ -3,7 +3,7 @@
     <view class="main">
       <view class="top" v-if="list.length !=0">
         <view class="text_1">
-            <checkbox class="checkbox" @click="selectAll(false)" :checked="isAll">全选</checkbox>
+          <checkbox class="checkbox" @click="selectAll(false)" :checked="isAll">全选</checkbox>
         </view>
         <view class="text_2" v-if="num==0" @click="edit(1)">编辑</view>
         <view class="text_2" v-if="num==1" @click="edit(0)">完成</view>
@@ -70,7 +70,7 @@
       </view>
       <view class="foot" v-if="list.length !=0">
         <view class="total">总价:<text>¥{{totalMoney}}(不含运费)</text></view>
-        <view class="btn">
+        <view class="btn" v-if="hasCheck()">
           <button type="primary" size="mini" @click="toSettle()" v-if="num==0">提交订单</button>
           <button type="primary" size="mini" @click="toDel()" v-if="num==1">删除</button>
         </view>
@@ -263,8 +263,9 @@ export default {
     async changeValue(value) {
       const that = this;
       this.$nextTick(async () => {
-        const { goodsSpec_id: goodsSpecId, num } = value
+        const { goodsSpec_id: goodsSpecId, num, cart_id: cartId } = value
         const res = await that.$api(`/cart/checkGoodsNum`, 'GET', {
+          cartId,
           goodsSpecId,
           num
         });
@@ -333,7 +334,27 @@ export default {
       if (file.length && file.length > 0) return file[0].url
     },
     // 去结算
-    toSettle() { },
+    async toSettle() {
+      // 将选中的购物车放到数组中,传回服务端进行检查.然后拿着key去订单页请求数据
+      const goodsList = this.list.map(i => i.goods).flat();
+      const cartIds = goodsList.filter(i => i.check).map(i => i.cart_id)
+      const res = await this.$api(`/util/checkCartBuy`, 'POST', {
+        cartIds
+      });
+      if (res.errcode == '0') {
+        const { data } = res
+        if (data.result) {
+          const key = data.key;
+          uni.navigateTo({
+            url: `/pagesHome/order/order?key=${key}`
+          })
+        }
+      }
+    },
+    // 是否选中商品,控制提交订单按钮
+    hasCheck() {
+      return this.list.some(e => e.goods.some(eg => eg.check))
+    }
   }
 }
 </script>