phoneCharges.js 5.1 KB

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