signup.js 4.7 KB

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