123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- import recordSource from '../../utils/recordSource';
- const config = require('../../config.js')
- const getReq = config.getReq
- const buyVGoods = config.buyVGoods
- let app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- currentIndex: 0, //页签索引
- rechargeGearActiveIndex: 0, //挡位项目索引
- tips:'', //顶部tips
- goods:[], //挡位数据
- goods_id:'', //当前选中挡位的goods_id
- card_type: 'sinopec', //油卡类型 (中石化/中石油)
- card_no: '', //油卡号
- cards: [],
- sinopec: {},
- petrochina: {},
- firstLoad: true,
- 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: ''
- },
- // 页签切换
- handlerClickTabItem(e) {
- var dataset = e.currentTarget.dataset
- const { activeindex, cardtype } = dataset
- const { cards } = this.data
- this.setData({
- currentIndex: dataset.activeindex,
- card_no: this.getValueBykey(cardtype ,cards).card_no
- });
- },
- //充值档位切换
- handlerClickRechargeGear(e) {
- var dataset = e.currentTarget.dataset
- this.setData({
- rechargeGearActiveIndex: dataset.activeindex,
- goods_id: dataset.currentvalue
- });
- },
- //跳转到油卡管理页面
- handlerAddCard(e){
- const { cardtype } = e.currentTarget.dataset
- wx.navigateTo({
- url: `/pages/postageManage/postageManage?card_type=${cardtype}`,
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
-
- let fromSource = recordSource(app, `act=index&op=card_goods`)
- this.setData({
- fromSource: app.globalData.fromSource,
- // card_no: this.data.tabsData[0].card_no
- });
- getReq({
- act: 'index',
- op: 'card_goods',
- page_type: 'oil',
- from: fromSource
- }, (res) => {
- this.setData({
- firstLoad: false
- });
- if (res.code == 200) {
- if(res.datas && res.datas.goods){
- const datas = res.datas
- const { tips = '', goods = [], cards = [], } = datas
- const sinopec = this.getValueBykey('sinopec', cards)
- const petrochina = this.getValueBykey('petrochina', cards)
- this.setData({ tips, goods, cards, sinopec, petrochina, card_no: sinopec.card_no, goods_id: datas.goods[0].goods_id });
- }
- } else {
- app.showToast(res.message)
- }
- })
- },
- // 通过键取值
- getValueBykey(key = '', data = []){
- return data.filter(val => val.card_type === key)[0]
- },
- // 立即充值
- handlerRecharge(){
- const { goods_id, card_no, card_type } = this.data
- if(!card_no){
- app.showToast('卡号不能为空')
- return
- }
- buyVGoods(goods_id,1,{ card_no,card_type }, (res) => {
- console.table({card_no,card_type})
- // console.log('res',res) 成功回调
- }, (err) => {
- // 失败回调
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- if(!this.data.firstLoad) {
- const record = app.globalData.record || {}
- const { card_no = '', card_type = '' } = record
- app.setFromSource(this.data.fromSource)
- if (record) {
- this.setData({ card_no, card_type })
- }
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- }
- })
|