phoneCharges.js 5.0 KB

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