微信小程序购物车实现
1,wxml
<view class="miniCart-wrap {{isIpx?'is-ipx':''}}">
<view class="miniCart-main">
<view class="miniCart-main-l">
<view class="cart-icon" bindtap='showCartDialog' hover-class='none'>
<image src="/assets/images/icon_minicart.png" mode='widthFix' />
<text class="num">{{count}}</text>
</view>
<view class="cart-info">
<view class="total">
总计:
<text class="price">¥{{cartShopPrice||''}}</text>
</view>
<view class="freight">已减 ¥{{cartShopReducePrice||''}} </view>
</view>
</view>
<view class="miniCart-main-r">
<view bindtap='submit' class="red-btn red-btn-l" wx:if="{{!closingTime}}">
去结算
</view>
<view class="red-btn gray-btn" wx:if="{{closingTime}}">本店已休息</view>
</view>
<view class="miniCart-dialog {{isIpx?'is-ipx':''}} {{showCart?'show':''}}">
<view class='showJH' wx:if="{{showJH}}">
<image class="loadingJH" src="/assets/images/loading.gif" mode='widthFix' />
</view>
<view class="shop-namenew" wx:if="{{cartItems.length>0}}">
<view class="shop-cart-head">
<view class="shop-cart-lf" bindtap="changeGoodsAllstatus">
<view>
<checkbox-group bindchange="shopCheckbox" data-store="{{item.storeSn}}" data-shopidx="{{shopidx}}">
<label class="checkbox">
<view wx:if="{{goodsAllstatus}}" class="goods--coin-icon"><image src="/assets/images/icon_detail-check.png"></image></view>
<view wx:if="{{!goodsAllstatus}}" class="goods-coin-boxDf"></view>
</label>
</checkbox-group>
</view>
<view class="shop-cart-lf-text">全选 <text style="color: #666;font-size:22rpx">(已选{{count||''}}件)</text></view>
</view>
<view class="shop-cart-rt" bindtap="deleteUserCart">
<view class="shop-cart-rt-img"><image src="/assets/images/icon_delete.png" bindtap="clearTheShop"/></view>
<view class="shop-cart-rt-text"></view>
</view>
</view>
</view>
<scroll-view class="content" scroll-y wx:if="{{cartItems.length==0}}">
<image class="GIcon" src="/assets/images/nodata_cart.png" mode='widthFix' />
<text>购物车里是空的</text>
</scroll-view> <!-- 购物车内容-->
<scroll-view class="content" scroll-y wx:if="{{cartItems.length>0}}">
<block >
<view class="shop-item" wx:for="{{cartItems}}" wx:key="cKey" wx:for-item="item" wx:for-index="outIndex">
<!-- 无促销类型-->
<view class="goods-list" wx:if="{{item.groupType!='1'}}">
<view class="goods-list-head">
<view class="goods-list-head-lf">
<view class="activityName">满减</view>
<view class="goods-list-head-lf-text">{{item.fullPromotionDesc}}</view>
</view>
<view class="goods-list-head-rt" bindtap="topSeckill" data-promoType="{{item.promotionInfo.promoSubType}}" data-promotionId="{{item.promotionInfo.promotionId}}">
<view class="goods-list-rt-text"> 继续选购</view>
<view class="goods-list-rt-icon"><image src="/assets/images/right_arrow.png"></image></view>
</view>
</view>
<view class="item" wx:for="{{item.singlePromoInfoList}}" wx:key="cKey" wx:for-item="goodsItem" wx:for-index="goodsidx" bindtap="toGoods" data-goodsSn="{{goodsItem.goodsSn}}" data-storeSn="{{stroreInfo.storeSn}}" data-storeId="{{stroreInfo.storeId}}" data-skuId="{{goodsItem.skuId}}">
<view class="item-l">
<label class="checkbox" catchtap="changeGoodstatus" data-item="{{goodsItem}}" data-outIndex="{{outIndex}}" data-index="{{goodsidx}}">
<view wx:if="{{goodsItem.status=='1'}}" class="goods--coin-icon"><image src="/assets/images/icon_detail-check.png"></image></view>
<view wx:if="{{goodsItem.status=='0'}}" class="goods-coin-boxDf"></view>
</label>
<view class="img">
<image src="{{goodsItem.skuImage}}" mode='widthFix' />
</view>
<view class="name-spec">
<view class="name">{{goodsItem.skuName}}</view>
<view class="spec">{{goodsItem.saleSpecDesc}}</view>
<view class="goodsPlueico">
<view class='goodsPlueico-price' >
<text class="goodsPlueicoquo">¥</text> <text class="goodspricered">{{goodsItem.basePrice}}</text>
<text class="goods-count-text">×{{goodsItem.purchaseQuantities}}</text>
</view>
<view class="quantity-handle">
<image class="icon" src="/assets/images/icon_minus.png" data-ident="{{goodsItem.id}}" data-num="{{goodsItem.purchaseQuantities}}" data-skuId="{{goodsItem.skuId}}" data-status="{{goodsItem.status}}" data-store="{{goodsItem.saleNum}}" data-type="false" catchtap="updateUserCart" mode='widthFix' />
<view class="quantity-num" catchtap="return">{{goodsItem.purchaseQuantities}}</view>
<image class="icon" src="/assets/images/icon_shop_add.png" data-ident="{{goodsItem.id}}" data-num="{{goodsItem.purchaseQuantities}}" data-skuId="{{goodsItem.skuId}}" data-status="{{goodsItem.status}}" data-store="{{goodsItem.saleNum}}" data-type="true" catchtap="updateUserCart" mode='widthFix' />
</view>
</view>
</view>
</view>
</view>
</view>
<view class="goods-list" wx:if="{{item.groupType=='1'&&item.promotionInfo.promotionType=='1'}}">
<view class="goods-list-head">
<view class="goods-list-head-lf">
<view class="activityName">满减</view>
<view class="goods-list-head-lf-text">{{item.fullPromotionDesc}}</view>
</view>
<view class="goods-list-head-rt" bindtap="topSeckill" data-promoType="{{item.promotionInfo.promoSubType}}" data-promotionId="{{item.promotionInfo.promotionId}}">
<view class="goods-list-rt-text"> 继续选购</view>
<view class="goods-list-rt-icon"><image src="/assets/images/right_arrow.png"></image></view>
</view>
</view>
<view class="item" wx:for="{{item.singlePromoInfoList}}" wx:key="cKey" wx:for-item="goodsItem" wx:for-index="goodsidx" bindtap="toGoods" data-goodsSn="{{goodsItem.goodsSn}}" data-storeSn="{{stroreInfo.storeSn}}" data-storeId="{{stroreInfo.storeId}}" data-skuId="{{goodsItem.skuId}}">
<view class="item-l">
<label class="checkbox" catchtap="changeGoodstatus" data-item="{{goodsItem}}" data-outIndex="{{outIndex}}" data-index="{{goodsidx}}">
<view wx:if="{{goodsItem.status=='1'}}" class="goods--coin-icon"><image src="/assets/images/icon_detail-check.png"></image></view>
<view wx:if="{{goodsItem.status=='0'}}" class="goods-coin-boxDf"></view>
</label>
<view class="img">
<image src="{{goodsItem.skuImage}}" mode='widthFix' />
</view>
<view class="name-spec">
<view class="name">{{goodsItem.skuName}}</view>
<view class="spec">{{goodsItem.saleSpecDesc}}</view>
<view class="goodsPlueico">
<view class='goodsPlueico-price' >
<text class="goodsPlueicoquo">¥</text> <text class="goodspricered">{{goodsItem.basePrice}}</text>
<text class="goods-count-text">×{{goodsItem.purchaseQuantities}}</text>
</view>
<view class="quantity-handle">
<image class="icon" src="/assets/images/icon_minus.png" data-ident="{{goodsItem.id}}" data-num="{{goodsItem.purchaseQuantities}}" data-skuId="{{goodsItem.skuId}}" data-status="{{goodsItem.status}}" data-store="{{goodsItem.saleNum}}" data-type="false" catchtap="updateUserCart" mode='widthFix' />
<view class="quantity-num" catchtap="return">{{goodsItem.purchaseQuantities}}</view>
<image class="icon" src="/assets/images/icon_shop_add.png" data-ident="{{goodsItem.id}}" data-num="{{goodsItem.purchaseQuantities}}" data-skuId="{{goodsItem.skuId}}" data-status="{{goodsItem.status}}" data-store="{{goodsItem.saleNum}}" data-type="true" catchtap="updateUserCart" mode='widthFix' />
</view>
</view>
</view>
</view>
</view>
</view>
<!-- 秒杀-->
<view class="goods-list" wx:if="{{item.groupType=='1'&&item.promotionInfo.promotionType=='2'}}">
<view class="goods-list-head">
<view class="goods-list-head-lf">
<view class="activityName">秒杀</view>
<view class="goods-list-head-lf-text">{{item.fullPromotionDesc}}</view>
</view>
<view class="goods-list-head-rt" bindtap="topSeckill" data-promoType="{{item.promotionInfo.promoSubType}}" data-promotionId="{{item.promotionInfo.promotionId}}">
<view class="goods-list-rt-text">继续选购</view>
<view class="goods-list-rt-icon"><image src="/assets/images/right_arrow.png"></image></view>
</view>
</view>
<view class="item" wx:for="{{item.singlePromoInfoList}}" wx:key="cKey" wx:for-item="goodsItem" wx:for-index="goodsidx" bindtap="toGoods" data-goodsSn="{{goodsItem.goodsSn}}" data-storeSn="{{stroreInfo.storeSn}}" data-storeId="{{stroreInfo.storeId}}" data-skuId="{{goodsItem.skuId}}">
<view class="item-l">
<label class="checkbox" catchtap="changeGoodstatus" data-item="{{goodsItem}}" data-outIndex="{{outIndex}}" data-index="{{goodsidx}}">
<view wx:if="{{goodsItem.status=='1'}}" class="goods--coin-icon"><image src="/assets/images/icon_detail-check.png"></image></view>
<view wx:if="{{goodsItem.status=='0'}}" class="goods-coin-boxDf"></view>
</label>
<view class="img">
<image src="{{goodsItem.skuImage}}" mode='widthFix' />
</view>
<view class="name-spec">
<view class="name" >{{goodsItem.skuName}}</view>
<view class="spec">{{goodsItem.saleSpecDesc}}</view>
<view class="goodsPlueico">
<view class='goodsPlueico-price'>
<text class="goodsPlueicoquo">¥</text> <text class="goodspricered">{{goodsItem.basePrice}} </text>
<text class="goods-count-text">×{{goodsItem.purchaseQuantities}}</text>
</view>
<view class="quantity-handle">
<image class="icon" src="/assets/images/icon_minus.png" data-ident="{{goodsItem.id}}" data-num="{{goodsItem.purchaseQuantities}}" data-skuId="{{goodsItem.skuId}}" data-status="{{goodsItem.status}}" data-store="{{goodsItem.saleNum}}" data-type="false" catchtap="updateUserCart" mode='widthFix' />
<view class="quantity-num" catchtap="return">{{goodsItem.purchaseQuantities}}</view>
<image class="icon" src="/assets/images/icon_shop_add.png" data-ident="{{goodsItem.id}}" data-num="{{goodsItem.purchaseQuantities}}" data-skuId="{{goodsItem.skuId}}" data-status="{{goodsItem.status}}" data-store="{{goodsItem.saleNum}}" data-type="true" catchtap="updateUserCart" mode='widthFix' />
</view>
</view>
</view>
</view>
</view>
</view>
<!-- 阶梯满减-->
<view class="goods-list" wx:if="{{item.groupType=='1'&&item.promotionInfo.promotionType=='3'}}">
<view class="goods-list-head">
<view class="goods-list-head-lf">
<view class="activityName">阶梯满减</view>
<view class="goods-list-head-lf-text">{{item.fullPromotionDesc}}</view>
</view>
<view class="goods-list-head-rt" bindtap="topSeckill" data-promoType="{{item.promotionInfo.promoSubType}}" data-promotionId="{{item.promotionInfo.promotionId}}">
<view class="goods-list-rt-text"> 继续选购</view>
<view class="goods-list-rt-icon"><image src="/assets/images/right_arrow.png"></image></view>
</view>
</view>
<view class="item" wx:for="{{item.singlePromoInfoList}}" wx:key="cKey" wx:for-item="goodsItem" wx:for-index="goodsidx" bindtap="toGoods" data-goodsSn="{{goodsItem.goodsSn}}" data-storeSn="{{stroreInfo.storeSn}}" data-storeId="{{stroreInfo.storeId}}" data-skuId="{{goodsItem.skuId}}">
<view class="item-l">
<label class="checkbox" catchtap="changeGoodstatus" data-item="{{goodsItem}}" data-outIndex="{{outIndex}}" data-index="{{goodsidx}}">
<view wx:if="{{goodsItem.status=='1'}}" class="goods--coin-icon"><image src="/assets/images/icon_detail-check.png"></image></view>
<view wx:if="{{goodsItem.status=='0'}}" class="goods-coin-boxDf"></view>
</label>
<view class="img" >
<image src="{{goodsItem.skuImage}}" mode='widthFix' />
</view>
<view class="name-spec">
<view class="name">{{goodsItem.skuName}}</view>
<view class="spec">{{goodsItem.saleSpecDesc}}</view>
<view class="goodsPlueico">
<view class='goodsPlueico-price'>
<text class="goodsPlueicoquo">¥</text> <text class="goodspricered">{{goodsItem.basePrice}} </text>
<text class="goods-count-text">×{{goodsItem.purchaseQuantities}}</text>
</view>
<view class="quantity-handle">
<image class="icon" src="/assets/images/icon_minus.png" data-ident="{{goodsItem.id}}" data-num="{{goodsItem.purchaseQuantities}}" data-skuId="{{goodsItem.skuId}}" data-status="{{goodsItem.status}}" data-store="{{goodsItem.saleNum}}" data-type="false" catchtap="updateUserCart" mode='widthFix' />
<view class="quantity-num" catchtap="return">{{goodsItem.purchaseQuantities}}</view>
<image class="icon" src="/assets/images/icon_shop_add.png" data-ident="{{goodsItem.id}}" data-num="{{goodsItem.purchaseQuantities}}" data-skuId="{{goodsItem.skuId}}" data-status="{{goodsItem.status}}" data-store="{{goodsItem.saleNum}}" data-type="true" catchtap="updateUserCart" mode='widthFix' />
</view>
</view>
</view>
</view>
</view>
</view >
<!-- m元n件-->
<view class="goods-list" wx:if="{{item.groupType=='1'&&item.promotionInfo.promotionType=='4'}}">
<view class="goods-list-head">
<view class="goods-list-head-lf">
<view class="activityName">m元n件</view>
<view class="goods-list-head-lf-text">{{item.fullPromotionDesc}}</view>
</view>
<view class="goods-list-head-rt" bindtap="topSeckill" data-promoType="{{item.promotionInfo.promoSubType}}" data-promotionId="{{item.promotionInfo.promotionId}}">
<view class="goods-list-rt-text"> 继续选购</view>
<view class="goods-list-rt-icon"><image src="/assets/images/right_arrow.png"></image></view>
</view>
</view>
<view class="item" wx:for="{{item.singlePromoInfoList}}" wx:key="cKey" wx:for-item="goodsItem" wx:for-index="goodsidx" bindtap="toGoods" data-goodsSn="{{goodsItem.goodsSn}}" data-storeSn="{{stroreInfo.storeSn}}" data-storeId="{{stroreInfo.storeId}}" data-skuId="{{goodsItem.skuId}}">
<view class="item-l">
<label class="checkbox" catchtap="changeGoodstatus" data-item="{{goodsItem}}" data-outIndex="{{outIndex}}" data-index="{{goodsidx}}">
<view wx:if="{{goodsItem.status=='1'}}" class="goods--coin-icon"><image src="/assets/images/icon_detail-check.png"></image></view>
<view wx:if="{{goodsItem.status=='0'}}" class="goods-coin-boxDf"></view>
</label>
<view class="img">
<image src="{{goodsItem.skuImage}}" mode='widthFix' />
</view>
<view class="name-spec">
<view class="name" >{{goodsItem.skuName}}</view>
<view class="spec">{{goodsItem.saleSpecDesc}}</view>
<view class="goodsPlueico">
<view class='goodsPlueico-price'>
<text class="goodsPlueicoquo">¥</text> <text class="goodspricered">{{goodsItem.basePrice}} </text>
<text class="goods-count-text">×{{goodsItem.purchaseQuantities}}</text>
</view>
<view class="quantity-handle">
<image class="icon" src="/assets/images/icon_minus.png" data-ident="{{goodsItem.id}}" data-num="{{goodsItem.purchaseQuantities}}" data-status="{{goodsItem.status}}" data-store="{{goodsItem.saleNum}}" data-skuId="{{goodsItem.skuId}}" data-type="false" catchtap="updateUserCart" mode='widthFix' />
<view class="quantity-num" catchtap="return">{{goodsItem.purchaseQuantities}}</view>
<image class="icon" src="/assets/images/icon_shop_add.png" data-ident="{{goodsItem.id}}" data-num="{{goodsItem.purchaseQuantities}}" data-status="{{goodsItem.status}}" data-store="{{goodsItem.saleNum}}" data-skuId="{{goodsItem.skuId}}" data-type="true" catchtap="updateUserCart" mode='widthFix' />
</view>
</view>
</view>
</view>
</view>
</view>
<!-- 满赠-->
<view class="goods-list" wx:if="{{item.groupType=='1'&&item.promotionInfo.promotionType=='5'}}">
<view class="goods-list-head">
<view class="goods-list-head-lf">
<view class="activityName">满赠</view>
<view class="goods-list-head-lf-text">{{item.fullPromotionDesc}}</view>
</view>
<view class="goods-list-head-rt" bindtap="topSeckill" data-promoType="{{item.promotionInfo.promoSubType}}" data-promotionId="{{item.promotionInfo.promotionId}}">
<view class="goods-list-rt-text"> 继续选购</view>
<view class="goods-list-rt-icon"><image src="/assets/images/right_arrow.png"></image></view>
</view>
</view>
<!-- 满赠的赠品-->
<view wx:for="{{item.singlePromoInfoList}}" wx:key="cKey" wx:for-item="goodsItem" wx:for-index="goodsidx">
<view class="item" wx:for="{{goodsItem.giftInfoList}}" wx:key="gifcKey" wx:for-item="gifgoodsItem" wx:for-index="gifgoodsidx" bindtap="toGoods" data-goodsSn="{{goodsItem.goodsSn}}" data-storeSn="{{stroreInfo.storeSn}}" data-storeId="{{stroreInfo.storeId}}" data-skuId="{{goodsItem.skuId}}">
<view style="width:100%">
<view class="item-l">
<label class="checkbox-zp">
</label>
<view class="img">
<image src="{{goodsItem.skuImage}}" mode='widthFix' />
</view>
<view class="name-spec">
<view class="name" >{{goodsItem.skuName}}</view>
<view class="spec">{{goodsItem.saleSpecDesc}}</view>
<view class="goodsPlueico">
<view class='goodsPlueico-price'>
<text class="goodsPlueicoquo">¥</text> <text class="goodspricered">{{goodsItem.basePrice}} </text>
<text class="goods-count-text">×{{goodsItem.purchaseQuantities}}</text>
</view>
<view class="goods-zenpin-manzeng">赠品</view>
</view>
</view>
</view>
</view>
</view>
<view class="item" bindtap="toGoods" data-goodsSn="{{goodsItem.goodsSn}}" data-storeSn="{{stroreInfo.storeSn}}" data-storeId="{{stroreInfo.storeId}}" data-skuId="{{goodsItem.skuId}}">
<view class="item-l">
<label class="checkbox" catchtap="changeGoodstatus" data-item="{{goodsItem}}" data-outIndex="{{outIndex}}" data-index="{{goodsidx}}">
<view wx:if="{{goodsItem.status=='1'}}" class="goods--coin-icon"><image src="/assets/images/icon_detail-check.png"></image></view>
<view wx:if="{{goodsItem.status=='0'}}" class="goods-coin-boxDf"></view>
</label>
<view class="img">
<image src="{{goodsItem.skuImage}}" mode='widthFix' />
</view>
<view class="name-spec">
<view class="name">{{goodsItem.skuName}}</view>
<view class="spec">{{goodsItem.saleSpecDesc}}</view>
<view class="goodsPlueico">
<view class='goodsPlueico-price'>
<text class="goodsPlueicoquo">¥</text> <text class="goodspricered">{{goodsItem.basePrice}} </text>
<text class="goods-count-text">×{{goodsItem.purchaseQuantities}}</text>
</view>
<view class="quantity-handle">
<image class="icon" src="/assets/images/icon_minus.png" data-ident="{{goodsItem.id}}" data-num="{{goodsItem.purchaseQuantities}}" data-status="{{goodsItem.status}}" data-store="{{goodsItem.saleNum}}" data-type="false" data-skuId="{{goodsItem.skuId}}" catchtap="updateUserCart" mode='widthFix' />
<view class="quantity-num" catchtap="return">{{goodsItem.purchaseQuantities}}</view>
<image class="icon" src="/assets/images/icon_shop_add.png" data-ident="{{goodsItem.id}}" data-num="{{goodsItem.purchaseQuantities}}" data-status="{{goodsItem.status}}" data-store="{{goodsItem.saleNum}}" data-type="true" data-skuId="{{goodsItem.skuId}}" catchtap="updateUserCart" mode='widthFix' />
</view>
</view>
</view>
</view>
</view>
</view>
</view>
<!-- 6买一赠一商品 -->
<view class="goods-list" wx:if="{{item.groupType=='1'&&item.promotionInfo.promotionType=='6'}}">
<view class="goods-list-head">
<view class="goods-list-head-lf">
<view class="activityName">满一赠一</view>
<view class="goods-list-head-lf-text">{{item.fullPromotionDesc}}</view>
</view>
<view class="goods-list-head-rt" bindtap="topSeckill" data-promoType="{{item.promotionInfo.promoSubType}}" data-promotionId="{{item.promotionInfo.promotionId}}">
<view class="goods-list-rt-text"> 继续选购</view>
<view class="goods-list-rt-icon"><image src="/assets/images/right_arrow.png"></image></view>
</view>
</view>
<view wx:for="{{item.singlePromoInfoList}}" wx:key="cKey" wx:for-item="goodsItem" wx:for-index="goodsidx" >
<view class="item" bindtap="toGoods" data-goodsSn="{{goodsItem.goodsSn}}" data-storeSn="{{stroreInfo.storeSn}}" data-storeId="{{stroreInfo.storeId}}" data-skuId="{{goodsItem.skuId}}">
<view class="item-l">
<label class="checkbox" catchtap="changeGoodstatus" data-item="{{goodsItem}}" data-outIndex="{{outIndex}}" data-index="{{goodsidx}}">
<view wx:if="{{goodsItem.status=='1'}}" class="goods--coin-icon"><image src="/assets/images/icon_detail-check.png"></image></view>
<view wx:if="{{goodsItem.status=='0'}}" class="goods-coin-boxDf"></view>
</label>
<view class="img">
<image src="{{goodsItem.skuImage}}" mode='widthFix'/>
</view>
<view class="name-spec">
<view class="name">{{goodsItem.skuName}}</view>
<view class="spec">{{goodsItem.saleSpecDesc}}</view>
<view class="goodsPlueico">
<view class='goodsPlueico-price'>
<text class="goodsPlueicoquo">¥</text> <text class="goodspricered">{{goodsItem.basePrice}} </text>
<text class="goods-count-text">×{{goodsItem.purchaseQuantities}}</text>
</view>
<view class="quantity-handle">
<image class="icon" src="/assets/images/icon_minus.png" data-ident="{{goodsItem.id}}" data-num="{{goodsItem.purchaseQuantities}}" data-status="{{goodsItem.status}}" data-store="{{goodsItem.saleNum}}" data-type="false" data-skuId="{{goodsItem.skuId}}" catchtap="updateUserCart" mode='widthFix' />
<view class="quantity-num" catchtap="return">{{goodsItem.purchaseQuantities}}</view>
<image class="icon" src="/assets/images/icon_shop_add.png" data-ident="{{goodsItem.id}}" data-num="{{goodsItem.purchaseQuantities}}" data-status="{{goodsItem.status}}" data-store="{{goodsItem.saleNum}}" data-type="true" data-skuId="{{goodsItem.skuId}}" catchtap="updateUserCart" mode='widthFix' />
</view>
</view>
</view>
</view>
</view>
<!-- 买已赠一的赠品-->
<view class="item" wx:for="{{goodsItem.giftInfoList}}" wx:key="gifcKey" wx:for-item="gifgoodsItem" wx:for-index="gifgoodsidx" bindtap="toGoods" data-goodsSn="{{goodsItem.goodsSn}}" data-storeSn="{{stroreInfo.storeSn}}" data-storeId="{{stroreInfo.storeId}}" data-skuId="{{goodsItem.skuId}}">
<view style="width:100%">
<view class="item-l">
<label class="checkbox-zp">
</label>
<view class="img">
<image src="{{goodsItem.skuImage}}" mode='widthFix'/>
</view>
<view class="name-spec">
<view class="name">{{goodsItem.skuName}}</view>
<view class="spec">{{goodsItem.saleSpecDesc}}</view>
<view class="goodsPlueico">
<view class='goodsPlueico-price'>
<text class="goodsPlueicoquo">¥</text> <text class="goodspricered">{{goodsItem.basePrice}} </text>
<text class="goods-count-text">×{{goodsItem.purchaseQuantities}}</text>
</view>
<view class="goods-zenpin-manzeng">赠品</view>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
<!-- 失效商品 -->
<view wx:for="{{invalidSkuList}}" wx:key="cKey" wx:for-item="item" wx:for-index="outIndex">
<view class="goods-list">
<view class="goods-list-head">
<view class="goods-list-head-lf">
<view class="activityNamesx">失效商品</view>
</view>
</view>
<view class="item" wx:for="{{item.singlePromoInfoList}}" wx:key="cKey" wx:for-item="goodsItem" wx:for-index="goodsidx" bindtap="toGoods" data-goodsSn="{{goodsItem.goodsSn}}" data-storeSn="{{stroreInfo.storeSn}}" data-storeId="{{stroreInfo.storeId}}" data-skuId="{{goodsItem.skuId}}">
<view class="item-l">
<label class="checkbox checkboxxj">
<text class="xjtext">已下架</text>
</label>
<view class="img">
<image src="{{goodsItem.skuImage}}" mode='widthFix' />
</view>
<view class="name-spec">
<view class="name" >{{goodsItem.skuName}}</view>
<view class="spec">{{goodsItem.saleSpecDesc}}</view>
<view class="goodsPlueico">
<view class='goodsPlueico-price'>
<text class="goodsPlueicoquo">¥</text> <text class="goodspricered">{{goodsItem.basePrice}} </text>
<text class="goods-count-text">×{{goodsItem.purchaseQuantities}}</text>
</view>
<view class="quantity-handle" catchtap="deleteOutdated" data-current="{{goodsItem}}">
<view class="quantity-handle-delete">删除</view>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
</block>
</scroll-view>
</view>
</view>
</view>
<view class="mask {{isIpx?'is-ipx':''}} {{showCart?'show':''}}" bindtap='showCartDialog'></view>
2,wxss
/*新购物车样式*/
.miniCart-wrap {
position: fixed;
bottom: ;
width: %;
left: ;
background: rgba(, , , 0.95);
border-top: 1rpx solid #eee;
z-index: ;
} .miniCart-main {
position: relative;
display: flex;
justify-content: space-between;
height: 100rpx;
} .miniCart-main-l .cart-icon {
position: absolute;
bottom: 0rpx;
left: 10rpx;
width: 130rpx;
z-index: ;
} .miniCart-main-l .cart-icon .num {
position: absolute;
top: %;
left: %;
transform: translate(-%, -%);
color: #e2231a;
font-size: 24rpx;
font-weight: bold;
} .miniCart-main-l .cart-info {
padding-left: 160rpx;
margin-top: 19rpx;
} .miniCart-main-l .cart-info .total {
font-size: 28rpx;
color: #;
} .miniCart-main-l .cart-info .price {
font-size: 26rpx;
font-weight: bold;
display: flex;
} .goodsPlueico-price {
display: flex;
align-items: center;
} .miniCart-main-l .cart-info .freight {
font-size: 22rpx;
color: #;
} .miniCart-main-r {
display: flex;
align-items: center;
margin-right: 20rpx;
} .red-btn {
height: 68rpx;
line-height: 68rpx;
padding: 20rpx;
font-size: 30rpx;
border-radius: 34rpx;
} .line1- {
font-size: 24rpx;
text-align: center;
color: #E2231A;
background: #FCE9E8;
margin-right: 10rpx;
padding-right: 11rpx;
padding-left: 8rpx;
display: inline-block;
} .gray-btn {
background: #BFBFBF;
color: #ffffff;
padding: 0rpx 20rpx;
font-size: 30rpx;
border-radius: 34rpx;
border: 1rpx solid #BFBFBF;
} .miniCart-dialog {
position: fixed;
bottom: -1000rpx;
width: %;
background: #fff;
z-index: ;
transition: .3s all ease;
padding-bottom: 30rpx;
opacity: ;
visibility: hidden;
} .miniCart-dialog.show {
bottom: 100rpx;
opacity: ;
visibility: visible;
} .miniCart-dialog.show.is-ipx {
bottom: 150rpx;
} .miniCart-dialog .title {
color: #;
padding: 20rpx;
} .miniCart-dialog .content {
min-height: 200rpx;
max-height: 700rpx;
text-align: center;
} .GIcon {
height: 150rpx;
width: 150rpx;
margin: auto;
margin-top: 18rpx;
} .miniCart-dialog .content text {
display: block;
width: %;
text-align: center;
color: #cacaca;
font-size: inherit;
margin-top: 10rpx;
} .goods-list {
padding-left: 30rpx;
} .goods-list .item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20rpx 30rpx 20rpx ;
} .goods-list .item:last-child {
border-bottom: none;
} .goods-list .item .item-l {
display: flex;
width: %;
} .goods-list .item .item-l .img {
display: flex;
align-items: center;
overflow: hidden;
width: 162rpx;
height: 162rpx;
border: 1rpx solid #eee;
flex-shrink: ;
margin-right: 20rpx;
} .goods-list .item .item-l .name {
color: #;
font-size: 30rpx;
font-family: SimHei;
text-align: left;
} .goods-list .item .item-r {
display: flex;
align-items: center;
} .quantity-handle {
display: flex;
align-items: center;
margin-left: 30rpx;
} .quantity-handle .icon {
width: 35rpx;
} .quantity-handle .num {
width: 65rpx;
text-align: center;
} .mask {
position: fixed;
top: ;
left: ;
width: %;
height: calc(% - 100rpx);
background: rgba(, , , 0.6);
z-index: ;
transition: .3s all ease;
visibility: hidden;
opacity: ;
} .mask.is-ipx {
height: calc(% - 150rpx);
} .mask.show {
visibility: visible;
opacity: ;
} .loadingJH {
width: 50rpx;
height: 50rpx;
position: absolute;
top: %;
transform: translateY(-%);
left: %;
margin-left: -25rpx;
} .goods-list-head {
display: flex;
padding: 18rpx 0rpx 17rpx 0rpx;
border-bottom: 1rpx dashed #E5E5E5;
border-top: 1rpx solid #E5E5E5;
margin-right: 20rpx;
} .goods-list-headxj {
display: flex;
padding: 18rpx 0rpx 0rpx 0rpx;
border-top: 1rpx solid #E5E5E5;
margin-right: 20rpx;
} .activityName {
background: #E2231A;
padding: 2rpx 8rpx;
color: #ffffff;
font-size: 24rpx;
margin-right: 10rpx;
display: inline-block;
} .activityNamesx {
color: #;
font-size: 30rpx;
margin-right: 10rpx;
display: inline-block;
font-weight: ;
} .goods-list-head-lf {
flex: ;
display: flex;
align-items: center;
} .goods-list-rt-icon {
width: 12rpx;
height: 22rpx;
margin-left: 10rpx;
} .goods-list-rt-icon image {
width: 12rpx;
height: 22rpx;
} .goods-list-rt-text {
color: #E2231A;
font-size: 24rpx;
} .goods-list-head-lf-text {
color: #;
font-size: 24rpx;
font-family: SimHei;
} .goods-list {
padding-left: 20rpx;
} .goods-list-head-rt {
display: flex;
align-items: center;
} .goods-list .item .item-l .checkbox {
margin-top: 65rpx;
} .goodsPlueico {
display: flex;
margin-top: 19rpx;
justify-content: space-between;
} .name-spec {
flex: ;
text-align: left;
} .shop-cart-head {
display: flex;
justify-content: space-between;
align-items: center;
width: %;
} .shop-cart-lf {
display: flex;
align-items: center;
} .shop-cart-rt {
display: flex;
align-items: center;
} .shop-cart-lf-text {
color: #;
font-size: 24rpx;
} .shop-cart-rt-text {
color: #;
font-size: 24rpx;
margin-left: 13rpx;
} .shop-cart-rt-img image {
width: 24rpx;
height: 30rpx;
} .quantity-handle-delete {
padding: 5rpx 20rpx;
border: 1rpx solid #E2231A;
color: #E2231A;
font-size: 24rpx;
border-radius: 22px;
} .xjtext {
font-size: 24rpx !important;
color: # !important;
} .checkboxxj {
width: 22rpx;
margin-right: 10rpx;
margin-top: 36rpx !important;
} .miniCart-dialog .content .goodsPlueicoquo {
font-size: 20rpx;
color: #E2231A;
} .miniCart-dialog .content .goodspricered {
font-size: 24rpx;
color: #E2231A;
font-weight: ;
} .shop-namenew {
background: #fdf0f0;
display: flex;
justify-content: space-between;
align-items: center;
padding: 15rpx 20rpx;
border-top: 1rpx solid #eee;
border-bottom: 1rpx solid #eee;
border-radius: 20rpx 20rpx 0rpx 0rpx;
} .goods-list .item .item-l .spec {
color: #;
font-size: 20rpx;
margin-top: 10rpx;
background: #FCE9E8;
padding: 5rpx 9rpx;
display: inline-block;
font-family: SimHei;
} .checkbox-zp {
width: 49rpx;
} .miniCart-dialog .content .goods-count-text {
font-size: 20rpx;
margin-left: 20rpx;
color: #;
} .goods-zenpin-manzeng {
font-size: 24rpx;
color: #;
}
3,js
//加入购物车 接口 新版
async addCart(e) {
let storeId = this.data.storeId;
let skuId = e.currentTarget.dataset.skuid;
try { //相关接口调用 } catch (error) { //出错了
}
},
注:
1,wxml相关代码是根据购物车商品不同类型进行分类的,如果商品类型只有一种,可以直接使用下面的代码
2,wxss可能有冗余代码
3,因为wxml中图片暂未提供,和相关方法js中未全部列举,直接使用上面的代码可能会报错,需要自己整理
4,实现后效果如下图
1,商品只有一种类型的购物车wxml代码
<!-- 购物车-->
<view class="miniCart-wrap {{isIpx?'is-ipx':''}}">
<view class="miniCart-main">
<view class="miniCart-main-l">
<view class="cart-icon" bindtap='showCartDialog' hover-class='none'>
<image src="" mode='widthFix' />
<!-- 购物车数量count-->
<text class="num">{{count}}</text>
</view>
<view class="cart-info">
<view class="total">
总计:
<text class="price">¥{{cartShopPrice||''}}</text>
</view>
<view class="freight">已减 ¥{{cartShopReducePrice||''}} </view>
</view>
</view>
<view class="miniCart-main-r">
<view bindtap='submit' class="red-btn red-btn-l">
去结算
</view>
</view>
<view class="miniCart-dialog {{isIpx?'is-ipx':''}} {{showCart?'show':''}}">
<view class='showJH' wx:if="{{showJH}}">
<image class="loadingJH" src="/assets/images/loading.gif" mode='widthFix' />
</view>
<view class="shop-namenew" wx:if="{{cartItems.length>0}}">
<view class="shop-cart-head">
<view class="shop-cart-lf" bindtap="changeGoodsAllstatus">
<view>
<checkbox-group bindchange="shopCheckbox" data-store="{{item.storeSn}}" data-shopidx="{{shopidx}}">
<label class="checkbox">
<view wx:if="{{goodsAllstatus}}" class="goods--coin-icon"><image src="/assets/images/icon_detail-check.png"></image></view>
<view wx:if="{{!goodsAllstatus}}" class="goods-coin-boxDf"></view>
</label>
</checkbox-group>
</view>
<view class="shop-cart-lf-text">全选 <text style="color: #666;font-size:22rpx">(已选{{count||''}}件)</text></view>
</view>
<view class="shop-cart-rt" bindtap="deleteUserCart">
<view class="shop-cart-rt-img"><image src="" bindtap="clearTheShop"/></view>
<view class="shop-cart-rt-text"></view>
</view>
</view>
</view>
<scroll-view class="content" scroll-y wx:if="{{cartItems.length==0}}">
<text>购物车里是空的</text>
</scroll-view> <!-- 购物车内容-->
<scroll-view class="content" scroll-y wx:if="{{cartItems.length>0}}">
<block >
<view class="shop-item" wx:for="{{cartItems}}" wx:key="cKey" wx:for-item="item" wx:for-index="outIndex">
<!-- 无促销类型-->
<view class="goods-list" wx:if="{{item.groupType!='1'}}">
<view class="goods-list-head">
<view class="goods-list-head-lf">
<view class="activityName">满减</view>
<view class="goods-list-head-lf-text">{{item.fullPromotionDesc}}</view>
</view>
<view class="goods-list-head-rt" bindtap="topSeckill" data-promoType="{{item.promotionInfo.promoSubType}}" data-promotionId="{{item.promotionInfo.promotionId}}">
<view class="goods-list-rt-text"> 继续选购</view>
<view class="goods-list-rt-icon"><image src=""></image></view>
</view>
</view>
<view class="item" wx:for="{{item.singlePromoInfoList}}" wx:key="cKey" wx:for-item="goodsItem" wx:for-index="goodsidx" bindtap="toGoods" data-goodsSn="{{goodsItem.goodsSn}}" data-storeSn="{{stroreInfo.storeSn}}" data-storeId="{{stroreInfo.storeId}}" data-skuId="{{goodsItem.skuId}}">
<view class="item-l">
<label class="checkbox" catchtap="changeGoodstatus" data-item="{{goodsItem}}" data-outIndex="{{outIndex}}" data-index="{{goodsidx}}">
<view wx:if="{{goodsItem.status=='1'}}" class="goods--coin-icon"><image src="/assets/images/icon_detail-check.png"></image></view>
<view wx:if="{{goodsItem.status=='0'}}" class="goods-coin-boxDf"></view>
</label>
<view class="img">
<image src="{{goodsItem.skuImage}}" mode='widthFix' />
</view>
<view class="name-spec">
<view class="name">{{goodsItem.skuName}}</view>
<view class="spec">{{goodsItem.saleSpecDesc}}</view>
<view class="goodsPlueico">
<view class='goodsPlueico-price' >
<text class="goodsPlueicoquo">¥</text> <text class="goodspricered">{{goodsItem.basePrice}}</text>
<text class="goods-count-text">×{{goodsItem.purchaseQuantities}}</text>
</view>
<view class="quantity-handle">
<image class="icon" src="/assets/images/icon_minus.png" data-ident="{{goodsItem.id}}" data-num="{{goodsItem.purchaseQuantities}}" data-skuId="{{goodsItem.skuId}}" data-status="{{goodsItem.status}}" data-store="{{goodsItem.saleNum}}" data-type="false" catchtap="updateUserCart" mode='widthFix' />
<view class="quantity-num" catchtap="return">{{goodsItem.purchaseQuantities}}</view>
<image class="icon" src="/assets/images/icon_shop_add.png" data-ident="{{goodsItem.id}}" data-num="{{goodsItem.purchaseQuantities}}" data-skuId="{{goodsItem.skuId}}" data-status="{{goodsItem.status}}" data-store="{{goodsItem.saleNum}}" data-type="true" catchtap="updateUserCart" mode='widthFix' />
</view>
</view>
</view>
</view>
</view>
</view>
</view>
</block>
</scroll-view>
</view>
</view>
</view>
<view class="mask {{isIpx?'is-ipx':''}} {{showCart?'show':''}}" bindtap='showCartDialog'></view>
完整js
var Util = require('../../utils/util.js')
const Map = require('../../utils/map.js');
const { regeneratorRuntime } = global
const app = getApp()
Page({
data: {
checkedSkuNumber:,
showCart:false,
showJH: false,
showTop: false,
isIpx: app.globalData.isIpx ? true : false,
goodsAllstatus:true,
cartItems:[],
},
onLoad: function (options) {
this.setData({
storeId:options.storeId,
});
this.getCart();
if(options.showCart=='true'){
this.setData({
showCart:true
})
}else{
this.setData({
showCart:false
})
} }, /**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () { }, /**
* 生命周期函数--监听页面显示
*/
onShow: function () { }, /**
* 生命周期函数--监听页面隐藏
*/
onHide: function () { }, /**
* 生命周期函数--监听页面卸载
*/
onUnload: function () { }, /**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () { }, /**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () { }, /**
* 用户点击右上角分享
*/
onShareAppMessage: function () { }, //购物车继续选购, 新版
async topSeckill(e) {
let storeId = this.data.storeId;
let promoId = e.currentTarget.dataset.promotionid;
let promotype = e.currentTarget.dataset.promotype;
wx.navigateTo({url: '/pages/cuxiao/cuxiao?storeId=' + storeId + '&promoId=' + promoId}); },
//购物车全选,反选
async changeGoodsAllstatus() {
}, //购物车选中,反选
async changeGoodstatus(e) { },
//获取购物车数据 初始 新版
async getCart() {
try {
let that = this;
let storeSn = that.data.storeSn;
let params = {
storeId:that.data.storeId
}
// 全局方法
let result = await Util.getCartNew(params);
that.setData({
cartItems: result.data.cart,
}) } catch (error) {
}
},
//加入购物车 接口 新版
async addCart(e) { }, //修改购物车商品数量 接口 新版
async updateUserCart(e) { }, async deleteUserCart() { }, submit(e) {
wx.navigateTo({ url: '/pages/jiesuanye/jiesuanye'});
},
showCartDialog(e) {
var that = this
if (Util.checkLogin()){
this.getCart();
}else{
wx.showToast({
title: '未登录无法查看,请先登录后查看',
icon: 'none',
duration: ,
mask: true
});
return
}
this.setData({
showCart: !that.data.showCart,
})
},
toGoods(e){
let storeId = this.data.storeId;
let skuId = e.currentTarget.dataset.skuid;
wx.navigateTo({ url: '/pages/goods/goods?storeId='+storeId+'&skuId='+skuId});
},
})
如果有遗漏wxss和相关js方法自行补充
效果图如下
微信小程序购物车实现的更多相关文章
- 微信小程序购物车产品计价
微信小程序购物车产品计价: 问题:当选中商品,价格累加时会出现无限循环小数 解答:在计算前先parseFloat(变量),再计算的最后使用(变量).toFixed(2)保留两位小数 例如: jiaCa ...
- 微信小程序全选,微信小程序checkbox,微信小程序购物车
微信小程序,这里实现微信小程序checkbox,有需要此功能的朋友可以参考下. 摘要: 加减商品数量,汇总价格,全选与全不选 设计思路: 一.从网络上传入以下Json数据格式的数组 1.标题titl ...
- “完美”解决微信小程序购物车抛物动画,在连续点击时出现计算错误问题,定时器停不下来。
最近做,微信点餐小程序,遇到添加商品时出现抛物动画,参考借鉴了这位大神的方法 https://www.cnblogs.com/greengage/p/7815842.html 但出现了一个问题,连续点 ...
- 微信小程序——购物车结算
项目需要做个购物车结算功能,先分析需求: 1.全选,反选的功能.当选中的个数 = 购物车的数量时,勾选全选按钮,反之则取消选中全选按钮: 2.改变选中状态时,计算总价和总数量: 3.单个产品的数量加减 ...
- 微信小程序——购物车数字加减
上一篇,我们有讲到如何造一个购物车弹层.今天来说一下,购物车数量的加减如何实现. 主要思路就是在data里面定义一个属性,属性值就是这个数量.点击+的时候就+1,点击-的时候就-1,再结合setDat ...
- 微信小程序购物车功能
<view class='shop-mana'> <text class='management'>管理您的购物车</text> <text class='g ...
- 微信小程序 购物车流程
购物车流程 一.需求分析 a:全选,单选,根据选中的计算数目和总价 b:单个商品加减 c:删除一个商品 wxml 布局 <view> <view v-if="flag&qu ...
- 微信小程序实例源码大全
微信小程序实例源码大全下载 微信小应用示例代码(phodal/weapp-quick)源码链接:https://github.com/phodal/weapp-quick 微信小应用地图定位demo( ...
- 微信小程序开源项目库汇总
最近做了一个微信小程序开源项目库汇总,里面集合了OpenDigg 上的优质的微信小程序开源项目库,方便移动开发人员便捷的找到自己需要的项目工具等,感兴趣的可以到GitHub上给个star. UI组件 ...
随机推荐
- Python 文件I/OⅢ
read()方法 read()方法从一个打开的文件中读取一个字符串.需要重点注意的是,Python字符串可以是二进制数据,而不是仅仅是文字. 语法: 在这里,被传递的参数是要从已打开文件中读取的字节计 ...
- 未能从程序集“netstandard, Version=2.0.0.0......”中加载类型“...”。
需要在机器上安装:4.7.1的framework 下载地址: https://www.microsoft.com/zh-CN/download/details.aspx?id=56116 说明:n ...
- JS实现表格隔行变色
用到的鼠标事件:(1)鼠标经过 onmouseover:(2)鼠标离开 onmouseout 核心思路:鼠标经过 tr 行的时候,当前行会改变背景颜色,鼠标离开的时候去掉背景颜色. 注意:第一行(th ...
- idea生成实体类
1.点击View->Tool Windows->Database 2.点击Datebase框的加号,DateSource,选择对应的数据源,配置对应信息,点击Test Connection ...
- @transient 注解 和 transient变量的作用
@transient 和 transient是两码事 1.@transient的作用 @transient是hibernate和Morphia中的注解,hibernate都熟悉,Morphia是通过同 ...
- RabbitMq运行原理浅析
转载:https://blog.csdn.net/Evankaka/article/details/80977027 1.RabbitMq简介 AMQP,即Advanced Message Q ...
- windows上批量杀指定进程
Taskkill 结束一个或多个任务或进程.可以根据进程 ID 或图像名来结束进程. 语法 taskkill [/s Computer] [/u Domain\User [/p Password]]] ...
- express 模板 及 文件上传
express 的三大功能: 1. 提供了静态服务(所谓的根目录) let express = require("express"); let app = express(); a ...
- leetcode-easy-listnode-237 Delete Node in a Linked List
mycode # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # sel ...
- heigth innerheigt outerheight详解
height() :height innerHeight(): height + paddingouterHeight(): height + padding + border outerHeight ...