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(e){
  39. app.navigateto('/pages/postageManage/postageManage?card_type=phone')
  40. },
  41. /**
  42. * 生命周期函数--监听页面加载
  43. */
  44. onLoad: function (options) {
  45. let fromSource = recordSource(app, `act=index&op=card_goods`)
  46. this.setData({
  47. fromSource: app.globalData.fromSource,
  48. });
  49. var self = this;
  50. getReq({
  51. act: 'index',
  52. op: 'card_goods',
  53. page_type: 'oil',
  54. from: fromSource
  55. }, function (res) {
  56. self.setData({
  57. firstLoad: false
  58. });
  59. if (res.code == 200) {
  60. if(res.datas && res.datas.goods){
  61. var datas = res.datas
  62. self.setData({
  63. tips: datas.tips,
  64. goods: datas.goods,
  65. goods_id: datas.goods[0].goods_id
  66. });
  67. }
  68. }else {
  69. wx.showToast({
  70. icon: 'none',
  71. title: res.message,
  72. duration: 2000
  73. })
  74. }
  75. })
  76. },
  77. // 立即充值
  78. handlerRecharge()
  79. {
  80. // wx.showToast({
  81. // icon: 'none',
  82. // title: `goods_id: ${this.data.goods_id}, card_no: ${this.data.card_no}`,
  83. // duration: 2000
  84. // })
  85. const { goods_id, card_no } = this.data
  86. if(!card_no){
  87. app.showToast('卡号不能为空')
  88. return
  89. }
  90. buyVGoods(goods_id,1,{ card_no }, (res) => {
  91. // console.log('res',res) 成功回调
  92. }, (err) => {
  93. // 失败回调
  94. })
  95. },
  96. /**
  97. * 生命周期函数--监听页面初次渲染完成
  98. */
  99. onReady: function () {
  100. },
  101. /**
  102. * 生命周期函数--监听页面显示
  103. */
  104. onShow: function () {
  105. if(!this.data.firstLoad) {
  106. const record = app.globalData.record || {}
  107. console.log('record',record)
  108. const { card_no = '' } = record
  109. app.setFromSource(this.data.fromSource)
  110. if (record) {
  111. this.setData({ card_no })
  112. }
  113. }
  114. },
  115. /**
  116. * 生命周期函数--监听页面隐藏
  117. */
  118. onHide: function () {
  119. },
  120. /**
  121. * 生命周期函数--监听页面卸载
  122. */
  123. onUnload: function () {
  124. },
  125. /**
  126. * 页面相关事件处理函数--监听用户下拉动作
  127. */
  128. onPullDownRefresh: function () {
  129. },
  130. /**
  131. * 页面上拉触底事件的处理函数
  132. */
  133. onReachBottom: function () {
  134. }
  135. })