...
|
...
|
@@ -25,10 +25,11 @@ Page({ |
|
|
totalping: 0,
|
|
|
giftstandard: '请选择规格',
|
|
|
standard: '请选择规格',
|
|
|
standardarr:[],
|
|
|
giftstandardarr:[],
|
|
|
buynum:1
|
|
|
|
|
|
standardarr: [],
|
|
|
giftstandardarr: [],
|
|
|
buynum: 1,
|
|
|
buytype: '', //1 加入购物车 2立即购买
|
|
|
attrshow: false
|
|
|
},
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -71,7 +72,7 @@ Page({ |
|
|
|
|
|
})
|
|
|
},
|
|
|
|
|
|
// 获取商品详情
|
|
|
getgoodtail() {
|
|
|
let that = this;
|
|
|
var url = 'goods/get_one';
|
...
|
...
|
@@ -94,7 +95,7 @@ Page({ |
|
|
|
|
|
that.data.goodtail.gift.standard.forEach(function(value, index, array) {
|
|
|
value.selindex = -1,
|
|
|
value.selname = ''
|
|
|
value.selname = ''
|
|
|
})
|
|
|
that.setData({
|
|
|
goodtail: that.data.goodtail
|
...
|
...
|
@@ -104,33 +105,38 @@ Page({ |
|
|
|
|
|
})
|
|
|
},
|
|
|
reducenum(){
|
|
|
this.data.buynum=this.data.buynum-1;
|
|
|
if(this.data.buynum==1){
|
|
|
reducenum() {
|
|
|
this.data.buynum = this.data.buynum - 1;
|
|
|
if (this.data.buynum == 1) {
|
|
|
this.setData({
|
|
|
buynum:this.data.buynum
|
|
|
buynum: this.data.buynum
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
addnum(){
|
|
|
this.data.buynum = this.data.buynum +1;
|
|
|
addnum() {
|
|
|
this.data.buynum = this.data.buynum + 1;
|
|
|
this.setData({
|
|
|
buynum: this.data.buynum
|
|
|
})
|
|
|
},
|
|
|
|
|
|
uniq(array) {
|
|
|
|
|
|
return temp;
|
|
|
},
|
|
|
// 选择属性
|
|
|
selattr(e) {
|
|
|
let that = this;
|
|
|
console.log(e)
|
|
|
let index = e.currentTarget.dataset.index;
|
|
|
let attrindex = e.currentTarget.dataset.bindex;
|
|
|
let name=e.currentTarget.dataset.name
|
|
|
let name = e.currentTarget.dataset.name
|
|
|
console.log(index);
|
|
|
console.log(attrindex)
|
|
|
that.data.standardarr.push(name)
|
|
|
that.data.goodtail.standard[attrindex].selindex = index;
|
|
|
that.data.goodtail.standard[attrindex].selname = name;
|
|
|
|
|
|
|
|
|
that.setData({
|
|
|
goodtail: that.data.goodtail,
|
|
|
standardarr: that.data.standardarr
|
...
|
...
|
@@ -138,7 +144,7 @@ Page({ |
|
|
console.log(that.data.goodtail)
|
|
|
console.log(that.data.standardarr)
|
|
|
},
|
|
|
selgiftattr(e){
|
|
|
selgiftattr(e) {
|
|
|
let that = this;
|
|
|
console.log(e)
|
|
|
let index = e.currentTarget.dataset.index;
|
...
|
...
|
@@ -159,13 +165,22 @@ Page({ |
|
|
},
|
|
|
//加入购物车
|
|
|
addcart() {
|
|
|
let that = this;
|
|
|
this.setData({
|
|
|
buytype: 1,
|
|
|
attrshow: true
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
addcartk() {
|
|
|
let that = this
|
|
|
var url = 'car/update_car';
|
|
|
var params = {
|
|
|
goods_id: that.data.goodid,
|
|
|
type: 1,
|
|
|
goods_standard:that.data.standardarr.join(","),
|
|
|
give_standard: that.data.giftstandardarr.join(",")
|
|
|
goods_standard: that.data.standardarr.join(","),
|
|
|
give_standard: that.data.giftstandardarr.join(","),
|
|
|
number: that.data.buynum
|
|
|
|
|
|
}
|
|
|
app.post(url, params).then((res) => {
|
...
|
...
|
@@ -174,6 +189,12 @@ Page({ |
|
|
title: '添加购物车成功',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
|
|
|
setTimeout(function(){
|
|
|
that.setData({
|
|
|
attrshow:false
|
|
|
})
|
|
|
},1500)
|
|
|
that.getqipao()
|
|
|
|
|
|
|
...
|
...
|
@@ -246,13 +267,22 @@ Page({ |
|
|
|
|
|
//立即抢购
|
|
|
lijiqiang() {
|
|
|
this.setData({
|
|
|
buytype: 2,
|
|
|
attrshow: true
|
|
|
})
|
|
|
},
|
|
|
|
|
|
lijiqiangk() {
|
|
|
let that = this;
|
|
|
var url = 'order/confirm_order';
|
|
|
var params = {
|
|
|
goods_ids: that.data.goodtail.id,
|
|
|
take_id: '',
|
|
|
type: 1
|
|
|
|
|
|
type: 1,
|
|
|
goods_standard: that.data.standardarr.join(","),
|
|
|
give_standard: that.data.giftstandardarr.join(","),
|
|
|
number: that.data.buynum
|
|
|
}
|
|
|
app.post(url, params).then((res) => {
|
|
|
console.log(res);
|
...
|
...
|
@@ -266,15 +296,16 @@ Page({ |
|
|
let freight = res.freight;
|
|
|
let price = res.price;
|
|
|
let total = res.total;
|
|
|
let give_standard = res.give_standard
|
|
|
let goods_standard = res.goods_standard
|
|
|
console.log(give_standard);
|
|
|
console.log(goods_standard)
|
|
|
app.globalData.give_standard = give_standard;
|
|
|
|
|
|
|
|
|
console.log(freight);
|
|
|
console.log(price);
|
|
|
console.log(total);
|
|
|
console.log(orderarr);
|
|
|
app.globalData.goods_standard = goods_standard;
|
|
|
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/sureorder/sureorder?orderarr=' + neworderarr + '&freight=' + freight + '&price=' + price + '&total=' + total + '&type=' + 1,
|
|
|
url: '/pages/sureorder/sureorder?orderarr=' + neworderarr + '&freight=' + freight + '&price=' + price + '&total=' + total + '&type=' + 1
|
|
|
})
|
|
|
|
|
|
|
...
|
...
|
@@ -285,6 +316,83 @@ Page({ |
|
|
})
|
|
|
})
|
|
|
},
|
|
|
//确定购买或加入购物车
|
|
|
surebuy() {
|
|
|
let that = this;
|
|
|
console.log(that.data.goodtail)
|
|
|
var arr = [];
|
|
|
var giftarr = [];
|
|
|
that.data.goodtail.standard.forEach(function(value, index, array) {
|
|
|
|
|
|
console.log(value);
|
|
|
console.log(value.selname)
|
|
|
if (value.selname != "") {
|
|
|
arr.push(value.selname);
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
var temp = []; //一个新的临时数组 去掉多选的商品属性
|
|
|
for (var i = 0; i < arr.length; i++) {
|
|
|
if (temp.indexOf(arr[i]) == -1) {
|
|
|
temp.push(arr[i]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
that.data.goodtail.gift.standard.forEach(function(value, index, array) {
|
|
|
|
|
|
console.log(value);
|
|
|
console.log(value.selname)
|
|
|
if (value.selname != "") {
|
|
|
giftarr.push(value.selname);
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
var gifttemp = []; //一个新的临时数组 去掉多选的商品属性
|
|
|
for (var i = 0; i < giftarr.length; i++) {
|
|
|
if (gifttemp.indexOf(giftarr[i]) == -1) {
|
|
|
gifttemp.push(giftarr[i]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
that.setData({
|
|
|
standardarr: temp,
|
|
|
giftstandardarr: gifttemp
|
|
|
})
|
|
|
|
|
|
|
|
|
if (that.data.standardarr.length != that.data.goodtail.standard.length) {
|
|
|
|
|
|
|
|
|
wx.showToast({
|
|
|
title: '请选择商品属性',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
|
|
|
} else if (that.data.giftstandardarr.length != that.data.goodtail.gift.standard.length) {
|
|
|
|
|
|
wx.showToast({
|
|
|
title: '请选择赠品属性',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
if (that.data.buytype == 1) {
|
|
|
that.addcartk()
|
|
|
} else {
|
|
|
that.lijiqiangk()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
...
|
...
|
|