wxml:

<!-- 购物车 -->
<view wx:if="{{showPro}}"><view style='padding-bottom: 100rpx;'><view wx:for="{{shopData}}" wx:key="shopData" class='pro'><view style='width: 60rpx;' class='xuanzhong' bindtap='danxuan' data-index="{{index}}"><image src='/img/img/icon_select@2x.png' style='width: 36rpx; height: 36rpx;margin-top: 8rpx' wx:if="{{item.selected? true:false}}"></image><image src='/img/img/icon_nomal@2x.png' style='width: 36rpx; height: 36rpx;margin-top: 8rpx;' wx:if="{{item.selected? false:true}}"></image></view><view class='tutu'><image src='{{item.url}}' class='pro-image'></image></view><view class='wenzi'><view class='goodsname'><text class='te' style='font-weight: 600'>{{item.name}}</text><image src='/img/img/btn_del2@2x.png' style='width: 36rpx; height: 36rpx;' bindtap='deleteEve'></image></view><view class='zuixia'><view class='price1'>¥{{item.price}}</view><view class='add'><image src='/img/img/btn_sku_dis_sub@2x.png' class='num' style='margin-right: 4rpx;' wx:if="{{item.num == 1}}" bindtap='subtraction' data-erji="{{proind}}" data-index="{{index}}"></image><image src='/img/img/btn_sku_nml_sub@2x.png' class='num' style='margin-right: 4rpx;' wx:else data-index="{{index}}" bindtap='subtraction' data-erji="{{proind}}" data-index="{{index}}"></image><text style='display: block; width: 80rpx; height: 60rpx; background: #eee; text-align: center;font-size: 28rpx;line-height: 60rpx;color:#333'>{{item.num}}</text><image src='/img/img/btn_sku_add@2x.png' class='num' style='margin-left: 4rpx;' bindtap='add' data-erji="{{proind}}" data-index="{{index}}"></image></view></view></view></view><view style='clear:both'></view></view><!-- 底部 --><view class='bottom'><view><text style='font-size: 28rpx;margin-right: 20rpx;color:#333'>合计</text><text style='font-size: 36rpx; color: #F87039'>¥{{jiesuan}}</text></view><view style='width: 260rpx;height: 98rpx;'><view bindtap='topay' class='topay'>去结算</view></view></view>
</view>
<view wx:else style='width: 100%; background: #fff; height: 100%'><view class='img-s'><image src='/img/img/bg_default_cart@2x.png' style='width: 300rpx; height: 300rpx;'></image></view><view style='width: 100%;' class='ttx'><text style='font-size: 26rpx; color: #999;display: block;'>去添加点东西吧~</text></view><view class='button' bindtap='toMall'><button class='btn'>去商城逛逛</button></view>
</view>

wxss:

page {width: 100%;height: 100%;background: #efefef;
}/* 购物车商品 */.pro {width: 100%;height: 200rpx;padding-bottom: 40rpx;box-sizing: border-box;display: flex;flex-direction: row;justify-content: flex-start;background: #fff;border-bottom: 1rpx solid #efefef;
}.xuanzhong {height: 200rpx;margin-left: 30rpx;line-height: 200rpx;
}.tutu {padding-top: 20rpx;
}.pro-image {width: 160rpx;height: 160rpx;
}.wenzi {margin-left: 20rpx;padding-top: 40rpx;width: 460rpx;display: flex;flex-direction: column;box-sizing: border-box;padding-right: 30rpx;
}.goodsname {width: 100%;height: 50%;display: flex;flex-direction: row;justify-content: space-between;
}.te {font-size: 28rpx;color: #333;
}.num {width: 60rpx;height: 60rpx;
}.add {display: flex;flex-direction: row;flex-wrap: nowrap;
}.zuixia {width: 100%;height: 50%;display: flex;flex-direction: row;justify-content: space-between;margin-top: 60rpx;
}.price1 {color: #F87039;font-size: 28rpx;
}.bottom {width: 100%;height: 98rpx;border-top: 1rpx solid #efefef;background-color: #fff;position: fixed;bottom: 0;display: flex;flex-direction: row;justify-content: space-between;align-items: center;padding-left: 30rpx;box-sizing: border-box;
}button::after {border: none;
}.topay {background-color: #F87039;color: #fff;width: 260rpx;height: 98rpx;line-height: 98rpx;font-size: 32rpx;text-align: center;
}.img-s {width: 100%;display: flex;justify-content: center;padding-top: 160rpx;
}.ttx {display: flex;flex-direction: row;justify-content: center;margin-top: 60rpx;
}.button {width: 100%;display: flex;flex-direction: row;justify-content: center;margin-top: 60rpx;
}.button .btn {background-color: #F87039;width: 360rpx;height: 80rpx;color: #fff;font-size: 32rpx;line-height: 80rpx;
}

