// pages/lw-gerenxinxi/lw-gerenxinxi.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    register:'',    // 1  已注册   2  未注册
    userInfoData:{},
    //人员信息
    userphoto:'',
    name:'',
    workType:'',
    uninName:'',
    date:'',
    loadShow:false,
  },
  onClickShow() {
    this.setData({ loadShow: true });
  },

  onClickHide() {
    this.setData({ loadShow: false });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var date = new Date();
    var dateYaer = date.getFullYear();
    var dateMonth = date.getMonth() + 1;
    var dateDay = date.getDate();
    if(options.register == 1){
      var json =JSON.parse(decodeURIComponent(options.userInfo));
      this.setData({
        register:options.register,
        userphoto:'data:image/jpeg;base64,'+json.pathUrl,
        name:json.name,
        workType:json.workType,
        uninName:json.uninName,
        date: dateYaer+'-'+dateMonth+ '-'+dateDay,
        userInfoData:json,
      });
    }else{
      this.setData({
        register:options.register,
        userphoto:'data:image/jpeg;base64,'+decodeURIComponent(options.pathUrl),
      });
    }
  },

  /**
   * 打卡确认
   */
  returnData:function(){
    var that = this;
    that.onClickShow();
    wx.request({
      url: app.globalData.reqUrl+'/weixin/labour/synClockData',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      method:"POST",
      data:{
        id:app.globalData.projectId,
        userInfoData:JSON.stringify(this.data.userInfoData),
      },
      success:function(res){
        that.onClickHide();
        app.toast(res.data.msg);
        wx.redirectTo({
          url: '../lw-index/lw-index',
        })
      }
    })
  },

  /**
   * 返回劳务管控页面
   */
  goBack:function(){
    wx.redirectTo({
      url: '../lw-index/lw-index',
    })
  },

  /**
   * 返回到注册页面
   */
  goRegisterPage:function(){
    wx.redirectTo({
      url: '../lw-jibenxinxi/lw-jibenxinxi',
    })
  }
})