const app = getApp() var util = require("../../../utils/util.js") Page({ data: { xa_consignee: '', xa_city: '', xa_county: '', xa_address: '', xa_phone: '', now_date: '', presentId: '', collection_date: '', obj: {}, sInd: 0, // 选择的兑换门店地址 btnText: '立即兑换', success: false }, onLoad: function (options) { this.setData({ presentId: options.id, navH: app.globalData.navHeight }) this.getPostInfo(options.id) this.getAddress() }, // 获取地址 getAddress() { let _this = this wx.request({ url: app.globalData.url + '/getEqUserAddress', method: 'get', data: {xu_openid: app.globalData.openid}, success: function (res) { if (res.data.length != 0) { _this.setData({ xa_consignee: res.data.xa_consignee, xa_city: res.data.xa_city, xa_county: res.data.xa_county, xa_address: res.data.xa_address, xa_phone: res.data.xa_phone }) } }, fail() { app.timeOut() } }) }, // 获取兑换详情 getPostInfo(id) { let date = new Date() let year = date.getFullYear() let month = (date.getMonth() + 1).toString().padStart(2, 0) let day = (date.getDate()).toString().padStart(2, 0) util.postData('/college/queryRedeemDetail', { openid: app.globalData.openid, presentId: id }).then(res => { this.setData({ now_date: year + '-' + month + '-' + day, collection_date: year + '-' + month + '-' + day, obj: res }) if (!res.redeem) { this.setData({ btnText: `LV${res.level} 开启兑换` }) } }) }, // 选择兑换门店 selectMen(event) { let ind = event.currentTarget.dataset.index || 0; this.setData({ sInd: ind }) }, // 选择时间 seletTim(e) { this.setData({ collection_date: e.detail.value }) }, // 兑换 duihuan() { if (!this.data.success) { if (!this.data.obj.redeem) { return } let params = { present_id: this.data.presentId, openid: app.globalData.openid } if (this.data.obj.presentType == 2) { params.collection_date = this.data.collection_date params.mkt_id = this.data.obj.mktInfo[this.data.sInd].id } else if (this.data.obj.presentType == 3) { params.address = this.data.xa_city + this.data.xa_county + this.data.xa_address if (!params.address || params.address == 'undefined') { wx.showToast({ title: '收货地址不能为空', icon: 'none' }) return } } util.postData('/college/userRedeem', params).then(res => { if (res.code == 1) { this.setData({ success: true, btnText: '回到首页' }) } else if (res.msg) { wx.showToast({ title: res.msg, icon: 'none' }) } }) } else { wx.reLaunch({ url: '/pages/scholarship/scholarship' }) } }, // 添加地址 hrefAddress() { let toUrl = '/pages/mine/myaddress/myaddress?type=bill' if (this.data.xa_consignee == null || this.data.xa_consignee == '') { toUrl = '/pages/mine/myaddress/createaddress/createaddress?type=bill' } wx.navigateTo({ url: toUrl }) } })