signup.js 5.5 KB

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