pplok #29

Manually merged
theluyuan merged 5 commits from pplok into master 2019-12-20 14:17:19 +08:00
2 changed files with 73 additions and 46 deletions
Showing only changes of commit 487fee5b04 - Show all commits

View File

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

View File

@ -18,7 +18,7 @@
<text class="pri">${{price}}</text> <text class="pri">${{price}}</text>
</view> </view>
<view class="right"> <view class="right">
<text class="del">删除</text> <text class="del" bind:tap="del">删除</text>
<text class="sub" bindtap="sub">结算</text> <text class="sub" bindtap="sub">结算</text>
</view> </view>
</view> </view>