pay.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // pages/pay/pay.js
  2. import md5 from '../../utils/md5.js';//支付页面引入md5.js
  3. const app = getApp()
  4. const host = app.globalData.host;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. accountArray: ["不需要","个人发票", "公司发票"],
  11. accountTypeArray: ["纸质发票"],
  12. account:0,
  13. account_type:0,
  14. data:{}
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. wx.request({
  21. url: host + '/api/wx/signup',
  22. method: 'GET',
  23. data: { id: options.id },
  24. success:res=>{
  25. this.setData({
  26. data:res.data.data
  27. })
  28. }
  29. })
  30. },
  31. pickerChange:function(e){
  32. if (e.target.dataset.name == 'account') {
  33. this.setData({
  34. account: e.detail.value
  35. })
  36. };
  37. if (e.target.dataset.name == 'account_type') {
  38. this.setData({
  39. account_type: e.detail.value
  40. })
  41. };
  42. },
  43. pay:function(e){
  44. // console.log(e.detail.value)
  45. var data = this.data.data, form = e.detail.value;
  46. wx.showLoading({
  47. title: '正在提交...',
  48. })
  49. wx.request({
  50. url: host+'/api/wx/signup/pay',
  51. method:'POST',
  52. header: {
  53. openid: app.globalData.openid
  54. },
  55. data:{
  56. total_fee: data.price,
  57. signup_id:data.id,
  58. bill_type: this.data.account+1,
  59. bill_no: form.bill_no,
  60. bill_mat:1
  61. },
  62. success:res=>{
  63. console.log(res.data.data)
  64. wx.hideLoading()
  65. var timestamp = Math.round(new Date().getTime() / 1000).toString();
  66. var paySign = md5('appId=' + res.data.data.appid + '&nonceStr=' + res.data.data.nonce_str + '&package=prepay_id=' + res.data.data.prepay_id + '&signType=MD5&timeStamp=' + timestamp + '&key=' + res.data.data.key).toUpperCase();
  67. console.log(paySign)
  68. wx.requestPayment({
  69. timeStamp: timestamp,
  70. nonceStr: res.data.data.nonce_str,
  71. package: 'prepay_id=' + res.data.data.prepay_id,
  72. signType: 'MD5',
  73. paySign: paySign,
  74. success(res) {
  75. wx.switchTab({
  76. url: '/pages/apply/apply'
  77. });
  78. },
  79. fail(res) { console.log(res)}
  80. })
  81. }
  82. })
  83. },
  84. /**
  85. * 生命周期函数--监听页面初次渲染完成
  86. */
  87. onReady: function () {
  88. },
  89. /**
  90. * 生命周期函数--监听页面显示
  91. */
  92. onShow: function () {
  93. },
  94. /**
  95. * 生命周期函数--监听页面隐藏
  96. */
  97. onHide: function () {
  98. },
  99. /**
  100. * 生命周期函数--监听页面卸载
  101. */
  102. onUnload: function () {
  103. },
  104. /**
  105. * 页面相关事件处理函数--监听用户下拉动作
  106. */
  107. onPullDownRefresh: function () {
  108. },
  109. /**
  110. * 页面上拉触底事件的处理函数
  111. */
  112. onReachBottom: function () {
  113. },
  114. /**
  115. * 用户点击右上角分享
  116. */
  117. onShareAppMessage: function () {
  118. }
  119. })