123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- // pages/user/user.js
- const app = getApp()
- var host = app.globalData.host;
- const $api = require('../../utils/api.js').API;
- import md5 from '../../utils/md5.js';//支付页面引入md5.js
- var logindata={}
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- info: {},
- index:-1,
- type:'',
- phone:'',
- phcode:'',
- signup_name:'',
- text:'获取验证码',
- isLoading:0,
- userinfo:{},
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({
- type:options.type
- })
- $api.getsignup().then(res=>{
- this.setData({
- info:res.data.data
- })
- if(options.type == 1){
- res.data.data.groups.forEach(item=>{
- if(!item.charge){
- this.setData({
- match_group:item.id
- })
- }
- })
-
- }
- })
- wx.getStorage({
- key: 'user',
- complete: res => {
- this.setData({
- userinfo: res.data,
- })
- }
- })
- },
- bindChange(e) {
- let match=this.data.info.groups;
- this.setData({
- index: e.detail.value,
- match_group: match[e.detail.value].id
- })
- },
- getcode(){
- if(this.data.phone.length>=11){
- this.setData({
- text:"59s重新发送"
- })
- this.countdown()
- $api.sendcode({phone:this.data.phone}).then(res=>{
-
- })
- }else{
- wx.showToast({
- icon: 'none',
- title: '请输入正确的手机号',
- })
- }
-
- },
- countdown(){
- var count=60,_this=this;
- var timer=setInterval(c,1000)
- function c(){
- if(count>0){
- count--;
- _this.setData({
- text:count+"s重新发送"
- })
- }else{
- _this.setData({
- text:'获取验证码'
- })
- clearInterval(timer)
- }
- }
- },
- inputchange(e) {
- this.setData({
- phone: e.detail.value
- })
- },
- inputchange1(e) {
- this.setData({
- signup_name: e.detail.value
- })
- },
- codechange(e) {
- this.setData({
- phcode: e.detail.value
- })
- },
- post(){
- var data={
- signup_type:this.data.type,
- total_fee:this.data.info.viewer_price,
- phone:this.data.phone,
- phcode:this.data.phcode,
- match_group:this.data.match_group,
- match_id:this.data.info.id,
- match_name:this.data.info.name,
- signup_name:this.data.signup_name
- }
- if(this.data.type == 2){
- data.total_fee=this.data.info.player_price
- }
- if (data.signup_name.length<=0){
- wx.showToast({
- icon: 'none',
- title: '请输入名字',
- })
- return
- }
- if (data.phone.length<11){
- wx.showToast({
- icon: 'none',
- title: '请输入正确的手机号',
- })
- return
- }
- if (!data.phcode) {
- wx.showToast({
- icon: 'none',
- title: '请输入验证码',
- })
- return
- }
- if(this.data.isLoading == 1){
- return
- }
- this.setData({
- isLoading:1
- })
- wx.showLoading({
- title: '正在提交订单',
- })
- $api.wxpay(data).then(res=>{
- wx.hideLoading()
- this.setData({
- isLoading:0
- })
- if(res.data.data.free){
- app.globalData.follow = 1
- wx.showToast({
- title: '报名成功',
- })
- wx.switchTab({
- url: '../index/index'
- });
- }
- var timestamp = Math.round(new Date().getTime() / 1000).toString();
- 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();
- console.log(paySign)
- wx.requestPayment({
- timeStamp: timestamp,
- nonceStr: res.data.data.nonce_str,
- package: 'prepay_id=' + res.data.data.prepay_id,
- signType: 'MD5',
- paySign: paySign,
- success(res) {
- app.globalData.follow = 1
- wx.showToast({
- title: '报名成功',
- })
- wx.switchTab({
- url: '../index/index'
- });
- },
- fail(res) { console.log(res)}
- })
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|