238 lines
6.5 KiB
JavaScript
238 lines
6.5 KiB
JavaScript
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
address : '', //默认收货地址
|
|
amount : '', //总金额
|
|
allAddress : '', //收货地址列表
|
|
addressShow : false, //收货地址显示
|
|
noticeShow : false, //须知显示状态
|
|
pointMoreShow : false, //重要提示显示状态
|
|
freight : '', //运费
|
|
isdeliver : -1,
|
|
groupId : '', //权益id
|
|
contData : '', //全局内容
|
|
rightData : '', //权益详情
|
|
content : '', //内容介绍
|
|
notification : '', //重要提示
|
|
remark : '', //使用须知
|
|
platformCp : [], //选择提交数组
|
|
platIndex : 0, //选择提交方式下标
|
|
payWayIndex : 0, //选择支付方式下标
|
|
subscribeTips : '', //订阅--临时舍去
|
|
payWay :[
|
|
{value: 0, name: "微信支付"}
|
|
// {value: 1, name: "沃钱包支付"}
|
|
]
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad (options) {
|
|
this.setData({
|
|
groupId : options.id
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
// 获取详情
|
|
this.rightsInfo();
|
|
},
|
|
|
|
/**
|
|
* 详情
|
|
*/
|
|
rightsInfo() {
|
|
wx.$api.index.welfares(this.data.groupId, this.data.address.id, this.data.isdeliver).then(res=>{
|
|
let obj = res.data.detail.right.express
|
|
let defGet = res.data.detail.right.def_get
|
|
let arr = new Array
|
|
|
|
arr = Object.keys(obj).map(val=>{
|
|
return { ...obj[val], ...{key: val} }
|
|
})
|
|
|
|
if(this.data.isdeliver == -1){
|
|
if(res.data.detail.right.type == 'physical') {
|
|
this.setData({
|
|
isdeliver : res.data.detail.right.def_get
|
|
})
|
|
}
|
|
if(res.data.detail.right.type == 'virtual') this.setData({isdeliver : 1})
|
|
}
|
|
|
|
this.setData({
|
|
address : res.data.address,
|
|
allAddress : res.data.all_address,
|
|
contData : res.data.detail,
|
|
freight : res.data.freight,
|
|
amount : res.data.total,
|
|
platformCp : arr,
|
|
rightData : res.data.detail.right,
|
|
remark : res.data.detail.remark.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;"'),
|
|
content : res.data.detail.content.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;"')
|
|
})
|
|
}).catch(err=>{
|
|
if(!err.login){
|
|
// 写入缓存
|
|
wx.setStorage({
|
|
key : 'token',
|
|
data : ''
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 须知展开收起状态
|
|
*/
|
|
noticeTap() {
|
|
this.setData({
|
|
noticeShow : !this.data.noticeShow
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 重要提示展开收起状态
|
|
*/
|
|
pointMoreTap() {
|
|
this.setData({
|
|
pointMoreShow : !this.data.pointMoreShow
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 普通商品支付提交
|
|
*/
|
|
ordinary() {
|
|
this.submitOrder();
|
|
this.setData({
|
|
disabled : true
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 选择提交方式
|
|
*/
|
|
platBind(e) {
|
|
this.setData({
|
|
platIndex : e.detail.value,
|
|
isdeliver : this.data.platformCp[e.detail.value].value
|
|
})
|
|
// 获取详情
|
|
this.rightsInfo()
|
|
},
|
|
|
|
/**
|
|
* 收货地址收起
|
|
*/
|
|
addressTap() {
|
|
this.setData({
|
|
addressShow : !this.data.addressShow
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 选择收货地址
|
|
*/
|
|
selectAddress(e){
|
|
let new_addressId = e.currentTarget.dataset.id,
|
|
addressId = this.data.address.id
|
|
if (new_addressId != addressId) {
|
|
this.setData({
|
|
address : e.currentTarget.dataset.index,
|
|
addressShow : false
|
|
})
|
|
}else{
|
|
this.setData({
|
|
addressShow : false
|
|
})
|
|
}
|
|
|
|
// 获取详情
|
|
this.rightsInfo()
|
|
},
|
|
|
|
/**
|
|
* 新增收货地址
|
|
*/
|
|
addSelect() {
|
|
wx.navigateTo({
|
|
url: '/pages/address/address?type=selectAddress'
|
|
})
|
|
this.setData({
|
|
addressShow : false
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 支付选择
|
|
*/
|
|
payBind(e) {
|
|
this.setData({
|
|
payWayIndex: e.detail.value
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 支付提交
|
|
*/
|
|
submitOrder() {
|
|
let welfareId = this.data.contData.welfare_id,
|
|
address_id = this.data.address.id,
|
|
is_deliver = this.data.isdeliver
|
|
|
|
wx.$api.index.fridayInfo(welfareId, address_id, is_deliver).then(res=>{
|
|
if(res.data.canPay == false) {
|
|
wx.showToast({
|
|
title : '支付成功',
|
|
icon : 'success',
|
|
duration: 2000
|
|
})
|
|
setTimeout(()=>{
|
|
if(this.data.isdeliver == 1) {
|
|
wx.reLaunch({
|
|
url: '/pages/order/order?orderType=rightsCoupons'
|
|
})
|
|
} else {
|
|
wx.reLaunch({
|
|
url: '/pages/order/order?orderType=rights'
|
|
})
|
|
}
|
|
},3000)
|
|
this.setData({
|
|
rightsTap: true
|
|
})
|
|
}else {
|
|
// 跳转收银台
|
|
wx.navigateTo({
|
|
url: "/pages/cashier/cashier?trade_no=" + res.data.trade_no + "&amount=" + this.data.amount + "&is_deliver=" + is_deliver + "&pay_type=welfarePay"
|
|
})
|
|
}
|
|
}).catch(err => {});
|
|
},
|
|
|
|
/**
|
|
* 订阅--临时舍去
|
|
*/
|
|
// subscribeTap() {
|
|
// wx.$api.index.subscribe(this.data.contData.welfare_id).then(res=>{
|
|
// wx.showLoading({
|
|
// title: res.data,
|
|
// icon : 'none',
|
|
// })
|
|
// setTimeout(function () {
|
|
// wx.hideLoading();
|
|
// }, 1000)
|
|
// }).catch(err=>{
|
|
|
|
// })
|
|
// }
|
|
}) |