signup.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. console.log(data,'aaaa')
  132. $api.wxpay(data).then(res=>{
  133. if(res.data.data.free){
  134. app.globalData.follow = 1
  135. wx.showToast({
  136. title: '报名成功',
  137. })
  138. wx.switchTab({
  139. url: '../index/index'
  140. });
  141. }
  142. var timestamp = Math.round(new Date().getTime() / 1000).toString();
  143. 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();
  144. console.log(paySign)
  145. wx.requestPayment({
  146. timeStamp: timestamp,
  147. nonceStr: res.data.data.nonce_str,
  148. package: 'prepay_id=' + res.data.data.prepay_id,
  149. signType: 'MD5',
  150. paySign: paySign,
  151. success(res) {
  152. app.globalData.follow = 1
  153. wx.showToast({
  154. title: '报名成功',
  155. })
  156. wx.switchTab({
  157. url: '../index/index'
  158. });
  159. },
  160. fail(res) { console.log(res)}
  161. })
  162. })
  163. },
  164. /**
  165. * 生命周期函数--监听页面初次渲染完成
  166. */
  167. onReady: function () {
  168. },
  169. /**
  170. * 生命周期函数--监听页面显示
  171. */
  172. onShow: function () {
  173. },
  174. /**
  175. * 生命周期函数--监听页面隐藏
  176. */
  177. onHide: function () {
  178. },
  179. /**
  180. * 生命周期函数--监听页面卸载
  181. */
  182. onUnload: function () {
  183. },
  184. /**
  185. * 页面相关事件处理函数--监听用户下拉动作
  186. */
  187. onPullDownRefresh: function () {
  188. },
  189. /**
  190. * 页面上拉触底事件的处理函数
  191. */
  192. onReachBottom: function () {
  193. },
  194. /**
  195. * 用户点击右上角分享
  196. */
  197. onShareAppMessage: function () {
  198. }
  199. })