chailvcode.js 4.6 KB
// pages/chailvcode/chailvcode.js
const app = getApp()
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		yes: true,
    number: '',//会员编号
    code:'',//验证码
    getCode: 0,
    yes: true
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {

	},
	// 输入验证码
  get_code(e){
    this.setData({
      code:e.detail.value
    })
  },
  //获取会员编号
  get_vipNum(e){
      console.log(e)
      this.setData({
        number:e.detail.value
      })
  },

  // 获取验证码
  getCodeFun: function() {
    let that = this;
    let AuglyTest_phone = /^1(3|4|5|6|7|8|9)\d{9}$/;
    if(that.data.number==''){
      wx.showToast({
        title: '请输入会员编号',
        icon:'none'
      })
      return false
    }
    let url = '/travel/get_code'
    let param = {
      number:that.data.number
    }
    app.postk(url, param).then((res) => {
        console.log(res)
        if(res.code == 1) {
          wx.showToast({
            title: '发送成功',
            icon:'none'
          })
          var num = 60;
            var timer = setInterval(function() {
              num--;
              if (num <= 0) {
                clearInterval(timer);
                that.setData({
                  getCode: '',
                  yes: true
                })
  
              } else {
                that.setData({
                  getCode: num + "s",
                  yes: false
                })
              }
            }, 1000);
        }else {
          wx.showToast({
            title: res.msg,
            icon:'none'
          })
        }
        
        // that.setData({
        //   code:res.data.code
        // })
    })
  },

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},
	loginFun(){
    let that = this
    if(that.data.number==''){
      wx.showToast({
        title: '请输入会员编号',
        icon:'none'
      })
      return false
    }
    if(that.data.code==''){
      wx.showToast({
        title: '请输入验证码',
        icon:'none'
      })
      return false
    }
    let url = '/travel/check';
    let data = {  
      number:that.data.number,
      code:that.data.code
    }
    app.postk(url, data, "POST").then((r) => {
      console.log(r)
      that.getaccess_token()
    }).catch((err) => { 
    })
   
  },
  // 获取access_token
  getaccess_token(){
    let that=this;
		wx.request({
			// url: 'https://openapi-uat.z-trip.cn/bin/token?grant_type=client_credentials&client_id=KReYlCQbQKOZFVg4h3zyIg&client_secret=RzWLyn8GTpi9J4JJadND0w', //测试域名
			 url: 'https://openapi.z-trip.cn/bin/token?grant_type=client_credentials&client_id=yuS0DohHS4uykJDDBVs71w&client_secret=8oFFLsxCQvaEhGNfEAmrXw',//生产域名
			data: '',
			method: 'GET',
			header: {
				'content-type': 'application/x-www-form-urlencoded',
			},
			success: function (res) { //返回取得的数据
				console.log('ssssssssssssssssssssssssssssssssssss',res)
				let access_token=res.data.access_token;
				let empCode=that.data.number;
				// let empCode='0001';
				that.geturl(access_token,empCode)
			},
			fail: function (e) {
				console.log
			}
		})
  },
	geturl(access_token,empCode){
    let that=this;
    // let  url="https://openapi-uat.z-trip.cn/tmc/v1/sso-url?access_token="+access_token+"&empCode="+empCode+"&system=h5" //测试域名
    let  url="https://openapi.z-trip.cn/tmc/v1/sso-url?access_token="+access_token+"&empCode="+empCode+"&system=h5" //生产域名
    wx.request({
      url:url,
      data: '',
      method: 'GET',
      header: {
        'content-type': 'application/x-www-form-urlencoded',
      },
      success: function (res) { //返回取得的数据
        console.log('ssssssssssssssssssssssssssssssssssss',res)
        if(res.data.error==0){
          wx.navigateTo({
            url: '/pages/jumplink/jumplink?url='+encodeURIComponent(res.data.data),
          })
        }else{
          wx.showToast({
            title: res.data.error_description,
            icon:'none'
          })
        }
      },
      fail: function (e) {
        console.log
      }
    })
  },
	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	}
})