侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

小程序外卖订单界面的示例代码

微信(小程序)  /  管理员 发布于 5年前   534

1.效果界面




2.涉及功能

*左侧商品类型、右侧商品可以相互控制;
*商品列表加减及购物车商品加减icon消失、显示;
*商品每一次加减,页面视图变化(数量、价格变化、购物车置灰);

3.贴上所有代码

1.wxml   

            {{item.name}}                        {{item.name}}                            {{itm.title}}        {{itm.info}}        ¥{{itm.price}}                                                                                                 {{totalNum}}        ¥{{totalMoney}}      去结算                  已选商品     清空                          {{item.name}}               ¥{{item.price}}                                                                                          {{goodDetail.title}}     ¥{{goodDetail.price}}     {{goodDetail.info}}              

2.script

createPage({ data: {  foodsList: [], // 商品数据  cartList: [], // 购物车数据  isShowCartMask: false,  totalNum: 0,  totalMoney: 0,  initView: 'item0', // 根据此变量的变化,控制左侧选中状态、右侧滑动  curId: 'item0',  isShowDetail: false,  goodDetail: {},  screenWidth: 0, // 手机屏幕宽度  heightArray: [0] // 右侧每一个类型的高度区间数组 }, onLoad() {  this.getGoodsData() }, methods: {  async getGoodsData() {   const that = this   const res = await getGoodsInfo({})   this.foodsList = res   wx.getSystemInfo({    success: (ress) => {     that.screenWidth = ress.windowWidth    }   })   this.getHeightSection()  },  // 设置高度区间 所有单位转化为rpx  getHeightSection() {   const that = this   let hg = 0   for (let index = 0; index < that.foodsList.length - 1; index++) {    hg += 70 + that.foodsList[index].list.length * 212    that.heightArray.push(hg)   }  },  // 获取高度区间的下标  getHeightIndex(arr, hg) {   const that = this   arr.forEach((item, index) => {    if (hg >= item) {     that.setData({      curId: 'item' + index     })    }   })  },  // 左边菜单控制右边  scrollToViewFn(e) {   this.setData({    initView: e.target.dataset.id,    curId: e.target.dataset.id   })  },  // 右边滚动控制左边  onPageScroll(e) {   const that = this   let scrollTop = e.detail.scrollTop * 750 / that.screenWidth   this.getHeightIndex(that.heightArray, scrollTop)  },  // 商品列表的减号点击  reduceNum(index, ind, item) {   const that = this   let val = 'foodsList[' + index + '].list[' + ind + '].num'   this.setData({    [val]: item.num - 1   })   // 如果商品为0,就把当前商品在购物车清除   // 如果不为0, 就将当前商品数量减1   if (that.foodsList[index].list[ind].num === 0) {    that.removeAarry(that.cartList, item.id)   } else {    that.cartList.forEach((itm, i) => {     if (itm.id === item.id) {      let value = 'cartList[' + i + '].num'      that.setData({       [value]: itm.num - 1      })     }    })   }   this.computed()  },  // 商品列表的加号点击  addNum(index, ind, item) {   const that = this   let val = 'foodsList[' + index + '].list[' + ind + '].num'   this.setData({    [val]: item.num + 1   })   // 如果商品为1,就把当前商品加入购物车   // 否则, 就将当前商品数量加1   if (that.foodsList[index].list[ind].num === 1) {    let val = { id: item.id, name: item.title, price: item.price, num: 1, index: index, ind: ind, pic: item.pic }    that.cartList.push(val)   } else {    that.cartList.forEach((itm, i) => {     if (itm.id === item.id) {      let value = 'cartList[' + i + '].num'      that.setData({       [value]: itm.num + 1      })     }    })   }   this.computed()  },  // 购物车的减号点击  reduceCart(index, item) {   const that = this   let val = 'foodsList[' + item.index + '].list[' + item.ind + '].num'   let val1 = 'cartList[' + index + '].num'   this.setData({    [val]: item.num - 1,    [val1]: item.num - 1   })   // 如果商品为0,就把当前商品在购物车清除   // 如果不为0, 就将当前商品数量减1   if (that.cartList[index].num === 0) {    that.removeAarry(that.cartList, item.id)   }   this.computed()  },  // 购物车的加号点击  addCart(index, item) {   const that = this   let val = 'cartList[' + index + '].num'   that.setData({    [val]: item.num + 1   })   this.computed()  },  // 清空购物车  clearCart() {   const that = this   wx.showModal({    title: '提示',    content: '清空购物车?',    success: function (res) {     if (res.confirm) {      that.setData({       cartList: []      })      that.foodsList.forEach((item, i) => {       item.list.forEach((itm, j) => {        let value = 'foodsList[' + i + '].list[' + j + '].num'        that.setData({         [value]: 0        })       })      })      that.computed()     }    }   })  },  // 计算选择商品总价格和总数量  computed() {   const that = this   let num = 0   let money = 0   that.cartList.forEach(item => {    num += item.num    money += parseFloat(item.price) * item.num   })   that.setData({    totalNum: num,    totalMoney: money   })  },  // 将数量为0的时候,对应商品在购物车中删除  removeAarry(arr, id) {   arr.forEach((item, index) => {    if (item.id === id) {     arr.splice(index, 1)    }   })   return arr  },  showCartMask() {   this.isShowCartMask = !this.isShowCartMask  },  hiddenCartMak() {   this.isShowCartMask = false  },  stopMaopao() {  },  showGoodDetail(item) {   this.goodDetail = item   this.isShowDetail = true  },  hideDetail() {   this.isShowDetail = false  },  // 订单提交  submitOrder() {  } }})

3.css


										

  • 上一条:
    微信小程序下载工具及调试详解
    下一条:
    微信小程序搭建及解决登录失败问题
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 微信模板消息改版后发送规则记录(微信订阅消息参数值内容限制说明)(1个评论)
    • 微信支付v3对接所需工具及命令(0个评论)
    • 2023年9月1日起:微信小程序必须备案才能上线运营(0个评论)
    • 腾讯官方客服回应了:微信好友上限约10000个!(1个评论)
    • 2023年做微信小程序的老铁注意:新增收费项、微信小程序获取手机号也收费了(2个评论)
    • 近期文章
    • 智能合约Solidity学习CryptoZombie第二课:让你的僵尸猎食(0个评论)
    • 智能合约Solidity学习CryptoZombie第一课:生成一只你的僵尸(0个评论)
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2017-10
    • 2018-01
    • 2020-03
    • 2021-06
    • 2021-10
    • 2022-03
    • 2023-02
    • 2023-06
    • 2023-07
    • 2023-08
    • 2023-10
    • 2023-11
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客