signup.js 5.7 KB

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