postage.js 4.4 KB

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