Browse Source

合并代码

mabaoyi 8 months ago
parent
commit
980e237b4f

+ 38 - 5
components/kj-tabbar/kj-tabbar.vue

@@ -3,7 +3,12 @@
     <view class="bottom u-flex u-row-between" v-if="value1 == 3">
       <view class="u-flex">
         <u-checkbox-group v-model="all" placement="column" @change="checkAll">
-          <u-checkbox shape="circle" :name="i18n.selectall"> </u-checkbox>
+          <u-checkbox
+            shape="circle"
+            :name="i18n.selectall"
+            activeColor="#F83224"
+          >
+          </u-checkbox>
         </u-checkbox-group>
         <text class="all">{{ i18n.selectall }}</text>
       </view>
@@ -12,10 +17,11 @@
       </view>
       <view class="u-flex" v-else>
         <view class="">
-          <text class="allweight">{{ i18n.Grossweight }} 50kg,</text>
+          <text class="allweight">{{ i18n.Grossweight }} </text>
+          <text class="allweight"> {{ goodsWeight }}kg,</text>
           <text class="sum">{{ i18n.total }}:</text>
           <text class="summon">¥</text>
-          <text class="summon" style="font-size: 36rpx">188</text>
+          <text class="summon" style="font-size: 36rpx">{{ goodsPrice }}</text>
           <text class="summon">.34</text>
         </view>
         <view class="settle" @click="account">{{ i18n.GotoResult }}</view>
