微信小步伐:完善购物车功能,购物车主页面展示,具体页面展示效果 ...

打印 上一主题 下一主题

主题 1041|帖子 1041|积分 3123

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
一、效果图 

1、主页面

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

2、购物车详情页

根据主页面选择的项,根据背景查询展示到页面,可进行多选,数目加减等

二、代码

1、主页面

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

  1. <view class="main">
  2.   <view class="topinfo">
  3.     <view class="topinfo_view flex center">
  4.       <view class="topinfo_model1 flex center">
  5.         <view class="topinfo_model1_search">
  6.           <image src="{{search}}"></image>
  7.           <input type="text" placeholder="请输入" placeholder-style="color:#CCCCCC" bindconfirm="search_info" />
  8.         </view>
  9.       </view>
  10.       <view class="topinfo_model2 flex center" >
  11.         <view class="topinfo_model2_circle flex center" bind:tap="shoppingClick">
  12.           <image src="{{ShoppingCarGreen}}" />
  13.           <view class="red_single1 flex center" wx:if="{{shoppingAllCount > 0}}">{{shoppingAllCount}}</view>
  14.         </view>
  15.       </view>
  16.     </view>
  17.   </view>
  18.   <view class="menu">
  19.     <view class="top-menu flex between">
  20.       <block wx:for="{{Menus}}" wx:key="index">
  21.         <view class="topmenu-item flex center {{currentTopMenu === item.topname ? 'topactive' :''}}" data-menu="{{item.topname}}" bind:tap="onTopMenuClick">{{item.topname}}</view>
  22.       </block>
  23.     </view>
  24.     <view class="top-content flex center" wx:if="{{!linenone}}">
  25.       <view class="left-menu">
  26.         <block wx:for="{{LeftMenus}}" wx:key="index">
  27.           <view class="left-menu-item flex center {{currentLeftMenu === item.name ? 'leftactive' : ''}}" bindtap="onLeftMenuClick" data-menu="{{item.name}}">
  28.             <view class="left {{currentLeftMenu === item.name ? 'leftactivegreen' : ''}}"></view>
  29.             <text>{{item.name}}</text>
  30.           </view>
  31.         </block>
  32.       </view>
  33.       <view class="right-content">
  34.         <block wx:for="{{RightInfo}}" wx:key="index">
  35.           <view class="right-content-view flex">
  36.             <view class="content-img flex center">
  37.               <image src="{{item.img}}" mode="aspectFill"/>
  38.             </view>
  39.             <view class="content-info">
  40.               <view class="cinfo-line flex between">
  41.                 <text>标题1:{{item.info1}}</text>
  42.                 <text>标题2:{{item.info2}}</text>
  43.               </view>
  44.               <view class="cinfo-line flex between">
  45.                 <text>标题3:{{item.info3}}</text>
  46.                 <text>标题4:{{item.info4}}</text>
  47.               </view>
  48.               <view class="cinfo-line flex between">标题5:{{item.info5}}</view>
  49.               <view class="cinfo-line flex flex-end">
  50.                 <view class="green-btn flex center" data-id="{{item.id}}" bind:tap="singleSel">
  51.                   <image src="{{ShoppingCarWhite}}" mode=""/>
  52.                   <view class="red_single flex center" wx:if="{{item.isshopping}}">{{item.shoppingCount}}</view>
  53.                 </view>
  54.               </view>
  55.             </view>
  56.           </view>
  57.         </block>
  58.       </view>
  59.     </view>
  60.     <view wx:else class="none">暂无数据</view>
  61.   </view>
  62. </view>
复制代码
wxss代码

