微信小程序:完善购物车功能,购物车主页面展示,详细页面展示效果

一、效果图 

1、主页面

根据物品信息进行菜单分类,点击单项购物车图标添加至购物车,记录总购物车数量

2、购物车详情页

根据主页面选择的项,根据后台查询展示到页面,可进行多选,数量加减等

二、代码

1、主页面

页面展示顶部导航栏,侧边导航栏,以及导航栏执行下的内容,购物车的点击事件,内容单项的点击数量汇总到顶部总购物车总数量

wxml代码

<view class="main"><view class="topinfo"><view class="topinfo_view flex center"><view class="topinfo_model1 flex center"><view class="topinfo_model1_search"><image src="{{search}}"></image><input type="text" placeholder="请输入" placeholder-style="color:#CCCCCC" bindconfirm="search_info" /></view></view><view class="topinfo_model2 flex center" ><view class="topinfo_model2_circle flex center" bind:tap="shoppingClick"><image src="{{ShoppingCarGreen}}" /><view class="red_single1 flex center" wx:if="{{shoppingAllCount > 0}}">{{shoppingAllCount}}</view></view></view></view></view><view class="menu"><view class="top-menu flex between"><block wx:for="{{Menus}}" wx:key="index"><view class="topmenu-item flex center {{currentTopMenu === item.topname ? 'topactive' :''}}" data-menu="{{item.topname}}" bind:tap="onTopMenuClick">{{item.topname}}</view></block></view><view class="top-content flex center" wx:if="{{!linenone}}"><view class="left-menu"><block wx:for="{{LeftMenus}}" wx:key="index"><view class="left-menu-item flex center {{currentLeftMenu === item.name ? 'leftactive' : ''}}" bindtap="onLeftMenuClick" data-menu="{{item.name}}"><view class="left {{currentLeftMenu === item.name ? 'leftactivegreen' : ''}}"></view><text>{{item.name}}</text></view></block></view><view class="right-content"><block wx:for="{{RightInfo}}" wx:key="index"><view class="right-content-view flex"><view class="content-img flex center"><image src="{{item.img}}" mode="aspectFill"/></view><view class="content-info"><view class="cinfo-line flex between"><text>标题1:{{item.info1}}</text><text>标题2:{{item.info2}}</text></view><view class="cinfo-line flex between"><text>标题3:{{item.info3}}</text><text>标题4:{{item.info4}}</text></view><view class="cinfo-line flex between">标题5:{{item.info5}}</view><view class="cinfo-line flex flex-end"><view class="green-btn flex center" data-id="{{item.id}}" bind:tap="singleSel"><image src="{{ShoppingCarWhite}}" mode=""/><view class="red_single flex center" wx:if="{{item.isshopping}}">{{item.shoppingCount}}</view></view></view></view></view></block></view></view><view wx:else class="none">暂无数据</view></view>
</view>

wxss代码

主要采用flex布局进行布局

page {background-color: #f5f5f5;font-size:95%;
}.flex {display: flex;
}.center {justify-content: center;align-items: center;
}
.left{position: absolute;left:0;
}
.flex-end{justify-content: flex-end;
}
.between {justify-content: space-between;
}.none {text-align: center;margin-top: 50rpx;color: #969292;
}
/* 顶行搜索栏+购物车 */
/* 搜索框 */
.topinfo_view {padding: 4% 0 4% 0;
}.topinfo_model1 {height: 60rpx;width: 85%;
}.topinfo_model1_search {display: flex;align-items: center;height: 100%;width: 90%;border-radius: 10px;padding: 0 20rpx;background-color: #fff;
}.topinfo_model1 image {height: 40rpx;width: 45rpx;margin-right: 10px;
}.topinfo_view input {width: 100%;
}/* 购物车 */
.topinfo_model2 {width: 12%;height: 60rpx;
}.topinfo_model2_circle {width: 60rpx;height: 60rpx;background-color: #fff;border-radius: 50%;position:relative;
}.topinfo_model2_circle image {width: 40rpx;height: 40rpx;
}/* 顶部菜单栏 */
.menu {width: 100%;
}.topmenu-item {width: 100%;padding-bottom: 5px;border-bottom: 3px solid #f5f5f5;
}.topactive {border-bottom: 3px solid #4cc46b;
}/* 主体内容 */
.top-content {height:83vh;padding:10px 0;
}/* 左侧菜单栏 */
.left-menu {width: 25%;height:100%;
}
.leftactivegreen{width:5px;height:80%;background-color: #4cc46b;
}
.leftactive {background-color:#fff;color:#4cc46b;
}
.left-menu-item{height:50px;position:relative
}
.right-content {height:100%;width: 75%;font-size: 90%;background-color: #fff; overflow-y: auto;
}
.right-content-view{border-bottom:3px solid #f6f6f6;width:100%;padding:2% 0;
}
.content-img {width: 30%;margin-right: 2px;/* border:1px solid black; */
}
.content-img image {width: 95%;height: 95%;
}
.content-info{width:65%;
}
.cinfo-line{width:100%;padding:2% 0;
}
.green-btn{background-color:#4cc46b ;width:50rpx;height:50rpx;border-radius: 5px;margin-top:-4%;position:relative;
}
.green-btn image{width:35rpx;height:35rpx;
}
.red_single{border:1px solid #fff;color:#fff;position:absolute;width:25rpx;height:25rpx;top:-15rpx; right:-15rpx;border-radius: 50%;background-color: red;font-size: 10px;
} 
.red_single1{border:1px solid #fff;color:#fff;position:absolute;width:25rpx;height:25rpx;top:-12rpx; right:-12rpx;border-radius: 50%;background-color: red;font-size: 10px;
} 

