// pages/cart/cart.js
Page({
data: {
cartlist: [
{
id: 1,
good: {
title: "雷柏v500 RGB机械游戏键盘 机械键盘 黑轴 青轴 游戏键盘 有线背光",
pic: "",
tc: 1,
tcs: [
"官方标配",
"套餐一",
"套餐二",
"套餐三"
],
tcprices: [
169,
200,
300,
400
],
price: 169,
prevprice: 599,
store: 4,
"type": {
id: 1,
name: "键盘外设"
}
},
num: 1,
mode: 0,
checked: false,
},
{
id: 2,
good: {
title: "雷柏v500 RGB机械游戏键盘 机械键盘 黑轴 青轴 游戏键盘 有线背光",
pic: "",
tc: 1,
tcs: [
"官方标配",
"套餐一",
"套餐二",
"套餐三"
],
tcprices: [
169,
200,
300,
400
],
price: 169,
prevprice: 599,
store: 14,
"type": {
id: 1,
name: "键盘外设"
}
},
num: 1,
mode: 0,
checked: false,
},
{
id: 3,
good: {
title: "雷柏v500 RGB机械游戏键盘 机械键盘 黑轴 青轴 游戏键盘 有线背光",
pic: "",
tc: 1,
tcs: [
"官方标配",
"套餐一",
"套餐二",
"套餐三"
],
tcprices: [
169,
200,
300,
400
],
price: 169,
prevprice: 599,
store: 14,
"type": {
id: 1,
name: "键盘外设"
}
},
num: 1,
mode: 0,
checked: false,
},
{
id: 4,
good: {
title: "雷柏v500 RGB机械游戏键盘 机械键盘 黑轴 青轴 游戏键盘 有线背光",
pic: "",
tc: 1,
tcs: [
"官方标配",
"套餐一",
"套餐二",
"套餐三"
],
tcprices: [
169,
200,
300,
400
],
price: 169,
prevprice: 599,
store: 14,
"type": {
id: 1,
name: "键盘外设"
}
},
num: 1,
mode: 0,
checked: false,
},
{
id: 5,
good: {
title: "雷柏v500 RGB机械游戏键盘 机械键盘 黑轴 青轴 游戏键盘 有线背光",
pic: "",
tc: 1,
tcs: [
"官方标配",
"套餐一",
"套餐二",
"套餐三"
],
tcprices: [
169,
200,
300,
400
],
price: 169,
prevprice: 599,
store: 14,
"type": {
id: 1,
name: "键盘外设"
}
},
num: 1,
mode: 0,
checked: false,
}
],
totalPrice: 0,
totalCount: 0,
isAll: false
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
},
onReady: function () {
// 页面渲染完成
},
onShow: function () {
// 页面显示
this.updateData();
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
onPullDownRefresh: function (e) {
this.updateData();
setTimeout(function () {
console.log("stopPull")
wx.stopPullDownRefresh();
}, 2000)
},
updateData: function () {
wx.showToast({
title: "Loading...",
icon: "loading",
duration: 300000
})
var that = this;
wx.request({
url: 'http://localhost:8080/Wxmini/cart_getlist.do',
// data: {},
method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
// header: {}, // 设置请求的 header
success: function (res) {
console.log(res.data)
that.setData({
cartlist: res.data
})
that.checkIsAll()
},
fail: function () {
setTimeout(function () {
wx.showToast({
title: "加载失败"
})
}, 100)
},
complete: function () {
wx.hideToast()
}
})
},
changeMode: function (e) {
var id = e.target.dataset.id;
var cartlist = this.data.cartlist;
console.log(id)
for (var i = 0; i < cartlist.length; i++) {
if (cartlist[i].id == id) {
cartlist[i].mode = cartlist[i].mode == 0 ? 1 : 0;
break;
}
}
console.log("over", cartlist);
this.setData({
cartlist: cartlist
})
}
,
checkItem: function (e) {
var id = e.target.dataset.id;
var checked = e.detail.value;
console.log(id)
var cartlist = this.data.cartlist;
for (var i = 0; i < cartlist.length; i++) {
if (cartlist[i].id == id) {
cartlist[i].checked = checked;
console.log(cartlist[i])
break;
}
}
this.setData({
cartlist: cartlist
})
this.calcateTotal()
this.checkIsAll()
},
checkAll: function (e) {
var checked = e.detail.value;
var cartlist = this.data.cartlist;
for (var i = 0; i < cartlist.length; i++) {
cartlist[i].checked = checked;
}
this.setData({
cartlist: cartlist
})
this.calcateTotal()
},
calcateTotal: function () {
var cartlist = this.data.cartlist;
var totalPrice = 0;
for (var i = 0; i < cartlist.length; i++) {
if (cartlist[i].checked) {
totalPrice += cartlist[i].good.tcprices[cartlist[i].good.tc] * cartlist[i].num;
}
}
console.log(totalPrice)
this.setData({
totalPrice: totalPrice
})
},
checkIsAll: function () {
var cartlist = this.data.cartlist;
var isAll = cartlist.length!=0?true:false;
for (var i = 0; i < cartlist.length; i++) {
if (cartlist[i].checked == false) {
isAll = false;
break;
}
}
this.setData({
isAll: isAll
})
},
updateNum: function (id, num) {
wx.showToast({
title: "Loading...",
icon: "loading",
duration: 300000
})
var that = this;
wx.request({
url: 'http://localhost:8080/Wxmini/cart_changeNum.do?id=' + id + '&num=' + num,
// data: {},
method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
// header: {}, // 设置请求的 header
success: function (res) {
console.log(res.data)
if (res.data.flag) {
setTimeout(function () {
wx.showToast({
title: "成功",
duration: 1500
})
}, 100)
}
},
fail: function () {
setTimeout(function () {
wx.showToast({
title: "操作失败"
})
}, 100)
},
complete: function () {
wx.hideToast()
}
})
this.calcateTotal()
},
updateTc: function (id, tc) {
wx.showToast({
title: "Loading...",
icon: "loading",
duration: 300000
})
var that = this;
wx.request({
url: 'http://localhost:8080/Wxmini/cart_changeTc.do?id=' + id + '&tc=' + tc,
// data: {},
method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
// header: {}, // 设置请求的 header
success: function (res) {
console.log(res.data)
if (res.data.flag) {
setTimeout(function () {
wx.showToast({
title: "成功",
duration: 1500
})
}, 100)
}
},
fail: function () {
setTimeout(function ()
数码商城【商城带后台源码】.rar
需积分: 5 11 浏览量
2023-06-18
19:13:36
上传
评论
收藏 1.34MB RAR 举报
毕业季zwlzyhzylzyl
- 粉丝: 316
- 资源: 5650
最新资源
- 基于python+flask+mysql实现的豆瓣电影可视化系统+源代码+文档说明+数据库sql.zip
- 程氏舞曲V4.2程氏舞曲V4.2程氏舞曲V4.2程氏舞曲V4.2
- FPGA读写 AD9708+ AD9280 ADDA实验Verilog逻辑源码Quartus工程文件+文档说明+硬件参考原理图
- 基于CH340C设计USB转TLL串口通信模块PADS 9.5设计硬件(原理图+PCB)文件.zip
- 信号与系统大作业-图像处理 实现了直接滤波法维纳滤波法最小二乘滤波法LR递归法matlab源码.zip
- php-leetcode题解之最小栈.zip
- php-leetcode题解之最长不含重复字符的子字符串.zip
- php-leetcode题解之最长公共前缀.zip
- php-leetcode题解之最小差值.zip
- php-leetcode题解之最小基因变化.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