123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- import recordSource from '../../utils/recordSource';
- const getReq = require('../../config.js').getReq
- let app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- currentIndex: 0, //页签索引
- rechargeGearActiveIndex: 0, //挡位项目索引
- tips:'', //顶部tips
- goods:[], //挡位数据
- goods_id:'', //当前选中挡位的goods_id
- card_type: '', //油卡类型 (中石化/中石油)
- card_no: '', //油卡号
- firstLoad: true,
- tabsData: [
- { id: 0, icon: '/image/postage/sinopec.png', title: '中国石化', tips: '选择油卡:(一人最多十张油卡)', card_no: '15853434113521' },
- { id: 1, icon: '/image/postage/petrochina.png', title: '中国石油', tips: '选择油卡:(一人最多八张油卡)', card_no: '41865461251351' }
- ],
- // <<<<<<< HEAD
- // selectArray: [{
- // "id": "10",
- // "text": "9066666888"
- // }, {
- // "id": "21",
- // "text": "25288888556"
- // }],
- // gearData: [
- // { faceValue: 100, price: 95 },
- // { faceValue: 200, price: 190 },
- // { faceValue: 500, price: 475 },
- // { faceValue: 1000, price: 950 }
- // ]
- // =======
- fromSource: ''
- // >>>>>>> 259bb9c31cb59d1d11de38b7b18920184eefb6c9
- },
- // 页签切换
- handlerClickTabItem(e) {
- var dataset = e.currentTarget.dataset
- this.setData({
- currentIndex: dataset.activeindex,
- card_no: dataset.cardno
- });
- },
- //充值档位切换
- handlerClickRechargeGear(e) {
- var dataset = e.currentTarget.dataset
- this.setData({
- rechargeGearActiveIndex: dataset.activeindex,
- goods_id: dataset.currentvalue
- });
- },
- //跳转到油卡管理页面
- handlerAddCard(){
- wx.navigateTo({
- url: '/pages/postageManage/postageManage',
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- 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
- });
- var self = this;
- getReq({
- act: 'index',
- op: 'card_goods',
- card_type: 'oil',
- from: fromSource
- }, function (res) {
- self.setData({
- firstLoad: false
- });
- if (res.code == 200) {
- if(res.datas && res.datas.goods){
- var datas = res.datas
- self.setData({
- tips: datas.tips,
- goods: datas.goods,
- goods_id: datas.goods[0].goods_id
- });
- }
- }else {
- wx.showToast({
- icon: 'none',
- title: res.message,
- duration: 2000
- })
- }
- })
- },
- // 立即充值
- handlerRecharge(){
- wx.showToast({
- icon: 'none',
- title: `goods_id: ${this.data.goods_id}, card_no: ${this.data.card_no}`,
- duration: 2000
- })
- console.table({'goods_id': this.data.goods_id, 'card_no': this.data.card_no})
- this.toPay()
- },
- toPay() {
- let goods_id = this.data.goods_id
- let goods_num = 1
- let iscart = this.data.ifcart
- let cart_id = this.data.cart_id
- let ifcart = cart_id ? 1 : 0
- let cartids = cart_id ? cart_id : (goods_id + '|' + goods_num)
- let params = {
- act: 'member_buy',
- op: 'step_vsecond',
- payment: 'minipay',
- usebonus: 1,
- ifcart:1,
- cart_id: 1,
- invoice_id: 0
- }
- params = Object.assign({}, params);
- getReq(params, function (res) {
- wx.hideLoading()
- if (res.code == 200) {
- let param = res.datas.param.data
- let pay_sn = res.datas.pay_sn
- wx.requestPayment({
- timeStamp: param.timeStamp, //时间戳,自1970年以来的秒数
- nonceStr: param.nonceStr, //随机串
- package: param.package,
- signType: param.signType, //微信签名方式:
- paySign: param.paySign, //微信签名
- success: function (res) {
- wx.reLaunch({
- url: "/pages/index/index"
- })
- },
- fail: function (res) {
- // wx.redirectTo({
- // url: `/pages/orderPaySn/orderPaySn?pay_sn=${pay_sn}`
- // })
- }
- });
- }
- else {
- wx.showToast({
- icon: 'none',
- title: res.message,
- duration: 2000
- })
- app.globalData.fcodeErr = res.message
- setTimeout(() => {
- wx.navigateBack()
- }, 2000);
- }
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- if(!this.data.firstLoad) {
- let defaultAddress = app.globalData.defaultAddress
- console.log('defaultAddress',defaultAddress)
- app.setFromSource(this.data.fromSource)
- if (defaultAddress) {
- this.setData({
- defaultAddress
- })
- }
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- }
- })
|