2019-12-23 10:04:09 +08:00
|
|
|
// pages/shopping/shopping.js
|
|
|
|
import { request } from "../../utils/bin"
|
|
|
|
Page({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面的初始数据
|
|
|
|
*/
|
|
|
|
data: {
|
|
|
|
list: [],
|
|
|
|
select: [],
|
|
|
|
userid: 0,
|
|
|
|
price: "0.00"
|
|
|
|
},
|
|
|
|
sel(a) {
|
|
|
|
console.log(a)
|
|
|
|
request({
|
|
|
|
url: "Cart/updateSelect",
|
|
|
|
urldata: {
|
|
|
|
id: this.data.list[a.detail.index].goods_id,
|
|
|
|
select: this.data[`select[${a.detail.index}]`] ? 1 : 0
|
|
|
|
}
|
|
|
|
}).then((res) => {
|
|
|
|
this.setData({
|
|
|
|
[`select[${a.detail.index}]`]: !a.detail.select
|
|
|
|
})
|
|
|
|
this.num();
|
|
|
|
})
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
*/
|
|
|
|
getlist() {
|
|
|
|
request({
|
|
|
|
url: "Cart/cartList/session_id/" + wx.getStorageSync('openid'),
|
|
|
|
urldata: {
|
|
|
|
user_id: this.data.userid
|
|
|
|
}
|
|
|
|
}).then((res) => {
|
|
|
|
console.log(res)
|
|
|
|
this.setData({
|
|
|
|
list: res.data.result
|
|
|
|
})
|
|
|
|
// this.num()
|
|
|
|
this.calls();
|
|
|
|
|
|
|
|
})
|
|
|
|
},
|
|
|
|
onLoad: function (options) {
|
|
|
|
request({
|
|
|
|
url: "User/validateOpenid"
|
|
|
|
}).then((res) => {
|
|
|
|
console.log(res)
|
|
|
|
this.setData({
|
|
|
|
userid: res.data.data.user_id
|
|
|
|
})
|
|
|
|
this.getlist()
|
|
|
|
|
|
|
|
})
|
|
|
|
},
|
|
|
|
sub() {
|
|
|
|
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 > 0) {
|
|
|
|
wx.navigateTo({
|
|
|
|
url: "/pages/orderconfirm/orderconfirm"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
*/
|
|
|
|
onReady: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
*/
|
|
|
|
onShow: function () {
|
|
|
|
this.onLoad()
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
*/
|
|
|
|
onHide: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
*/
|
|
|
|
onUnload: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
*/
|
|
|
|
onPullDownRefresh: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
*/
|
|
|
|
onReachBottom: function () {
|
|
|
|
|
|
|
|
},
|
2019-12-24 16:32:27 +08:00
|
|
|
gai(a){
|
|
|
|
console.log(a)
|
|
|
|
for(let i in this.data.list){
|
|
|
|
if(this.data.list[i].id == a.detail.id){
|
|
|
|
let text = `list[${i}].goods_num`
|
|
|
|
this.setData({
|
|
|
|
[text]:a.detail.num
|
|
|
|
})
|
|
|
|
console.log(123)
|
2019-12-23 10:04:09 +08:00
|
|
|
|
2019-12-24 16:32:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
this.num()
|
|
|
|
},
|
2019-12-23 10:04:09 +08:00
|
|
|
/**
|
|
|
|
* 用户点击右上角分享
|
|
|
|
*/
|
|
|
|
onShareAppMessage: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
num() {
|
|
|
|
let num = 0;
|
|
|
|
let sel = 0;
|
|
|
|
for (let i in this.data.select) {
|
|
|
|
console.log(i)
|
|
|
|
if (this.data.select[i]) {
|
2019-12-24 16:32:27 +08:00
|
|
|
num += parseFloat(this.data.list[i].goods_price) * 100 * this.data.list[i].goods_num
|
2019-12-23 10:04:09 +08:00
|
|
|
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) {
|
|
|
|
request({
|
|
|
|
url: "Cart/updateAllSelect",
|
|
|
|
urldata: {
|
|
|
|
open_id: wx.getStorageSync("openid"),
|
|
|
|
selected: 0
|
|
|
|
}
|
|
|
|
}).then((res) => {
|
|
|
|
this.setData({
|
|
|
|
all: false,
|
|
|
|
select: []
|
|
|
|
})
|
|
|
|
this.num()
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
} else {
|
|
|
|
request({
|
|
|
|
url: "Cart/updateAllSelect",
|
|
|
|
urldata: {
|
|
|
|
open_id: wx.getStorageSync("openid"),
|
|
|
|
selected: 1
|
|
|
|
}
|
|
|
|
}).then((res) => {
|
|
|
|
this.setData({
|
|
|
|
all: true,
|
|
|
|
select
|
|
|
|
})
|
|
|
|
this.num()
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
calls() {
|
|
|
|
let sel = 0;
|
|
|
|
let select = []
|
|
|
|
for (let i in this.data.list) {
|
|
|
|
console.log(i)
|
|
|
|
|
|
|
|
select[i] = true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-13 11:59:11 +08:00
|
|
|
})
|