|
|
// pages/cart/cart.js
|
|
|
const app = getApp()
|
|
|
Page({
|
|
|
|
|
|
/**
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
array: ['2k', '4k', '8k'],
|
|
|
cartindex: 0,
|
|
|
cartlist: [],
|
|
|
totalmoney: 0,
|
|
|
video_id: [],
|
|
|
pic_id: [],
|
|
|
totalcartarr: [],
|
|
|
totalsel: false,
|
|
|
pp: [],
|
|
|
diannum: 0,
|
|
|
hebing: [],
|
|
|
delshow: false,
|
|
|
video_attr: [],
|
|
|
goucartid: []
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function(options) {
|
|
|
|
|
|
},
|
|
|
ti(){
|
|
|
|
|
|
},
|
|
|
|
|
|
// 图片详情
|
|
|
picdetail(e) {
|
|
|
console.log(e)
|
|
|
let id = e.currentTarget.dataset.id
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/picdetail/picdetail?id=' + id,
|
|
|
})
|
|
|
},
|
|
|
// 视频详情
|
|
|
|
|
|
videodetail(e) {
|
|
|
console.log(e)
|
|
|
let id = e.currentTarget.dataset.id;
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/videodetail/videodetail?id=' + id,
|
|
|
})
|
|
|
},
|
|
|
|
|
|
manage() {
|
|
|
this.setData({
|
|
|
delshow: !this.data.delshow
|
|
|
})
|
|
|
},
|
|
|
|
|
|
bindPickerChange: function(e) {
|
|
|
let newdiannum = this.data.diannum;
|
|
|
newdiannum++;
|
|
|
this.setData({
|
|
|
diannum: newdiannum
|
|
|
})
|
|
|
console.log(newdiannum)
|
|
|
console.log('picker发送选择改变,携带值为', e.detail.value)
|
|
|
console.log(e)
|
|
|
let index = e.currentTarget.dataset.index;
|
|
|
let newcartlist = this.data.cartlist;
|
|
|
|
|
|
let firmoney = newcartlist[index].videoprice
|
|
|
|
|
|
newcartlist[index].cartindex = e.detail.value;
|
|
|
if (newcartlist[index].video_id.vipprice == undefined) {
|
|
|
if (newcartlist[index].video_id.videotype[e.detail.value] == '2k') {
|
|
|
newcartlist[index].videoprice = newcartlist[index].video_id.price
|
|
|
} else if (newcartlist[index].video_id.videotype[e.detail.value] == '4k') {
|
|
|
newcartlist[index].videoprice = newcartlist[index].video_id.four_price
|
|
|
} else if (newcartlist[index].video_id.videotype[e.detail.value] == '8k') {
|
|
|
newcartlist[index].videoprice = newcartlist[index].video_id.eight_price
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
if (newcartlist[index].video_id.videotype[e.detail.value] == '2k') {
|
|
|
newcartlist[index].videoprice = newcartlist[index].video_id.vipprice
|
|
|
} else if (newcartlist[index].video_id.videotype[e.detail.value] == '4k') {
|
|
|
newcartlist[index].videoprice = newcartlist[index].video_id.four_vipprice
|
|
|
} else if (newcartlist[index].video_id.videotype[e.detail.value] == '8k') {
|
|
|
newcartlist[index].videoprice = newcartlist[index].video_id.eight_vipprice
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
let tt = 0;
|
|
|
let newtotalmoney = this.data.totalmoney;
|
|
|
|
|
|
|
|
|
let pp = this.data.pp;
|
|
|
pp.push(Number(newcartlist[index].videoprice));
|
|
|
console.log(pp)
|
|
|
let len = pp.length;
|
|
|
tt = Number(tt) + pp[len - 1]
|
|
|
|
|
|
if (newcartlist[index].sel == true) {
|
|
|
if (this.data.diannum == 1) {
|
|
|
console.log(newcartlist[index].videoprice)
|
|
|
newtotalmoney = newtotalmoney - firmoney;
|
|
|
newtotalmoney = newtotalmoney + tt
|
|
|
} else {
|
|
|
newtotalmoney = newtotalmoney - pp[newdiannum - 2];
|
|
|
console.log()
|
|
|
newtotalmoney = newtotalmoney + tt
|
|
|
|
|
|
}
|
|
|
} else {
|
|
|
newtotalmoney = newtotalmoney + tt
|
|
|
}
|
|
|
|
|
|
console.log(newtotalmoney)
|
|
|
if (newcartlist[index].sel == true) {
|
|
|
this.setData({
|
|
|
totalmoney: newtotalmoney
|
|
|
})
|
|
|
}
|
|
|
|
|
|
let newhebing=this.data.hebing;
|
|
|
|
|
|
for (var i = 0; i < newcartlist.length; i++) {
|
|
|
for (var j = 0; j < newhebing.length; j++) {
|
|
|
if (newhebing[j].id == newcartlist[i].id) {
|
|
|
newhebing[j] = newcartlist[i]
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// newcartlist[index].cartindex = e.detail.value;
|
|
|
|
|
|
this.setData({
|
|
|
cartlist: newcartlist,
|
|
|
hebing:newhebing
|
|
|
|
|
|
})
|
|
|
|
|
|
console.log(this.data.cartlist);
|
|
|
console.log(this.data.hebing)
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
//获取购物车列表
|
|
|
getcartlsit() {
|
|
|
let that = this;
|
|
|
let url = 'user/car';
|
|
|
|
|
|
app.post(url, '', 'post').then((res) => {
|
|
|
console.log(res)
|
|
|
for (var obj of res) {
|
|
|
obj.sel = false;
|
|
|
obj.cartindex = 0;
|
|
|
if (obj.video_id != null) {
|
|
|
if (obj.video_id.vipprice == undefined) {
|
|
|
if (obj.video_id.two_url != '') {
|
|
|
obj.videoprice = obj.video_id.price
|
|
|
} else if (obj.video_id.four_url != '') {
|
|
|
obj.videoprice = obj.video_id.four_price
|
|
|
} else if (obj.video_id.eight_url != '') {
|
|
|
obj.videoprice = obj.video_id.eight_price
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
if (obj.video_id.two_url != '') {
|
|
|
obj.videoprice = obj.video_id.vipprice
|
|
|
} else if (obj.video_id.four_url != '') {
|
|
|
obj.videoprice = obj.video_id.four_vipprice
|
|
|
} else if (obj.video_id.eight_url != '') {
|
|
|
obj.videoprice = obj.video_id.eight_vipprice
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if(obj.pic_id!=null){
|
|
|
console.log(obj)
|
|
|
console.log(obj.pic_id.vipprice)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
that.setData({
|
|
|
cartlist: res
|
|
|
})
|
|
|
|
|
|
|
|
|
let newcartlist = res;
|
|
|
|
|
|
|
|
|
for (var obj of newcartlist) {
|
|
|
if (obj.video_id != null) {
|
|
|
let arr = [];
|
|
|
if (obj.video_id.eight_url != '') {
|
|
|
arr.unshift(8 + 'k')
|
|
|
}
|
|
|
|
|
|
if (obj.video_id.four_url != '') {
|
|
|
arr.unshift(4 + 'k')
|
|
|
}
|
|
|
if (obj.video_id.two_url != '') {
|
|
|
arr.unshift(2 + 'k')
|
|
|
}
|
|
|
|
|
|
obj.video_id.videotype = arr
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
that.setData({
|
|
|
cartlist: newcartlist
|
|
|
})
|
|
|
|
|
|
console.log(that.data.cartlist)
|
|
|
|
|
|
}).catch((err) => {
|
|
|
|
|
|
})
|
|
|
},
|
|
|
|
|
|
// 选择购物车
|
|
|
selcart(e) {
|
|
|
let that = this;
|
|
|
let token = wx.getStorageSync("token");
|
|
|
if (token == '') {
|
|
|
wx.showToast({
|
|
|
title: '请先登录',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
|
|
|
setTimeout(function() {
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/index/index',
|
|
|
})
|
|
|
}, 1500)
|
|
|
} else {
|
|
|
console.log(e)
|
|
|
let cartid = e.currentTarget.dataset.cartid;
|
|
|
let sel = e.currentTarget.dataset.sel;
|
|
|
let type = e.currentTarget.dataset.type;
|
|
|
let newpic_id = that.data.pic_id;
|
|
|
let newvideo_id = that.data.video_id;
|
|
|
let newgoucartid = that.data.goucartid;
|
|
|
let newtotalcartarr = that.data.totalcartarr;
|
|
|
let newcartlist = this.data.cartlist;
|
|
|
let newtotalmoney = that.data.totalmoney;
|
|
|
let newhebing = that.data.hebing;
|
|
|
let newvideo_attr = that.data.video_attr;
|
|
|
|
|
|
for (var obj of newcartlist) {
|
|
|
if (obj.id == cartid) {
|
|
|
obj.sel = !obj.sel;
|
|
|
if (obj.sel == true && type == 1) {
|
|
|
newvideo_id.push(obj.video_id.id);
|
|
|
newtotalcartarr.push(cartid);
|
|
|
newtotalmoney = Number(newtotalmoney) + Number(obj.videoprice);
|
|
|
newhebing.push(obj)
|
|
|
console.log('111', newtotalcartarr)
|
|
|
|
|
|
} else if (obj.sel == false && type == 1) {
|
|
|
|
|
|
|
|
|
for(var i=0;i<newtotalcartarr.length;i++){
|
|
|
if (newtotalcartarr[i]==cartid){
|
|
|
newtotalcartarr.splice(i,1);
|
|
|
newtotalmoney = Number(newtotalmoney) - Number(obj.videoprice);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
console.log('333', newvideo_id, newtotalcartarr)
|
|
|
|
|
|
for (var j = 0; j < newtotalcartarr.length; j++) {
|
|
|
if (newtotalcartarr[j] == cartid) {
|
|
|
newtotalcartarr.splice(j, 1)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for (var k = 0; k < newhebing.length; k++) {
|
|
|
if (newhebing[k].id == cartid) {
|
|
|
newhebing.splice(k, 1)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} else if (obj.sel == true && type == 2) {
|
|
|
newpic_id.push(obj.pic_id.id);
|
|
|
newtotalcartarr.push(cartid);
|
|
|
newhebing.push(obj)
|
|
|
if (obj.pic_id.vipprice == undefined) {
|
|
|
newtotalmoney = Number(newtotalmoney) + Number(obj.pic_id.price)
|
|
|
} else {
|
|
|
newtotalmoney = Number(newtotalmoney) + Number(obj.pic_id.vipprice)
|
|
|
}
|
|
|
|
|
|
console.log(newpic_id, newtotalcartarr)
|
|
|
|
|
|
|
|
|
} else if (obj.sel == false && type == 2) {
|
|
|
for(var i=0;i<newtotalcartarr.length;i++){
|
|
|
if(newtotalcartarr[i]==cartid){
|
|
|
newtotalcartarr.splice(i,1);
|
|
|
if (obj.pic_id.vipprice == undefined) {
|
|
|
newtotalmoney = Number(newtotalmoney) - Number(obj.pic_id.price)
|
|
|
} else {
|
|
|
newtotalmoney = Number(newtotalmoney) - Number(obj.pic_id.vipprice)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// console.log('444', newpic_id, newtotalcartarr);
|
|
|
// for (var j = 0; j < newtotalcartarr.length; j++) {
|
|
|
// if (newtotalcartarr[j] == cartid) {
|
|
|
// newtotalcartarr.splice(j, 1)
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
for (var k = 0; k < newhebing.length; k++) {
|
|
|
if (newhebing[k].id == cartid) {
|
|
|
newhebing.splice(k, 1)
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (newcartlist.length == newtotalcartarr.length) {
|
|
|
that.setData({
|
|
|
totalsel: true
|
|
|
})
|
|
|
} else {
|
|
|
that.setData({
|
|
|
totalsel: false
|
|
|
})
|
|
|
}
|
|
|
|
|
|
newtotalmoney = newtotalmoney.toFixed(2)
|
|
|
|
|
|
that.setData({
|
|
|
cartlist: newcartlist,
|
|
|
video_id: newvideo_id,
|
|
|
pic_id: newpic_id,
|
|
|
totalcartarr: newtotalcartarr,
|
|
|
totalmoney: newtotalmoney,
|
|
|
hebing: newhebing
|
|
|
})
|
|
|
console.log(that.data.video_id);
|
|
|
// console.log(that.data.pic_id);
|
|
|
// console.log(that.data.totalcartarr);
|
|
|
// console.log(that.data.totalmoney);
|
|
|
// console.log(that.data.hebing)
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
// 全部选择
|
|
|
selallcart() {
|
|
|
this.setData({
|
|
|
totalsel: !this.data.totalsel
|
|
|
})
|
|
|
|
|
|
let newcartlist = this.data.cartlist;
|
|
|
let newtotalmoney = 0;
|
|
|
let newpic_id = this.data.pic_id;
|
|
|
let newvideo_id = this.data.video_id;
|
|
|
let newtotalcartarr = [];
|
|
|
let newhebing = this.data.hebing
|
|
|
|
|
|
if (this.data.totalsel == true) {
|
|
|
|
|
|
|
|
|
for (var obj of newcartlist) {
|
|
|
obj.sel = true;
|
|
|
|
|
|
if (obj.pic_id == null) {
|
|
|
console.log(obj.video_id)
|
|
|
newvideo_id.push(obj.video_id.id);
|
|
|
newtotalcartarr.push(obj.id);
|
|
|
newhebing.push(obj)
|
|
|
newtotalmoney = newtotalmoney + Number(obj.videoprice)
|
|
|
|
|
|
// if (obj.video_id.videotype[0] == '2k') {
|
|
|
// if (obj.video_id.vipprice == undefined) {
|
|
|
// newtotalmoney = newtotalmoney + obj.video_id.price
|
|
|
// } else {
|
|
|
// newtotalmoney = newtotalmoney + obj.video_id.vipprice
|
|
|
// }
|
|
|
// } else if (obj.video_id.videotype[0] == '4k') {
|
|
|
// if (obj.video_id.four_vipprice == undefined) {
|
|
|
// newtotalmoney = newtotalmoney + obj.video_id.four_price
|
|
|
// } else {
|
|
|
// newtotalmoney = newtotalmoney + obj.video_id.four_vipprice
|
|
|
// }
|
|
|
// } else if (obj.video_id.videotype[0] == '8k') {
|
|
|
// if (obj.video_id.four_vipprice == undefined) {
|
|
|
// newtotalmoney = newtotalmoney + obj.video_id.eight_price
|
|
|
// } else {
|
|
|
// newtotalmoney = newtotalmoney + obj.video_id.eight_vipprice
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
|
|
|
} else if (obj.video_id == null) {
|
|
|
newpic_id.push(obj.pic_id.id);
|
|
|
newtotalcartarr.push(obj.id)
|
|
|
newhebing.push(obj)
|
|
|
if (obj.pic_id.vipprice == undefined) {
|
|
|
newtotalmoney = newtotalmoney + obj.pic_id.price
|
|
|
} else {
|
|
|
newtotalmoney = newtotalmoney + obj.pic_id.vipprice
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
for (var obj of newcartlist) {
|
|
|
obj.sel = false;
|
|
|
|
|
|
}
|
|
|
newtotalmoney = 0;
|
|
|
newhebing = [];
|
|
|
newtotalcartarr=[]
|
|
|
|
|
|
}
|
|
|
newtotalmoney = newtotalmoney.toFixed(2)
|
|
|
this.setData({
|
|
|
totalmoney: newtotalmoney,
|
|
|
cartlist: newcartlist,
|
|
|
pic_id: newpic_id,
|
|
|
video_id: newvideo_id,
|
|
|
totalcartarr: newtotalcartarr,
|
|
|
hebing: newhebing
|
|
|
|
|
|
})
|
|
|
|
|
|
console.log('76543', this.data.video_id)
|
|
|
},
|
|
|
|
|
|
hejisuan() {
|
|
|
|
|
|
if (this.data.totalcartarr.length == 0) {
|
|
|
wx.showToast({
|
|
|
title: '请选结算的视频或图片',
|
|
|
icon: "none"
|
|
|
})
|
|
|
} else {
|
|
|
let newhebing = this.data.hebing;
|
|
|
newhebing = JSON.stringify(newhebing);
|
|
|
let newpic_id = JSON.stringify(this.data.pic_id);
|
|
|
let newvideo_id = JSON.stringify(this.data.video_id);
|
|
|
let newtotalcartarr=JSON.stringify(this.data.totalcartarr)
|
|
|
console.log(newpic_id);
|
|
|
console.log(newvideo_id)
|
|
|
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/jiesuanpage/jiesuanpage?totalmoney=' + this.data.totalmoney + '&hebing=' + newhebing + '&totalcartarr=' + newtotalcartarr
|
|
|
})
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
delcart() {
|
|
|
let that = this;
|
|
|
|
|
|
|
|
|
if (that.data.totalcartarr.length == 0) {
|
|
|
wx.showToast({
|
|
|
title: '请选择要删除的图片或视频',
|
|
|
icon: "none"
|
|
|
})
|
|
|
} else {
|
|
|
let url = 'user/delcar';
|
|
|
|
|
|
|
|
|
let param = {
|
|
|
ids: that.data.totalcartarr.join(",")
|
|
|
}
|
|
|
app.post(url, param, 'post').then((res) => {
|
|
|
console.log(res);
|
|
|
|
|
|
let newcartlist = that.data.cartlist;
|
|
|
let newtotalmoney = that.data.totalmoney;
|
|
|
let newtotalcartarr = that.data.totalcartarr;
|
|
|
let money = 0;
|
|
|
for (var i = 0; i < newcartlist.length; i++) {
|
|
|
for (var j = 0; j < newtotalcartarr.length; j++) {
|
|
|
if (newtotalcartarr[j] == newcartlist[i].id) {
|
|
|
console.log(newtotalcartarr[j]);
|
|
|
console.log(newcartlist[i])
|
|
|
if (newcartlist[i].pic_id == null) {
|
|
|
console.log(777)
|
|
|
money = newcartlist[i].videoprice
|
|
|
newtotalmoney = newtotalmoney - money
|
|
|
|
|
|
} else if (newcartlist[i].video_id == null) {
|
|
|
if (newcartlist[i].pic_id.vipprice == undefined) {
|
|
|
money = newcartlist[i].pic_id.price
|
|
|
} else {
|
|
|
money = newcartlist[i].pic_id.vipprice
|
|
|
}
|
|
|
|
|
|
newtotalmoney = newtotalmoney - money
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
that.setData({
|
|
|
totalmoney: newtotalmoney
|
|
|
})
|
|
|
|
|
|
|
|
|
wx.showToast({
|
|
|
title: '删除购物车成功',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
|
|
|
setTimeout(function() {
|
|
|
that.getcartlsit();
|
|
|
that.setData({
|
|
|
totalcartarr:[],
|
|
|
totalsel: false
|
|
|
})
|
|
|
|
|
|
}, 1000)
|
|
|
|
|
|
|
|
|
}).catch((err) => {
|
|
|
|
|
|
})
|
|
|
}
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
|
|
onReady: function() {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
onShow: function() {
|
|
|
this.getcartlsit();
|
|
|
this.setData({
|
|
|
totalmoney: 0,
|
|
|
video_id: [],
|
|
|
pic_id: [],
|
|
|
totalcartarr: [],
|
|
|
totalsel: false,
|
|
|
pp: [],
|
|
|
diannum: 0,
|
|
|
hebing: []
|
|
|
})
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
*/
|
|
|
onHide: function() {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
*/
|
|
|
onUnload: function() {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
*/
|
|
|
onPullDownRefresh: function() {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
*/
|
|
|
onReachBottom: function() {
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 用户点击右上角分享
|
|
|
*/
|
|
|
onShareAppMessage: function() {
|
|
|
|
|
|
}
|
|
|
}) |
|
|
\ No newline at end of file |
...
|
...
|
|