// pages/shopping/shopping.js import { request } from "../../utils/bin" Page({ /** * 页面的初始数据 */ data: { list: [], select: [], userid: 0, price: "0.00" }, sel(a) { console.log(a) this.setData({ [`select[${a.detail.index}]`]: !a.detail.select }) this.num(); }, /** * 生命周期函数--监听页面加载 */ getlist() { request({ url: "Cart/cartList/session_id/" + wx.getStorageSync('openid'), data: { user_id: this.data.userid } }).then((res) => { console.log(res) this.setData({ list: res.data.result }) this.num() }) }, onLoad: function (options) { request({ url: "User/validateOpenid" }).then((res) => { console.log(res) this.setData({ userid: res.data.data.user_id }) this.getlist() }) }, sub() { wx.navigateTo({ url: "/pages/orderconfirm/orderconfirm" }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.onLoad() }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, num() { let num = 0; let sel = 0; for (let i in this.data.select) { console.log(i) if (this.data.select[i]) { num += parseFloat(this.data.list[i].goods_price) * 100 sel++ } } if (sel == this.data.list.length && this.data.list.length != 0) { this.setData({ all: true }) } else { this.setData({ all: false }) } this.setData({ price: num / 100 }) }, call() { let sel = 0; let select = [] for (let i in this.data.list) { console.log(i) if (this.data.select[i]) { // num += parseFloat(this.data.list[i].goods_price)*100 sel++ } else { select[i] = true } } if (sel == this.data.list.length) { this.setData({ all: false, select: [] }) } else { this.setData({ all: true, select }) } this.num() }, del() { for (let i in this.data.list) { // console.log(i) if (this.data.select[i]) { // num += parseFloat(this.data.list[i].goods_price)*100 // sel++ request({ url: "Cart/delCart", urldata: { id: this.data.list[i].id } }).then((res) => { console.log('删除成功') this.setData({ list: [], select: [], userid: 0, price: "0.00" }) this.onLoad() }) } } } })