小程序购物车js中data数据初始与列表数据存储

页面初始时data数据  

data: {

    statusbar:0,// 小程序状态栏的高度

    height:0,

    startX:"",// 当前触摸的位置坐标

    moveX:"",// 滑动后的位置坐标

    iconSize: [20, 30, 40, 50, 60, 70],

    iconColor: ['red', 'orange', 'yellow', 'green', 'rgb(0,255,255)', 'blue', 'purple'],

    iconType: ['success', 'success_no_circle', 'info', 'warn', 'waiting', 'cancel', 'download', 'search', 'clear'],

    isSelectAll:false,// 全选按钮的状态

    isSelectStore:false,// 店铺按钮的状态

    isSelect:false,// 单个按钮选中状态

    num:0,// 选中的商品数量

    storeNum:0,// 选中的店铺数量

    list:[],//获取选中的数组

    totalPrice:"0.00",//总价

    pageName:1,

    post:[],

    total:"",

    empty:true,// 购物车是否显示为空

    compile:true,// 初始时显示的是编辑还是完成

    uId:"",

    token:""

  },

getDetail:function(){

    var that = this;

    var isSelectAll = that.data.isSelectAll;

    wx.request({

      url: "",

      method:"GET",

      data:{},

      success:function(res){

        if(res.data.code == 900){

          var list = res.data.data.storeVos;

          // 进入页面时判断全选按钮是否选中如果是则选中所有数据

          if(isSelectAll){

            for(var i = 0;i<storeVos.length;i++){

              list[i].isSelectStore = isSelectAll;

              for(var t= 0;t<list[i].abuyCarVos.length;t++){

                list[i].abuyCarVos[t].isSelect = isSelectAll;

              }

            };

            that.setData({

              list:list,

              empty:true

            })

            that.gototalPrice();

          }else{

            that.setData({

              list:res.data.data.storeVos,

              empty:true

            })

          }

        }else{

          that.setData({

            empty:false

          })

        }

      },

      complete:function(){// 调用结束的回调函数(失败、成功都会执行)

        

      },

      fail:function(){// 调用失败的回调函数

        that.setData({

          empty:false

        })

        

      }

    })

  },

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值