signup.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. // pages/user/user.js
  2. const app = getApp()
  3. var host = app.globalData.host;
  4. const $api = require('../../utils/api.js').API;
  5. import md5 from '../../utils/md5.js';//支付页面引入md5.js
  6. var logindata={}
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. info: {},
  13. index:-1,
  14. type:'',
  15. phone:'',
  16. phcode:'',
  17. text:'获取验证码'
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. this.setData({
  24. type:options.type
  25. })
  26. $api.getsignup().then(res=>{
  27. this.setData({
  28. info:res.data.data
  29. })
  30. if(options.type == 1){
  31. res.data.data.groups.forEach(item=>{
  32. if(!item.charge){
  33. this.setData({
  34. match_group:item.id
  35. })
  36. }
  37. })
  38. }
  39. })
  40. },
  41. bindChange(e) {
  42. let match=this.data.info.groups;
  43. this.setData({
  44. index: e.detail.value,
  45. match_group: match[e.detail.value].id
  46. })
  47. },
  48. getcode(){
  49. if(this.data.phone.length>=11){
  50. this.setData({
  51. text:"59s重新发送"
  52. })
  53. this.countdown()
  54. $api.sendcode({phone:this.data.phone}).then(res=>{
  55. })
  56. }else{
  57. wx.showToast({
  58. icon: 'none',
  59. title: '请输入正确的手机号',
  60. })
  61. }
  62. },
  63. countdown(){
  64. var count=60,_this=this;
  65. var timer=setInterval(c,1000)
  66. function c(){
  67. if(count>0){
  68. count--;
  69. _this.setData({
  70. text:count+"s重新发送"
  71. })
  72. }else{
  73. _this.setData({
  74. text:'获取验证码'
  75. })
  76. clearInterval(timer)
  77. }
  78. }
  79. },
  80. inputchange(e) {
  81. this.setData({
  82. phone: e.detail.value
  83. })
  84. },
  85. codechange(e) {
  86. this.setData({
  87. phcode: e.detail.value
  88. })
  89. },
  90. post(){
  91. var data={
  92. signup_type:this.data.type,
  93. total_fee:this.data.info.viewer_price,
  94. phone:this.data.phone,
  95. phcode:this.data.phcode,
  96. match_group:this.data.match_group,
  97. match_id:this.data.info.id,
  98. match_name:this.data.info.name
  99. }
  100. if(this.data.type == 2){
  101. data.total_fee=this.data.info.player_price
  102. }
  103. if (!data.match_group) {
  104. wx.showToast({
  105. icon: 'none',
  106. title: '请选择比赛分组',
  107. })
  108. return
  109. }
  110. if (data.phone.length<11){
  111. wx.showToast({
  112. icon: 'none',
  113. title: '请输入正确的手机号',
  114. })
  115. return
  116. }
  117. if (!data.phcode) {
  118. wx.showToast({
  119. icon: 'none',
  120. title: '请输入验证码',
  121. })
  122. return
  123. }
  124. $api.wxpay(data).then(res=>{
  125. var timestamp = Math.round(new Date().getTime() / 1000).toString();
  126. 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();
  127. console.log(paySign)
  128. wx.requestPayment({
  129. timeStamp: timestamp,
  130. nonceStr: res.data.data.nonce_str,
  131. package: 'prepay_id=' + res.data.data.prepay_id,
  132. signType: 'MD5',
  133. paySign: paySign,
  134. success(res) {
  135. wx.showToast({
  136. title: '报名成功',
  137. })
  138. wx.switchTab({
  139. url: '../index/index'
  140. });
  141. },
  142. fail(res) { console.log(res)}
  143. })
  144. })
  145. },
  146. /**
  147. * 生命周期函数--监听页面初次渲染完成
  148. */
  149. onReady: function () {
  150. },
  151. /**
  152. * 生命周期函数--监听页面显示
  153. */
  154. onShow: function () {
  155. },
  156. /**
  157. * 生命周期函数--监听页面隐藏
  158. */
  159. onHide: function () {
  160. },
  161. /**
  162. * 生命周期函数--监听页面卸载
  163. */
  164. onUnload: function () {
  165. },
  166. /**
  167. * 页面相关事件处理函数--监听用户下拉动作
  168. */
  169. onPullDownRefresh: function () {
  170. },
  171. /**
  172. * 页面上拉触底事件的处理函数
  173. */
  174. onReachBottom: function () {
  175. },
  176. /**
  177. * 用户点击右上角分享
  178. */
  179. onShareAppMessage: function () {
  180. }
  181. })