signup.js 5.0 KB

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