主要采用flex布局进行布局
  1. page {
  2.   background-color: #f5f5f5;
  3.   font-size:95%;
  4. }
  5. .flex {
  6.   display: flex;
  7. }
  8. .center {
  9.   justify-content: center;
  10.   align-items: center;
  11. }
  12. .left{
  13.   position: absolute;
  14.   left:0;
  15. }
  16. .flex-end{
  17.   justify-content: flex-end;
  18. }
  19. .between {
  20.   justify-content: space-between;
  21. }
  22. .none {
  23.   text-align: center;
  24.   margin-top: 50rpx;
  25.   color: #969292;
  26. }
  27. /* 顶行搜索栏+购物车 */
  28. /* 搜索框 */
  29. .topinfo_view {
  30.   padding: 4% 0 4% 0;
  31. }
  32. .topinfo_model1 {
  33.   height: 60rpx;
  34.   width: 85%;
  35. }
  36. .topinfo_model1_search {
  37.   display: flex;
  38.   align-items: center;
  39.   height: 100%;
  40.   width: 90%;
  41.   border-radius: 10px;
  42.   padding: 0 20rpx;
  43.   background-color: #fff;
  44. }
  45. .topinfo_model1 image {
  46.   height: 40rpx;
  47.   width: 45rpx;
  48.   margin-right: 10px;
  49. }
  50. .topinfo_view input {
  51.   width: 100%;
  52. }
  53. /* 购物车 */
  54. .topinfo_model2 {
  55.   width: 12%;
  56.   height: 60rpx;
  57. }
  58. .topinfo_model2_circle {
  59.   width: 60rpx;
  60.   height: 60rpx;
  61.   background-color: #fff;
  62.   border-radius: 50%;
  63.   position:relative;
  64. }
  65. .topinfo_model2_circle image {
  66.   width: 40rpx;
  67.   height: 40rpx;
  68. }
  69. /* 顶部菜单栏 */
  70. .menu {
  71.   width: 100%;
  72. }
  73. .topmenu-item {
  74.   width: 100%;
  75.   padding-bottom: 5px;
  76.   border-bottom: 3px solid #f5f5f5;
  77. }
  78. .topactive {
  79.   border-bottom: 3px solid #4cc46b;
  80. }
  81. /* 主体内容 */
  82. .top-content {
  83.   height:83vh;
  84.   padding:10px 0;
  85. }
  86. /* 左侧菜单栏 */
  87. .left-menu {
  88.   width: 25%;
  89.   height:100%;
  90. }
  91. .leftactivegreen{
  92.   width:5px;
  93.   height:80%;
  94.   background-color: #4cc46b;
  95. }
  96. .leftactive {
  97.   background-color:#fff;
  98.   color:#4cc46b;
  99. }
  100. .left-menu-item{
  101.   height:50px;
  102.   position:relative
  103. }
  104. .right-content {
  105.   height:100%;
  106.   width: 75%;
  107.   font-size: 90%;
  108.   background-color: #fff;
  109.   overflow-y: auto;
  110. }
  111. .right-content-view{
  112.   border-bottom:3px solid #f6f6f6;
  113.   width:100%;
  114.   padding:2% 0;
  115. }
  116. .content-img {
  117.   width: 30%;
  118.   margin-right: 2px;
  119.   /* border:1px solid black; */
  120. }
  121. .content-img image {
  122.   width: 95%;
  123.   height: 95%;
  124. }
  125. .content-info{
  126.   width:65%;
  127. }
  128. .cinfo-line{
  129.   width:100%;
  130.   padding:2% 0;
  131. }
  132. .green-btn{
  133.   background-color:#4cc46b ;
  134.   width:50rpx;
  135.   height:50rpx;
  136.   border-radius: 5px;
  137.   margin-top:-4%;
  138.   position:relative;
  139. }
  140. .green-btn image{
  141.   width:35rpx;
  142.   height:35rpx;
  143. }
  144. .red_single{
  145.   border:1px solid #fff;
  146.   color:#fff;
  147.   position:absolute;
  148.   width:25rpx;
  149.   height:25rpx;
  150.   top:-15rpx;
  151.   right:-15rpx;
  152.   border-radius: 50%;
  153.   background-color: red;
  154.   font-size: 10px;
  155. }
  156. .red_single1{
  157.   border:1px solid #fff;
  158.   color:#fff;
  159.   position:absolute;
  160.   width:25rpx;
  161.   height:25rpx;
  162.   top:-12rpx;
  163.   right:-12rpx;
  164.   border-radius: 50%;
  165.   background-color: red;
  166.   font-size: 10px;
  167. }
