uniapp 学习笔记二十七 购物车总价计算及弹窗交互逻辑完善

uniapp 学习笔记二十七 购物车总价计算及弹窗交互逻辑完善

cart.vue

<template><view><view class="flex padding" v-for="(item,index) in cartList"><view class="flex align-center"><text @click="handleCheck(index)" :class="['iconfont','icon-youxiajiaogouxuan','margin-right',{'yellow':item.isCheck}]"></text><image class="poster margin-right" :src="item.img" mode=""></image></view><view class="flex justify-between info"><view class="">{{item.name}}<view class="margin-tb-xs">   {{item.french}} </view>Y{{item.list[item.idx].price}}</view><view class="flex flex-direction align-end"><view @click="handleEdit(index)" class="edit margin-bottom-xs"><text class="iconfont icon-bianjishuru"></text></view>{{item.list[item.idx].spec}} X {{item.num}}</view></view></view><!-- 弹窗 --><u-overlay :show="show" @click="show=false"><view class="bg-fff margin cover-cont" @click.stop><view class="padding"><view class="flex justify-between info"><image class="poster margin-right" src="" mode=""></image><view class="">{{cartList[cartIdx].name}}<view class="margin-tb-xs"> {{cartList[cartIdx].french}}    </view>Y{{checkedCartInfo.price}}</view></view><view class="flex justify-between padding-tb u-border-bottom"><view class="">规格选择</view><view class="drop"><view @click="dropShow=true">{{checkedCartInfo.spec}} - {{checkedCartInfo.edible}}<text class="iconfont icon-xiangxiazhankai"></text></view><view v-if="dropShow" class="drop-list bg-fff"><view v-for="(item,index) in cartList[cartIdx].list" class="padding-sm":key="index" @click="handleDropList(index)">{{item.spec}} - {{item.edible}}</view></view></view></view><view class="flex justify-between align-center padding-tb u-border-bottom"><view class="">数量选择</view><u-number-box button-size="36" @change="handleNum"></u-number-box></view></view><view class="flex margin-top"><button @click="show=false" type="default" class="cu-btn lg bg-brown">取消</button><button @click="handleOk" type="default" class="cu-btn lg bg-yellow">确认</button></view></view></u-overlay><view class="fixed bg-fff flex"><view class="flex flex-sub padding align-center"><text @click="handleAllCheck(allInfo.allCheck)" :class="['iconfont', 'icon-youxiajiaogouxuan', 'margin-right-xs',{'yellow':allInfo.allCheck}]"></text>全选<view class="margin-left">共计:{{allInfo.allPrice}}</view></view><view class="bg-yellow padding text-center color-fff">立即结算</view></view></view>
</template><script>import {mapState,mapMutations,mapGetters} from 'vuex'export default {data() {return {show:false,dropShow:false,cartIdx:0, // 主商品序号num:1,//当前弹窗商品数量dropIdx:0 // 子商品序号}},computed: {...mapState({cartList:state=>state.cart.cartList }),...mapGetters({allInfo:'cart/allInfo'}),checkedCartInfo(){ // 过滤下拉选中的商品对象let {cartIdx,cartList,dropIdx} = thisreturn cartList[cartIdx].list[dropIdx]}},methods:{...mapMutations({handleCheck:'cart/cartCheckMut',handleAllCheck:'cart/cartAllCheckMut'}),handleEdit(idx){// 弹窗控制this.cartIdx = idx;this.show=true;this.dropIdx = this.cartList[idx].idx;},handleDropList(dropIdx){ //子商品下拉列表this.dropShow = false;this.dropIdx = dropIdx;},handleOk(){ //弹窗确定            this.show = false;let {cartIdx,dropIdx,num} = this;console.log(cartIdx,dropIdx,num);this.$store.commit('cart/cartListCheckMut',{cartIdx,dropIdx,num});},handleNum({value}){this.num = value;}}}
</script><style lang="scss">
page{padding-bottom: 100upx;
}
.poster{width: 180upx;height: 180upx;background-color: #d8d8d8;
}
.info{width: 60%;.edit{width: 80upx;height: 80upx;text-align: center;line-height: 80upx;background-color: #e6e6e6;border-radius: 50%;}
}
.icon-youxiajiaogouxuan{width: 50upx;height: 50upx;text-align: center;line-height: 50upx;background-color: #e6e6e6;border-radius: 20%;
}
.fixed {position: fixed;bottom: 0;left: 0;width: 100%;box-shadow: 0 0 10upx 2upx rgba(0, 0, 0, 0.2);
}.yellow{background-color: yellow;
}
.cu-btn.lg{width: 50%;
}
.cover-cont{position: absolute;top: 50%;left: 0;width: 690upx;transform: translateY(-50%);border-radius: 10upx;
}
.drop{position: relative;.drop-list{width:300upx;position: absolute;top: 60upx;right: 0;box-shadow: 0 0 10upx 2upx rgba(0, 0, 0, 0.2);z-index: 10;view:hover{background-color: #e6e6e6;}}
}</style>

cart.js

export default {namespaced:true,state(){return {cartList:[{id:"10090",twoId:10089,name:"拿破仑草莓恋爱",french:"Napoleon aux fraises",price:"208.00",isCheck:false,img:"/static/logo.png",list:[{id:10090,sku:"n0201",ahead:'提前5小时预定',edible:"2-3人食用",spec:"1磅",price:"218.00"},{id:10091,sku:"n0202",ahead:'提前5小时预定',edible:"4-7人食用",spec:"2磅",price:"318.00"},{id:10092,sku:"n0203",ahead:'提前5小时预定',edible:"8-12人食用",spec:"3磅",price:"458.00"},{id:10093,sku:"n0204",ahead:'提前5小时预定',edible:"12-20人食用",spec:"5磅",price:"750.00"}],num:1,//商品数量idx:0 //标记选中的子商品信息},{id:"10090",twoId:10089,name:"拿破仑草莓",french:"Napoleon aux fraises",price:"218.00",tid:11,tname:'限定',isCheck:false,img:"/static/logo.png",list:[{id:10090,sku:"n0201",ahead:'提前5小时预定',edible:"2-3人食用",spec:"1磅",price:"218.00"},{id:10091,sku:"n0202",ahead:'提前5小时预定',edible:"4-7人食用",spec:"2磅",price:"318.00"},{id:10092,sku:"n0203",ahead:'提前5小时预定',edible:"8-12人食用",spec:"3磅",price:"458.00"},{id:10093,sku:"n0204",ahead:'提前5小时预定',edible:"12-20人食用",spec:"5磅",price:"750.00"}],num:1, //商品数量idx:0 //标记选中的子商品信息}]}},getters:{/*** 统计信息*/allInfo(state){ let allCheck = truelet allPrice = 0state.cartList.forEach(item=>{if(!item.isCheck){allCheck = false}if(item.isCheck){allPrice += item.list[item.idx].price * item.num}})return {allCheck,allPrice}}},mutations:{cartCheckMut(state,idx){ // 单选state.cartList[idx].isCheck = !state.cartList[idx].isCheck},cartAllCheckMut(state,bool){ // 全选 bool 是原本的全选状态state.cartList.forEach(item=>{item.isCheck = !bool})},cartListCheckMut(state,{cartIdx,dropIdx,num}){ // 子商品下拉确认处理state.cartList[cartIdx].idx = dropIdxstate.cartList[cartIdx].num = num}}
}

uniapp 学习笔记二十七 购物车总价计算及弹窗交互逻辑完善相关推荐

  1. uniapp 学习笔记二十二 购物车页面结构搭建

    uniapp 学习笔记二十二 购物车页面结构搭建 cart.vue <template><view><view class="flex padding" ...

  2. Mr.J-- jQuery学习笔记(二十七)--DOM操作方法(删除获取文本)

    清除 <body> <button>调用remove</button> <div>我是div<p>我是段落</p> </d ...

  3. Qt学习笔记(二十七):QLabel 的常用方法

    一.QLabel 的构造函数: 1.QLabel(QWidget * parent = 0, Qt::WindowFlags f = 0):创建 QLabel 控件时,指定其父对象,并设置其窗口属性( ...

  4. C++语法学习笔记二十七: 引用折叠,转发、完美转发,forward

    实例代码 // 引用折叠,转发.完美转发,forward#include <iostream>using namespace std;template<typename T> ...

  5. python学习笔记(二十七) -- 常用内建模块(二) Base64、MD5、SHA1、hmac

    目录 base64 hashlib MD5 SHA1 hmac base64 原理 base64就是对二进制数据进行编码,比如我有6字节的二进制数据,然后每3个字节分为一组,也就是一组有3*8 = 2 ...

  6. 马哥学习笔记二十七——IO复用

    I/O动作模式 阻塞 非阻塞 I/O复用 信号驱动 异步 转载于:https://www.cnblogs.com/wangyongbin/p/3817353.html

  7. Java学习笔记 (二十七) 使用NIO写文件

    使用Channel 写数据 代码如下: public static void main(String []args){try(FileOutputStream fos=new FileOutputSt ...

  8. 武汉大学-黄如花-信息检索课程学习笔记二

    武汉大学-黄如花-信息检索课程学习笔记二 一.信息检索基本方法 1.布尔逻辑检索 2.临近检索 3.短语检索(精确检索) 4.截词检索 5.字段限制检索 6.区分大小写的检索 二.多种检索方法的综合运 ...

  9. 计算鬼成像学习笔记二:二阶关联函数探究

    计算鬼成像学习笔记二:二阶关联函数探究 1 一阶关联函数 2 二阶关联函数 3 二阶关联如何重构物体 4 差分鬼成像关联公式 5 归一化鬼成像关联公式 1 一阶关联函数 一阶关联函数是光场的电场强度之 ...

最新文章

  1. python毫秒级时间戳
  2. 第八届全国计算机数学学术会议,第一届全国计算机数学学术会议 报告摘要
  3. 云存储巧解三大存储难题
  4. centos6.5_x64远程链接输入正确的账号密码无法登陆
  5. sql针对某字段去重查询_sql的简单查询
  6. myelicpes怎么导入PHP项目,利用PHP执行SQL文件,将SQL文件导入到数据库
  7. 经典:编程面试的 10 大算法概念汇总
  8. 在ASP.NET中使用Session常见问题集锦
  9. @广州开发者,华为送来一份说明书——助你轻松应对开发难题
  10. linux下矩阵键盘设备名,Linux下矩阵键盘驱动分析与移植
  11. 23种设计模式之适配器模式代码实例
  12. 80004005错误代码_80004005错误代码怎么回事_安装软件错误代码0×80004005如何解决...
  13. Ubuntu下给U盘分区
  14. Tikhonov regularization 吉洪诺夫正则化
  15. 什么从什么写短句_照样子写句子.(写清“谁或什么 “在什么地方 “做什么或怎么样 ) 例1:小朋友在河边种树. 例2:麻雀在窝里睡着了. 题目和参考答案——青夏教育精英家教网——...
  16. linux test指令大全,linux test命令详解
  17. Web全栈~06.CSS选择器
  18. JavaScript制作简易聊天窗口
  19. React实战:留言板
  20. 出现 DB2 SQL Error: SQLCODE = -798, SQLSTATE = 428C9 错误的原因及解决方法

热门文章

  1. php 中trim的意义,php中的trim
  2. 纯硬件简单人体感应灯(无需编程)
  3. 检验用计算机清单,来自微软亚洲研究院推荐的计算机视觉项目清单
  4. Cloze Test Helps: Effective Video Anomaly Detection via Learning to Complete Video Events 速读整理
  5. discard connection
  6. 原神3D卡通动漫二次元角色模型Blender已绑骨骼
  7. redis hset方法
  8. git 和 SVN 上传代码步骤
  9. OSGi框架之Eclipse Equinox
  10. assertion: 18 { ok: 0.0, errmsg: auth failed, code: 18 }