import recordSource from '../../utils/recordSource'; const config = require('../../config.js') const getReq = config.getReq const buyVGoods = config.buyVGoods let app = getApp(); Page({ /** * 页面的初始数据 */ data: { fGoodsRequesting: false, currentIndex: 0, //页签索引 rechargeGearActiveIndex: 0, //挡位项目索引 tips: '', //顶部tips inviter_tip: '', show_invite: true, goods_inviter_tips: new Map(), goods: [], //挡位数据 goods_id: '', //当前选中挡位的goods_id sinopec: { card_no: '', card_type: 'sinopec' }, petrochina: { card_no: '', card_type: 'petrochina' }, phone: { card_no: '', card_type: 'phone' }, member_mobile: '', tabsData: [ { id: 0, icon: '/image/postage/sinopec.png', title: '中国石化', tips: '选择油卡', card_type: 'sinopec', card_no: '' }, { id: 1, icon: '/image/postage/petrochina.png', title: '中国石油', tips: '选择油卡', card_type: 'petrochina', card_no: '' } ], fromSource: '', payInfoChecked: true, showShareDialog: false, shareGoodsId: 0, showtermsOfServiceDialog: false, special_id: 0, //订单成功,弹出的专题页面 msgList: [] }, onShowShareDialog() { var goods_id = this.data.goods_id this.setData({ showShareDialog: true, shareGoodsId: goods_id, }) }, onCloseShareDialog() { this.setData({ showShareDialog: false }) }, onCheckedPayInfo() { this.setData({ payInfoChecked: !this.data.payInfoChecked }) }, onShowPayInfoModal() { this.setData({ showtermsOfServiceDialog: true }) }, onShowtermsOfServiceDialog() { this.setData({ showtermsOfServiceDialog: false }) }, // 页签切换 handlerClickTabItem(e) { var dataset = e.currentTarget.dataset const { activeindex, cardtype } = dataset console.log('handlerClickTabItem activeindex=', activeindex, 'cart_type=', cardtype) this.setData({ currentIndex: activeindex }); }, //充值档位切换 handlerClickRechargeGear(e) { var dataset = e.currentTarget.dataset console.log('handlerClickRechargeGear dataset:', e.currentTarget.dataset) let goods_id = dataset.currentvalue let item = this.data.goods_inviter_tips.get(goods_id) let inviter_tip = item.tip let show_invite = item.show_invite console.log('item=', item) this.setData({ rechargeGearActiveIndex: dataset.activeindex, goods_id: goods_id, inviter_tip: inviter_tip, show_invite: show_invite }); }, //跳转到油卡管理页面 handlerAddCard(e) { const { cardtype } = e.currentTarget.dataset app.navigateto(`/pages/postageManage/postageManage?card_type=${cardtype}`) }, onAuthenPhone() { if (!app.globalData.hasmobile) { app.navigateto('/pages/auth/auth') return; } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, requestGoods() { if (this.fGoodsRequesting) return; this.fGoodsRequesting = true let fromSource = recordSource(app, `act=index&op=card_goods`) this.setData({ fromSource: app.globalData.fromSource, }); wx.showLoading({ title: '数据加载中', mask:true }) getReq(app, { act: 'index', op: 'card_goods', page_type: 'oil', from: fromSource }, (res) => { setTimeout(()=>{ wx.hideLoading(); },200) wx.stopPullDownRefresh() if (res.code == 200) { if (res.datas && res.datas.goods) { const datas = res.datas console.log('datas=', datas) let goods_inviter_tips = this.formGoodsInviterTips(res.datas.goods_inviter_tips) const { tips = '', goods = [], cards = [], member_mobile, special_id } = datas let phone = app.getValueByKey('phone', cards) let petrochina = app.getValueByKey('petrochina', cards) let sinopec = app.getValueByKey('sinopec', cards) phone = app.isNullObject(phone) ? { card_no: '', card_type: 'phone' } : phone petrochina = app.isNullObject(petrochina) ? { card_no: '', card_type: 'petrochina' } : petrochina sinopec = app.isNullObject(sinopec) ? { card_no: '', card_type: 'sinopec' } : sinopec let index = this.data.rechargeGearActiveIndex; let goods_id = datas.goods[index].goods_id let item = goods_inviter_tips.get(goods_id) let inviter_tip = item.tip let show_invite = item.show_invite this.setData({ tips, goods_inviter_tips, inviter_tip, show_invite, goods, sinopec, petrochina, phone, goods_id, member_mobile, special_id, inputMobile: member_mobile }); } } else { app.showToast(res.message) } this.fGoodsRequesting = false }) }, formGoodsInviterTips(godosInviterTips) { let ret = new Map(); godosInviterTips.forEach(item => { let goods_id = item.goods_id let tip = item.tip let show_invite = item.show_invite ret.set(goods_id, { tip, show_invite }) }); return ret; }, // 立即充值 handlerRecharge() { if (!this.data.payInfoChecked) { wx.showToast({ icon: 'none', title: '请同意充值代缴服务说明' }) return; } if (!app.globalData.hasmobile) { app.navigateto('/pages/auth/auth') return; } console.log('handlerRecharge:', this.data) const rechargeMobile = this.data.inputMobile || this.data.member_mobile; if (this.data.inputMobile != '') { if (!(/^1[3456789]\d{9}$/.test(this.data.inputMobile))) { wx.showToast({ icon: 'none', title: '请输入正确的手机号' }) return; } } else { this.setData({ inputMobile:this.data.member_mobile }) } const { goods_id } = this.data let card_type = '' let card_no = '' if (this.data.currentIndex == 0) { card_type = 'sinopec' card_no = this.data.sinopec.card_no } else { card_type = 'petrochina' card_no = this.data.petrochina.card_no } if (!card_no) { app.showToast('卡号不能为空') return } buyVGoods(app, goods_id, 1, { card_no, card_type }, (res) => { let special_id = this.data.special_id let title = '支付成功' app.navigateto(`/pages/special/special?special_id=${special_id}&title=${title}`) }, (err) => { wx.showToast({ icon: 'none', title: '支付未完成,订单将在10分钟后取消...', duration: 5000 }) this.requestGoods(); }) }, onChangeMobile(e) { console.log(e.detail.value); this.setData({ inputMobile: e.detail.value }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.requestGoods(); let msgs = app.genMsgs(); this.setData({ msgList: msgs }); const record = app.globalData.record || {} const { card_no = '', card_type = '' } = record app.setFromSource(this.data.fromSource) console.log('onShow ') if (!app.isNullObject(record) && card_no && card_type) { if (card_type === 'sinopec') { this.setData({ sinopec: { card_no: card_no, card_type: 'sinopec' } }) } else if (card_type === 'petrochina') { this.setData({ petrochina: { card_no: card_no, card_type: 'petrochina' } }) } console.log(this.sinopec, this.petrochina) } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { console.log('onHide'); if (this.data.showShareDialog) { this.setData({ showShareDialog: true, showtermsOfServiceDialog: false, }) } else { this.setData({ showShareDialog: false, showShareDialog: false, shareGoodsId: 0, showtermsOfServiceDialog: false }) } }, onShareInfo: function () { console.log('onShareInfo') wx.getShareInfo({ success: function (res) { console.log(res) } }) }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { this.requestGoods(); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, onShareAppMessage: function (e) { return app.cardShareInfo(); } })