signup.js 4.6 KB

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