signup.js 5.0 KB

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