pay.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. if (this.data.account == 2){
  47. if (!form.bill_name){
  48. wx.showToast({
  49. title: '请输入公司全称',
  50. icon: 'none',
  51. duration: 2000
  52. })
  53. return false
  54. }
  55. if (!form.bill_no) {
  56. wx.showToast({
  57. title: '请输入税号',
  58. icon: 'none',
  59. duration: 2000
  60. })
  61. return false
  62. }
  63. }
  64. wx.showLoading({
  65. title: '正在提交...',
  66. })
  67. wx.request({
  68. url: host+'/api/wx/signup/pay',
  69. method:'POST',
  70. header: {
  71. openid: app.globalData.openid
  72. },
  73. data:{
  74. total_fee: data.price,
  75. signup_id:data.id,
  76. bill_type: Number(this.data.account)+1,
  77. bill_no: form.bill_no,
  78. bill_mat:1
  79. },
  80. success:res=>{
  81. console.log(res.data.data)
  82. wx.hideLoading()
  83. var timestamp = Math.round(new Date().getTime() / 1000).toString();
  84. 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();
  85. console.log(paySign)
  86. wx.requestPayment({
  87. timeStamp: timestamp,
  88. nonceStr: res.data.data.nonce_str,
  89. package: 'prepay_id=' + res.data.data.prepay_id,
  90. signType: 'MD5',
  91. paySign: paySign,
  92. success(res) {
  93. wx.switchTab({
  94. url: '/pages/apply/apply'
  95. });
  96. },
  97. fail(res) { console.log(res)}
  98. })
  99. }
  100. })
  101. },
  102. /**
  103. * 生命周期函数--监听页面初次渲染完成
  104. */
  105. onReady: function () {
  106. },
  107. /**
  108. * 生命周期函数--监听页面显示
  109. */
  110. onShow: function () {
  111. },
  112. /**
  113. * 生命周期函数--监听页面隐藏
  114. */
  115. onHide: function () {
  116. },
  117. /**
  118. * 生命周期函数--监听页面卸载
  119. */
  120. onUnload: function () {
  121. },
  122. /**
  123. * 页面相关事件处理函数--监听用户下拉动作
  124. */
  125. onPullDownRefresh: function () {
  126. },
  127. /**
  128. * 页面上拉触底事件的处理函数
  129. */
  130. onReachBottom: function () {
  131. },
  132. /**
  133. * 用户点击右上角分享
  134. */
  135. onShareAppMessage: function () {
  136. }
  137. })