postage.js 4.5 KB

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