const app = getApp(); const util = require('../../../utils/utils.js'); let videoAd = null; Page({ data: { index: 0, //0 缴纳押金 1退回押金 2退押金状态 pay: 0, // 1 支付押金 0 支付/缴纳/退回 popShow: true, //是否显示弹窗 money: '', depoSuce: true, imgUrl: '', depShow: true, //是否选中缴纳押金 true选中 false 未选中 curShow: '', //是否选中购买免押金卡 undefined 未选中 有值选中 cardList: [], //免押金卡列表 state:[], deposit_status:'', phone:'', is_deposit_ad:wx.getStorageSync('setting').is_return_deposit_ad_video }, //获取免押金卡列表 getCard() { let data = { area_id: wx.getStorageSync('home').id // area_id: 1 } app.request('/deposit_card/index', data, 'GET').then(res => { console.log(res.data); this.setData({ cardList: res.data.data }) wx.hideLoading({ complete: (res) => {}, }) console.log(this.data.cardList) }) }, // 切换免押金卡 cut(e) { let that = this; let id = e.currentTarget.dataset.id; if(that.data.state.is_deposit==1 && that.data.state.deposit_type==1 && id!= undefined){ wx.showToast({ title: '您已缴纳押金无需购买免押金卡', icon:'none' }) return; } if (id == undefined) { that.setData({ depShow: true, curShow: "text_undefined", depshow:true }) } else { that.setData({ curShow: id, depShow: false, depshow:false }) } }, explain(){ wx.navigateTo({ url: '/pages/explain_card_free/explain_card_free', }) }, call_phone(){ var phone = this.data.phone[0]; wx.makePhoneCall({ phoneNumber: phone, }) }, //进入页面判断是否缴纳押金 getState(e){ app.request('/user/status', '', 'GET').then(res => { console.log(res, '判断'); this.setData({ index: res.data.is_deposit, state:res.data }) }) app.request('/pages/user-deposit-status', '', 'GET').then(res => { console.log(res) this.setData({deposit_status:res.data.type}) }) }, //缴纳押金 pay: util.throttle(function (e) { this.setData({ pay: 1 }) }, 100), //显示弹窗 showPop: util.throttle(function (e) { this.setData({ popShow: false, }) }, 1000), //取消退回押金 cancle: util.throttle(function (e) { this.setData({ popShow: true, }) }, 1000), //确定退回押金 confirm: util.throttle(function (e) { this.setData({ popShow: true, index: 1, }) if(this.data.is_deposit_ad==1){ app.request('/deposit/refund-job', '', 'POST').then(res => { console.log(res); if (res.statusCode == 200) { wx.reLaunch({ url: '/pages/refund_success/refund_success', }) } }) } if(this.data.is_deposit_ad==0){ app.request('/deposit/refund', '', 'POST').then(res => { console.log(res); if (res.statusCode == 200) { wx.showToast({ title: '申请成功,1个工作日内到账!', icon:'none' }) this.getState() } }) } }, 1000), //立即支付 depoSuce: util.throttle(function (e) { console.log('支付') var that = this; let url = ''; var data = ''; if (app.globalData.req) { console.log(that.data.depShow) if (that.data.depShow) { //缴纳押金 console.log(11111) url = "/deposit/pay"; data = { area_id: wx.getStorageSync('home').id } } else { //购买免押金卡 console.log(2222) url = "/deposit_card/pay"; data = { area_id: wx.getStorageSync('home').id, id: that.data.curShow } } if (wx.getStorageSync('setting') == '') { wx.showModal({ title: '提示', content: '您附近暂无运营区域~', showCancel: false, success: function (res) { if (res.confirm) { wx.navigateBack() } } }) }else{ app.request(url, data, 'POST', app.globalData.req).then(res => { if (res.statusCode == 200) { console.log(res) wx.requestPayment({ timeStamp: res.data.timeStamp.toString(), nonceStr: res.data.nonceStr, package: res.data.package, signType: res.data.signType, paySign: res.data.paySign, success(res) { console.log(res) let init = ''; if (that.data.depShow) { init = "购买成功" } else { init = "支付成功" } wx.showToast({ title: init, icon: 'none', duration: 1000, success: function () { wx.reLaunch({ url: '/pages/personal/depoSuce/depoSuce', }) } }) that.setData({ depoSuce: true }) }, fail(err) { console.log(err) wx.showToast({ title: '支付失败', icon: 'none' }) that.setData({ depoSuce: true }) } }) } else { console.log(res) that.setData({ depoSuce: true }) } }) } } else { wx.showToast({ title: '您的操作过于频繁,请稍后再试~', icon: 'none' }) } }, 1000), onLoad: function (options) { // 是否缴纳押金 console.log(this.data.depShow) var that = this; wx.showLoading({ title: '加载中...', }) var imgurl = wx.getStorageSync('imgUrl'); this.setData({ imgUrl: 'http://resource.' + imgurl[2] }) this.getState(); this.setData({ money: wx.getStorageSync('setting').deposit }) if (wx.getStorageSync('setting') == '') { this.setData({ money: '59.00' }) } else { this.setData({ money: wx.getStorageSync('setting').deposit }) } if (options.home) { this.setData({ pay: 1 }) } if (wx.createRewardedVideoAd) { videoAd = wx.createRewardedVideoAd({ adUnitId: 'adunit-edc5c4664389a87a' }) videoAd.onLoad(() => {}) videoAd.onError((err) => {}) videoAd.onClose((res) => { if (res && res.isEnded || res === undefined) { app.request('/deposit/refund', '', 'POST').then(res => { console.log(res); if (res.statusCode == 200) { wx.showToast({ title: '加速成功,稍后到账', icon:'none' }) that.getState() } }) } else { wx.showToast({ title: '加速失败!', icon:'none' }) } }) } this.getCard(); }, adShow(){ if (videoAd) { videoAd.show().catch(() => { // 失败重试 videoAd.load() .then(() => videoAd.show()) .catch(err => { console.log('激励视频 广告显示失败') }) }) } }, agreement: util.throttle(function (e) { //充值条约 wx.navigateTo({ url: '/pages/agreement/agreement', }) }, 1000), onReady: function () { }, onShow: function () { var phones = wx.getStorageSync('home').customer_service_phone this.setData({ phone: this.data.phone.concat(phones), is_deposit_ad:wx.getStorageSync('setting').is_return_deposit_ad_video }) }, onHide: function () { }, onUnload: function () { }, onPullDownRefresh: function () { }, onReachBottom: function () { }, onShareAppMessage: function () { } })