170 lines
4.1 KiB
JavaScript
170 lines
4.1 KiB
JavaScript
// pages/couponDetails/couponDetails.js
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
id : 0, //优惠券id
|
|
longitude : 0, //经度
|
|
latitude : 0, //纬度
|
|
details : '', //优惠券信息
|
|
stores : [], //商家列表
|
|
content : '', //内容介绍
|
|
remark : '', //使用须知
|
|
qrcode : '', //二维码
|
|
barcode : '', //条形码
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
|
|
onLoad (options) {
|
|
|
|
// 优惠券id
|
|
this.setData({
|
|
id :options.id
|
|
})
|
|
|
|
// 获取二维码
|
|
this.detailsCode()
|
|
|
|
// 获取条形码
|
|
this.detailsBarcode()
|
|
|
|
// 获取详情信息
|
|
this.detailsInfo();
|
|
|
|
},
|
|
|
|
onShow(){
|
|
// 检查定位是否为空
|
|
if(this.data.latitude == 0 && this.data.longitude == 0){
|
|
wx.getSetting({
|
|
success: res=>{
|
|
this.getCity()
|
|
}
|
|
})
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 获取城市信息
|
|
*/
|
|
getCity(){
|
|
wx.getLocation({
|
|
type : 'wgs84',
|
|
success : res=> {
|
|
this.setData({
|
|
longitude : res.longitude,
|
|
latitude : res.latitude
|
|
})
|
|
|
|
// 获取详情信息
|
|
this.detailsInfo();
|
|
}
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 二维码
|
|
*/
|
|
detailsCode() {
|
|
let coupon_id = this.data.id
|
|
wx.$api.user.qrcode(coupon_id).then(res=>{
|
|
this.setData({
|
|
qrcode : res.data.qrcode
|
|
})
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 条形码
|
|
*/
|
|
detailsBarcode() {
|
|
let coupon_id = this.data.id
|
|
wx.$api.user.barcode(coupon_id).then(res=>{
|
|
this.setData({
|
|
barcode : res.data.barcode
|
|
})
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 详情信息
|
|
*/
|
|
detailsInfo() {
|
|
let coupon_id = this.data.id,
|
|
user_lng = this.data.longitude,
|
|
user_lat = this.data.latitude
|
|
wx.$api.user.couponinfo(coupon_id, user_lng, user_lat).then(res=>{
|
|
let stores = res.data.stores
|
|
stores.map(res=>{
|
|
let distance = res.distance
|
|
if(res.distance > 1000){
|
|
distance = (distance / 1000) + "km"
|
|
}else{
|
|
distance = distance + "m"
|
|
}
|
|
res.km = distance
|
|
})
|
|
|
|
this.setData({
|
|
details : res.data.info,
|
|
stores : stores,
|
|
remark : res.data.info.right.remark.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;"'),
|
|
content : res.data.info.right.content.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;"')
|
|
})
|
|
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 拨打电话
|
|
*/
|
|
tel(e) {
|
|
let tel = e.currentTarget.dataset.tel
|
|
wx.showActionSheet({
|
|
itemList : ['呼叫商家电话'],
|
|
success : res =>{
|
|
if(res.tapIndex==0){
|
|
wx.makePhoneCall({
|
|
phoneNumber: tel
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 查看门店详情页
|
|
*/
|
|
detailsTap(e) {
|
|
let store_id = e.currentTarget.dataset.id,
|
|
user_lng = this.data.longitude,
|
|
user_lat = this.data.latitude
|
|
|
|
wx.navigateTo({
|
|
url: '/pages/storeDetails/storeDetails?store_id=' + store_id + '&user_lng=' + user_lng + '&user_lat=' + user_lat,
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 加入微信卡包
|
|
*/
|
|
join(e) {
|
|
let cardId = this.data.id
|
|
wx.$api.user.jssdk(cardId).then(res=>{
|
|
let pay = JSON.parse(res.data)
|
|
wx.addCard({
|
|
cardList : pay,
|
|
success : res => {
|
|
// 获取详情信息
|
|
this.detailsInfo();
|
|
},fail : res=> {
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}) |