postage.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. tabsData: [
  20. { id: 0, icon: '/image/postage/sinopec.png', title: '中国石化', tips: '选择油卡', card_type: 'sinopec', card_no: '' },
  21. { id: 1, icon: '/image/postage/petrochina.png', title: '中国石油', tips: '选择油卡', card_type: 'petrochina', card_no: '' }
  22. ],
  23. fromSource: ''
  24. },
  25. // 页签切换
  26. handlerClickTabItem(e) {
  27. var dataset = e.currentTarget.dataset
  28. this.setData({
  29. currentIndex: dataset.activeindex,
  30. card_no: dataset.cardno
  31. });
  32. },
  33. //充值档位切换
  34. handlerClickRechargeGear(e) {
  35. var dataset = e.currentTarget.dataset
  36. this.setData({
  37. rechargeGearActiveIndex: dataset.activeindex,
  38. goods_id: dataset.currentvalue
  39. });
  40. },
  41. //跳转到油卡管理页面
  42. handlerAddCard(e){
  43. const { cardtype } = e.currentTarget.dataset
  44. wx.navigateTo({
  45. url: `/pages/postageManage/postageManage?card_type=${cardtype}`,
  46. })
  47. },
  48. /**
  49. * 生命周期函数--监听页面加载
  50. */
  51. onLoad: function (options) {
  52. let fromSource = recordSource(app, `act=index&op=card_goods`)
  53. this.setData({
  54. fromSource: app.globalData.fromSource,
  55. card_no: this.data.tabsData[0].card_no
  56. });
  57. var self = this;
  58. getReq({
  59. act: 'index',
  60. op: 'card_goods',
  61. card_type: 'oil',
  62. from: fromSource
  63. }, function (res) {
  64. self.setData({
  65. firstLoad: false
  66. });
  67. if (res.code == 200) {
  68. if(res.datas && res.datas.goods){
  69. var datas = res.datas
  70. self.setData({
  71. tips: datas.tips,
  72. goods: datas.goods,
  73. goods_id: datas.goods[0].goods_id
  74. });
  75. }
  76. }else {
  77. wx.showToast({
  78. icon: 'none',
  79. title: res.message,
  80. duration: 2000
  81. })
  82. }
  83. })
  84. },
  85. // 立即充值
  86. handlerRecharge(){
  87. // wx.showToast({
  88. // icon: 'none',
  89. // title: `goods_id: ${this.data.goods_id}, card_no: ${this.data.card_no}`,
  90. // duration: 2000
  91. // })
  92. const { goods_id, card_no } = this.data
  93. if(!card_no){
  94. app.showToast('卡号不能为空')
  95. return
  96. }
  97. buyVGoods(goods_id,1,{ card_no }, (res) => {
  98. // console.log('res',res) 成功回调
  99. }, (err) => {
  100. // 失败回调
  101. })
  102. },
  103. /**
  104. * 生命周期函数--监听页面初次渲染完成
  105. */
  106. onReady: function () {
  107. },
  108. /**
  109. * 生命周期函数--监听页面显示
  110. */
  111. onShow: function () {
  112. if(!this.data.firstLoad) {
  113. const record = app.globalData.record || {}
  114. const { card_no = '' } = record
  115. app.setFromSource(this.data.fromSource)
  116. if (record) {
  117. this.setData({ card_no })
  118. }
  119. }
  120. },
  121. /**
  122. * 生命周期函数--监听页面隐藏
  123. */
  124. onHide: function () {
  125. },
  126. /**
  127. * 生命周期函数--监听页面卸载
  128. */
  129. onUnload: function () {
  130. },
  131. /**
  132. * 页面相关事件处理函数--监听用户下拉动作
  133. */
  134. onPullDownRefresh: function () {
  135. },
  136. /**
  137. * 页面上拉触底事件的处理函数
  138. */
  139. onReachBottom: function () {
  140. }
  141. })