wangyong 6 роки тому
батько
коміт
ad83e2387d

+ 69 - 2
customized/pages/made/car/car.js

@@ -8,6 +8,9 @@ Page({
    */
   data: {
     carList:[],// 购物车列表数组
+    host: app.globalData.servsers,
+    amount:0, //总价
+    checkAll:false, // 全选
   },
 
   /**
@@ -28,7 +31,9 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow: function () {
-    this.getCarlist(this)
+    let that = this;
+    that.getCarlist(that)
+    
   },
 
   /**
@@ -65,6 +70,42 @@ Page({
   onShareAppMessage: function () {
 
   },
+  subtraction(e){ // 减少
+  let that = this;
+    console.log(e)
+    let index = e.target.dataset.index,carList = that.data.carList;
+    if (carList[index].customGoodsNum > 1){
+      // 表示最小数量,不可减少
+      carList[index].customGoodsNum--;
+      that.setData({
+        carList: carList
+      })
+    }
+    that.totalPrice(that)
+  },
+  add(e) { // 减少
+    let that = this;
+    console.log(e)
+    let index = e.target.dataset.index, carList = that.data.carList;
+      carList[index].customGoodsNum++;
+      that.setData({
+        carList: carList
+      })
+    that.totalPrice(that)
+  },
+  checkboxChange(e){
+    let index = e.target.dataset.index, that = this, carList = that.data.carList;
+    if (e.detail.value[0]){ // 表示价格增加
+      that.data.carList[index].checked = true; // 表示选中
+    } else {
+      that.data.carList[index].checked = false; // 表示选中
+    }
+    that.setData({
+      carList: carList
+    })
+    that.totalPrice(that)
+
+  },
   getCarlist(that){
     wx.request({
       url: host +'/queryShopCar',
@@ -73,11 +114,37 @@ Page({
         'content-type': 'application/x-www-form-urlencoded'
       },
       data:{
-        userId: app.globalData.user_id,
+        userId: 'oovpNwjlsY6xx8ceCebFa1dOLd9E'  //app.globalData.user_id,
       },
       success:function(res){
         console.log('购物车列表数据',res)
+        let carList = [],imgArray=[];
+        res.data.forEach((el,index)=>{
+          imgArray =el.customGoodsImg.split(',');
+          carList.push(el);
+          carList[index]['imgArray'] = imgArray;
+          carList[index]['checked'] = false;
+        })
+        that.setData({
+          carList: carList
+        })
+        console.log(that.data.carList,"carListcarList")
       }
     })
+  },
+  totalPrice(that){
+    let amount = 0,checkAll = true;
+    that.data.carList.forEach(res=>{
+      if(res.checked){
+        amount += res.customgoodsPriceNow * res.customGoodsNum
+      }
+      if (!res.checked) {
+        checkAll = false
+      }
+    })
+    that.setData({
+      amount:amount.toFixed(2),
+      checkAll: checkAll
+    })
   }
 })

+ 15 - 13
customized/pages/made/car/car.wxml

@@ -1,27 +1,26 @@
 <view>
   <!-- 购物车列表 -->
   <view class='car-box '>
-    <view  class='car-list  bg-white'>
+    <view  class='car-list  bg-white' wx:for="{{carList}}" wx:for-index="idx">
     <view class='f-box car-auto'>
-        <checkbox-group class="car-checkbox f-box f-align-items-center" bindchange="checkboxChange">
+        <checkbox-group class="car-checkbox f-box f-align-items-center" bindchange="checkboxChange" data-index="{{idx}}">
           <label class="checkbox">
-            <checkbox checked="true" />
+            <checkbox value='{{item.shopCarId}}' checked='{{item.checked}}' />
           </label>
         </checkbox-group>
         <view class='f-item'>
-          <text>奶钢-黑色 350ml</text>
+          <text class='f-s30'>{{item.customGoodsName}}</text>
           <view  class='f-box f-align-items-center' style='margin:20rpx 0;'>
-            <text class='f-item'>¥123.00</text>
+            <text class='f-item f-s28'>¥{{item.customgoodsPriceNow}}</text>
             <view class='car-numBtn f-box'>
-              <view bindtap='subtraction'>-</view>
-              <input value="1"/>
-              <view bindtap='add'>+</view>
+              <view bindtap='subtraction' data-index="{{idx}}">-</view>
+              <input disabled="true" value="{{item.customGoodsNum}}"/>
+              <view bindtap='add' data-index="{{idx}}">+</view>
             </view>
           </view>
           <!-- 图片list -->
-          <view class='f-box car-img-list'>
-            <image src='https://dlz.info666.com/temp/8c44130a-6eb7-452a-bf67-0998c62977dc.png' mode="aspectFit"></image>
-            <image src='https://dlz.info666.com/temp/8c44130a-6eb7-452a-bf67-0998c62977dc.png' mode="aspectFit"></image>
+          <view class='f-box car-img-list' wx:for='{{item.imgArray}}' wx:for-item="itemSrc">
+            <image src='{{host}}{{itemSrc}}' mode="aspectFit"></image>
           </view>
         </view>
       </view>
@@ -31,8 +30,11 @@
 
 <view class='footer bg-white'>
   <view  class='car-footer'>
-    <view  class='car-auto f-box'>
-      <view class='f-item f-s30'>订单金额:¥123</view>
+    <view  class='f-box'>
+        <checkbox-group class="f-s30 f-box f-align-items-center mar-l20">
+          <label class="checkbox"><checkbox checked='{{checkAll}}'/>全选</label>
+        </checkbox-group>
+      <view class='f-item f-s30 mar-l20 f-box mar-r20 f-justify-content-end'>金额:¥{{amount}}</view>
       <view class='f-s32 f-item car-btn bg-orange c-white'>提交订单</view>
     </view>
   </view>

+ 2 - 1
customized/pages/made/car/car.wxss

@@ -2,6 +2,7 @@
 .car-checkbox{
   width:100rpx;
 }
+
 .car-auto{
   margin:0 25rpx;
 }
@@ -12,7 +13,7 @@
 }
 .car-list{
   padding:20rpx;
-  margin:20rpx;
+  margin-bottom:20rpx;
 }
 .car-numBtn{
   width:244rpx;

+ 1 - 1
customized/pages/made/comb/comb.wxml

@@ -24,6 +24,6 @@
 </view>
 
 <view class='footer f-box f-justify-content-between' hover-class="none">
-  <view class='f-item footer-btn f-s32' style='background:#ffc102;color:#fff' bindtap='addImgRouter' hover-class="none">加入购物车</view>
+  <view class='f-item footer-btn f-s32 bg-orange c-white' bindtap='addImgRouter' hover-class="none">加入购物车</view>
   <!-- <view class='f-item footer-btn f-s32' style='background:#ff7103;color:#fff' bindtap='addFontRouter' hover-class="none">立即购买</view> -->
 </view>

+ 1 - 1
style/customized.wxss

@@ -85,7 +85,7 @@
   color:black;
 }
 .bg-orange{
-  color:#e8976a;
+  background:#e8976a;
 }
 .bg-green{
   background:#00af66;