phoneCharges.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. fGoodsRequesting: false,
  12. currentIndex: 0, //页签索引
  13. rechargeGearActiveIndex: 0, //挡位项目索引
  14. tips:'', //顶部tips
  15. inviter_tip: '',
  16. goods_inviter_tips: new Map(),
  17. goods:[], //挡位数据
  18. goods_id:'', //当前选中挡位的goods_id
  19. card_type: 'phone',
  20. card_no: '',
  21. fromSource: ''
  22. },
  23. // 页签切换
  24. handlerClickTabItem(e) {
  25. var dataset = e.currentTarget.dataset
  26. this.setData({
  27. currentIndex: dataset.activeindex,
  28. card_no: dataset.cardno
  29. });
  30. },
  31. //充值档位切换
  32. handlerClickRechargeGear(e) {
  33. var dataset = e.currentTarget.dataset
  34. let goods_id = dataset.currentvalue
  35. this.setData({
  36. rechargeGearActiveIndex: dataset.activeindex,
  37. goods_id: goods_id,
  38. inviter_tip: this.data.goods_inviter_tips.get(goods_id)
  39. });
  40. },
  41. //跳转到油卡管理页面
  42. handlerAddCard(e){
  43. app.navigateto('/pages/postageManage/postageManage?card_type=phone')
  44. },
  45. /**
  46. * 生命周期函数--监听页面加载
  47. */
  48. onLoad: function (options) {
  49. this.requestGoods();
  50. },
  51. findCard(cards,card_type) {
  52. for (const card of cards) {
  53. if (card.card_type == card_type) {
  54. return card;
  55. }
  56. }
  57. return {};
  58. },
  59. requestGoods() {
  60. if (this.fGoodsRequesting) return;
  61. this.fGoodsRequesting = true
  62. let fromSource = recordSource(app, `act=index&op=card_goods`)
  63. this.setData({
  64. fromSource: app.globalData.fromSource,
  65. });
  66. var self = this;
  67. getReq(app, {
  68. act: 'index',
  69. op: 'card_goods',
  70. page_type: 'phone',
  71. from: fromSource
  72. },
  73. function (res) {
  74. wx.stopPullDownRefresh()
  75. if (res.code == 200) {
  76. if (res.datas && res.datas.goods) {
  77. var datas = res.datas
  78. let card = app.getValueByKey('phone', datas.cards)
  79. card = app.isNullObject(card) ? { card_no: '', card_type: 'phone' } : card
  80. console.log('card no:', card.card_no)
  81. let goods_inviter_tips = self.formGoodsInviterTips(datas.goods_inviter_tips)
  82. let goods_id = datas.goods[0].goods_id
  83. let inviter_tip = goods_inviter_tips.get(goods_id)
  84. self.setData({
  85. tips: datas.tips,
  86. goods: datas.goods,
  87. inviter_tip: inviter_tip,
  88. goods_inviter_tips,
  89. goods_id: goods_id,
  90. card_no: card.card_no
  91. });
  92. }
  93. } else {
  94. wx.showToast({
  95. icon: 'none',
  96. title: '支付未完成,订单将在10分钟后取消...',
  97. duration: 5000
  98. })
  99. }
  100. self.fGoodsRequesting = false
  101. })
  102. },
  103. formGoodsInviterTips(godosInviterTips) {
  104. let ret = new Map();
  105. godosInviterTips.forEach(item => {
  106. let goods_id = item.goods_id
  107. let tip = item.tip
  108. ret.set(goods_id, tip)
  109. });
  110. return ret;
  111. },
  112. // 立即充值
  113. handlerRecharge()
  114. {
  115. const { goods_id, card_no, card_type } = this.data
  116. if(!card_no){
  117. app.showToast('卡号不能为空')
  118. return
  119. }
  120. buyVGoods(app, goods_id, 1, { card_no, card_type}, (res) => {
  121. let page = getCurrentPages().pop();
  122. page.onLoad()
  123. }, (err) => {
  124. wx.showToast({
  125. icon: 'none',
  126. title: '支付未完成,订单将在10分钟后取消...',
  127. duration: 5000
  128. })
  129. let page = getCurrentPages().pop();
  130. page.onLoad()
  131. })
  132. },
  133. /**
  134. * 生命周期函数--监听页面初次渲染完成
  135. */
  136. onReady: function () {
  137. },
  138. /**
  139. * 生命周期函数--监听页面显示
  140. */
  141. onShow: function () {
  142. const record = app.globalData.record || {}
  143. const { card_no = '' } = record
  144. if (card_no) {
  145. this.setData({ card_no })
  146. }
  147. app.setFromSource(this.data.fromSource)
  148. },
  149. /**
  150. * 生命周期函数--监听页面隐藏
  151. */
  152. onHide: function () {
  153. },
  154. /**
  155. * 生命周期函数--监听页面卸载
  156. */
  157. onUnload: function () {
  158. },
  159. /**
  160. * 页面相关事件处理函数--监听用户下拉动作
  161. */
  162. onPullDownRefresh: function () {
  163. this.requestGoods();
  164. },
  165. /**
  166. * 页面上拉触底事件的处理函数
  167. */
  168. onReachBottom: function () {
  169. },
  170. onShareAppMessage: function () {
  171. return app.cardShareInfo();
  172. }
  173. })