const app = require('../../utils/util.js');
// var util = require('../../utils/md5.js')
var formateTime = require('../../utils/formateTime.js')
Page({
  data: {
    info: {},
    time: '',
    imgPath: '',
    isTrue: true,
    isHeadPicPath:true,
  },
  getInfoUser(){
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: app.globalData.publicUrl + '/applet/findUserInfo',
      method: "GET",
      header: {
        appletsId: wx.getStorageSync('openId')
      },
      success: (res) => {
        console.log(res, "000");
        if(res.data.data.headPicPath)
        {
          this.setData({
          info: res.data.data,
          isHeadPicPath:true,
        })
       }else{
        // wx.navigateTo({
        //       url: '/pages/idCard/idCard',
        //     })
        this.setData({
          isHeadPicPath:false,
        })
       }
      },
      complete: (e) => {
        wx.hideLoading();
      }
    })
  },
  goShenFen() {
    if (!this.data.isTrue) {
      wx.request({
        url: app.globalData.publicUrl + '/applet/suppleUserInfo',
        method: "POST",
        header: {
          appletsId: wx.getStorageSync('openId')
        },
        data: {
          headPicPath: this.data.imgPath
        },
        success: (res) => {
          // console.log(res, "111");
          // wx.redirectTo({
          //   url: '/pages/idCardDetail/idCardDetail',
          // })
          this.getInfoUser();
        }
      })
    } else {
      wx.showToast({
        title: "请点击相机上传照片",
        icon: 'none',
        duration: 2000,
      })
    }
  },
  goPhoto() {
    wx.chooseImage({
      count: 1,
      sizeType: ['compressed'],
      sourceType: ['camera'],
      success: (res) => {
        var tempFilePaths = res.tempFilePaths
        wx.uploadFile({
          url: app.globalData.publicUrl + '/sys/user/upload',
          filePath: tempFilePaths[0],
          name: 'uploadFile',
          formData: {
            "user": "test",
          },
          header: {
            appletsId: wx.getStorageSync('openId'),
          },
          success: (res) => {
            console.log(JSON.parse(res.data), "45454545");
            let datas = JSON.parse(res.data)
            if (datas.code == 0) {
              this.setData({
                imgPath: datas.data,
                isTrue: false
              })
            }
          }
        })
      }
    })

  },
  closeImage(e) {
    this.setData({
      isTrue: true,
      imgPath: '',
    })
  },
  onLoad: function () {
    this.getInfoUser();
    var time = time;
    setInterval(() => {
      this.setData({
        time: formateTime.setNowTimes(new Date())
      });
    }, 1000);
  },
})