复制代码
js代码

这里主要展示核心数据部门,具体可参考资源
  1. Menus: [{
  2.     topname: '顶部菜单1',
  3.     leftMenus: [{
  4.         name: '侧边菜单1',
  5.         items: [{
  6.             id: 1,
  7.             info1: '11',
  8.             info2: '22',
  9.             info3: '33',
  10.             info4: '44',
  11.             info5: '55',
  12.             img: '../img/process_2.png'
  13.           },
  14.           {
  15.             id: 2,
  16.             info1: '22',
  17.             info2: '22',
  18.             info3: '22',
  19.             info4: '22',
  20.             info5: '22',
  21.             img: '../img/process_1.png'
  22.           },
  23.         ],
  24.       },
  25.       {
  26.         name: '侧边菜单2',
  27.         items: [{
  28.           id: 3,
  29.           info1: '33',
  30.           info2: '33',
  31.           info3: '33',
  32.           info4: '33',
  33.           info5: '33',
  34.           img: '../img/process_3.png'
  35.         }],
  36.       },
  37.     ]
  38.   },
  39.   {
  40.     topname: '顶部菜单2',
  41.     leftMenus: []
  42.   },
  43.   {
  44.     topname: '顶部菜单3',
  45.     leftMenus: [{
  46.       name: '侧边菜单3',
  47.       items: [{
  48.         id: 4,
  49.         info1: '44',
  50.         info2: '44',
  51.         info3: '44',
  52.         info4: '44',
  53.         info5: '44',
  54.         img: '../img/process_2.png'
  55.       }],
  56.     }],
  57.   },
  58.   {
  59.     topname: '顶部菜单4',
  60.     leftMenus: [{
  61.       name: '侧边菜单4',
  62.       items: [{
  63.         id: 5,
  64.         info1: '55',
  65.         info2: '55',
  66.         info3: '55',
  67.         info4: '55',
  68.         info5: '55',
  69.         img: '../img/process_1.png'
  70.       }],
  71.     }],
  72.   },
  73. ],
复制代码
2、购物车界面

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

实现页面
  1. <view class="main">
  2.   <view class="itemallinfo">
  3.     <view class="item_info flex center" wx:for="{{allinfo}}" wx:key="index" data-id="{{item.id}}">
  4.       <view class="item flex center">
  5.         <view class="sel_checkbox flex center">
  6.           <checkbox value="{{item.id}}" checked="{{item.checked}}" bindtap="handleSelectItem" data-id="{{item.id}}" />
  7.         </view>
  8.         <view class="info_image flex center">
  9.           <image src="{{item.img}}" mode="aspectFill" />
  10.         </view>
  11.         <view class="info_content">
  12.           <view class="info_line1">配件名称:{{item.name}}</view>
  13.           <view class="info_line1">库存数量:{{item.stockQty}}{{item.uom}}</view>
  14.           <view class="info_line1 flex flex-end numbtn">
  15.             <view class="btn_minus flex center" bindtap="handleMinus" data-id="{{item.id}}">-</view>
  16.             <input class="input_count" type="number" value="{{item.count}}" bindinput="handleInputChange" data-id="{{item.id}}" />
  17.             <view class="btn_plus flex center" bindtap="handlePlus" data-id="{{item.id}}">+</view>
  18.           </view>
  19.         </view>
  20.       </view>
  21.     </view>
  22.   </view>
  23.   <view class="footer flex between">
  24.     <view class="select_all flex center">
  25.       <checkbox bindtap="handleSelectAll" checked="{{isAllSelected}}" /> 全选
  26.     </view>
  27.     <view class="bottom2 flex center">
  28.       <view class="delete_btn surebtn flex center" bindtap="handleDelete">删除</view>
  29.     </view>
  30.     <view class="bottom3 flex center">
  31.       <view class="submit_btn surebtn flex center" bindtap="handleSubmit">提交</view>
  32.     </view>
  33.   </view>
  34. </view>
