signup.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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.signup_name.length>7){
  128. wx.showToast({
  129. icon: 'none',
  130. title: '名字小于7个字',
  131. })
  132. return
  133. }
  134. if (data.phone.length<11){
  135. wx.showToast({
  136. icon: 'none',
  137. title: '请输入正确的手机号',
  138. })
  139. return
  140. }
  141. if (!data.phcode) {
  142. wx.showToast({
  143. icon: 'none',
  144. title: '请输入验证码',
  145. })
  146. return
  147. }
  148. if(this.data.isLoading == 1){
  149. return
  150. }
  151. this.setData({
  152. isLoading:1
  153. })
  154. wx.showLoading({
  155. title: '正在提交订单',
  156. })
  157. $api.wxpay(data).then(res=>{
  158. wx.hideLoading()
  159. this.setData({
  160. isLoading:0
  161. })
  162. if(res.data.data.free){
  163. app.globalData.follow = 1
  164. wx.showToast({
  165. title: '报名成功',
  166. })
  167. wx.switchTab({
  168. url: '../index/index'
  169. });
  170. }
  171. var timestamp = Math.round(new Date().getTime() / 1000).toString();
  172. 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();
  173. console.log(paySign)
  174. wx.requestPayment({
  175. timeStamp: timestamp,
  176. nonceStr: res.data.data.nonce_str,
  177. package: 'prepay_id=' + res.data.data.prepay_id,
  178. signType: 'MD5',
  179. paySign: paySign,
  180. success(res) {
  181. app.globalData.follow = 1
  182. wx.showToast({
  183. title: '报名成功',
  184. })
  185. wx.switchTab({
  186. url: '../index/index'
  187. });
  188. },
  189. fail(res) {
  190. console.log(res)
  191. wx.showModal({
  192. title: '支付错误',
  193. content: '请重新登录',
  194. complete: (res) => {
  195. if (res.cancel) {
  196. }
  197. if (res.confirm) {
  198. wx.removeStorage({
  199. key: 'userInfo'
  200. })
  201. wx.navigateTo({
  202. url: '../login/user',
  203. })
  204. }
  205. }
  206. })
  207. }
  208. })
  209. })
  210. },
  211. /**
  212. * 生命周期函数--监听页面初次渲染完成
  213. */
  214. onReady: function () {
  215. },
  216. /**
  217. * 生命周期函数--监听页面显示
  218. */
  219. onShow: function () {
  220. },
  221. /**
  222. * 生命周期函数--监听页面隐藏
  223. */
  224. onHide: function () {
  225. },
  226. /**
  227. * 生命周期函数--监听页面卸载
  228. */
  229. onUnload: function () {
  230. },
  231. /**
  232. * 页面相关事件处理函数--监听用户下拉动作
  233. */
  234. onPullDownRefresh: function () {
  235. },
  236. /**
  237. * 页面上拉触底事件的处理函数
  238. */
  239. onReachBottom: function () {
  240. },
  241. /**
  242. * 用户点击右上角分享
  243. */
  244. onShareAppMessage: function () {
  245. }
  246. })