js代码

这里主要展示核心数据部分,详细可参考资源

Menus: [{topname: '顶部菜单1',leftMenus: [{name: '侧边菜单1',items: [{id: 1,info1: '11',info2: '22',info3: '33',info4: '44',info5: '55',img: '../img/process_2.png'},{id: 2,info1: '22',info2: '22',info3: '22',info4: '22',info5: '22',img: '../img/process_1.png'},],},{name: '侧边菜单2',items: [{id: 3,info1: '33',info2: '33',info3: '33',info4: '33',info5: '33',img: '../img/process_3.png'}],},]},{topname: '顶部菜单2',leftMenus: []},{topname: '顶部菜单3',leftMenus: [{name: '侧边菜单3',items: [{id: 4,info1: '44',info2: '44',info3: '44',info4: '44',info5: '44',img: '../img/process_2.png'}],}],},{topname: '顶部菜单4',leftMenus: [{name: '侧边菜单4',items: [{id: 5,info1: '55',info2: '55',info3: '55',info4: '55',info5: '55',img: '../img/process_1.png'}],}],},
],

2、购物车界面

主要完成页面的选中项的展示,根据主页页面传递的id参数可进行数据库的查询,这里没连接后端,所以直接展示的实例数据,循环出数据项后,可对数据项进行多选,数据加减等功能

wxml代码

实现页面

<view class="main"><view class="itemallinfo"><view class="item_info flex center" wx:for="{{allinfo}}" wx:key="index" data-id="{{item.id}}"><view class="item flex center"><view class="sel_checkbox flex center"><checkbox value="{{item.id}}" checked="{{item.checked}}" bindtap="handleSelectItem" data-id="{{item.id}}" /></view><view class="info_image flex center"><image src="{{item.img}}" mode="aspectFill" /></view><view class="info_content"><view class="info_line1">配件名称:{{item.name}}</view><view class="info_line1">库存数量:{{item.stockQty}}{{item.uom}}</view><view class="info_line1 flex flex-end numbtn"><view class="btn_minus flex center" bindtap="handleMinus" data-id="{{item.id}}">-</view><input class="input_count" type="number" value="{{item.count}}" bindinput="handleInputChange" data-id="{{item.id}}" /><view class="btn_plus flex center" bindtap="handlePlus" data-id="{{item.id}}">+</view></view></view></view></view></view><view class="footer flex between"><view class="select_all flex center"><checkbox bindtap="handleSelectAll" checked="{{isAllSelected}}" /> 全选</view><view class="bottom2 flex center"><view class="delete_btn surebtn flex center" bindtap="handleDelete">删除</view></view><view class="bottom3 flex center"><view class="submit_btn surebtn flex center" bindtap="handleSubmit">提交</view></view></view>
</view>

wxss代码

page {background-color: #f6f6f6;font-size: 90%;
}.flex {display: flex;
}checkbox {transform: scale(0.8);
}.center {justify-content: center;align-items: center;
}.flex-end {justify-content: flex-end;align-items: center;
}
.between{justify-content: space-between;
}/* 列表内容 */
.item_info {width: 100%;padding: 5px 0;
}
.itemallinfo{padding:15px 0 100px 0;
}
.item {width: 95%;background-color: #fff;padding: 2% 0;border-radius: 5px;box-shadow: 3px 3px 3px rgb(0, 0, 0, 0.1);
}.sel_radio {width: 12%;
}radio {transform: scale(0.8);
}.info_image {width: 20%;
}.info_image image {width: 60px;height: 60px;
}.info_content {width: 68%;
}.info_line1 {margin: 2% 0;
}.numbtn {height: 25px;align-items: stretch;padding-right:2%;
}.btn_minus,
.btn_plus {border: 1px solid #c0c0c0;width: 30px;/* 设置按钮宽度 */height: 100%;cursor: pointer;/* 可选:设置鼠标指针样式 */
}.input_count {border: 1px solid #c0c0c0;width: 50px;/* 设置输入框宽度 */text-align: center;margin: 0 -1px;height: 100%;border-right:0;border-left:0;
}.footer {align-items: center;background-color: #fff;border-top: 1px solid #eee;position:fixed;width:100%;bottom:0;height:70px;
}
.select_all{height:100%;width:30%;
}
.bottom3,.bottom2{height:100%;width:35%;
}
.delete_btn {background-color: #bebebe;color: #fff;
}
.submit_btn {background-color: #f3454e;color: #fff;
}
.surebtn{border-radius: 5px;width:80%;height:30px;
}

