pay.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. bill_name: form.bill_name
  80. },
  81. success:res=>{
  82. console.log(res.data.data)
  83. wx.hideLoading()
  84. var timestamp = Math.round(new Date().getTime() / 1000).toString();
  85. 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();
  86. console.log(paySign)
  87. wx.requestPayment({
  88. timeStamp: timestamp,
  89. nonceStr: res.data.data.nonce_str,
  90. package: 'prepay_id=' + res.data.data.prepay_id,
  91. signType: 'MD5',
  92. paySign: paySign,
  93. success(res) {
  94. wx.switchTab({
  95. url: '/pages/apply/apply'
  96. });
  97. },
  98. fail(res) { console.log(res)}
  99. })
  100. }
  101. })
  102. },
  103. /**
  104. * 生命周期函数--监听页面初次渲染完成
  105. */
  106. onReady: function () {
  107. },
  108. /**
  109. * 生命周期函数--监听页面显示
  110. */
  111. onShow: function () {
  112. },
  113. /**
  114. * 生命周期函数--监听页面隐藏
  115. */
  116. onHide: function () {
  117. },
  118. /**
  119. * 生命周期函数--监听页面卸载
  120. */
  121. onUnload: function () {
  122. },
  123. /**
  124. * 页面相关事件处理函数--监听用户下拉动作
  125. */
  126. onPullDownRefresh: function () {
  127. },
  128. /**
  129. * 页面上拉触底事件的处理函数
  130. */
  131. onReachBottom: function () {
  132. },
  133. /**
  134. * 用户点击右上角分享
  135. */
  136. onShareAppMessage: function () {
  137. }
  138. })