929 lines
26 KiB
JavaScript
929 lines
26 KiB
JavaScript
// packageH/starMusic/starMusicGroupDetails/starMusicGroupDetails.js
|
||
var app = getApp();
|
||
var WxParse = require("../../../wxParse/wxParse.js");
|
||
Page({
|
||
/**
|
||
* 页面的初始数据
|
||
*/
|
||
data: {
|
||
language: "",
|
||
// 图片域名
|
||
imagUrl: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/",
|
||
// current: 1,
|
||
showOpenGroup: false,
|
||
// show2: false,
|
||
// datop: false,
|
||
groupStock: 1, // 当前拼团商品的库存
|
||
|
||
// 判断显示限时还是结束
|
||
istime: false,
|
||
// 是否有更多评论
|
||
//noMoreComment: false,
|
||
// 初始评论页数
|
||
//commentPage: 1,
|
||
//posterShow: false, // 商品分享二维码显示
|
||
//hoet: false,
|
||
|
||
popStock: 0, // 库存
|
||
popPrice: 0,
|
||
|
||
gooddatas: {}, // 总商品数据
|
||
goodsInfo: {}, // 商品详情信息
|
||
activityId: "", // 活动id
|
||
goodsId: "",
|
||
// group_price: '', // 拼团价
|
||
// goodsDescription: '',
|
||
goodsCount: 1, // 购买数量
|
||
// team: [], //成团信息
|
||
//show1: true,
|
||
|
||
// 商品详情
|
||
first_content: "",
|
||
second_content: "",
|
||
|
||
activeName: "first",
|
||
end_time: "", // 截止结束时间
|
||
start_time: "", // 截止开始时间
|
||
// 轮播高度自适应
|
||
aheight: 750,
|
||
// end_time_team: '', // 团队结束时间
|
||
// option_level_id: '', // 规格层级id
|
||
heightDome: "", // 高度
|
||
nowTime: "", // 现在的时间
|
||
iPnoneBottomBol: false,
|
||
// isCheckActivity: true, //下单前检查客户今天是否超出限制
|
||
showGoodslist: false,
|
||
//活动是否结束
|
||
isTimeEnd: false,
|
||
begTimeStr: "",
|
||
//限时购据开始时间倒计时
|
||
beginDownObj: {
|
||
day: "00",
|
||
hou: "00",
|
||
min: "00",
|
||
sec: "00",
|
||
},
|
||
leader_partake: 1, //团长是否参与中奖 1-是 2-否
|
||
getMarketPrice: "",
|
||
goodType: null, //商品类型: 拼购商品 groupBuy ||抢团商品 grabGroup
|
||
|
||
// 规格 -------
|
||
optionsId: 0, //选择后的 规格ID
|
||
popupSpecs: false,
|
||
optionsMaxCount: 1,
|
||
popupSpecs2: false, //无规格选择商品数量
|
||
popThumb: "",
|
||
specsManage: [], //选择池 用于排序
|
||
goodsDescription: "",
|
||
popupModeshow: true, //动态模糊框
|
||
// 规格end
|
||
isAward: 1, //下单时选择是否参与中奖
|
||
|
||
explainFlag: false,
|
||
joinListShow: false,
|
||
joinListData: [],
|
||
team_state: 0,
|
||
activity_state: 0,
|
||
is_join: 0,
|
||
explainText: "",
|
||
service_mobile: "",
|
||
service_QRcode: "",
|
||
xqBoxShow: true,
|
||
win_data: {},
|
||
isCountDown: false,
|
||
|
||
is_dividend: 0, //是否经销商
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面加载
|
||
*/
|
||
onLoad: function (options) {
|
||
if (options.mid) {
|
||
app._setMid(option.mid);
|
||
}
|
||
this.data.activityId = options.id;
|
||
this.getiPnoneBottom();
|
||
let language = wx.getStorageSync("langIndex");
|
||
this.setData({
|
||
language: language.en,
|
||
});
|
||
|
||
this.getData();
|
||
},
|
||
|
||
setExplainFlag() {
|
||
this.setData({
|
||
explainFlag: !this.data.explainFlag,
|
||
});
|
||
},
|
||
|
||
openKfServerFlag() {
|
||
this.setData({
|
||
kfServerFlag: !this.data.kfServerFlag,
|
||
});
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面初次渲染完成
|
||
*/
|
||
onReady: function () {},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面显示
|
||
*/
|
||
onShow: function () {},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面隐藏
|
||
*/
|
||
onHide: function () {},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面卸载
|
||
*/
|
||
onUnload: function () {},
|
||
|
||
/**
|
||
* 页面相关事件处理函数--监听用户下拉动作
|
||
*/
|
||
onPullDownRefresh: function () {},
|
||
|
||
/**
|
||
* 页面上拉触底事件的处理函数
|
||
*/
|
||
onReachBottom: function () {},
|
||
|
||
/**
|
||
* 用户点击右上角分享
|
||
*/
|
||
onShareAppMessage: function () {
|
||
let value = wx.getStorageSync("yz_uid");
|
||
let mid = "";
|
||
if (value) {
|
||
mid = value;
|
||
}
|
||
return {
|
||
path: "packageH/starMusic/starMusicGroupDetails/starMusicGroupDetails?id=" +
|
||
this.data.activityId +
|
||
"&mid=" +
|
||
mid,
|
||
};
|
||
},
|
||
setJoinListShow() {
|
||
this.setData({
|
||
joinListShow: !this.data.joinListShow,
|
||
});
|
||
},
|
||
getiPnoneBottom() {
|
||
let that = this;
|
||
try {
|
||
var value = wx.getStorageSync("iPhoneBottom");
|
||
if (value) {
|
||
that.setData({
|
||
iPnoneBottomBol: true,
|
||
});
|
||
// Do something with return value
|
||
}
|
||
} catch (e) {
|
||
// Do something when catch error
|
||
}
|
||
},
|
||
showGoodslistM() {
|
||
this.setData({
|
||
showGoodslist: true,
|
||
});
|
||
},
|
||
clicktapshow() {
|
||
this.setData({
|
||
showGoodslist: false,
|
||
});
|
||
},
|
||
|
||
gotoShopGoods(e) {
|
||
let _id = e.target.dataset.id || e.currentTarget.dataset.id;
|
||
wx.navigateTo({
|
||
url: "/packageA/detail_v2/detail_v2?id=" + _id,
|
||
});
|
||
},
|
||
|
||
imageLoad(res) {
|
||
if (res.target.dataset.index == 1) {
|
||
this.setData({
|
||
heightDome: res.detail.height,
|
||
});
|
||
}
|
||
},
|
||
|
||
// 获取数据
|
||
getData() {
|
||
let urlStr = null;
|
||
urlStr = app.getNetAddresss("plugin.star-spell.frontend.index.teamDetail");
|
||
urlStr += "&leader_id=" + this.data.activityId;
|
||
|
||
app._getNetWork({
|
||
url: urlStr,
|
||
success: (resdata) => {
|
||
var res = resdata.data;
|
||
if (res.result == 1) {
|
||
console.log("team", res.data.team);
|
||
let thumb = [];
|
||
thumb.push(res.data.goods.thumb);
|
||
this.setData({
|
||
gooddatas: res.data.goods,
|
||
popStock: res.data.goods.stock,
|
||
goodsId: res.data.goods.goods_id,
|
||
joinListData: res.data.team,
|
||
explainText: res.data.explain,
|
||
end_time: res.data.goods.end_time,
|
||
"gooddatas.thumb": thumb,
|
||
team_state: res.data.team_state,
|
||
activity_state: res.data.activity_state,
|
||
is_join: res.data.is_join,
|
||
service_mobile: res.data.cservice.service_mobile,
|
||
service_QRcode: res.data.cservice.service_QRcode,
|
||
win_data: res.data.win_data,
|
||
is_dividend: res.data.is_dividend,
|
||
});
|
||
//console.log("team",this.data.team,res.data.team)
|
||
this.initPopView(); //初始化弹窗view
|
||
// if (this.data.goodType == 'groupBuy') {
|
||
|
||
// 分享的自定义图片
|
||
wx.setStorageSync("GoddsShareImg", thumb[0]);
|
||
this.triggerEvent("parentEvent", [this.data.gooddatas.title]);
|
||
let start_time = new Date().getTime() / 1000;
|
||
this.setData({
|
||
nowTime: start_time,
|
||
});
|
||
|
||
this._timeCompare(res.data.goods.end_time);
|
||
|
||
let article = this.data.first_content;
|
||
try {
|
||
if (article.indexOf("&#") <= -1) {
|
||
WxParse.wxParse("article", "html", article, this);
|
||
}
|
||
} catch (e) {
|
||
//TODO handle the exception
|
||
}
|
||
let explainText = res.data.explain;
|
||
try {
|
||
if (article.indexOf("&#") <= -1) {
|
||
WxParse.wxParse("explainText", "html", explainText, this);
|
||
}
|
||
} catch (e) {
|
||
//TODO handle the exception
|
||
}
|
||
|
||
// WxParse.wxParse('article', 'html', article, this)
|
||
} else {
|
||
wx.showToast({
|
||
icon: "none",
|
||
title: res.msg,
|
||
duration: 1500,
|
||
});
|
||
}
|
||
},
|
||
});
|
||
},
|
||
|
||
//查看大图
|
||
seePicture(evt) {
|
||
let pics = evt.currentTarget.dataset.pics;
|
||
let index = evt.currentTarget.dataset.index;
|
||
wx.previewImage({
|
||
current: pics[index], // 当前显示图片的http链接
|
||
urls: pics, // 需要预览的图片http链接列表
|
||
});
|
||
},
|
||
|
||
// 跳转主页
|
||
gotoHome() {
|
||
wx.reLaunch({
|
||
url: '/packageG/index/index',
|
||
});
|
||
},
|
||
gotoStarMusicOpenGroup() {
|
||
wx.reLaunch({
|
||
url: "/packageH/starMusic/starMusicOpenGroup/starMusicOpenGroup",
|
||
});
|
||
},
|
||
gotoStarMusicIndex() {
|
||
wx.reLaunch({
|
||
url: "/packageH/starMusic/starMusicIndex/starMusicIndex",
|
||
});
|
||
},
|
||
|
||
// 选择规格
|
||
checkGroup(e) {
|
||
let index = e.target.dataset.index || e.currentTarget.dataset.index;
|
||
let arr = this.data.has_many_level;
|
||
arr[index].bool = !arr[index].bool;
|
||
this.setData({
|
||
has_many_level: arr,
|
||
});
|
||
},
|
||
|
||
//获取时间-限时购
|
||
_timeCompare(begin) {
|
||
let beginTime = new Date().getTime() / 1000;
|
||
console.log("begin", begin, beginTime);
|
||
if (begin >= beginTime) {
|
||
this.setData({
|
||
isTime: true,
|
||
});
|
||
//开启倒计时
|
||
this._countDown();
|
||
}
|
||
},
|
||
//倒计时
|
||
_countDown: function () {
|
||
let newTime = new Date().getTime();
|
||
let endTime = this.data.gooddatas.end_time * 1000;
|
||
let obj = null;
|
||
if (endTime - newTime > 0) {
|
||
let time = (endTime - newTime) / 1000;
|
||
// 获取天、时、分、秒
|
||
let day = parseInt(time / (60 * 60 * 24));
|
||
let hou = parseInt((time % (60 * 60 * 24)) / 3600);
|
||
let min = parseInt(((time % (60 * 60 * 24)) % 3600) / 60);
|
||
let sec = parseInt(((time % (60 * 60 * 24)) % 3600) % 60);
|
||
obj = {
|
||
day: this._timeFormat(day),
|
||
hou: this._timeFormat(hou),
|
||
min: this._timeFormat(min),
|
||
sec: this._timeFormat(sec),
|
||
};
|
||
} else {
|
||
//活动已结束,全部设置为'00'
|
||
// this.setData({team_state:false})
|
||
obj = {
|
||
day: "00",
|
||
hou: "00",
|
||
min: "00",
|
||
sec: "00",
|
||
};
|
||
}
|
||
this.setData({
|
||
countDownObj: obj,
|
||
});
|
||
// console.log('gggggggggggggggg',endTime ,newTime )
|
||
if (endTime - newTime < 0) {
|
||
this.setData({
|
||
countDownObj: {
|
||
day: "00",
|
||
hou: "00",
|
||
min: "00",
|
||
sec: "00",
|
||
},
|
||
isTimeEnd: true,
|
||
});
|
||
} else {
|
||
setTimeout(this._countDown.bind(this), 1000);
|
||
}
|
||
},
|
||
//小于10的格式化函数
|
||
_timeFormat(param) {
|
||
//小于10的格式化函数
|
||
return param < 10 ? "0" + param : param;
|
||
},
|
||
showPopView(e) {
|
||
if (
|
||
this.data.gooddatas.has_option == 1 &&
|
||
(app._isTextEmpty(this.data.optionsId) || this.data.optionsId == 0)
|
||
) {
|
||
// 默认选择第一个
|
||
for (let i = 0; i < this.data.gooddatas.has_many_specs.length; i++) {
|
||
this.data.gooddatas.has_many_specs[
|
||
i
|
||
].description = this.data.gooddatas.has_many_specs[i].specitem[0].id;
|
||
this.selectSpecs(
|
||
this.data.gooddatas.has_many_specs[i].specitem[0],
|
||
"first",
|
||
i
|
||
);
|
||
}
|
||
}
|
||
this.setData({
|
||
isAward: e.currentTarget.dataset.type,
|
||
popupSpecs: true,
|
||
popupModeshow: false,
|
||
});
|
||
},
|
||
//关闭popupSpecs
|
||
popupSpecsbtn() {
|
||
this.setData({
|
||
popupSpecs: false,
|
||
popupModeshow: true,
|
||
});
|
||
},
|
||
//初始化弹窗view
|
||
initPopView() {
|
||
// try {
|
||
// this.setData({
|
||
// 'gooddatas.has_option': this.data.gooddatas.has_many_specs.length > 0 ? 1 : 0
|
||
// })
|
||
// } catch (error) {
|
||
// this.setData({
|
||
// 'gooddatas.has_option': 0
|
||
// })
|
||
// }
|
||
|
||
console.log("执行initPopView");
|
||
if (this.data.gooddatas.has_option == 1) {
|
||
this.setData({
|
||
popPrice: this.data.gooddatas.min_price + "-" + this.data.gooddatas.max_price, //设置默认价格
|
||
popThumb: this.data.gooddatas.thumb, //设置默认图片
|
||
popStock: this.data.gooddatas.stock, //设置默认库存
|
||
goodsDescription: "选择",
|
||
});
|
||
for (let i = 0; i < this.data.gooddatas.has_many_specs.length; i++) {
|
||
this.setData({
|
||
goodsDescription: this.data.goodsDescription +
|
||
" " +
|
||
this.data.gooddatas.has_many_specs[i].title,
|
||
});
|
||
}
|
||
} else {
|
||
this.setData({
|
||
popThumb: this.data.gooddatas.thumb, //设置默认图片
|
||
popStock: this.data.gooddatas.stock, //设置默认库存
|
||
popPrice: this.data.gooddatas.price, //设置默认价格
|
||
goodsDescription: "",
|
||
optionsMaxCount: this.data.gooddatas.stock,
|
||
});
|
||
}
|
||
},
|
||
|
||
// 输入数量
|
||
inputGoodsNum: function (e) {
|
||
var num = parseInt(e.detail.value);
|
||
var lastgoodsCount = this.data.goodsCount;
|
||
if (e.detail.keyCode == 8) {
|
||
if (app._isTextEmpty(e.detail.value)) {
|
||
this.setData({
|
||
goodsCount: "",
|
||
});
|
||
return;
|
||
}
|
||
}
|
||
if (num) {
|
||
this.setData({
|
||
goodsCount: num,
|
||
});
|
||
} else {
|
||
this.setData({
|
||
goodsCount: lastgoodsCount,
|
||
});
|
||
}
|
||
},
|
||
//减少
|
||
reduceGoods() {
|
||
let lastgoodsCount = this.data.goodsCount;
|
||
if (this.data.goodsCount == 1 || this.data.goodsCount == 0) {
|
||
return;
|
||
}
|
||
this.setData({
|
||
goodsCount: lastgoodsCount - 1,
|
||
});
|
||
},
|
||
//增加
|
||
addGoods() {
|
||
if (this.data.goodType == "grabGroup") {
|
||
return;
|
||
}
|
||
let lastgoodsCount = this.data.goodsCount;
|
||
let specsManage = this.data.specsManage;
|
||
let optionsMaxCount = this.data.optionsMaxCount;
|
||
console.log("增加");
|
||
if (
|
||
specsManage.length == this.data.gooddatas.has_many_specs.length &&
|
||
this.data.goodsCount == optionsMaxCount
|
||
) {
|
||
console.log("数量超出范围");
|
||
wx.showToast({
|
||
icon: "none",
|
||
title: "数量超出范围",
|
||
duration: 1500,
|
||
});
|
||
console.log("max=" + this.data.goodsCount);
|
||
return;
|
||
}
|
||
this.setData({
|
||
goodsCount: lastgoodsCount + 1,
|
||
});
|
||
},
|
||
//界面选择规格触发事件
|
||
selectSpecs(e, str, i) {
|
||
let data = {};
|
||
let specsIdex = 0;
|
||
if (str == "first") {
|
||
specsIdex = i;
|
||
data = e;
|
||
} else if (str == "sku_swiper") {
|
||
data = e;
|
||
} else {
|
||
specsIdex = e.currentTarget.dataset.specsidex;
|
||
data = e.currentTarget.dataset.specitem;
|
||
}
|
||
|
||
if (data.c) {
|
||
return false;
|
||
}
|
||
this.setData({
|
||
["gooddatas.has_many_specs[" + specsIdex + "].description"]: data.id,
|
||
});
|
||
// let specid = data.specid; //对其他数据筛选 不筛选同级
|
||
//处理选择池
|
||
this.manageSpecs(data);
|
||
//处理规格组合选择状态
|
||
this.setGoodsSpecs(data);
|
||
//设置选择规格后的 价格、照片、库存
|
||
this.setGoodsSpecsChangeInfo();
|
||
//判断当前购买总量与库存的关系
|
||
this.getMaxCount();
|
||
},
|
||
//处理选择池
|
||
manageSpecs(data) {
|
||
let specsObject = new Object();
|
||
let specsManage = this.data.specsManage;
|
||
specsObject.id = data.id;
|
||
specsObject.specid = data.specid;
|
||
specsObject.title = data.title;
|
||
|
||
if (specsManage.length > 0) {
|
||
for (let i = 0; i < specsManage.length; i++) {
|
||
if (specsManage[i].specid == specsObject.specid) {
|
||
specsManage.splice(i, 1);
|
||
}
|
||
}
|
||
specsManage.push(specsObject);
|
||
} else {
|
||
specsManage.push(specsObject);
|
||
}
|
||
|
||
//排序
|
||
if (specsManage.length == this.data.gooddatas.has_many_specs.length) {
|
||
var newSpecsManage = [];
|
||
for (let i = 0; i < this.data.gooddatas.has_many_specs.length; i++) {
|
||
for (let j = 0; j < specsManage.length; j++) {
|
||
if (
|
||
this.data.gooddatas.has_many_specs[i].id == specsManage[j].specid
|
||
) {
|
||
newSpecsManage.push(specsManage[j]);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
specsManage = newSpecsManage;
|
||
}
|
||
this.setData({
|
||
specsManage: specsManage,
|
||
});
|
||
this.setGoodsDescription();
|
||
},
|
||
//处理goodsDescription 数据
|
||
setGoodsDescription() {
|
||
let description = "";
|
||
let specsManage = this.data.specsManage;
|
||
//相等代表全选了 体现语句
|
||
if (specsManage.length == this.data.gooddatas.has_many_specs.length) {
|
||
description = "已选择 ";
|
||
for (let i = 0; i < specsManage.length; i++) {
|
||
description += specsManage[i].title + " ";
|
||
}
|
||
this.setData({
|
||
goodsDescription: description,
|
||
});
|
||
} else {
|
||
description = "请选择 ";
|
||
for (let i = 0; i < this.data.gooddatas.has_many_specs.length; i++) {
|
||
for (let j = 0; j < specsManage.length; j++) {
|
||
if (
|
||
this.data.gooddatas.has_many_specs[i].id != specsManage[j].specid
|
||
) {
|
||
description += this.data.gooddatas.has_many_specs[i].title + " ";
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
this.setData({
|
||
goodsDescription: description,
|
||
});
|
||
}
|
||
},
|
||
//处理规格组合选择状态 过滤数据
|
||
setGoodsSpecs(specs) {
|
||
// let gooddatas = this.data.gooddatas;
|
||
for (let i = 0; i < this.data.gooddatas.has_many_specs.length; i++) {
|
||
if (specs.specid != this.data.gooddatas.has_many_specs[i].id) {
|
||
// let specitem = this.setGoodsSpecsStatus(
|
||
// this.data.gooddatas.has_many_specs[i].specitem,
|
||
// specs.id
|
||
// );
|
||
// this.setData({
|
||
// ["gooddatas.has_many_specs[" + i + "].specitem"]: specitem
|
||
// })
|
||
}
|
||
}
|
||
},
|
||
//处理规格组合选择状态 处理状态 specitem 组合数组(未选中的) id当前选中的ID 根据ID 组合算是否有当前组合
|
||
setGoodsSpecsStatus(specitem, id) {
|
||
let options = []; //数据池
|
||
if (this.data.gooddatas && this.data.gooddatas.has_many_options) {
|
||
for (let i = 0; i < this.data.gooddatas.has_many_options.length; i++) {
|
||
let _specs = this.data.gooddatas.has_many_options[i].specs.split("_");
|
||
//console.log(_specs);
|
||
//判断是否包含
|
||
for (let j = 0; j < _specs.length; j++) {
|
||
if (_specs[j] == id) {
|
||
options.push(this.data.gooddatas.has_many_options[i]);
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//关键处理方式 后期要优化 效率低
|
||
for (let m = 0; m < options.length; m++) {
|
||
let _specs = options[m].specs.split("_");
|
||
for (let y = 0; y < _specs.length; y++) {
|
||
if (_specs[y] != id && options[m].stock == 0) {
|
||
for (let n = 0; n < specitem.length; n++) {
|
||
if (_specs[y] == specitem[n].id) {
|
||
specitem[n].c = true;
|
||
}
|
||
}
|
||
} else if (_specs[y] != id && options[m].stock > 0) {
|
||
for (let n = 0; n < specitem.length; n++) {
|
||
if (_specs[y] == specitem[n].id) {
|
||
specitem[n].c = false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return specitem;
|
||
},
|
||
//设置选择规格后的 价格、照片、库存
|
||
setGoodsSpecsChangeInfo() {
|
||
let specsManage = this.data.specsManage;
|
||
//根据ID 排序 specsManage.sort();
|
||
specsManage.sort(function (a, b) {
|
||
return a.id - b.id;
|
||
});
|
||
if (specsManage.length == this.data.gooddatas.has_many_specs.length) {
|
||
let goodsSpecs = "";
|
||
for (let j = 0; j < specsManage.length; j++) {
|
||
goodsSpecs += specsManage[j].id + "_";
|
||
}
|
||
goodsSpecs = goodsSpecs.substring(0, goodsSpecs.length - 1); //处理"_"
|
||
if (this.data.gooddatas && this.data.gooddatas.has_many_options) {
|
||
for (let i = 0; i < this.data.gooddatas.has_many_options.length; i++) {
|
||
if (
|
||
goodsSpecs ==
|
||
this.setGoodsSpecsBySort(
|
||
this.data.gooddatas.has_many_options[i].specs
|
||
)
|
||
) {
|
||
this.setData({
|
||
activeSkuIndex: i,
|
||
popPrice: this.data.gooddatas.has_many_options[i].product_price, //设置价格
|
||
popThumb: app._isTextEmpty(
|
||
this.data.gooddatas.has_many_options[i].thumb
|
||
) ?
|
||
this.data.gooddatas.thumb : this.data.gooddatas.has_many_options[i].thumb, //设置图片
|
||
popStock: this.data.gooddatas.has_many_options[i].stock, //设置库存
|
||
optionsId: this.data.gooddatas.has_many_options[i].id, //设置规格ID,用于生成订单
|
||
});
|
||
this.data.optionsMaxCount = this.data.gooddatas.has_many_options[
|
||
i
|
||
].stock; //库存最大数 用于切换更改买家购买数量
|
||
if (this.data.optionsMaxCount > 0) {
|
||
this.setData({
|
||
activeSkuIndex: i,
|
||
popPrice: this.data.gooddatas.has_many_options[i].product_price, //设置价格
|
||
popThumb: app._isTextEmpty(
|
||
this.data.gooddatas.has_many_options[i].thumb
|
||
) ?
|
||
this.data.gooddatas.thumb :
|
||
this.data.gooddatas.has_many_options[i].thumb, //设置图片
|
||
popStock: this.data.gooddatas.has_many_options[i].stock, //设置库存
|
||
optionsId: this.data.gooddatas.has_many_options[i].id, //设置规格ID,用于生成订单
|
||
});
|
||
this.data.optionsMaxCount = this.data.gooddatas.has_many_options[
|
||
i
|
||
].stock; //库存最大数 用于切换更改买家购买数量
|
||
if (this.data.optionsMaxCount > 0) {
|
||
this.setData({
|
||
goodsCount: 1,
|
||
});
|
||
}
|
||
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
this.setData({
|
||
specsManage: specsManage,
|
||
});
|
||
},
|
||
//处理商品goodsSpecs 并排序 新方法
|
||
setGoodsSpecsBySort(specs) {
|
||
let _specs = specs.split("_"); //先变成数组
|
||
//_specs.sort();//排序
|
||
_specs.sort(function (a, b) {
|
||
return a - b;
|
||
});
|
||
// 在组装回去
|
||
let goodsSpecs = "";
|
||
for (let j = 0; j < _specs.length; j++) {
|
||
goodsSpecs += _specs[j] + "_";
|
||
}
|
||
goodsSpecs = goodsSpecs.substring(0, goodsSpecs.length - 1); //处理"_"
|
||
return goodsSpecs;
|
||
},
|
||
//判断当前购买总量与库存的关系
|
||
getMaxCount() {
|
||
let specsManage = this.data.specsManage;
|
||
let optionsMaxCount = this.data.optionsMaxCount;
|
||
if (specsManage.length == this.data.gooddatas.has_many_specs.length) {
|
||
if (optionsMaxCount == 0) {
|
||
//库存不足
|
||
this.setData({
|
||
goodsCount: 0,
|
||
});
|
||
}
|
||
if (this.data.goodsCount > optionsMaxCount) {
|
||
this.setData({
|
||
goodsCount: optionsMaxCount,
|
||
});
|
||
}
|
||
}
|
||
},
|
||
OpenLeader() {
|
||
let urlStr = app.getNetAddresss(
|
||
"plugin.snatch-regiment.api.team.OpenLeader"
|
||
);
|
||
urlStr +=
|
||
"&at_id=" + this.data.activityId + "&goods_id=" + this.data.goodsId;
|
||
|
||
app._getNetWork({
|
||
url: urlStr,
|
||
success: (resdata) => {
|
||
var res = resdata.data;
|
||
if (res.result == 1) {
|
||
wx.showToast({
|
||
icon: "none",
|
||
title: "开团成功!",
|
||
duration: 1500,
|
||
});
|
||
wx.navigateTo({
|
||
url: "/packageE/grab_group/grab_group_my/grab_group_my",
|
||
});
|
||
} else {
|
||
wx.showToast({
|
||
icon: "none",
|
||
title: res.msg,
|
||
duration: 1500,
|
||
});
|
||
}
|
||
},
|
||
});
|
||
},
|
||
sendJoinGroup() {
|
||
if (this.data.optionsMaxCount == 0) {
|
||
wx.showToast({
|
||
icon: "none",
|
||
title: "商品库存不足",
|
||
duration: 1500,
|
||
});
|
||
return;
|
||
}
|
||
if (this.data.goodsCount <= 0) {
|
||
wx.showToast({
|
||
icon: "none",
|
||
title: "请选择商品数量",
|
||
duration: 1500,
|
||
});
|
||
return;
|
||
}
|
||
console.log(this.data.gooddatas);
|
||
if (this.data.gooddatas.qualified_vip == true) {
|
||
wx.showActionSheet({
|
||
itemList: ["积分参团", "付款参团"],
|
||
success: (res) => {
|
||
console.log(res.tapIndex);
|
||
if (res.tapIndex == 0) {
|
||
this.winJoinGroup();
|
||
} else if (res.tapIndex == 1) this.nowinJoinGroup();
|
||
},
|
||
});
|
||
} else {
|
||
this.nowinJoinGroup();
|
||
}
|
||
},
|
||
winJoinGroup() {
|
||
let urlStr = app.getNetAddresss(
|
||
"plugin.star-spell.frontend.team.vipJoinTeam"
|
||
);
|
||
app._postNetWork({
|
||
showToastIn: false,
|
||
data: {
|
||
goods_data: {
|
||
goods_id: this.data.goodsId,
|
||
option_id: this.data.optionsId,
|
||
total: this.data.goodsCount,
|
||
},
|
||
at_id: this.data.gooddatas.activity_id,
|
||
leader_id: this.data.activityId,
|
||
},
|
||
url: urlStr,
|
||
success: function (resdata) {
|
||
var res = resdata.data;
|
||
app.tips(res.msg);
|
||
if (res.result != 1) return;
|
||
this.getData();
|
||
},
|
||
});
|
||
},
|
||
nowinJoinGroup() {
|
||
let _goodsId = this.data.goodsId;
|
||
let _optionsId = this.data.optionsId;
|
||
let _total = this.data.goodsCount;
|
||
//库存不足
|
||
if (this.data.optionsMaxCount == 0) {
|
||
wx.showToast({
|
||
icon: "none",
|
||
title: "商品库存不足",
|
||
duration: 1500,
|
||
});
|
||
return;
|
||
}
|
||
if (_total <= 0) {
|
||
wx.showToast({
|
||
icon: "none",
|
||
title: "请选择商品数量",
|
||
duration: 1500,
|
||
});
|
||
return;
|
||
}
|
||
let that = this;
|
||
let goods = [];
|
||
goods.push(_goodsId);
|
||
let urlStr = app.getNetAddresss("from.div-from.isDisplay");
|
||
urlStr += "&goods_ids=" + JSON.stringify(goods);
|
||
app._getNetWork({
|
||
showToastIn: false,
|
||
url: urlStr,
|
||
success: function (resdata) {
|
||
var res = resdata.data;
|
||
if (res.result == 1) {
|
||
var _data = res.data;
|
||
console.log("xxxx", _data);
|
||
if (res.data.status && !res.data.member_status) {
|
||
wx.showModal({
|
||
title: "提示",
|
||
content: "购买此商品,请补充您的个人信息",
|
||
success(res) {
|
||
if (res.confirm) {
|
||
//保税真实信息添加
|
||
wx.navigateTo({
|
||
url: "/packageB/member/address/myinfo/myinfo?tag=delta",
|
||
});
|
||
} else if (res.cancel) {
|
||
console.log("用户点击取消");
|
||
}
|
||
},
|
||
});
|
||
} else {
|
||
wx.navigateTo({
|
||
url: "/packageD/buy/myOrder_v2/myOrder_v2?tag=-2" +
|
||
"&optionsId=" +
|
||
_optionsId +
|
||
"&goodsId=" +
|
||
_goodsId +
|
||
"&total=" +
|
||
_total +
|
||
"&type=starGroup" +
|
||
"&at_id=" +
|
||
that.data.gooddatas.activity_id +
|
||
"&leader_id=" +
|
||
that.data.activityId,
|
||
});
|
||
}
|
||
} else {
|
||
wx.showToast({
|
||
icon: "none",
|
||
title: res.msg,
|
||
duration: 1500,
|
||
});
|
||
}
|
||
},
|
||
fail: function (res) {},
|
||
});
|
||
},
|
||
}); |