js代码

这里主要展示核心数据部分,详细可参考资源

var allinfo = [{id: 1,info1: '11',info2: '22',info3: '33',info4: '44',info5: '55',img: '../img/process_2.png',count: 1,checked: false, // 默认未选中},{id: 3,info1: '33',info2: '33',info3: '33',info4: '33',info5: '33',img: '../img/process_3.png',count: 2,checked: false, // 默认未选中},{id: 5,info1: '55',info2: '55',info3: '55',info4: '55',info5: '55',img: '../img/process_1.png',count: 1,checked: false, // 默认未选中},
];

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/26594.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

微服务学习(2):实现SpringAMQP对RabbitMQ的消息收发

目录 SpringAMQP是什么 为什么采用SpringAMQP SpringAMQP应用 准备springBoot工程 实现消息发送 SpringAMQP是什么 Spring AMQP是Spring框架下用于简化AMQP&#xff08;高级消息队列协议&#xff09;应用开发的一套工具集&#xff0c;主要针对RabbitMQ等消息中间件的集成…

echarts柱状图不是完全铺满容器,左右两边有空白

目录 处理前&#xff1a;echarts柱状图不是完全铺满容器&#xff0c;左右两边有空白处理前&#xff1a;通过调整 grid 组件配置处理后效果修改代码&#xff1a;1. 调整 grid 组件配置原理解决办法 2. 处理 xAxis 的 boundaryGap 属性原理解决办法 3. 调整 barMaxWidth 和 barMi…

【K8S】Kubernetes 基本架构、节点类型及运行流程详解(附架构图及流程图)

Kubernetes 架构 k8s 集群 多个 master node 多个 work nodeMaster 节点&#xff08;主节点&#xff09;&#xff1a;负责集群的管理任务&#xff0c;包括调度容器、维护集群状态、监控集群、管理服务发现等。Worker 节点&#xff08;工作节点&#xff09;&#xff1a;实际运…

千峰React:案例二

完成对html文档还有css的引入&#xff0c;引入一下数据&#xff1a; import { func } from prop-types import ./购物车样式.css import axios from axios import { useImmer } from use-immer import { useEffect } from reactfunction Item() {return (<li classNameacti…

C语言【指针篇】(四)

前言&#xff1a;正文1. 字符指针变量2. 数组指针变量2.1 数组指针变量是什么?2.2 数组指针变量怎么初始化 3. 二维数组传参的本质4. 函数指针变量4.1 函数指针变量的创建4.2 函数指针变量的使用4.3 两段有趣的代码4.3.1 typedef关键字 5. 函数指针数组6. 转移表 总结 前言&am…

GitCode 助力 python-office:开启 Python 自动化办公新生态

项目仓库&#xff1a;https://gitcode.com/CoderWanFeng1/python-office 源于需求洞察&#xff0c;打造 Python 办公神器 项目作者程序员晚枫在运营拥有 14w 粉丝的 B 站账号 “Python 自动化办公社区” 时&#xff0c;敏锐察觉到非程序员群体对 Python 学习的强烈需求。在数字…

对话Stack Overflow,OceanBase CTO 杨传辉谈分布式数据库的“前世今生”

近日&#xff0c; OceanBase CTO 杨传辉受邀出席全球知名开发者论坛 Stack Overflow 的最新一期播客节目&#xff0c;与 Stack Overflow 高级内容创作官 Ryan Donovan 展开对话。双方围绕分布式数据库的可靠性、一致性保障、HTAP 架构以及 AI 时代分布式数据库的发展趋势等热点…

小结:计算机网路中的性能指标小结

发现B站的这套课程不错&#xff0c;开始学习并笔记之&#xff1a;计算机网络微课堂&#xff08;有字幕无背景音乐版&#xff09;_哔哩哔哩_bilibili 1) 速率 2) 带宽 3) 吞吐量 带宽1 Gb/s的以太网&#xff0c;代表其额定速率是1 Gb/s&#xff0c;这个数值也…

seasms v9 注入漏洞 + order by注入+​information_schema​解决方法

目录 一、当注入时&#xff0c;information_schema被禁用的解决方法 1.通过sys库可以获取到表名和库名 2.通过无列名注入join获取列名 二、seasms v9 注入漏洞 三、order by注入 一、当注入时&#xff0c;information_schema被禁用的解决方法 information_schema数据库是My…

FFmpeg-chapter2-C++中的线程

1 常规的线程 一般常规的线程如下所示 // CMakeProject1.cpp: 定义应用程序的入口点。 //#include "CMakeProject1.h" #include <thread> using namespace std;void threadFunction(int index) {for (int i 0; i < 1000; i){std::cout << "Th…

【华三】从零开始掌握SR技术:原理、架构与应用全解析

【华三】从零开始掌握SR技术&#xff1a;原理、架构与应用全解析 一、初识SR&#xff1a;路由技术的新革命1.1 传统网络的困扰&#xff1a;从真实案例看技术瓶颈1.1.1 企业网络运维之痛问题2&#xff1a;流量工程实现困难问题3&#xff1a;网络智能化缺失 1.2 SR的诞生意义&…

CogBlobTool工具

CogBlobTool是一款专用于图像斑点检测于分析的 工具&#xff0c;通过灰度值阈值分割和特征过滤&#xff0c;帮助在复杂背景中提取目标区域&#xff0c;并计算几何属性。 效果图 注意&#xff1a;在这里只有一张图像可以不使用模板匹配工具 CogBlobTool工具的功能 斑点检测于…

大模型应用案例 | 大模型+金融运维,擎创携手某证券创新运维能力新范式

一、当大模型遇上金融运维&#xff1a;一场让告警处理“脱胎换骨”的变革 2022年底&#xff0c;ChatGPT的横空出世让AI技术彻底出圈&#xff1b;短短两年后&#xff0c;大模型已悄然潜入金融行业的“心脏地带”——运维系统。面对指数级暴增的告警信息、碎片化的处理流程&#…

Linux三种网络方式

前言 发现运维啥都得会&#xff0c;这周就遇到了网络问题自己无法解决&#xff0c;因此痛定思痛学一下。 参考文献 你管这破玩意叫网络&#xff1f; 桥接模式、NAT模式、仅主机模式&#xff0c;原来是这样工作的 交换机 构成局域网&#xff0c;实现所有设备之间的通信。 …

基于PHP和MySQL的用户登录注册系统实现

系统架构 系统采用前后端分离的架构&#xff0c;使用PHP作为后端语言&#xff0c;MySQL作为数据库。以下是系统的整体架构图&#xff1a; 这个架构图展示了系统的三个主要层次&#xff1a; 前端界面层&#xff1a;包含用户交互的三个页面&#xff08;注册、登录和欢迎页面&am…

脚本无法获取响应主体(原因:CORS Missing Allow Credentials)

背景&#xff1a; 前端的端口号8080&#xff0c;后端8000。需在前端向后端传一个参数&#xff0c;让后端访问数据库去检测此参数是否出现过。涉及跨域请求&#xff0c;一直有这个bug是404文件找不到。 在修改过程当中不小心删除了一段代码&#xff0c;出现了这个bug&#xff0…

【计网】计算机网络概述

第一章 计算机网络概述 1.2 因特网概述1.2.1 网络、互联网和因特网1.2.2 因特网发展的三个阶段1.2.3 因特网的标准化工作1.2.4 因特网的组成 1.3 三种交换方式1.3.1 电路交换1.3.2 分组交换1.3.3 报文交换1.3.4 三种交换的对比 1.4 计网的定义与分类1.4.1 定义1.4.2 分类 1.5 计…

前端依赖nrm镜像管理工具

npm 默认镜像 &#xff1a;https://registry.npmjs.org/ 1、安装 nrm npm install nrm --global2、查看镜像源列表 nrm ls3、测试当前环境下&#xff0c;哪个镜像源速度最快。 nrm test4、 切换镜像源 npm config get registry # 查看当前镜像源 nrm use taobao # 等价于 npm…

LinkedList与链表

目录 1、链表 2、实现自己的链表 (不带头结点) 2.1、遍历链表 2.2、求链表长度 2.3、判断链表是否包含关键字 2.4、插入节点 2.5、任意位置插入一个节点 2.6、删除一个节点 2.7、删除所有值为key的节点 2.8、清空所有节点 1、链表 链表是一种物理结构上不连续的存储结…

StableDiffusion打包 项目迁移 项目分发 1

文章目录 SD项目迁移前置知识webui-user.batwebui.batlaunch_utils.py 下一篇开始实践 SD项目迁移 显卡驱动更新&#xff1a;https://www.nvidia.cn/geforce/drivers/ 下载安装三个程序&#xff1a; python3.10.6: https://www.python.org/downloads/release/python-3106/gi…