const app = getApp()
|
var util = require('../../utils/util.js');
|
var api = require('../../utils/service-api.js');
|
var comReq = require('../../utils/common-request.js');
|
var shopcart = require('../../utils/shopcart.js');
|
|
Page({
|
data: {
|
userInfo: '', //用户信息
|
stardata: [1, 2, 3, 4, 5],
|
interval: 2000,
|
duration: 1000,
|
imgUrls: [],
|
imagetext: ['商品介绍', '规格与包装'],
|
currentTabsIndex: 0,
|
checkCollect: true,
|
goodsInfo: {},
|
adverList: '',
|
adverLists: '',
|
normspopup: false,
|
currentIndex: 0,
|
id: '',
|
num: 1,
|
whetherSpecification: false, //是否选择规格
|
specification: '', //规格
|
specificationId: '', //规格id
|
specificationPrice: '', //规格价格
|
price: '', //价格
|
originalPrice: '', //划线价
|
normsList: [],
|
couponList: [],
|
activity:[],//满减活动
|
evaluateList: [], // 评论列表
|
evaluateNum: 0, // 评论数量
|
currentIndexs: 0,
|
currentIndex: 0,
|
hidden: false,
|
limit: 10,
|
offset: 0,
|
inform: true,
|
hidden: true,
|
shareShow: false,
|
cartProductId: "", //商品id
|
title: "", //商品名
|
imgSrc: "", //商品图片
|
isShare: 0,
|
qrcode:false,
|
},
|
onLoad: function(options) {
|
var _this = this;
|
//debugger;
|
var goodsId = options.id;
|
var shopId = options.shopId;
|
|
if (goodsId == undefined || goodsId == null) {
|
const scene = decodeURIComponent(options.scene);
|
console.log("scene", scene)
|
var params=scene.split(",");
|
|
goodsId = params[1];
|
shopId = params[0];
|
app.shopInfo = { id: shopId};
|
|
//获取门店信息
|
util.request({
|
api: api.yuyue.findShopInfoById + "/" + shopId,
|
callback: function (data) {
|
app.shopInfo = data.rows[0];
|
},
|
checkLogin:true,
|
});
|
}
|
if (goodsId == undefined || goodsId == null) {
|
wx.showModal({
|
title: '提示',
|
content: '产品信息加载失败',
|
showCancel: false
|
})
|
}
|
|
|
_this.showGoods(goodsId);
|
|
|
_this.setData({
|
id: goodsId,
|
});
|
|
// 判断是否从通知跳进来
|
if (options.isShare == 1) {
|
this.setData({
|
isShare: options.isShare
|
})
|
}
|
|
|
},
|
onShow(options) {
|
|
},
|
// 回到首页
|
goBack() {
|
wx.switchTab({
|
url: '../index/index'
|
})
|
},
|
|
goIndex() {
|
wx.reLaunch({
|
url: '/pages/index/index'
|
})
|
},
|
//转发
|
onShareAppMessage(res) {
|
|
var title = this.data.goodsInfo.title;
|
var shopCoupon=this.data.goodsInfo.shopCoupon;
|
|
if (shopCoupon){
|
title = title +" - "+ shopCoupon.cname;
|
}
|
|
var index = this.data.index
|
var id = this.data.id;
|
if (res.from === "button") {}
|
return {
|
title: title,
|
imageUrl: this.data.imgUrls[0].imgPath,
|
path: "pages/service/details?id=" + id + "&shopId="+app.shopInfo.id+"&isShare=" + 1,
|
success(res) {
|
|
},
|
fail(res) {
|
|
}
|
}
|
},
|
// 咨询药师
|
consult(e) {
|
this.setData({
|
telShow: true
|
})
|
},
|
// 分享
|
share(e) {
|
this.setData({
|
shareShow: true,
|
popupShow: true
|
})
|
},
|
//跳转到购物车
|
goCart(e) {
|
wx.switchTab({
|
url: '../shopCar/shopCar',
|
})
|
},
|
|
// 图文选项卡
|
onTabsItemEvent(e) {
|
var index = e.currentTarget.dataset.index;
|
// console.log(index)
|
this.setData({
|
currentTabsIndex: index
|
})
|
},
|
// 收藏
|
collect() {
|
var _this = this;
|
var id = _this.data.id;
|
util.request("POST", "/wxapi/Collection/saveCollection", {
|
"collProductid": id
|
}, function(data) {
|
if (data.status == 200) {
|
_this.setData({
|
checkCollect: true
|
})
|
}
|
|
}, false);
|
|
},
|
// 取消收藏
|
cancel() {
|
var _this = this;
|
var id = _this.data.id;
|
console.log(id)
|
util.request("POST", "/wxapi/Collection/deleteByProductId/" + id, {}, function(data) {
|
console.log(data.rows)
|
if (data.status == 200) {
|
_this.setData({
|
checkCollect: false
|
})
|
}
|
}, false);
|
},
|
|
|
|
|
// 查询商品详情
|
showGoods: function(id) {
|
|
var _this = this;
|
|
util.request({
|
api: "/wxapi/ShopProduct/getProductById/"+app.shopInfo.id+"/" + id,
|
callback:function(data){
|
|
if (data.rows[0].mobileDetails != null) {
|
data.rows[0].mobileDetails = data.rows[0].mobileDetails.replace(/<img /g, '<img class="rich_img" ');
|
console.log(data.rows[0].mobileDetails);
|
}
|
_this.setData({
|
goodsInfo: data.rows[0],
|
imgUrls: data.rows[0].productImgs,
|
normsList: data.rows[0].skus,
|
specification: data.rows[0].skus[0].name,
|
specificationPrice: data.rows[0].skus[0].price,
|
price: data.rows[0].skus[0].price,
|
specificationId: data.rows[0].skus[0].id,
|
imgSrc: data.rows[0].imgMobile,
|
title: data.rows[0].title,
|
hidden: true,
|
activity: data.mapInfo.activity,
|
couponList: data.mapInfo.couponList,
|
evaluateNum: data.mapInfo.evaluateNum,
|
checkCollect: data.mapInfo.checkCollect,
|
})
|
|
}
|
});
|
|
|
},
|
|
yuyue(){
|
|
if (util.isBlank(getApp().userInfo.nickName)) {
|
wx.navigateTo({
|
url: '/pages/welcome/welcome?url=/pages/yuyue/khyuyue',
|
})
|
} else if (util.isBlank(getApp().userInfo.phoneNumber)) {
|
wx.navigateTo({
|
url: '/pages/phone/phone?url=/pages/yuyue/khyuyue',
|
})
|
} else {
|
|
var product = this.data.goodsInfo;
|
wx.setStorageSync('chooseService', product);
|
|
wx.switchTab({
|
url: '/pages/yuyue/khyuyue'
|
});
|
}
|
|
|
},
|
|
|
|
//规格选择
|
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
|
});
|
},
|
|
|
// 立即购买
|
buy(e) {
|
var _this = this;
|
//获取用户信息
|
console.log("立即购买");
|
|
// 判断是否绑定过手机号
|
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 {
|
|
|
var id = _this.data.goodsInfo.id; // 商品id
|
var cartSkuId = _this.data.specificationId; //规格id
|
var cartNumber = _this.data.num; //数量
|
|
var stockNum = goodsInfo.stockNum;
|
if (stockNum < 1) {
|
wx.showToast({
|
title: "您来晚了,商品已经抢光了",
|
icon: 'none',
|
});
|
return;
|
}
|
//取消所有购物车选中项目
|
util.request({
|
method: "POST",
|
api: api.shoppingCart.updateCartAllSelected + app.shopInfo.id +"/2",
|
|
callback: function () {
|
|
//加入购物车
|
comReq.addShoppingCar(cartSkuId, cartNumber, function (totalNum) {
|
|
//隐藏规格
|
_this.cancelNorms();
|
|
//进入结算
|
wx.navigateTo({
|
url: '/pages/service/shopOrder?model=2',
|
})
|
|
|
|
});
|
|
|
|
}
|
});
|
|
|
|
}
|
}
|
|
|
|
},
|
// 轮播图预览保存
|
onSwiperEvent(e) {
|
let index = e.currentTarget.dataset.index;
|
let imgArr = [];
|
for (var i = 0; i < this.data.imgUrls.length; i++) {
|
imgArr.push(this.data.imgUrls[i].imgPath);
|
}
|
wx.previewImage({
|
current: imgArr[index],
|
urls: imgArr,
|
})
|
// console.log(1111)
|
console.log(imgArr[index])
|
},
|
//领券
|
couple(e) {
|
this.setData({
|
popup: true
|
})
|
},
|
//取消领券弹窗选择
|
popupTap(e) {
|
this.setData({
|
popup: false,
|
normspopup: false,
|
telShow: false,
|
shareShow: false
|
})
|
},
|
|
|
|
|
|
// 领取优惠券
|
getCoupon(e) {
|
var _this = this;
|
var index = e.currentTarget.dataset.index;
|
var value = e.currentTarget.dataset.value;
|
var couponList = _this.data.couponList;
|
// console.log(value);
|
//获取用户信息
|
wx.getStorage({
|
key: 'userInfo',
|
success: function(res) {
|
let userInfo = res.data
|
if (!userInfo.phoneNumber) {
|
wx.navigateTo({
|
url: '../phone/phone',
|
})
|
} else {
|
util.request("GET", "/wxapi/shopCoupon/receiveCoupon/" + value.id, {}, function(data) {
|
|
couponList[index].canReceive = 0;
|
_this.setData({
|
couponList: couponList
|
})
|
|
}, null,true)
|
}
|
}
|
})
|
},
|
|
evaluate(e) {
|
wx.navigateTo({
|
url: '../wholeEvaluate/whoeEvaluate?id=' + e.currentTarget.dataset.id,
|
})
|
},
|
|
|
|
// 生成卡片跳转
|
card(e) {
|
var id = e.currentTarget.dataset.id
|
wx.navigateTo({
|
url: '../card/card?id=' + id,
|
})
|
},
|
|
|
|
/**
|
* 获取二维码
|
*/
|
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;
|
var id = _this.data.id;
|
var data = {
|
shopId: shopId,
|
productId: id,
|
scene: shopId + "," + id,
|
path: "pages/service/details"
|
};
|
|
|
util.request({
|
|
|
|
method: "POST",
|
api:'/wxapi/shareProduct/getProductShareQrcode/',
|
data:data,
|
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);
|
}
|
})
|
}
|
})
|
}
|
})
|
|
|
}})
|
|
|
}
|
|
|
},
|
|
|
/**
|
* 分享
|
*/
|
formSubmit: function (e) {
|
console.log('获取二维码:', e)
|
this.getQrcode()
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
})
|