热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

微信小程序类似购物车列表效果,计算总共价格数量,加减商品计算,滑动删除

先看下效果图:一个小demo,记录下。html:<!--pagesmycollectmycollect.wxml--><!--最外层大盒子--&g

先看下效果图:


一个小demo,记录下。

html:



  
  
    

      

      
        
        
          
          
            
              
              
                
              
              
              
                {{item.title}}
                
                  {{item.sort}}
                  {{item.color}}
                  

                  
                    ¥ {{item.price}}
                    
                    
                      
                        
                      
                      
                      
                      
                        
                      
                    
                    
                    
                      
                        
                      
                    
                  


                
              

            
          

          
          删除
        
      

    
  
  
    
      
        共计{{add_car_num}}件商品
        ¥ {{price}}
      
    
    
      马上购买
    
  

css:

/* pages/mycollect/mycollect.wxss */

page {
  background: #f5f5f5;
  height: 100%;
}

.collect_list_box {
  padding-top: 20rpx;
}

.collect_bottom {
  width: 100%;
  height: 80rpx;
  background: #fff;
  line-height: 80rpx;
}

.recordList_box {
  box-sizing: border-box;
  /* background: #ffffff; */
}

.content_box {
  /* border-top: 1rpx solid #dcdcdc; */
    border-bottom: 1rpx solid #ececec;
  position: relative;
}

.ProductIco_box {
  width: 130rpx;
  height: 130rpx;
  border-radius: 5px;
  border: 1rpx solid #ececec;
  margin-right: 18rpx;
  float: left;
}

.ProductIco {
  width: 100%;
  height: 100%;
  border-radius: 5px;
}

.view_ce {
  width: 100%;
  height: 130rpx;
  position: relative;
  padding-top: 20rpx;
  padding-bottom: 30rpx;
  /* background: red;  */
  border-bottom: 1rpx solid #ececec;
}

.content_box_center {
  width: 100%;
  padding: 0rpx 20rpx 30rpx 20rpx;
  padding-top: 20rpx;
  /* margin-bottom: 30rpx; */
  height: 182rpx;
  z-index: 2;
  background: #fff;
  position: absolute;
  left: 0;
  top: 0;
  box-sizing: border-box;
  border-bottom: 1rpx solid #ececec;
}

.view_content {
  float: left;
  width: 556rpx;
}

.view_title {
  display: inline-block;
  float: left;
  width: 556rpx;
  font-size: 28rpx;
  color: #393939;
}

.view_fl>text {
  font-size: 22rpx;
  color: #898989;
  margin-right: 18rpx;
}

.view_btn_box>text {
  font-size: 28rpx;
  color: #f55212;
}

.view_btn {
  width: 150rpx;
  height: 44rpx;
  border: 1px solid #cecece;
  border-radius: 5px;
  float: right;
  font-size: 22rpx;
  color: #898989;
  line-height: 44rpx;
  /* display: none; *//* margin-bottom: 5rpx; */
}

.view_text_center, .view_img_left, .view_img_right {
  float: left;
}

.view_img_left, .view_img_right {
  width: 44rpx;
  height: 44rpx;
}

.view_img_left {
  border-right: 1rpx solid #cecece;
}

.view_img_right {
  border-left: 1rpx solid #cecece;
}

.view_text_center {
  width: 58rpx;
  height: 44rpx;
  text-align: center;
  line-height: 44rpx;
  box-sizing: border-box;
  font-size: 22rpx;
  color: #898989;
}

.view_btn image {
  width: 100%;
  height: 100%;
}

.view_add {
  width: 44rpx;
  height: 44rpx;
  border: 1px solid #cecece;
  border-radius: 5px;
  float: right;
  font-size: 22rpx;
  color: #898989;
  line-height: 44rpx;
  /* margin-bottom: 5rpx; */
}

.view_img_add {
  width: 44rpx;
  height: 44rpx;
}

.view_add image {
  width: 100%;
  height: 100%;
}