@@ -55,7 +61,18 @@ import { mapState } from "vuex";
 export default {
   name: "kj-tabbar",
   props: {
-    value1: Number,
+    value1: {
+      type: Number,
+      default: 0,
+    },
+    goodsWeight: {
+      type: Number,
+      default: 0,
+    },
+    goodsPrice: {
+      type: Number,
+      default: 0,
+    },
   },
   computed: {
     i18n() {
@@ -64,6 +81,7 @@ export default {
   },
   data() {
     return {
+      success: true,
       list: [
         {
           iconPath: "../../static/express1.png",
@@ -96,7 +114,7 @@ export default {
           pagePath: "pages/mine/mine",
         },
       ],
-      all: "",
+      all: [],
     };
   },
   created() {
@@ -145,6 +163,21 @@ export default {
     // 	}
     // 	uni.setStorageSync('tabbar', e)
     // },
+    checkAll() {
+      this.$emit("allSelect");
+    },
+
+    //
+    cancelAll(value) {
+      if (value == "全选") {
+        return this.all;
+      } else if (value == "取消") {
+        this.all = [];
+      } else {
+        this.all.push(this.i18n.selectall);
+      }
+    },
+
     click1(e) {
       console.log(e);
       if (e == 4) {

+ 1 - 1
pageC/mineFollow/mineFollow.vue

@@ -123,7 +123,7 @@ export default {
     },
     toDetail(item) {
       uni.navigateTo({
-        url: "/pageA/productdetails",
+        url: `/pageA/productdetails?id=${item.id}`,
       });
     },
     getInfoList(num) {

+ 154 - 21
pages/cart/cart.vue

@@ -5,7 +5,7 @@
       <view class="u-nav-slot" slot="left">
         <view class="">
           <text class="shopcart">{{ i18n.Shopping }}</text>
-          <text class="sum">(12)</text>
+          <text class="sum">({{ goodsNum }})</text>
         </view>
       </view>
       <view class="u-nav-slot" slot="right">
@@ -25,6 +25,21 @@
         <view class="item">
           <view class="shopname u-flex">
             <image
+              src="/static/mine/354.png"
+              class="circle"
+              mode="scaleToFill"
+              @click="shopSelectAll(item.goods)"
+              v-if="shop(item.goods)"
+            />
+            <image
+              src="/static/mine/353.png"
+              class="circle"
+              mode="scaleToFill"
+              @click="shopSelectAll(item.goods)"
+              v-else
+            />
+
+            <image
               :src="item.image"
               style="width: 28rpx; height: 28rpx"
               mode=""
@@ -48,7 +63,8 @@
                 <u-checkbox
                   shape="circle"
                   :customStyle="{ marginBottom: '8px' }"
-                  :name="shopitem"
+                  :name="chid.cart.merchant_goods_id"
+                  activeColor="#F83224"
                 >
                 </u-checkbox>
                 <view
@@ -94,11 +110,14 @@
                         >{{ chid.sku_item[0].weight }}kg</text
                       >
                     </view>
-                    <view class="">
+                    <view class="aaaaaa">
                       <!-- <view class="delect" v-if='dele'>{{i18n.delete}}</view> -->
-                      <view class="" v-if="num && success">
+                      <view class="" v-if="num == chid.cart.id && success">
                         <!-- <u-number-box v-model="value" @change="valChange"></u-number-box> -->
-                        <u-number-box v-model="value">
+                        <u-number-box
+                          v-model="chid.cart.goods_num"
+                          @change="addOrReduce"
+                        >
                           <view slot="minus" class="minus">
                             <u-icon
                               name="minus"
@@ -114,7 +133,7 @@
                               font-size: 20rpx;
                             "
                             class="input"
-                            >{{ value }}</text
+                            >{{ chid.cart.goods_num }}</text
                           >
                           <view slot="plus" class="plus">
                             <u-icon
@@ -127,10 +146,10 @@
                       </view>
                       <view
                         class="num"
-                        v-if="num == false && success"
-                        @click="num = true"
+                        v-if="num != chid.cart.id && success"
+                        @click="num = chid.cart.id"
                       >
-                        x1
+                        x{{ chid.cart.goods_num }}
                       </view>
                     </view>
                     <view v-if="success == false" class="icon">
@@ -145,7 +164,13 @@
       </view>
     </u-checkbox-group>
     <view class="" style="height: 260rpx"></view>
-    <kj-tabbar ref="tabbar1" :value1="3"></kj-tabbar>
+    <kj-tabbar
+      ref="tabbar1"
+      :value1="3"
+      @allSelect="allSelect"
+      :goodsWeight="goodsWeight"
+      :goodsPrice="goodsPrice"
+    ></kj-tabbar>
   </view>
 </template>
 
@@ -161,18 +186,21 @@ export default {
       all: [], //全选数组
       goodsList: [],
       selectall: -1,
+      goodsNum: 0,
       num: false,
+      goodsWeight: 0, //商品重量
+      goodsPrice: 0, //商品价格
       options2: [
         {
-          text: "收藏",
+          text: "移入关注",
           style: {
-            backgroundColor: "#3c9cff",
+            backgroundColor: "#FFB115",
           },
         },
         {
           text: "删除",
           style: {
-            backgroundColor: "#f56c6c",
+            backgroundColor: "#F83224",
           },
         },
       ],
@@ -186,18 +214,73 @@ export default {
   },
   onLoad() {
     const systemInfo = wx.getSystemInfoSync();
-    console.log(systemInfo);
     const tab =
       systemInfo.screenHeight -
       systemInfo.safeArea.bottom +
       systemInfo.statusBarHeight;
     this.tabarheight = tab;
-    console.log(this.tabarheight);
   },
   methods: {
+    shop(value) {
+      let num = 0;
+      value.map((item) => {
+        if (this.checkboxValue1.indexOf(item.cart.merchant_goods_id) >= 0) {
+          num++;
+        }
+      });
+      return num;
+    },
+
+    addOrReduce(n) {
+      uni.$u.http
+        .post(`/api/cart/num/${this.num}`, { goods_num: n.value, type: "" })
+        .then((res) => {
+          console.log(res);
+        });
+    },
+
+    //店铺商品全选
+    shopSelectAll(value) {
+      //先判断存放选中的数组有没有选中的数据
+      if (this.checkboxValue1.length == 0) {
+        //没有数据则直接将选中店铺中的商品存入数组
+        value.map((item) => {
+          this.checkboxValue1.push(item.cart.merchant_goods_id);
+        });
+      } else {
+        if (this.shop(value) > 0 && this.shop(value) == value.length) {
+          value.map((item) => {
+            //先判断选中的商品数组中该店铺商品是否已被选中,已被选中则取消选中,未被选中则推入选中状态
+            if (this.checkboxValue1.indexOf(item.cart.merchant_goods_id) >= 0) {
+              this.checkboxValue1.splice(
+                this.checkboxValue1.indexOf(item.cart.merchant_goods_id),
+                1
+              );
+            }
+          });
+        } else if (
+          (this.shop(value) > 0 && this.shop(value) != value.length) ||
+          this.shop(value) == 0
+        ) {
+          value.map((item) => {
+            //先判断选中的商品数组中该店铺商品是否已被选中,已被选中则取消选中,未被选中则推入选中状态
+            if (
+              this.checkboxValue1.indexOf(item.cart.merchant_goods_id) == -1
+            ) {
+              this.checkboxValue1.push(item.cart.merchant_goods_id);
+            }
+          });
+        }
+      }
+      if (this.checkboxValue1.length == this.goodsNum) {
+        this.$refs.tabbar1.cancelAll();
+      } else {
+        this.$refs.tabbar1.cancelAll("取消");
+      }
+      this.shop(value);
+    },
     admin() {
       this.success = !this.success;
-      console.log(this.success);
     },
     valChange(e) {
       console.log("当前值为: " + e.value);
@@ -206,17 +289,61 @@ export default {
     checkAll(e) {
       console.log("all", e);
     },
-    aaa() {
-      console.log(this.$refs.tabbar1.getLabelHeight());
-    },
     checkboxChange(n) {
-      console.log("change", n);
+      this.goodsWeight = 0;
+      this.goodsPrice = 0;
+      this.checkboxValue1 = n;
+      this.goodsList.map((item) => {
+        item.goods.map((items) => {
+          if (n.indexOf(items.id) > -1) {
+            this.goodsWeight += items.sku_item[0].weight;
+            this.goodsPrice += Number(items.sku_item[0].price);
+          }
+        });
+      });
+      //判断是否全部选中
+      if (this.checkboxValue1.length == this.goodsNum && this.goodsNum != 0) {
+        this.$refs.tabbar1.cancelAll();
+      } else if (this.checkboxValue1.length < this.goodsNum) {
+        this.$refs.tabbar1.cancelAll("取消");
+      }
+    },
+    //购物车全选
+    allSelect() {
+      const all = this.$refs.tabbar1.cancelAll("全选");
+      if (this.checkboxValue1.length == this.goodsNum && all.length == 0) {
+        return;
+      }
+      console.log(this.checkboxValue1.length, this.goodsNum);
+      console.log(this.checkboxValue1, this.goodsNum);
+      //判断是否已经全选,如已全选,则取消全选
+      if (this.checkboxValue1.length == this.goodsNum) {
+        this.checkboxValue1 = [];
+        this.goodsPrice = 0;
+        this.goodsWeight = 0;
+      } else {
+        this.goodsList.map((item) => {
+          item.goods.map((items) => {
+            //判断是否有商品已被选中
+            if (
+              this.checkboxValue1.indexOf(items.cart.merchant_goods_id) == -1
+            ) {
+              this.checkboxValue1.push(items.cart.merchant_goods_id);
+              this.goodsWeight += items.sku_item[0].weight;
+              this.goodsPrice += Number(items.sku_item[0].price);
+            }
+          });
+        });
+      }
     },
     //获取购物车数据
     getShopCarList() {
       uni.$u.http.get(`/api/cart`).then((res) => {
-        console.log(res);
         this.goodsList = res.data;
+        //循环店铺,获取购物车商品数量
+        this.goodsList.map((item) => {
+          this.goodsNum += item.goods.length;
+        });
       });
     },
   },
@@ -418,6 +545,7 @@ export default {
       line-height: 28rpx;
       text-align: left;
       font-style: normal;
+      margin-right: 6rpx;
     }
 
     .goods {
@@ -458,6 +586,11 @@ export default {
       line-height: 36rpx;
       text-align: left;
       font-style: normal;
+      .circle {
+        width: 32rpx;
+        height: 32rpx;
+        margin-right: 10rpx;
+      }
     }
   }
 }

BIN
static/mine/353.png


BIN
static/mine/354.png


File diff suppressed because it is too large
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/components/kj-tabbar/kj-tabbar.js.map


File diff suppressed because it is too large
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/pages/cart/cart.js.map


+ 4 - 0
unpackage/dist/dev/mp-weixin/components/kj-tabbar/kj-tabbar.js

@@ -216,6 +216,7 @@ var _default = {
   },
   data: function data() {
     return {
+      success: true,
       list: [{
         iconPath: "../../static/express1.png",
         selectedIconPath: "../../static/express2.png",
@@ -291,6 +292,9 @@ var _default = {
     // 	}
     // 	uni.setStorageSync('tabbar', e)
     // },
+    checkAll: function checkAll() {
+      console.log(111);
+    },
     click1: function click1(e) {
       console.log(e);
       if (e == 4) {

+ 58 - 6
unpackage/dist/dev/mp-weixin/pages/cart/cart.js

@@ -148,6 +148,7 @@ var render = function () {
   var _c = _vm._self._c || _h
   var l1 = _vm.__map(_vm.goodsList, function (item, idx) {
     var $orig = _vm.__get_orig(item)
+    var m0 = _vm.shop(item.goods)
     var l0 = _vm.__map(item.goods, function (chid, index) {
       var $orig = _vm.__get_orig(chid)
       var g0 = chid.sku_item.length
@@ -164,6 +165,7 @@ var render = function () {
     })
     return {
       $orig: $orig,
+      m0: m0,
       l0: l0,
     }
   })
@@ -370,6 +372,22 @@ exports.default = void 0;
 //
 //
 //
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
 var _default = {
   data: function data() {
     return {
@@ -383,6 +401,7 @@ var _default = {
       //全选数组
       goodsList: [],
       selectall: -1,
+      goodsNum: 0,
       num: false,
       options2: [{
         text: "收藏",
@@ -405,15 +424,43 @@ var _default = {
   },
   onLoad: function onLoad() {
     var systemInfo = wx.getSystemInfoSync();
-    console.log(systemInfo);
     var tab = systemInfo.screenHeight - systemInfo.safeArea.bottom + systemInfo.statusBarHeight;
     this.tabarheight = tab;
-    console.log(this.tabarheight);
   },
   methods: {
+    shop: function shop(value) {
+      var _this = this;
+      var num = 0;
+      value.map(function (item) {
+        if (_this.checkboxValue1.indexOf(item.id) >= 0) {
+          num++;
+        }
+      });
+      return num;
+    },
+    //店铺商品全选
+    shopSelectAll: function shopSelectAll(value) {
+      var _this2 = this;
+      //先判断存放选中的数组有没有选中的数据
+      if (this.checkboxValue1.length == 0) {
+        //没有数据则直接将选中店铺中的商品存入数组
+        value.map(function (item) {
+          _this2.checkboxValue1.push(item.id);
+        });
+      } else {
+        value.map(function (item) {
+          //先判断选中的商品数组中该店铺商品是否已被选中,已被选中则取消选中,未被选中则推入选中状态
+          if (_this2.checkboxValue1.indexOf(item.id) >= 0) {
+            _this2.checkboxValue1.splice(_this2.checkboxValue1.indexOf(item.id), 1);
+          } else {
+            _this2.checkboxValue1.push(item.id);
+          }
+        });
+      }
+      this.shop(value);
+    },
     admin: function admin() {
       this.success = !this.success;
-      console.log(this.success);
     },
     valChange: function valChange(e) {
       console.log("当前值为: " + e.value);
@@ -427,13 +474,18 @@ var _default = {
     },
     checkboxChange: function checkboxChange(n) {
       console.log("change", n);
+      console.log(this.checkboxValue1);
     },
+    //购物车全选
+    allSelect: function allSelect() {},
     //获取购物车数据
     getShopCarList: function getShopCarList() {
-      var _this = this;
+      var _this3 = this;
       uni.$u.http.get("/api/cart").then(function (res) {
-        console.log(res);
-        _this.goodsList = res.data;
+        _this3.goodsList = res.data;
+        _this3.goodsList.map(function (item) {
+          _this3.goodsNum += item.goods.length;
+        });
       });
     }
   },

File diff suppressed because it is too large
+ 0 - 0
unpackage/dist/dev/mp-weixin/pages/cart/cart.wxml


Some files were not shown because too many files changed in this diff