const app = getApp();
|
var util = require('../../utils/util.js');
|
var api = require('../../utils/service-api.js');
|
|
Page({
|
|
/**
|
* 页面的初始数据
|
*/
|
data: {
|
userInfo: '', //用户信息
|
interval: 2000,
|
duration: 1000,
|
imgUrls: [],
|
imagetext: ['商品介绍', '规格与包装'],
|
currentTabsIndex: 0,
|
checkCollect: true,
|
goodsInfo: {},
|
normspopup: false,
|
currentIndex: 0,
|
id: '',
|
num: 1,
|
whetherSpecification: false, //是否选择规格
|
specification: '', //规格
|
specificationId: '', //规格id
|
specificationPrice: '', //规格价格
|
price: '', //价格
|
originalPrice: '', //划线价
|
normsList: [],
|
currentIndexs: 0,
|
currentIndex: 0,
|
hidden: false,
|
limit: 10,
|
offset: 0,
|
inform: true,
|
hidden: true,
|
shareShow: false,
|
cartProductId: "", //商品id
|
title: "", //商品名
|
imgSrc: "", //商品图片
|
isShare: 0,
|
qrcode: false,
|
djsTime: {}, //倒计时
|
isFirst: 1,//是否第一次进入页面
|
},
|
|
/**
|
* 生命周期函数--监听页面加载
|
*/
|
onLoad: function (options) {
|
var _this = this;
|
var id = options.id; //秒杀id
|
var shopId = options.shopId;
|
var needGetShopInfo = false;
|
|
if (id == undefined) {
|
//通过二维码进入
|
const scene = decodeURIComponent(options.scene);
|
var params = scene.split(",");
|
console.log("扫码参数", params);
|
shopId = params[0];
|
id = params[1];
|
app.shopInfo = {
|
id: shopId
|
};
|
needGetShopInfo = true;
|
}
|
|
//未获取到活动id
|
if (!id) {
|
wx.showModal({
|
title: '提示',
|
content: '产品信息加载失败',
|
showCancel: false
|
})
|
return;
|
} else {
|
_this.setData({
|
id: id
|
});
|
|
}
|
|
//检测用户登录
|
if (!getApp().loginToken) {
|
|
util.userLogin(function() {
|
|
_this.getPageInfo(id);
|
});
|
|
} else {
|
this.getPageInfo(id);
|
|
}
|
|
//获取门店信息
|
if (needGetShopInfo) {
|
setShopInf(shopId);
|
}
|
|
|
},
|
|
|
/**
|
* 秒杀数据
|
*/
|
getPageInfo(id) {
|
|
var _this = this;
|
//处理产品信息
|
util.request({
|
api: api.seckill.findSecKillGoodsInfo + id,
|
method: 'GET',
|
checkLogin: true,
|
callback: function(data) {
|
|
|
let msActivitInfo=data.mapInfo.goodsInfo;
|
let goodsInfo = data.mapInfo.goodsInfo.goods;
|
|
if (goodsInfo.mobileDetails != null) {
|
goodsInfo.mobileDetails = goodsInfo.mobileDetails.replace(/<img /g, '<img class="rich_img" ');
|
console.log(goodsInfo.mobileDetails);
|
}
|
_this.setData({
|
goodsInfo: goodsInfo,
|
imgUrls: goodsInfo.productImgs,
|
normsList: goodsInfo.skus,
|
specification: goodsInfo.skus[0].name,
|
specificationPrice: goodsInfo.skus[0].price,
|
price: goodsInfo.skus[0].price,
|
specificationId: goodsInfo.skus[0].id,
|
imgSrc: goodsInfo.imgMobile,
|
title: goodsInfo.title,
|
hidden: true,
|
//整场秒杀活动信息
|
activity: data.mapInfo.activity,
|
//本产品秒杀活动信息
|
msActivitInfo: msActivitInfo,
|
});
|
_this.djs();
|
|
}})
|
|
|
},
|
|
|
|
/**
|
* 倒计时
|
*/
|
djs() {
|
var _this = this;
|
let time = _this.data.activity.remainTime;
|
|
var interval = setInterval(function() {
|
time--;
|
if (time < 0) {
|
_this.data.activity.actStatus=2;
|
clearInterval(interval);
|
} else {
|
_this.setData({
|
djs: util.getTimeSpance(time),
|
time: time,
|
});
|
}
|
|
}, 1000);
|
},
|
|
|
//从服务器加载门店信息
|
setShopInf(shopId) {
|
util.request({
|
api: api.yuyue.findShopInfoById + "/" + shopId,
|
callback: function(data) {
|
app.shopInfo = data.mapInfo.shopInfo;
|
},
|
checkLogin: true,
|
});
|
},
|
|
|
|
// 立即购买
|
buy() {
|
var _this = this;
|
var userInfo = getApp().userInfo;
|
if (util.isBlank(userInfo.nickName)) {
|
wx.navigateTo({
|
url: '/pages/welcome/welcome?url=back',
|
})
|
}
|
|
|
//判断是否授权头像
|
|
|
// 判断是否绑定过手机号
|
if (util.isBlank(getApp().userInfo.phoneNumber)) {
|
wx.navigateTo({
|
url: '../phone/phone',
|
})
|
} else {
|
|
let goodsInfo = _this.data.goodsInfo;
|
|
if (!_this.data.whetherSpecification) {
|
console.log("存在多个规格,且没有选择过规格,弹出请选择");
|
_this.setData({
|
whetherSpecification: true,
|
normspopup: true
|
});
|
} else {
|
//隐藏规格
|
this.cancelNorms();
|
|
var id = _this.data.goodsInfo.id; // 商品id
|
var cartSkuId = _this.data.specificationId; //规格id
|
var cartNumber = _this.data.num; //数量
|
|
var stockNum = _this.data.msActivitInfo.siRemainCnt;
|
if (stockNum < 1) {
|
wx.showToast({
|
title: "您来晚了,商品已经抢光了",
|
icon: 'none',
|
});
|
return;
|
}
|
//订单参数
|
let orderMsg = {
|
goodsInfo: goodsInfo,
|
cartSkuId: cartSkuId,
|
cartNumber: cartNumber,
|
specification: _this.data.specification,
|
msActivitInfo: _this.data.msActivitInfo,
|
};
|
|
wx.setStorageSync("orderMsg", orderMsg);
|
//进入结算
|
wx.navigateTo({
|
url: '/pages/miaosha/msOrder',
|
})
|
|
}
|
}
|
|
|
|
},
|
|
|
//规格选择
|
norms(e) {
|
var index = e.currentTarget.dataset.index;
|
var value = e.currentTarget.dataset.value;
|
var price = e.currentTarget.dataset.price;
|
var id = e.currentTarget.dataset.id;
|
this.setData({
|
currentIndex: index,
|
specification: value,
|
specificationPrice: price,
|
specificationId: id
|
|
})
|
},
|
|
|
// 显示规格
|
showNorms() {
|
this.setData({
|
whetherSpecification: true,
|
normspopup: true
|
})
|
},
|
|
|
//隐藏规格
|
cancelNorms() {
|
this.setData({
|
normspopup: false
|
})
|
},
|
|
|
/**
|
* 绑定加数量事件
|
*/
|
addCount(e) {
|
var _this = this;
|
let num = _this.data.num;
|
num = num + 1;
|
this.setData({
|
num: num
|
});
|
},
|
|
/**
|
* 绑定减数量事件
|
*/
|
minusCount(e) {
|
var _this = this;
|
let num = _this.data.num;
|
if (num <= 1) {
|
return false;
|
}
|
num = num - 1;
|
this.setData({
|
num: num
|
});
|
},
|
/**
|
* 生命周期函数--监听页面初次渲染完成
|
*/
|
onReady: function () {
|
|
},
|
|
/**
|
* 生命周期函数--监听页面显示
|
*/
|
onShow: function () {
|
|
},
|
|
/**
|
* 生命周期函数--监听页面隐藏
|
*/
|
onHide: function () {
|
|
},
|
|
/**
|
* 生命周期函数--监听页面卸载
|
*/
|
onUnload: function () {
|
|
},
|
|
/**
|
* 页面相关事件处理函数--监听用户下拉动作
|
*/
|
onPullDownRefresh: function () {
|
|
},
|
|
/**
|
* 页面上拉触底事件的处理函数
|
*/
|
onReachBottom: function () {
|
|
},
|
|
|
|
/**
|
* 获取二维码
|
*/
|
getQrcode: function() {
|
|
var _this = this;
|
if (_this.data.qrcode) {
|
wx.previewImage({
|
current: _this.data.qrcode, // 当前显示图片的http链接
|
urls: [_this.data.qrcode] // 需要预览的图片http链接列表
|
})
|
} else {
|
|
var shopId = app.shopInfo.id;
|
const msActivitInfo = _this.data.msActivitInfo;
|
var data = {
|
shopId:shopId,
|
actId: msActivitInfo.actId,
|
scene: shopId + "," + msActivitInfo.id,
|
path: "pages/miaosha/msDetails",
|
skillId: msActivitInfo.id,
|
activityType:3,
|
};
|
|
util.request({
|
|
|
method: "POST",
|
data:data,
|
api: '/wxapi/shareProduct/getProductShareQrcode/',
|
callback: function(data2) {
|
|
|
var qrcode = data2.rows[0].qrcodeUrl
|
console.log(qrcode);
|
_this.setData({
|
qrcode: qrcode,
|
})
|
|
wx.previewImage({
|
current: _this.data.qrcode, // 当前显示图片的http链接
|
urls: [_this.data.qrcode], // 需要预览的图片http链接列表
|
success: function() {
|
|
wx.downloadFile({
|
url: _this.data.qrcode,
|
success: function(res) {
|
console.log(res);
|
//图片保存到本地
|
wx.saveImageToPhotosAlbum({
|
filePath: res.tempFilePath,
|
success: function(data) {
|
wx.showToast({
|
title: '保存成功',
|
icon: 'success',
|
duration: 2000
|
})
|
},
|
fail: function(err) {
|
console.log(err);
|
if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
|
console.log("当初用户拒绝,再次发起授权")
|
wx.openSetting({
|
success(settingdata) {
|
console.log(settingdata)
|
if (settingdata.authSetting['scope.writePhotosAlbum']) {
|
console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
|
} else {
|
console.log('获取权限失败,给出不给权限就无法正常使用的提示')
|
}
|
}
|
})
|
}
|
},
|
complete(res) {
|
console.log(res);
|
}
|
})
|
}
|
})
|
}
|
})
|
|
|
}
|
})
|
|
|
}
|
|
|
},
|
//取消领券弹窗选择
|
popupTap(e) {
|
this.setData({
|
popup: false,
|
normspopup: false,
|
telShow: false,
|
shareShow: false
|
})
|
},
|
|
//隐藏规格
|
cancelNorms() {
|
this.setData({
|
normspopup: false
|
})
|
},
|
/**
|
* 分享
|
*/
|
formSubmit: function (e) {
|
console.log('获取二维码:', e)
|
this.getQrcode()
|
},
|
|
|
|
// 分享
|
share(e) {
|
this.setData({
|
shareShow: true,
|
popupShow: true
|
})
|
},
|
|
/**
|
* 用户点击右上角分享
|
*/
|
onShareAppMessage: function () {
|
|
var id = this.data.id;
|
|
var title = this.data.goodsInfo.title;
|
|
let url = "pages/miaosha/msDetails?id=" + id + "&shopId=" + app.shopInfo.id;
|
console.log(url);
|
return {
|
title: "[秒杀]" + title,
|
imageUrl: this.data.imgUrls[0].imgPath,
|
path: url,
|
success(res) {
|
|
},
|
fail(res) {
|
|
}
|
}
|
}
|
})
|