.delete_btn {
  position: absolute;
  right: 0;
  top: 0;
  font-size: 32rpx;
  background: #ff3b30;
  width: 134rpx;
  height: 100%;
  text-align: center;
  line-height: 175rpx;
  /* border-bottom: 1px solid #ff3b30; */
  color: #fff;
  z-index: 1;
}
.collect_one {
  font-size: 28rpx;
  color: #393939;
}
.collect_two {
  margin-left: 20rpx;
  font-szie:32rpx;
  color:  #393939;
  margin-right: 20rpx;
}
 .collect_right {
 margin: 0 auto;
} 
.buy_btn_box {
  width: 100%;
  height: auto;
  text-align: center;
  background: #fff;
}
.buy_btn {
  width: 710rpx;
  height: 88rpx;
  background: #1da1f2;
  margin: 0 auto;
  font-size: 30rpx;
  line-height: 88rpx;
  color: #fff;
  text-align: center;
   display: flex;
   border-radius:5px; 
}
.buy_btn:active {
  background: red;
}
.buy_btn>text {
   margin: 0 auto;
}
.collect_big_box {
  width: 100%;
  height: 100%;
   /* position: relative;  */
}
  .buy_btn_box {
  position: fixed;
  left: 0;
   bottom: 0; 
   padding-bottom: 24rpx; 
  z-index: 999;
 }   

js:

// pages/mycollect/mycollect.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    arr: '',//存储请求回来的数组
    ini: 0,
    uhide: '',
    add_car_num: 0,//控制是否初次进入界面
    delBtnWidth: 134,//删除按钮宽度单位(rpx)
    price:'0.00'//价钱
  },
  // 滚动到底部
  lower:function(){
    console.log("我到了底部")
  },
  //删除
  delete_btn:function(e){
    var that = this;
    var index = e.currentTarget.dataset.index;
    wx.showModal({
      // title: '提示',
      content: '删除后不能恢复,是否删除?',
      confirmColor:'#1da1f2',
      success: function (res) {
        if (res.confirm) {
          console.log(index)
          var list = that.data.arr;
          //移除列表中下标为index的项  
          list.splice(index, 1);
          //更新列表的状态  
          that.setData({
            arr: list
          });
          let carts = that.data.arr;
          // var _this = this;
          var sum = 0;
          for (var i = 0; i  0) {
            for (var i = 0; i  0) {
      for (var i = 0; i  0) {
      for (var i = 0; i  0) {
      for (var i = 0; i  0) {
      for (var i = 0; i  0) {//移动距离大于0,文本层left值等于手指移动距离
        txtStyle = "left:-" + disX + "rpx";
        if (disX >= delBtnWidth) {
          //控制手指移动距离最大值为删除按钮的宽度
          txtStyle = "left:-" + delBtnWidth + "rpx";
        }
      }
      //获取手指触摸的是哪一个item
      var index = e.currentTarget.dataset.index;
      var list = that.data.arr;
      //将拼接好的样式设置到当前item中
      list[index].txtStyle = txtStyle;
      //更新列表的状态
      this.setData({
        arr: list
      });
    }
  },
  touchE: function (e) {
    // console.log(e);
    var that = this
    if (e.changedTouches.length == 1) {
      //手指移动结束后触摸点位置的X坐标
      var endX = e.changedTouches[0].clientX;
      //触摸开始与结束,手指移动的距离
      var disX = that.data.startX - endX;
      var delBtnWidth = that.data.delBtnWidth;
      //如果距离小于删除按钮的1/2,不显示删除按钮
      var txtStyle = disX > delBtnWidth / 2 ? "left:-" + delBtnWidth + "rpx" : "left:0rpx";
      //获取手指触摸的是哪一项
      var index = e.currentTarget.dataset.index;
      var list = that.data.arr;
      list[index].txtStyle = txtStyle;
      //更新列表的状态
      that.setData({
        arr: list
      });
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '我的收藏'
    })
    var This = this;
    //请求接口
    wx.request({
      url: 'http://192.168.1.222:8081/StaticPage/searchlist.json', //仅为示例,并非真实的接口地址
      method: 'GET',
      data: {},
      success: function (res) {
        console.log(res.data.links)
        This.setData({
          arr: res.data.links
        })
      },
      fail: function (err) {
        console.log(err)
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})



推荐阅读
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • Spring常用注解(绝对经典),全靠这份Java知识点PDF大全
    本文介绍了Spring常用注解和注入bean的注解,包括@Bean、@Autowired、@Inject等,同时提供了一个Java知识点PDF大全的资源链接。其中详细介绍了ColorFactoryBean的使用,以及@Autowired和@Inject的区别和用法。此外,还提到了@Required属性的配置和使用。 ... [详细]
  • SpringMVC接收请求参数的方式总结
    本文总结了在SpringMVC开发中处理控制器参数的各种方式,包括处理使用@RequestParam注解的参数、MultipartFile类型参数和Simple类型参数的RequestParamMethodArgumentResolver,处理@RequestBody注解的参数的RequestResponseBodyMethodProcessor,以及PathVariableMapMethodArgumentResol等子类。 ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • 本文介绍了使用AJAX的POST请求实现数据修改功能的方法。通过ajax-post技术,可以实现在输入某个id后,通过ajax技术调用post.jsp修改具有该id记录的姓名的值。文章还提到了AJAX的概念和作用,以及使用async参数和open()方法的注意事项。同时强调了不推荐使用async=false的情况,并解释了JavaScript等待服务器响应的机制。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 本文介绍了P1651题目的描述和要求,以及计算能搭建的塔的最大高度的方法。通过动态规划和状压技术,将问题转化为求解差值的问题,并定义了相应的状态。最终得出了计算最大高度的解法。 ... [详细]
  • 使用正则表达式爬取36Kr网站首页新闻的操作步骤和代码示例
    本文介绍了使用正则表达式来爬取36Kr网站首页所有新闻的操作步骤和代码示例。通过访问网站、查找关键词、编写代码等步骤,可以获取到网站首页的新闻数据。代码示例使用Python编写,并使用正则表达式来提取所需的数据。详细的操作步骤和代码示例可以参考本文内容。 ... [详细]
  • 本文讨论了一个数列求和问题,该数列按照一定规律生成。通过观察数列的规律,我们可以得出求解该问题的算法。具体算法为计算前n项i*f[i]的和,其中f[i]表示数列中有i个数字。根据参考的思路,我们可以将算法的时间复杂度控制在O(n),即计算到5e5即可满足1e9的要求。 ... [详细]
  • 本文介绍了使用cacti监控mssql 2005运行资源情况的操作步骤,包括安装必要的工具和驱动,测试mssql的连接,配置监控脚本等。通过php连接mssql来获取SQL 2005性能计算器的值,实现对mssql的监控。详细的操作步骤和代码请参考附件。 ... [详细]
  • 本文讨论了如何在codeigniter中识别来自angularjs的请求,并提供了两种方法的代码示例。作者尝试了$this->input->is_ajax_request()和自定义函数is_ajax(),但都没有成功。最后,作者展示了一个ajax请求的示例代码。 ... [详细]
  • 网络请求模块选择——axios框架的基本使用和封装
    本文介绍了选择网络请求模块axios的原因,以及axios框架的基本使用和封装方法。包括发送并发请求的演示,全局配置的设置,创建axios实例的方法,拦截器的使用,以及如何封装和请求响应劫持等内容。 ... [详细]
  • iOS超签签名服务器搭建及其优劣势
    本文介绍了搭建iOS超签签名服务器的原因和优势,包括不掉签、用户可以直接安装不需要信任、体验好等。同时也提到了超签的劣势,即一个证书只能安装100个,成本较高。文章还详细介绍了超签的实现原理,包括用户请求服务器安装mobileconfig文件、服务器调用苹果接口添加udid等步骤。最后,还提到了生成mobileconfig文件和导出AppleWorldwideDeveloperRelationsCertificationAuthority证书的方法。 ... [详细]
  • 本文介绍了在Mac上安装Xamarin并使用Windows上的VS开发iOS app的方法,包括所需的安装环境和软件,以及使用Xamarin.iOS进行开发的步骤。通过这种方法,即使没有Mac或者安装苹果系统,程序员们也能轻松开发iOS app。 ... [详细]
author-avatar
happy王琦2010_190
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有