js:


import modals from '../../../class/base/modal.js'
import usual from '../../../class/base/usual.js'Page({data: {shopData:[{name: '商品1',url: '/img/img/sort1@2x.png',selected: true,num: 1,price: '484'},{name: '商品2',url: '/img/img/sort1@2x.png',selected: true,num: 1,price: '404'},{name: '商品3',url: '/img/img/sort1@2x.png',selected: true,num: 1,price: '10.56'},{name: '商品4',url: '/img/img/sort1@2x.png',selected: true,num: 1,price: '100'},{name: '商品5',url: '/img/img/sort1@2x.png',selected: true,num: 1,price: '0.5'}],showPro:true,jiesuan: 0.00},//加减操作add(e) {var that = thislet index = e.currentTarget.dataset.indexconsole.log(index)let shopData = that.data.shopDatashopData[index].num++usual.sum(shopData)let jiesuan = wx.getStorageSync('jiesuan', jiesuan)that.setData({jiesuan: jiesuan,shopData: shopData})},// 加减subtraction(e) {var that = thislet index = e.currentTarget.dataset.indexlet shopData = that.data.shopDataconsole.log(index)if (shopData[index].num > 1) {shopData[index].num--}else {modals.hideLoading('不能再少了')}usual.sum(shopData)let jiesuan = wx.getStorageSync('jiesuan', jiesuan)that.setData({jiesuan: jiesuan,shopData: shopData})},//单选danxuan(e) {var that = thislet index = e.currentTarget.dataset.indexconsole.log(index)let shopData = that.data.shopDatashopData[index].selected = !shopData[index].selectedusual.sum(shopData)let jiesuan = wx.getStorageSync('jiesuan', jiesuan)that.setData({jiesuan: jiesuan,shopData: shopData})},//去结算topay() {let url = "../pay/pay?jsonStr="let str = JSON.stringify(this.data.shopData)modals.navigate(url,str)},onLoad: function (options) {let that = thislet shopData = that.data.shopDatausual.sum(shopData)let jiesuan = wx.getStorageSync('jiesuan', jiesuan)that.setData({jiesuan: jiesuan})}
})

调用的方法:

const app = getApp()
export default class usual {static sum(shopData) {//计算总价new Promise((res, rej) => {var that = thislet jiesuan = 0for (let i = 0; i < shopData.length; i++) {if (shopData[i].selected) {jiesuan += shopData[i].price * 1000 * shopData[i].num / 1000}}console.log(jiesuan)wx.setStorageSync('jiesuan', jiesuan)})}static selectAll(shopData) {return new Promise((res, rej) => {//一进页面即全为选中状态var that = thisfor (let i = 0; i < shopData.length; i++) {let datashop = shopData[i].profor (let i in datashop) {datashop[i].selected = false}}})}
}

微信小程序 购物车布局以及逻辑相关推荐

  1. 7.微信小程序(布局适配与物理逻辑像素)

    微信小程序(布局适配与物理逻辑像素) 前言 移动端开发经常遇到一些概念:物理像素.逻辑像素.像素密度.像素比等,本节来详细介绍下 关键词: 屏幕尺寸.物理像素/屏幕分辨率/物理分辨率.逻辑像素DIP. ...

  2. 微信小程序全选,微信小程序checkbox,微信小程序购物车

    微信小程序,这里实现微信小程序checkbox,有需要此功能的朋友可以参考下. 摘要: 加减商品数量,汇总价格,全选与全不选 设计思路: 一.从网络上传入以下Json数据格式的数组  1.标题titl ...

