phoneCharges.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import recordSource from '../../utils/recordSource';
  2. const config = require('../../config.js')
  3. const getReq = config.getReq
  4. const buyVGoods = config.buyVGoods
  5. let app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. currentIndex: 0, //页签索引
  12. rechargeGearActiveIndex: 0, //挡位项目索引
  13. tips:'', //顶部tips
  14. goods:[], //挡位数据
  15. goods_id:'', //当前选中挡位的goods_id
  16. card_type: '', //油卡类型 (中石化/中石油)
  17. card_no: '', //油卡号
  18. firstLoad: true,
  19. fromSource: ''
  20. },
  21. // 页签切换
  22. handlerClickTabItem(e) {
  23. var dataset = e.currentTarget.dataset
  24. this.setData({
  25. currentIndex: dataset.activeindex,
  26. card_no: dataset.cardno
  27. });
  28. },
  29. //充值档位切换
  30. handlerClickRechargeGear(e) {
  31. var dataset = e.currentTarget.dataset
  32. this.setData({
  33. rechargeGearActiveIndex: dataset.activeindex,
  34. goods_id: dataset.currentvalue
  35. });
  36. },
  37. //跳转到油卡管理页面
  38. handlerAddCard(){
  39. wx.navigateTo({
  40. url: '/pages/postageManage/postageManage',
  41. })
  42. },
  43. /**
  44. * 生命周期函数--监听页面加载
  45. */
  46. onLoad: function (options) {
  47. let fromSource = recordSource(app, `act=index&op=card_goods`)
  48. this.setData({
  49. fromSource: app.globalData.fromSource,
  50. });
  51. var self = this;
  52. getReq({
  53. act: 'index',
  54. op: 'card_goods',
  55. card_type: 'oil',
  56. from: fromSource
  57. }, function (res) {
  58. self.setData({
  59. firstLoad: false
  60. });
  61. if (res.code == 200) {
  62. if(res.datas && res.datas.goods){
  63. var datas = res.datas
  64. self.setData({
  65. tips: datas.tips,
  66. goods: datas.goods,
  67. goods_id: datas.goods[0].goods_id
  68. });
  69. }
  70. }else {
  71. wx.showToast({
  72. icon: 'none',
  73. title: res.message,
  74. duration: 2000
  75. })
  76. }
  77. })
  78. },
  79. // 立即充值
  80. handlerRecharge(){
  81. // wx.showToast({
  82. // icon: 'none',
  83. // title: `goods_id: ${this.data.goods_id}, card_no: ${this.data.card_no}`,
  84. // duration: 2000
  85. // })
  86. console.table({'goods_id': this.data.goods_id, 'card_no': this.data.card_no})
  87. buyVGoods(this.data.goods_id,1,{ card_no: this.data.card_no }, (res) => {
  88. // console.log('res',res) 成功回调
  89. }, (err) => {
  90. // 失败回调
  91. })
  92. },
  93. /**
  94. * 生命周期函数--监听页面初次渲染完成
  95. */
  96. onReady: function () {
  97. },
  98. /**
  99. * 生命周期函数--监听页面显示
  100. */
  101. onShow: function () {
  102. if(!this.data.firstLoad) {
  103. let defaultAddress = app.globalData.defaultAddress
  104. console.log('defaultAddress',defaultAddress)
  105. app.setFromSource(this.data.fromSource)
  106. if (defaultAddress) {
  107. this.setData({
  108. defaultAddress
  109. })
  110. }
  111. }
  112. },
  113. /**
  114. * 生命周期函数--监听页面隐藏
  115. */
  116. onHide: function () {
  117. },
  118. /**
  119. * 生命周期函数--监听页面卸载
  120. */
  121. onUnload: function () {
  122. },
  123. /**
  124. * 页面相关事件处理函数--监听用户下拉动作
  125. */
  126. onPullDownRefresh: function () {
  127. },
  128. /**
  129. * 页面上拉触底事件的处理函数
  130. */
  131. onReachBottom: function () {
  132. }
  133. })