复制代码
wxss代码

  1. page {
  2.   background-color: #f6f6f6;
  3.   font-size: 90%;
  4. }
  5. .flex {
  6.   display: flex;
  7. }
  8. checkbox {
  9.   transform: scale(0.8);
  10. }
  11. .center {
  12.   justify-content: center;
  13.   align-items: center;
  14. }
  15. .flex-end {
  16.   justify-content: flex-end;
  17.   align-items: center;
  18. }
  19. .between{
  20.   justify-content: space-between;
  21. }
  22. /* 列表内容 */
  23. .item_info {
  24.   width: 100%;
  25.   padding: 5px 0;
  26. }
  27. .itemallinfo{
  28.   padding:15px 0 100px 0;
  29. }
  30. .item {
  31.   width: 95%;
  32.   background-color: #fff;
  33.   padding: 2% 0;
  34.   border-radius: 5px;
  35.   box-shadow: 3px 3px 3px rgb(0, 0, 0, 0.1);
  36. }
  37. .sel_radio {
  38.   width: 12%;
  39. }
  40. radio {
  41.   transform: scale(0.8);
  42. }
  43. .info_image {
  44.   width: 20%;
  45. }
  46. .info_image image {
  47.   width: 60px;
  48.   height: 60px;
  49. }
  50. .info_content {
  51.   width: 68%;
  52. }
  53. .info_line1 {
  54.   margin: 2% 0;
  55. }
  56. .numbtn {
  57.   height: 25px;
  58.   align-items: stretch;
  59.   padding-right:2%;
  60. }
  61. .btn_minus,
  62. .btn_plus {
  63.   border: 1px solid #c0c0c0;
  64.   width: 30px;
  65.   /* 设置按钮宽度 */
  66.   height: 100%;
  67.   cursor: pointer;
  68.   /* 可选:设置鼠标指针样式 */
  69. }
  70. .input_count {
  71.   border: 1px solid #c0c0c0;
  72.   width: 50px;
  73.   /* 设置输入框宽度 */
  74.   text-align: center;
  75.   margin: 0 -1px;
  76.   height: 100%;
  77.   border-right:0;
  78.   border-left:0;
  79. }
  80. .footer {
  81.   align-items: center;
  82.   background-color: #fff;
  83.   border-top: 1px solid #eee;
  84.   position:fixed;
  85.   width:100%;
  86.   bottom:0;
  87.   height:70px;
  88. }
  89. .select_all{
  90.   height:100%;
  91.   width:30%;
  92. }
  93. .bottom3,.bottom2{
  94.   height:100%;
  95.   width:35%;
  96. }
  97. .delete_btn {
  98.   background-color: #bebebe;
  99.   color: #fff;
  100. }
  101. .submit_btn {
  102.   background-color: #f3454e;
  103.   color: #fff;
  104. }
  105. .surebtn{
  106.   border-radius: 5px;
  107.   width:80%;
  108.   height:30px;
  109. }
复制代码
js代码

这里主要展示核心数据部门,具体可参考资源
  1. var allinfo = [{
  2.     id: 1,
  3.     info1: '11',
  4.     info2: '22',
  5.     info3: '33',
  6.     info4: '44',
  7.     info5: '55',
  8.     img: '../img/process_2.png',
  9.     count: 1,
  10.     checked: false, // 默认未选中
  11.   },
  12.   {
  13.     id: 3,
  14.     info1: '33',
  15.     info2: '33',
  16.     info3: '33',
  17.     info4: '33',
  18.     info5: '33',
  19.     img: '../img/process_3.png',
  20.     count: 2,
  21.     checked: false, // 默认未选中
  22.   },
  23.   {
  24.     id: 5,
  25.     info1: '55',
  26.     info2: '55',
  27.     info3: '55',
  28.     info4: '55',
  29.     info5: '55',
  30.     img: '../img/process_1.png',
  31.     count: 1,
  32.     checked: false, // 默认未选中
  33.   },
  34. ];
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

圆咕噜咕噜

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表