postage.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. import recordSource from '../../utils/recordSource';
  2. const getReq = require('../../config.js').getReq
  3. let app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. currentIndex: 0, //页签索引
  10. rechargeGearActiveIndex: 0, //挡位项目索引
  11. tips:'', //顶部tips
  12. goods:[], //挡位数据
  13. goods_id:'', //当前选中挡位的goods_id
  14. card_type: '', //油卡类型 (中石化/中石油)
  15. card_no: '', //油卡号
  16. firstLoad: true,
  17. tabsData: [
  18. { id: 0, icon: '/image/postage/sinopec.png', title: '中国石化', tips: '选择油卡:(一人最多十张油卡)', card_no: '15853434113521' },
  19. { id: 1, icon: '/image/postage/petrochina.png', title: '中国石油', tips: '选择油卡:(一人最多八张油卡)', card_no: '41865461251351' }
  20. ],
  21. // <<<<<<< HEAD
  22. // selectArray: [{
  23. // "id": "10",
  24. // "text": "9066666888"
  25. // }, {
  26. // "id": "21",
  27. // "text": "25288888556"
  28. // }],
  29. // gearData: [
  30. // { faceValue: 100, price: 95 },
  31. // { faceValue: 200, price: 190 },
  32. // { faceValue: 500, price: 475 },
  33. // { faceValue: 1000, price: 950 }
  34. // ]
  35. // =======
  36. fromSource: ''
  37. // >>>>>>> 259bb9c31cb59d1d11de38b7b18920184eefb6c9
  38. },
  39. // 页签切换
  40. handlerClickTabItem(e) {
  41. var dataset = e.currentTarget.dataset
  42. this.setData({
  43. currentIndex: dataset.activeindex,
  44. card_no: dataset.cardno
  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(){
  57. wx.navigateTo({
  58. url: '/pages/postageManage/postageManage',
  59. })
  60. },
  61. /**
  62. * 生命周期函数--监听页面加载
  63. */
  64. onLoad: function (options) {
  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. var self = this;
  71. getReq({
  72. act: 'index',
  73. op: 'card_goods',
  74. card_type: 'oil',
  75. from: fromSource
  76. }, function (res) {
  77. self.setData({
  78. firstLoad: false
  79. });
  80. if (res.code == 200) {
  81. if(res.datas && res.datas.goods){
  82. var datas = res.datas
  83. self.setData({
  84. tips: datas.tips,
  85. goods: datas.goods,
  86. goods_id: datas.goods[0].goods_id
  87. });
  88. }
  89. }else {
  90. wx.showToast({
  91. icon: 'none',
  92. title: res.message,
  93. duration: 2000
  94. })
  95. }
  96. })
  97. },
  98. // 立即充值
  99. handlerRecharge(){
  100. wx.showToast({
  101. icon: 'none',
  102. title: `goods_id: ${this.data.goods_id}, card_no: ${this.data.card_no}`,
  103. duration: 2000
  104. })
  105. console.table({'goods_id': this.data.goods_id, 'card_no': this.data.card_no})
  106. this.toPay()
  107. },
  108. toPay() {
  109. let goods_id = this.data.goods_id
  110. let goods_num = 1
  111. let iscart = this.data.ifcart
  112. let cart_id = this.data.cart_id
  113. let ifcart = cart_id ? 1 : 0
  114. let cartids = cart_id ? cart_id : (goods_id + '|' + goods_num)
  115. let params = {
  116. act: 'member_buy',
  117. op: 'step_vsecond',
  118. payment: 'minipay',
  119. usebonus: 1,
  120. ifcart:1,
  121. cart_id: 1,
  122. invoice_id: 0
  123. }
  124. params = Object.assign({}, params);
  125. getReq(params, function (res) {
  126. wx.hideLoading()
  127. if (res.code == 200) {
  128. let param = res.datas.param.data
  129. let pay_sn = res.datas.pay_sn
  130. wx.requestPayment({
  131. timeStamp: param.timeStamp, //时间戳,自1970年以来的秒数
  132. nonceStr: param.nonceStr, //随机串
  133. package: param.package,
  134. signType: param.signType, //微信签名方式:
  135. paySign: param.paySign, //微信签名
  136. success: function (res) {
  137. wx.reLaunch({
  138. url: "/pages/index/index"
  139. })
  140. },
  141. fail: function (res) {
  142. // wx.redirectTo({
  143. // url: `/pages/orderPaySn/orderPaySn?pay_sn=${pay_sn}`
  144. // })
  145. }
  146. });
  147. }
  148. else {
  149. wx.showToast({
  150. icon: 'none',
  151. title: res.message,
  152. duration: 2000
  153. })
  154. app.globalData.fcodeErr = res.message
  155. setTimeout(() => {
  156. wx.navigateBack()
  157. }, 2000);
  158. }
  159. })
  160. },
  161. /**
  162. * 生命周期函数--监听页面初次渲染完成
  163. */
  164. onReady: function () {
  165. },
  166. /**
  167. * 生命周期函数--监听页面显示
  168. */
  169. onShow: function () {
  170. if(!this.data.firstLoad) {
  171. let defaultAddress = app.globalData.defaultAddress
  172. console.log('defaultAddress',defaultAddress)
  173. app.setFromSource(this.data.fromSource)
  174. if (defaultAddress) {
  175. this.setData({
  176. defaultAddress
  177. })
  178. }
  179. }
  180. },
  181. /**
  182. * 生命周期函数--监听页面隐藏
  183. */
  184. onHide: function () {
  185. },
  186. /**
  187. * 生命周期函数--监听页面卸载
  188. */
  189. onUnload: function () {
  190. },
  191. /**
  192. * 页面相关事件处理函数--监听用户下拉动作
  193. */
  194. onPullDownRefresh: function () {
  195. },
  196. /**
  197. * 页面上拉触底事件的处理函数
  198. */
  199. onReachBottom: function () {
  200. }
  201. })