  3. 微信小程序购物车 数量加减功能

    微信小程序购物车 数量加减功能 wxml <!-- 主容器 --> <view class="stepper"> <!-- 减号 --> < ...

  4. “完美”解决微信小程序购物车抛物动画,在连续点击时出现计算错误问题,定时器停不下来。

    "完美"解决微信小程序购物车抛物动画,在连续点击时出现计算错误问题,定时器停不下来. 参考文章: (1)"完美"解决微信小程序购物车抛物动画,在连续点击时出现计 ...

  5. 微信小程序中布局使用的css布局语法

    微信小程序的布局是基于css的布局,可以参考一些学习网站上面的css的基础学习 以下是布局的一些语法规则 class 用  .class{} id    用  #id{} 类的子元素添加css  (1 ...

  6. 微信小程序页面竖向滚动逻辑

    微信小程序页面竖向滚动逻辑 1.实现下面类似的数组 注:下面这个生成的数组最好是整数,滑动的时候会失去精度的,要不然你永远会差一点,让你崩溃的.而且你永远不知道差在哪里. this.leftScrol ...

  7. 原生微信小程序购物车

    原生微信小程序购物车!! 效果: html: <view style="background-color: #eeeeee;height: 100vh;"><vi ...

  8. image 微信小程序flex_微信小程序flex布局案例(1)

    微信小程序 flex 布局案例一 前言 最近在学习微信小程序时,看到很多布局都用到了 flex 布局,其实 flex 布局学习过好多东西不用就忘记了,这次用上就只得再去看了,争取学会.下面是我做的简单 ...

  9. 微信小程序购物车弹出层

    https://www.jianshu.com/p/a0c2c8712dab  微信小程序购物车 数量加减功能 wxml: <!--index.wxml--> <button bin ...

最新文章

  1. 单片机彩灯移动实验_用S7-1200 PLC实现循环彩灯的控制,含源程序
  2. CSS的表白:七夕巧克力心
  3. leetcode 1339. Maximum Product of Splitted Binary Tree | 1339. 分裂二叉树的最大乘积(树形dp)
  4. .NET Conf 2021 正在进行中,带你看一看微软带来了什么内容
  5. svm 图片加标签_基于半监督的SVM多标签图数据分类算法研究
  6. 一维数组kmeans聚类c语言,一维数组的 K-Means 聚类算法理解
  7. MATLAB用递归法求解集合子集,用递归法求一个集合的子集c语言,急!!!
  8. 判断当前窗口是否是全屏的山寨版和官方版
  9. 转:不同的行业和工作的真实情况是怎样的?
  10. JavaScript 学习-42.jQuery 提交表单 submit() 方法
  11. 既往不恋,当下不杂,未来不迎
  12. HTML+CSS+JS实现 ❤️3D立体魔方小游戏❤️
  13. 图的表示(Adjacency List + Adjacency Matrix)
  14. Utgard连接OPC Server常见故障码及解决方案
  15. 读《曾经,我们爱过一个世纪》有感(附原文)
  16. 2022-02-17 Android11 删除系统某种语言,我这里删掉粤语,修改frameworks/base/core/res/res/values/locale_config.xml里面的内容。
  17. 基于Pubmed数据库的蛋白质修饰后的信息挖掘
  18. 小技巧(1)「MacBook➕iPad」
  19. 网易云音乐数据治理探索与实践
  20. 使用BitLocker加密磁盘

热门文章

  1. 网络层 ARP地址解析协议
  2. java实现等腰三角形星字塔
  3. 从互联网大厂生态长出的新业务:网易智企要做“卖水人”?
  4. 如何将两个高度不同的div放在同一行
  5. 自动化测试之jest的使用
  6. eNSP中玩转Python自动化——解锁网工新姿势(六)
  7. 『docker笔记』通过docker搭建深度学习环境
  8. 10种经典的时间序列预测模型 本文演示了 10 种不同的经典时间序列预测方法
  9. linux启动盘制作hdd无法启动不了,我的U盘安装了pe重启后不认u盘,已在bois设置了第一启动为hdd为什么?求助!...
  10. 关于分治法的时间复杂度计算