...
|
...
|
@@ -2,636 +2,647 @@ |
|
|
const app = getApp();
|
|
|
Page({
|
|
|
|
|
|
/**
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
imgUrl: app.globalData.imgUrl,
|
|
|
shoucang: false,
|
|
|
active: true,
|
|
|
show: false,
|
|
|
shows: false,
|
|
|
id: 0,
|
|
|
goods: [],
|
|
|
ids: [],
|
|
|
idss: [],
|
|
|
status: 0,
|
|
|
cart_count: 0,
|
|
|
skuid: '',
|
|
|
num: 1,
|
|
|
id_arr: [],
|
|
|
gPrice: 0,
|
|
|
collocation: [],
|
|
|
goods_star: 1,
|
|
|
star_arr: [],
|
|
|
commentCount: 0,
|
|
|
favorite: 0,
|
|
|
totalPrice: 0,
|
|
|
gPrice: 0,
|
|
|
is_group: 0,
|
|
|
packageList: [],
|
|
|
showList: [],
|
|
|
showMore: false,
|
|
|
show1: false,
|
|
|
goods1: {},
|
|
|
origin: 0,
|
|
|
skuid_arr: [],
|
|
|
is_vip: 0
|
|
|
},
|
|
|
fetchVip() {
|
|
|
let url = '/wxapp/user/index'
|
|
|
app.post(url).then(r => {
|
|
|
if (r.code == 1) {
|
|
|
console.log(r)
|
|
|
this.setData({
|
|
|
is_vip: r.data.user.is_vip
|
|
|
})
|
|
|
this.fetchGoods()
|
|
|
}
|
|
|
/**
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
imgUrl: app.globalData.imgUrl,
|
|
|
shoucang: false,
|
|
|
active: true,
|
|
|
show: false,
|
|
|
shows: false,
|
|
|
id: 0,
|
|
|
goods: [],
|
|
|
ids: [],
|
|
|
idss: [],
|
|
|
status: 0,
|
|
|
cart_count: 0,
|
|
|
skuid: '',
|
|
|
num: 1,
|
|
|
id_arr: [],
|
|
|
gPrice: 0,
|
|
|
collocation: [],
|
|
|
goods_star: 1,
|
|
|
star_arr: [],
|
|
|
commentCount: 0,
|
|
|
favorite: 0,
|
|
|
totalPrice: 0,
|
|
|
gPrice: 0,
|
|
|
is_group: 0,
|
|
|
packageList: [],
|
|
|
showList: [],
|
|
|
showMore: false,
|
|
|
show1: false,
|
|
|
goods1: {},
|
|
|
origin: 0,
|
|
|
skuid_arr: [],
|
|
|
is_vip: 0,
|
|
|
countn: null
|
|
|
},
|
|
|
fetchVip() {
|
|
|
let url = '/wxapp/user/index'
|
|
|
app.post(url).then(r => {
|
|
|
if (r.code == 1) {
|
|
|
console.log(r)
|
|
|
this.setData({
|
|
|
is_vip: r.data.user.is_vip
|
|
|
})
|
|
|
},
|
|
|
//进入评论列表
|
|
|
jump_user_comment(e) {
|
|
|
let id = e.currentTarget.dataset.id
|
|
|
wx.navigateTo({
|
|
|
url: '../user_comment/user_comment?id=' + this.data.id
|
|
|
this.fetchGoods()
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
//进入评论列表
|
|
|
jump_user_comment(e) {
|
|
|
let id = e.currentTarget.dataset.id
|
|
|
wx.navigateTo({
|
|
|
url: '../user_comment/user_comment?id=' + this.data.id
|
|
|
})
|
|
|
},
|
|
|
//进入商品详情
|
|
|
goDetail(e) {
|
|
|
wx.navigateTo({
|
|
|
url: '../goodsDetials/goodsDetials?id=' + e.currentTarget.dataset.id
|
|
|
})
|
|
|
},
|
|
|
//减少数量
|
|
|
dec_num() {
|
|
|
var num = this.data.num;
|
|
|
if (num <= 1) {
|
|
|
return;
|
|
|
} else {
|
|
|
num--
|
|
|
}
|
|
|
this.setData({
|
|
|
num: num
|
|
|
});
|
|
|
this.totalPrice()
|
|
|
},
|
|
|
//增加数量
|
|
|
add_num() {
|
|
|
var num = this.data.num;
|
|
|
num++
|
|
|
this.setData({
|
|
|
num: num
|
|
|
});
|
|
|
this.totalPrice();
|
|
|
},
|
|
|
//总价格
|
|
|
totalPrice() {
|
|
|
var that = this
|
|
|
var total = that.data.goods.info.price * that.data.num
|
|
|
that.setData({
|
|
|
totalPrice: total
|
|
|
})
|
|
|
},
|
|
|
//点击收藏
|
|
|
collection_true(e) {
|
|
|
let id = e.currentTarget.dataset.id
|
|
|
let that = this
|
|
|
let url = '/wxapp/cookbook_package/setFavorites?id=' + id
|
|
|
let params = {
|
|
|
id: id
|
|
|
}
|
|
|
app.post(url).then(r => {
|
|
|
if (r.code == 1) {
|
|
|
wx.showToast({
|
|
|
title: r.msg,
|
|
|
icon: 'none'
|
|
|
})
|
|
|
},
|
|
|
//进入商品详情
|
|
|
goDetail(e) {
|
|
|
wx.navigateTo({
|
|
|
url: '../goodsDetials/goodsDetials?id=' + e.currentTarget.dataset.id
|
|
|
that.fetchGoods();
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
//促销进商品详情
|
|
|
jump_goodsDetial2(e) {
|
|
|
wx.navigateTo({
|
|
|
url: '../goodsDetial2/goodsDetial2?id=' + e.currentTarget.dataset.id
|
|
|
})
|
|
|
},
|
|
|
//关闭弹窗
|
|
|
close_mask_carts() {
|
|
|
this.setData({
|
|
|
shows: false
|
|
|
});
|
|
|
},
|
|
|
//根据id获取内容
|
|
|
fetchGoods() {
|
|
|
let url = '/wxapp/cookbook_package/getPackageInfo';
|
|
|
let params = {
|
|
|
id: this.data.id
|
|
|
};
|
|
|
let that = this
|
|
|
let showList = []
|
|
|
let arr1 = []
|
|
|
let skuid1 = 0
|
|
|
let skuid_price1 = 0
|
|
|
let old_skuid_price1 = 0
|
|
|
let skuid_arr = that.data.skuid_arr;
|
|
|
let is_vip = that.data.is_vip
|
|
|
console.log(is_vip + 'shibushis')
|
|
|
app.post(url, params).then(r => {
|
|
|
// console.log(r);
|
|
|
r.data.list.forEach(function(ele, indexxx) {
|
|
|
if (is_vip == 1) {
|
|
|
ele.ggprice = ele.vip_price
|
|
|
} else {
|
|
|
ele.ggprice = ele.price
|
|
|
}
|
|
|
if (ele.is_default == 1) {
|
|
|
showList.push(ele)
|
|
|
}
|
|
|
ele.t = false
|
|
|
if (indexxx < r.data.info.num) {
|
|
|
ele.t = true
|
|
|
}
|
|
|
ele.attr.attr_sku.forEach(function(eles, indexxxx) {
|
|
|
for (let i = 0; i < eles.item.length; i++) {
|
|
|
eles.item[i].t = false
|
|
|
eles.item[0].t = true;
|
|
|
arr1.push(eles.item[0].id)
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
//减少数量
|
|
|
dec_num() {
|
|
|
var num = this.data.num;
|
|
|
if (num <= 1) {
|
|
|
return;
|
|
|
arr1.sort();
|
|
|
let arr2 = [...new Set(arr1)]
|
|
|
ele.arr = arr2
|
|
|
let str1 = arr2.join('_');
|
|
|
let sys_attrprice1 = r.data.list[indexxx].sys_attrprice
|
|
|
|
|
|
if (ele.attr.attr_sku.length == 0) {
|
|
|
return;
|
|
|
} else {
|
|
|
num--
|
|
|
for (let i in sys_attrprice1) {
|
|
|
if (i == str1) {
|
|
|
skuid1 = sys_attrprice1[i].skuid
|
|
|
skuid_price1 = sys_attrprice1[i].price
|
|
|
old_skuid_price1 = sys_attrprice1[i].old_price
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
this.setData({
|
|
|
num: num
|
|
|
ele.ggid = skuid1
|
|
|
if (ele.ggid) {
|
|
|
skuid_arr.push(skuid1)
|
|
|
}
|
|
|
str1 = ''
|
|
|
arr1 = []
|
|
|
})
|
|
|
if (r.data.groupType) {
|
|
|
var days = ''
|
|
|
var hours = ''
|
|
|
var minutes = ''
|
|
|
var seconds = ''
|
|
|
var percent = 0
|
|
|
|
|
|
function time() {
|
|
|
var cut_time = r.data.groupType.count_down_time
|
|
|
days = Math.floor((cut_time) / (60 * 60 * 24));
|
|
|
hours = Math.floor((cut_time) / (60 * 60)) % 24;
|
|
|
minutes = Math.floor((cut_time) / (60)) % 60;
|
|
|
seconds = cut_time % 60;
|
|
|
percent = Math.floor(r.data.info.group_number * 100 / r.data.info.group_min_number)
|
|
|
}
|
|
|
time();
|
|
|
// setInterval(time, 1000);
|
|
|
that.setData({
|
|
|
day: days,
|
|
|
hour: hours,
|
|
|
minute: minutes,
|
|
|
second: seconds,
|
|
|
percent: percent,
|
|
|
goods: r.data,
|
|
|
gPrice: r.data.info.price,
|
|
|
collocation: r.data.collocation,
|
|
|
comment: r.data.comment,
|
|
|
// star_arr: star_arr,
|
|
|
is_group: r.data.info.group_min_number,
|
|
|
countn: r.data.info.num
|
|
|
});
|
|
|
this.totalPrice()
|
|
|
},
|
|
|
//增加数量
|
|
|
add_num() {
|
|
|
var num = this.data.num;
|
|
|
num++
|
|
|
this.setData({
|
|
|
num: num
|
|
|
} else {
|
|
|
that.setData({
|
|
|
goods: r.data,
|
|
|
gPrice: r.data.info.price,
|
|
|
// comment: r.data.comment,
|
|
|
packageList: r.data.list,
|
|
|
showList: showList,
|
|
|
countn: r.data.info.num
|
|
|
});
|
|
|
this.totalPrice();
|
|
|
},
|
|
|
//总价格
|
|
|
totalPrice() {
|
|
|
var that = this
|
|
|
var total = that.data.goods.info.price * that.data.num
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
//渲染评论列表
|
|
|
fetchCommentList() {
|
|
|
let url = '/wxapp/product/comment?id=' + this.data.id
|
|
|
app.post(url).then(r => {
|
|
|
this.setData({
|
|
|
commentCount: r.data.length
|
|
|
});
|
|
|
})
|
|
|
},
|
|
|
//点击更换菜品
|
|
|
replaceDishes() {
|
|
|
this.setData({
|
|
|
showMore: true
|
|
|
})
|
|
|
wx.pageScrollTo({
|
|
|
scrollTop: 0,
|
|
|
})
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function(options) {
|
|
|
console.log(options)
|
|
|
this.fetchVip();
|
|
|
var query = wx.createSelectorQuery();
|
|
|
var offset = query.select('.itme_list5');
|
|
|
this.setData({
|
|
|
id: options.id
|
|
|
});
|
|
|
// this.fetchGoods();
|
|
|
this.fetchCommentList();
|
|
|
},
|
|
|
// 返回上一页
|
|
|
get_back() {
|
|
|
wx.navigateBack({})
|
|
|
},
|
|
|
//弹框返回
|
|
|
closeShowMore() {
|
|
|
let that = this
|
|
|
let goods = that.data.goods
|
|
|
let num = goods.info.num
|
|
|
let showList = []
|
|
|
let n = 0
|
|
|
goods.list.forEach(function(ele, index) {
|
|
|
if (ele.t) {
|
|
|
showList.push(ele)
|
|
|
n++;
|
|
|
}
|
|
|
})
|
|
|
if ((n < goods.info.num && n >= 0) || n > goods.info.num) {
|
|
|
wx.showToast({
|
|
|
title: '您最多能选择' + num + '种商品',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
return;
|
|
|
} else {
|
|
|
if (showList.length == 0) {
|
|
|
that.setData({
|
|
|
totalPrice: total
|
|
|
})
|
|
|
},
|
|
|
//点击收藏
|
|
|
collection_true(e) {
|
|
|
let id = e.currentTarget.dataset.id
|
|
|
let that = this
|
|
|
let url = '/wxapp/cookbook_package/setFavorites?id=' + id
|
|
|
let params = {
|
|
|
id: id
|
|
|
}
|
|
|
app.post(url).then(r => {
|
|
|
if (r.code == 1) {
|
|
|
wx.showToast({
|
|
|
title: r.msg,
|
|
|
icon: 'none'
|
|
|
})
|
|
|
that.fetchGoods();
|
|
|
}
|
|
|
showMore: false,
|
|
|
})
|
|
|
},
|
|
|
//促销进商品详情
|
|
|
jump_goodsDetial2(e) {
|
|
|
wx.navigateTo({
|
|
|
url: '../goodsDetial2/goodsDetial2?id=' + e.currentTarget.dataset.id
|
|
|
} else {
|
|
|
that.setData({
|
|
|
showMore: false,
|
|
|
showList: showList
|
|
|
})
|
|
|
},
|
|
|
//关闭弹窗
|
|
|
close_mask_carts() {
|
|
|
this.setData({
|
|
|
shows: false
|
|
|
});
|
|
|
},
|
|
|
//根据id获取内容
|
|
|
fetchGoods() {
|
|
|
let url = '/wxapp/cookbook_package/getPackageInfo';
|
|
|
let params = {
|
|
|
id: this.data.id
|
|
|
};
|
|
|
let that = this
|
|
|
let showList = []
|
|
|
let arr1 = []
|
|
|
let skuid1 = 0
|
|
|
let skuid_price1 = 0
|
|
|
let old_skuid_price1 = 0
|
|
|
let skuid_arr = that.data.skuid_arr;
|
|
|
let is_vip = that.data.is_vip
|
|
|
console.log(is_vip + 'shibushis')
|
|
|
app.post(url, params).then(r => {
|
|
|
// console.log(r);
|
|
|
r.data.list.forEach(function (ele, indexxx) {
|
|
|
if (is_vip == 1) {
|
|
|
ele.ggprice = ele.vip_price
|
|
|
} else {
|
|
|
ele.ggprice = ele.price
|
|
|
}
|
|
|
if (ele.is_default == 1) {
|
|
|
showList.push(ele)
|
|
|
}
|
|
|
ele.t = false
|
|
|
if(indexxx<r.data.info.num){
|
|
|
ele.t=true
|
|
|
}
|
|
|
ele.attr.attr_sku.forEach(function (eles, indexxxx) {
|
|
|
for (let i = 0; i < eles.item.length; i++) {
|
|
|
eles.item[i].t = false
|
|
|
eles.item[0].t = true;
|
|
|
arr1.push(eles.item[0].id)
|
|
|
}
|
|
|
})
|
|
|
arr1.sort();
|
|
|
let arr2 = [...new Set(arr1)]
|
|
|
ele.arr = arr2
|
|
|
let str1 = arr2.join('_');
|
|
|
let sys_attrprice1 = r.data.list[indexxx].sys_attrprice
|
|
|
|
|
|
if (ele.attr.attr_sku.length == 0) {
|
|
|
return;
|
|
|
} else {
|
|
|
for (let i in sys_attrprice1) {
|
|
|
if (i == str1) {
|
|
|
skuid1 = sys_attrprice1[i].skuid
|
|
|
skuid_price1 = sys_attrprice1[i].price
|
|
|
old_skuid_price1 = sys_attrprice1[i].old_price
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
ele.ggid = skuid1
|
|
|
if (ele.ggid) {
|
|
|
skuid_arr.push(skuid1)
|
|
|
}
|
|
|
str1 = ''
|
|
|
arr1 = []
|
|
|
})
|
|
|
if (r.data.groupType) {
|
|
|
var days = ''
|
|
|
var hours = ''
|
|
|
var minutes = ''
|
|
|
var seconds = ''
|
|
|
var percent = 0
|
|
|
function time() {
|
|
|
var cut_time = r.data.groupType.count_down_time
|
|
|
days = Math.floor((cut_time) / (60 * 60 * 24));
|
|
|
hours = Math.floor((cut_time) / (60 * 60)) % 24;
|
|
|
minutes = Math.floor((cut_time) / (60)) % 60;
|
|
|
seconds = cut_time % 60;
|
|
|
percent = Math.floor(r.data.info.group_number * 100 / r.data.info.group_min_number)
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
//attr选择规格
|
|
|
chooseStandard(e) {
|
|
|
let origin = e.currentTarget.dataset.origin
|
|
|
if (e.currentTarget.dataset.shop.attr.attr_sku.length == 0) {
|
|
|
wx.showToast({
|
|
|
title: '暂无规格',
|
|
|
icon: "none",
|
|
|
duration: 1300
|
|
|
})
|
|
|
} else {
|
|
|
this.setData({
|
|
|
goods1: e.currentTarget.dataset.shop,
|
|
|
show1: true,
|
|
|
origin: origin,
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
//关闭弹框
|
|
|
close_mask_cart1() {
|
|
|
this.setData({
|
|
|
show1: false
|
|
|
})
|
|
|
},
|
|
|
//加购筛选
|
|
|
changeIds1(e) {
|
|
|
let t = this;
|
|
|
let goods = t.data.showList;
|
|
|
let iindex = e.currentTarget.dataset.origin
|
|
|
//父级索引
|
|
|
let parent = e.currentTarget.dataset.parent
|
|
|
goods.forEach(function(ele, index) {
|
|
|
if (iindex == index) {
|
|
|
let new_arr = ele.arr
|
|
|
let listAll = ele.attr.attr_sku;
|
|
|
// 父级索引
|
|
|
let x = e.currentTarget.dataset.index;
|
|
|
// 当前点击Id
|
|
|
let nowId = e.currentTarget.dataset.gid;
|
|
|
//当前点击value
|
|
|
let nowValue = e.currentTarget.dataset.item;
|
|
|
// 子集索引
|
|
|
let nowIndex = e.currentTarget.dataset.index;
|
|
|
// 当前可否多选
|
|
|
let is_checkMore = false
|
|
|
let foo = new_arr.indexOf(nowId)
|
|
|
if (foo > -1) {
|
|
|
new_arr.splice(foo, 1)
|
|
|
} else {
|
|
|
ele.attr.attr_sku.forEach(function(eles, indexxxx) {
|
|
|
if (indexxxx == parent) {
|
|
|
for (let i = 0; i < eles.item.length; i++) {
|
|
|
let havId = ele.attr.attr_sku[indexxxx].item[i].id
|
|
|
let have = new_arr.indexOf(havId)
|
|
|
if (have > -1) {
|
|
|
new_arr.splice(have, 1)
|
|
|
}
|
|
|
time();
|
|
|
// setInterval(time, 1000);
|
|
|
that.setData({
|
|
|
day: days,
|
|
|
hour: hours,
|
|
|
minute: minutes,
|
|
|
second: seconds,
|
|
|
percent: percent,
|
|
|
goods: r.data,
|
|
|
gPrice: r.data.info.price,
|
|
|
collocation: r.data.collocation,
|
|
|
comment: r.data.comment,
|
|
|
// star_arr: star_arr,
|
|
|
is_group: r.data.info.group_min_number
|
|
|
});
|
|
|
} else {
|
|
|
that.setData({
|
|
|
goods: r.data,
|
|
|
gPrice: r.data.info.price,
|
|
|
// comment: r.data.comment,
|
|
|
packageList: r.data.list,
|
|
|
showList: showList
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
//渲染评论列表
|
|
|
fetchCommentList() {
|
|
|
let url = '/wxapp/product/comment?id=' + this.data.id
|
|
|
app.post(url).then(r => {
|
|
|
this.setData({
|
|
|
commentCount: r.data.length
|
|
|
});
|
|
|
})
|
|
|
},
|
|
|
//点击更换菜品
|
|
|
replaceDishes() {
|
|
|
this.setData({
|
|
|
showMore: true
|
|
|
})
|
|
|
}
|
|
|
// 当前点击父级值
|
|
|
let tempArry = JSON.parse(JSON.stringify(ele.attr.attr_sku[parent]));
|
|
|
!tempArry.chooseIndex ? tempArry.chooseIndex = [] : '';
|
|
|
// 是否多选
|
|
|
if (is_checkMore) {} else {
|
|
|
tempArry.chooseIndex.pop();
|
|
|
tempArry.chooseIndex.push(nowId);
|
|
|
for (let obj of tempArry.item) {
|
|
|
obj.t = false
|
|
|
}
|
|
|
tempArry.item[nowIndex].t = true;
|
|
|
}
|
|
|
ele.attr.attr_sku[parent] = tempArry;
|
|
|
}
|
|
|
})
|
|
|
t.setData({
|
|
|
goods1: goods[iindex]
|
|
|
})
|
|
|
// let goods = t.data.goodsList;
|
|
|
goods.forEach(function(ele, indexaa) {
|
|
|
if (iindex == indexaa) {
|
|
|
let new_arr = ele.arr
|
|
|
let sys_attrprice = goods[indexaa].sys_attrprice;
|
|
|
let new_arr_item = [];
|
|
|
let str = ''
|
|
|
let skuid = 0
|
|
|
let skuid_price = 0
|
|
|
let old_skuid_price = 0
|
|
|
let vip_skuid_price = 0
|
|
|
ele.attr.attr_sku.forEach(function(eles, indexx) {
|
|
|
if (indexx == parent) {
|
|
|
new_arr = new_arr.concat(eles.chooseIndex);
|
|
|
}
|
|
|
})
|
|
|
wx.pageScrollTo({
|
|
|
scrollTop: 0,
|
|
|
new_arr = new_arr.sort()
|
|
|
str = new_arr.join('_')
|
|
|
ele.arr = new_arr
|
|
|
t.setData({
|
|
|
goodsList: goods
|
|
|
})
|
|
|
},
|
|
|
new_arr_item = new_arr_item.join(',');
|
|
|
new_arr_item = new_arr_item.replace(/,/g, " ");
|
|
|
for (let i in sys_attrprice) {
|
|
|
if (i == str) {
|
|
|
skuid = sys_attrprice[i].skuid
|
|
|
skuid_price = sys_attrprice[i].price
|
|
|
old_skuid_price = sys_attrprice[i].old_price
|
|
|
vip_skuid_price = sys_attrprice[i].vip_price
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function (options) {
|
|
|
console.log(options)
|
|
|
this.fetchVip();
|
|
|
var query = wx.createSelectorQuery();
|
|
|
var offset = query.select('.itme_list5');
|
|
|
this.setData({
|
|
|
id: options.id
|
|
|
});
|
|
|
// this.fetchGoods();
|
|
|
this.fetchCommentList();
|
|
|
},
|
|
|
// 返回上一页
|
|
|
get_back() {
|
|
|
wx.navigateBack({})
|
|
|
},
|
|
|
//弹框返回
|
|
|
closeShowMore() {
|
|
|
let that = this
|
|
|
let goods = that.data.goods
|
|
|
let num = goods.info.num
|
|
|
let showList = []
|
|
|
let n = 0
|
|
|
goods.list.forEach(function (ele, index) {
|
|
|
if (ele.t) {
|
|
|
showList.push(ele)
|
|
|
n++;
|
|
|
}
|
|
|
})
|
|
|
if ((n < goods.info.num && n > 0) || n > goods.info.num) {
|
|
|
wx.showToast({
|
|
|
title: '您最多只能选择' + num + '种商品',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
return;
|
|
|
} else {
|
|
|
if (showList.length == 0) {
|
|
|
that.setData({
|
|
|
showMore: false,
|
|
|
})
|
|
|
ele.ggid = skuid;
|
|
|
var ggprice = 0
|
|
|
if (t.data.is_vip == 1) {
|
|
|
ggprice = vip_skuid_price
|
|
|
} else {
|
|
|
that.setData({
|
|
|
showMore: false,
|
|
|
showList: showList
|
|
|
})
|
|
|
ggprice = skuid_price
|
|
|
}
|
|
|
ele.ggprice = ggprice
|
|
|
ele.arr = new_arr
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
//attr选择规格
|
|
|
chooseStandard(e) {
|
|
|
let origin = e.currentTarget.dataset.origin
|
|
|
if (e.currentTarget.dataset.shop.attr.attr_sku.length == 0) {
|
|
|
}
|
|
|
})
|
|
|
t.setData({
|
|
|
goodsList: goods
|
|
|
})
|
|
|
console.log(101010101)
|
|
|
},
|
|
|
//skuid加入skuid_arr
|
|
|
hide_mask1(e) {
|
|
|
var skuid_arr = this.data.skuid_arr
|
|
|
var skuid1 = this.data.skuid1
|
|
|
var indexs = e.currentTarget.dataset.index
|
|
|
if (skuid1 != 0) {
|
|
|
// skuid_arr.push(skuid1)
|
|
|
}
|
|
|
var goods = this.data.showList
|
|
|
goods.forEach(function(ele, index) {
|
|
|
if (index == indexs) {
|
|
|
for (let i = 0; i < ele.attr.attr_sku.length; i++) {
|
|
|
if (ele.arr.length == 1) {
|
|
|
wx.showToast({
|
|
|
title: '暂无规格',
|
|
|
icon: "none",
|
|
|
duration: 1300
|
|
|
title: '请选择全部属性',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
} else {
|
|
|
this.setData({
|
|
|
goods1: e.currentTarget.dataset.shop,
|
|
|
show1: true,
|
|
|
origin: origin,
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
//关闭弹框
|
|
|
close_mask_cart1() {
|
|
|
this.setData({
|
|
|
show1: false
|
|
|
})
|
|
|
},
|
|
|
//加购筛选
|
|
|
changeIds1(e) {
|
|
|
let t = this;
|
|
|
let goods = t.data.showList;
|
|
|
let iindex = e.currentTarget.dataset.origin
|
|
|
//父级索引
|
|
|
let parent = e.currentTarget.dataset.parent
|
|
|
goods.forEach(function (ele, index) {
|
|
|
if (iindex == index) {
|
|
|
let new_arr = ele.arr
|
|
|
let listAll = ele.attr.attr_sku;
|
|
|
// 父级索引
|
|
|
let x = e.currentTarget.dataset.index;
|
|
|
// 当前点击Id
|
|
|
let nowId = e.currentTarget.dataset.gid;
|
|
|
//当前点击value
|
|
|
let nowValue = e.currentTarget.dataset.item;
|
|
|
// 子集索引
|
|
|
let nowIndex = e.currentTarget.dataset.index;
|
|
|
// 当前可否多选
|
|
|
let is_checkMore = false
|
|
|
let foo = new_arr.indexOf(nowId)
|
|
|
if (foo > -1) {
|
|
|
new_arr.splice(foo, 1)
|
|
|
} else {
|
|
|
ele.attr.attr_sku.forEach(function (eles, indexxxx) {
|
|
|
if (indexxxx == parent) {
|
|
|
for (let i = 0; i < eles.item.length; i++) {
|
|
|
let havId = ele.attr.attr_sku[indexxxx].item[i].id
|
|
|
let have = new_arr.indexOf(havId)
|
|
|
if (have > -1) {
|
|
|
new_arr.splice(have, 1)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
// 当前点击父级值
|
|
|
let tempArry = JSON.parse(JSON.stringify(ele.attr.attr_sku[parent]));
|
|
|
!tempArry.chooseIndex ? tempArry.chooseIndex = [] : '';
|
|
|
// 是否多选
|
|
|
if (is_checkMore) { } else {
|
|
|
tempArry.chooseIndex.pop();
|
|
|
tempArry.chooseIndex.push(nowId);
|
|
|
for (let obj of tempArry.item) {
|
|
|
obj.t = false
|
|
|
}
|
|
|
tempArry.item[nowIndex].t = true;
|
|
|
}
|
|
|
ele.attr.attr_sku[parent] = tempArry;
|
|
|
}
|
|
|
})
|
|
|
t.setData({
|
|
|
goods1: goods[iindex]
|
|
|
})
|
|
|
// let goods = t.data.goodsList;
|
|
|
goods.forEach(function (ele, indexaa) {
|
|
|
if (iindex == indexaa) {
|
|
|
let new_arr = ele.arr
|
|
|
let sys_attrprice = goods[indexaa].sys_attrprice;
|
|
|
let new_arr_item = [];
|
|
|
let str = ''
|
|
|
let skuid = 0
|
|
|
let skuid_price = 0
|
|
|
let old_skuid_price = 0
|
|
|
let vip_skuid_price = 0
|
|
|
ele.attr.attr_sku.forEach(function (eles, indexx) {
|
|
|
if (indexx == parent) {
|
|
|
new_arr = new_arr.concat(eles.chooseIndex);
|
|
|
}
|
|
|
})
|
|
|
new_arr = new_arr.sort()
|
|
|
str = new_arr.join('_')
|
|
|
ele.arr = new_arr
|
|
|
t.setData({
|
|
|
goodsList: goods
|
|
|
})
|
|
|
new_arr_item = new_arr_item.join(',');
|
|
|
new_arr_item = new_arr_item.replace(/,/g, " ");
|
|
|
for (let i in sys_attrprice) {
|
|
|
if (i == str) {
|
|
|
skuid = sys_attrprice[i].skuid
|
|
|
skuid_price = sys_attrprice[i].price
|
|
|
old_skuid_price = sys_attrprice[i].old_price
|
|
|
vip_skuid_price = sys_attrprice[i].vip_price
|
|
|
|
|
|
ele.ggid = skuid;
|
|
|
var ggprice = 0
|
|
|
if (t.data.is_vip == 1) {
|
|
|
ggprice = vip_skuid_price
|
|
|
} else {
|
|
|
ggprice = skuid_price
|
|
|
}
|
|
|
ele.ggprice = ggprice
|
|
|
ele.arr = new_arr
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
t.setData({
|
|
|
goodsList: goods
|
|
|
})
|
|
|
console.log(101010101)
|
|
|
},
|
|
|
//skuid加入skuid_arr
|
|
|
hide_mask1(e) {
|
|
|
var skuid_arr = this.data.skuid_arr
|
|
|
var skuid1 = this.data.skuid1
|
|
|
var indexs = e.currentTarget.dataset.index
|
|
|
if (skuid1 != 0) {
|
|
|
// skuid_arr.push(skuid1)
|
|
|
}
|
|
|
})
|
|
|
this.setData({
|
|
|
show1: false,
|
|
|
skuid_arr: skuid_arr
|
|
|
})
|
|
|
},
|
|
|
//立即购买
|
|
|
go_pay_sale() {
|
|
|
var that = this
|
|
|
var goodsList = that.data.showList
|
|
|
var skuid_arr = []
|
|
|
var total_price = 0
|
|
|
goodsList.forEach(function(ele, index) {
|
|
|
var skuid = ele.ggid
|
|
|
if (ele.ggprice) {
|
|
|
ele.ggprice = ele.ggprice.substring(0, ele.ggprice.length - 3)
|
|
|
}
|
|
|
var price = ele.ggprice * 1
|
|
|
if (ele.stock > 0) {
|
|
|
if (ele.ggid && ele.ggid != 0) {
|
|
|
total_price += price
|
|
|
skuid_arr.push(skuid)
|
|
|
} else {
|
|
|
wx.showToast({
|
|
|
title: '本件商品没有规格属性',
|
|
|
icon: 'none',
|
|
|
duration: 1000
|
|
|
})
|
|
|
ele.t = false
|
|
|
that.setData({
|
|
|
goodsList: goodsList
|
|
|
})
|
|
|
}
|
|
|
var goods = this.data.showList
|
|
|
goods.forEach(function (ele, index) {
|
|
|
if (index == indexs) {
|
|
|
for (let i = 0; i < ele.attr.attr_sku.length; i++) {
|
|
|
if (ele.arr.length == 1) {
|
|
|
wx.showToast({
|
|
|
title: '请选择全部属性',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
this.setData({
|
|
|
show1: false,
|
|
|
skuid_arr: skuid_arr
|
|
|
})
|
|
|
},
|
|
|
//立即购买
|
|
|
go_pay_sale() {
|
|
|
var that = this
|
|
|
var goodsList = that.data.showList
|
|
|
var skuid_arr = []
|
|
|
var total_price = 0
|
|
|
goodsList.forEach(function (ele, index) {
|
|
|
var skuid = ele.ggid
|
|
|
if (ele.ggprice) {
|
|
|
ele.ggprice = ele.ggprice.substring(0, ele.ggprice.length - 3)
|
|
|
}
|
|
|
var price = ele.ggprice * 1
|
|
|
if (ele.stock > 0) {
|
|
|
if (ele.ggid && ele.ggid != 0) {
|
|
|
total_price += price
|
|
|
skuid_arr.push(skuid)
|
|
|
} else {
|
|
|
wx.showToast({
|
|
|
title: '本件商品没有规格属性',
|
|
|
icon: 'none',
|
|
|
duration: 1000
|
|
|
})
|
|
|
ele.t = false
|
|
|
that.setData({
|
|
|
goodsList: goodsList
|
|
|
})
|
|
|
}
|
|
|
} else {
|
|
|
wx.showToast({
|
|
|
title: '商品已卖完',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
console.log(total_price + "总价")
|
|
|
wx.navigateTo({
|
|
|
url: '../../my/settle_account/settle_account?pakSale=' + skuid_arr + '&pakId=' + that.data.goods.info.id
|
|
|
} else {
|
|
|
wx.showToast({
|
|
|
title: '商品已卖完',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
},
|
|
|
//选区食品包
|
|
|
changeFlag(e) {
|
|
|
let indexs = e.currentTarget.dataset.index
|
|
|
let that = this
|
|
|
let list = that.data.packageList
|
|
|
let n=0
|
|
|
list.forEach(function (ele, index) {
|
|
|
if (indexs == index) {
|
|
|
ele.t = !ele.t
|
|
|
}
|
|
|
if(ele.t){
|
|
|
n++
|
|
|
}
|
|
|
if(n>that.data.goods.info.num){
|
|
|
wx.showToast({
|
|
|
title: '您最多可选择'+that.data.goods.info.num+'种商品',
|
|
|
icon:'none'
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
that.setData({
|
|
|
packageList: list
|
|
|
})
|
|
|
},
|
|
|
// 跳转图文食谱
|
|
|
get_recipe() {
|
|
|
wx.navigateTo({
|
|
|
url: '../production_steps/production_steps?id=' + this.data.id,
|
|
|
})
|
|
|
},
|
|
|
// 跳转购物车
|
|
|
get_car() {
|
|
|
this.setData({
|
|
|
show: true
|
|
|
});
|
|
|
},
|
|
|
//隐藏mask
|
|
|
hide_masks() {
|
|
|
var that = this
|
|
|
if (that.data.skuid != '') {
|
|
|
that.setData({
|
|
|
shows: false
|
|
|
});
|
|
|
var str = ''
|
|
|
str = that.data.id_arr.join(',');
|
|
|
if (that.data.id_arr.length > 1) {
|
|
|
var gPrice = that.data.num * that.data.gPrice
|
|
|
console.log(gPrice);
|
|
|
if (that.data.is_group == 0) {
|
|
|
wx.navigateTo({
|
|
|
url: '../../my/settle_account/settle_account?ids=' + that.data.skuid + '&gid=' + that.data.id + '&num=' + that.data.num + '&gPrice=' + gPrice
|
|
|
})
|
|
|
} else {
|
|
|
wx.navigateTo({
|
|
|
url: '../../my/settle_account/settle_account?ids=' + that.data.skuid + '&gid=' + that.data.id + '&num=' + that.data.num + '&gPrice=' + gPrice + '&is_group=' + that.data.is_group
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
}
|
|
|
})
|
|
|
console.log(total_price + "总价")
|
|
|
wx.navigateTo({
|
|
|
url: '../../my/settle_account/settle_account?pakSale=' + skuid_arr + '&pakId=' + that.data.goods.info.id
|
|
|
})
|
|
|
},
|
|
|
//选区食品包
|
|
|
changeFlag(e) {
|
|
|
let indexs = e.currentTarget.dataset.index
|
|
|
let that = this
|
|
|
let list = that.data.packageList
|
|
|
let n = that.data.countn
|
|
|
list.forEach(function(ele, index) {
|
|
|
if (indexs == index) {
|
|
|
if(ele.t){
|
|
|
n--
|
|
|
ele.t=false
|
|
|
}else{
|
|
|
n++
|
|
|
if(n>that.data.goods.info.num){
|
|
|
wx.showToast({
|
|
|
title: '请先选择商品属性组合',
|
|
|
icon: 'none'
|
|
|
title: '您最多选择'+that.data.goods.info.num+'种商品',
|
|
|
icon:'none'
|
|
|
})
|
|
|
ele.t = false
|
|
|
n--
|
|
|
}else{
|
|
|
ele.t=true
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
//跳至图文详情
|
|
|
jump_detail() {
|
|
|
this.setData({
|
|
|
active: false
|
|
|
});
|
|
|
wx.pageScrollTo({
|
|
|
scrollTop: 1200,
|
|
|
duration: 300
|
|
|
})
|
|
|
},
|
|
|
jump_goods() {
|
|
|
this.setData({
|
|
|
active: true
|
|
|
});
|
|
|
wx.pageScrollTo({
|
|
|
scrollTop: 0,
|
|
|
duration: 300
|
|
|
})
|
|
|
},
|
|
|
//收藏
|
|
|
collection() {
|
|
|
this.setData({
|
|
|
shoucang: !this.data.shoucang
|
|
|
});
|
|
|
},
|
|
|
}
|
|
|
})
|
|
|
that.setData({
|
|
|
packageList: list,
|
|
|
countn: n
|
|
|
})
|
|
|
},
|
|
|
// 跳转图文食谱
|
|
|
get_recipe() {
|
|
|
wx.navigateTo({
|
|
|
url: '../production_steps/production_steps?id=' + this.data.id,
|
|
|
})
|
|
|
},
|
|
|
// 跳转购物车
|
|
|
get_car() {
|
|
|
this.setData({
|
|
|
show: true
|
|
|
});
|
|
|
},
|
|
|
//隐藏mask
|
|
|
hide_masks() {
|
|
|
var that = this
|
|
|
if (that.data.skuid != '') {
|
|
|
that.setData({
|
|
|
shows: false
|
|
|
});
|
|
|
var str = ''
|
|
|
str = that.data.id_arr.join(',');
|
|
|
if (that.data.id_arr.length > 1) {
|
|
|
var gPrice = that.data.num * that.data.gPrice
|
|
|
console.log(gPrice);
|
|
|
if (that.data.is_group == 0) {
|
|
|
wx.navigateTo({
|
|
|
url: '../../my/settle_account/settle_account?ids=' + that.data.skuid + '&gid=' + that.data.id + '&num=' + that.data.num + '&gPrice=' + gPrice
|
|
|
})
|
|
|
} else {
|
|
|
wx.navigateTo({
|
|
|
url: '../../my/settle_account/settle_account?ids=' + that.data.skuid + '&gid=' + that.data.id + '&num=' + that.data.num + '&gPrice=' + gPrice + '&is_group=' + that.data.is_group
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
wx.showToast({
|
|
|
title: '请先选择商品属性组合',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
//跳至图文详情
|
|
|
jump_detail() {
|
|
|
this.setData({
|
|
|
active: false
|
|
|
});
|
|
|
wx.pageScrollTo({
|
|
|
scrollTop: 1200,
|
|
|
duration: 300
|
|
|
})
|
|
|
},
|
|
|
jump_goods() {
|
|
|
this.setData({
|
|
|
active: true
|
|
|
});
|
|
|
wx.pageScrollTo({
|
|
|
scrollTop: 0,
|
|
|
duration: 300
|
|
|
})
|
|
|
},
|
|
|
//收藏
|
|
|
collection() {
|
|
|
this.setData({
|
|
|
shoucang: !this.data.shoucang
|
|
|
});
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
|
|
onReady: function () {
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
|
|
onReady: function() {
|
|
|
|
|
|
},
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
onShow: function () {
|
|
|
/**
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
onShow: function() {
|
|
|
|
|
|
},
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
*/
|
|
|
onHide: function () {
|
|
|
/**
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
*/
|
|
|
onHide: function() {
|
|
|
|
|
|
},
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
*/
|
|
|
onUnload: function () {
|
|
|
/**
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
*/
|
|
|
onUnload: function() {
|
|
|
|
|
|
},
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
*/
|
|
|
onPullDownRefresh: function () {
|
|
|
/**
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
*/
|
|
|
onPullDownRefresh: function() {
|
|
|
|
|
|
},
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
*/
|
|
|
onReachBottom: function () {
|
|
|
/**
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
*/
|
|
|
onReachBottom: function() {
|
|
|
|
|
|
},
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 用户点击右上角分享
|
|
|
*/
|
|
|
onShareAppMessage: function () {
|
|
|
var shareObj = {
|
|
|
// title: options.target.dataset.title, // 默认是小程序的名称(可以写slogan等)
|
|
|
path: '/pages/start/start',
|
|
|
imgUrl: '',
|
|
|
title: ''
|
|
|
}
|
|
|
// if (options.from == 'button') {
|
|
|
// // 此处可以修改 shareObj 中的内容
|
|
|
// shareObj.path = '/pages/start/start?status=' + options.target.dataset.status
|
|
|
// }
|
|
|
return shareObj;
|
|
|
/**
|
|
|
* 用户点击右上角分享
|
|
|
*/
|
|
|
onShareAppMessage: function() {
|
|
|
var shareObj = {
|
|
|
// title: options.target.dataset.title, // 默认是小程序的名称(可以写slogan等)
|
|
|
path: '/pages/start/start',
|
|
|
imgUrl: '',
|
|
|
title: ''
|
|
|
}
|
|
|
// if (options.from == 'button') {
|
|
|
// // 此处可以修改 shareObj 中的内容
|
|
|
// shareObj.path = '/pages/start/start?status=' + options.target.dataset.status
|
|
|
// }
|
|
|
return shareObj;
|
|
|
}
|
|
|
}) |
|
|
\ No newline at end of file |
...
|
...
|
|