213 lines
5.3 KiB
JavaScript
213 lines
5.3 KiB
JavaScript
// pages/couponDetails/couponDetails.js
|
||
Page({
|
||
|
||
/**
|
||
* 页面的初始数据
|
||
*/
|
||
data: {
|
||
id : 0, //优惠券id
|
||
longitude : 0, //经度
|
||
latitude : 0, //纬度
|
||
details : '', //优惠券信息
|
||
stores : [], //商家列表
|
||
content : '', //内容介绍
|
||
remark : '', //使用须知
|
||
qrcode : '', //二维码
|
||
barcode : '', //条形码
|
||
merchantcardinfo:'', //商家券信息
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面加载
|
||
*/
|
||
|
||
onLoad (options) {
|
||
|
||
// 优惠券id
|
||
this.setData({
|
||
id :options.id
|
||
})
|
||
|
||
// 获取二维码
|
||
this.detailsCode()
|
||
|
||
// 获取条形码
|
||
this.detailsBarcode()
|
||
},
|
||
|
||
onShow(){
|
||
this.getCity();
|
||
|
||
// 检查定位是否为空
|
||
// if(this.data.latitude == 0 && this.data.longitude == 0){
|
||
// wx.getSetting({
|
||
// success: res=>{
|
||
// this.getCity()
|
||
// }
|
||
// })
|
||
// }
|
||
},
|
||
|
||
/**
|
||
* 获取城市信息
|
||
*/
|
||
getCity(){
|
||
wx.getLocation({
|
||
success: res => {
|
||
this.setData({
|
||
latitude : res.latitude,
|
||
longitude : res.longitude
|
||
})
|
||
|
||
},
|
||
complete: () => {
|
||
// 获取详情信息
|
||
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;"')
|
||
})
|
||
|
||
|
||
//获取商家券信息
|
||
if(res.data.info.card_type=='merchant_card'){
|
||
this.getMerchantCardInfo()
|
||
}
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 拨打电话
|
||
*/
|
||
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=> {
|
||
}
|
||
})
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 商家券信息
|
||
*/
|
||
getMerchantCardInfo(){
|
||
let coupon_id = this.data.id
|
||
wx.$api.user.merchant_card(coupon_id).then(res=>{
|
||
this.setData({
|
||
merchantcardinfo : res.data
|
||
})
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 小程序插件领取
|
||
*/
|
||
getcoupon(params) {
|
||
let detail = params.detail
|
||
if(detail.errcode !=='OK'){
|
||
wx.showToast({
|
||
title : detail.errmsg,
|
||
icon : 'none'
|
||
})
|
||
}else{
|
||
if(detail.send_coupon_result[0].code !=='SUCCESS'){
|
||
wx.showToast({
|
||
title : detail.send_coupon_result[0].message,
|
||
icon : 'none'
|
||
})
|
||
}else{
|
||
wx.showToast({
|
||
title : '领取成功',
|
||
icon : 'none'
|
||
})
|
||
}
|
||
|
||
}
|
||
}
|
||
}) |