phoneCharges.js 5.4 KB

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