// pages/member/memberInfo/memberInfo.js
let app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 1,
    userInfo: {},
    custormInfo: {},
    branchList: [],
    sanImg: '',
    sanImg1: '',
    sanImg2: '',
    sanImg3: '',
    orderAdd: {},
    verificationMsg: {
      CertificationPics: [],
      CustomerID: 0,
      ApplyType: 1,
      ID: 0
    },
  },
  seveSanMsg: function (e) {
    let index = e.target.id.split('save')[1];
    this.data.verificationMsg.CustomerID = this.data.userInfo.id;
    if (index == '0') {
      if (this.data.sanImg === '') {
        wx.showToast({
          title: '请先上传图片',
          icon: 'none',
          duration: 1000
        })
        return
      }
      this.data.verificationMsg.ApplyType = 2;
      this.data.verificationMsg.CertificationPics.push(this.data.sanImg);
    } else {
      if (this.data.sanImg1 === '' || this.data.sanImg2 === '' || this.data.sanImg3 === '') {
        wx.showToast({
          title: '请先上传图片',
          icon: 'none',
          duration: 1000
        })
        return
      }
      this.data.verificationMsg.CertificationPics = [this.data.sanImg1, this.data.sanImg2, this.data.sanImg3];
    }
    app.$api("app_customer_SetCertification", this.data.verificationMsg).then(res => {
      wx.showToast({
        title: '保存成功',
        icon: 'none',
        duration: 1000
      })
    }).catch(err => { })
  },
  chooseImage: function (e) {
    let index = e.target.id.split('img')[1];
    console.log(index)
    let _this = this,
      path = '/Upload/DMC/';
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) { 
        const tempFilePaths = res.tempFilePaths
        res.tempFilePaths.map(x => {
          wx.uploadFile({
            url: 'http://upload.oytour.com/Upload?filePath=' + path, //仅为示例，非真实的接口地址
            filePath: x,
            name: 'file',
            formData: {
              'user': x
            },
            success: function (res) {
              var data = JSON.parse(res.data)
              let img = "http://imgfile.oytour.com" + data.FilePath
              if (index == '0') {
                _this.setData({
                  sanImg: img
                })
              } else if (index == '1') {
                _this.setData({
                  sanImg1: img
                })
              } else if (index == '2') {
                _this.setData({
                  sanImg2: img
                })
              } else if (index == '3') {
                _this.setData({
                  sanImg3: img
                })
              }
            }
          })
        })
      }
    })
  },
  setActive: function (e) {
    let type = e.target.id.split('active')[1]
    this.setData({
      active: Number(type)
    })
  },
  getOrderAdd: function () {
    app.$apiJavaData("api/orderForm/getOrderAdd", {}).then(res => {
      console.log(res)
      this.setData({
        orderAdd: res.data
      })
    }).catch(err => { })
  },
  getUserInfo: function () {
    app.$api("b2b_get_GetCustomerManagerInfo", {}).then(res => {
      this.setData({
        custormInfo: res,
        branchList: res.branchList
      })
      this.getOrderAdd()
    }).catch(err => { })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //修改title
    let data = {},_this = this;
    wx.setNavigationBarTitle({
      title: '个人信息'
    })
    this.getUserInfo()
    wx.getStorage({
      key: 'admin',
      success(res) {
        data = res.data
        _this.setData({
          userInfo: data
        })
      }
    })
  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let _this = this;
    this.getUserInfo()
    wx.getStorage({
      key: 'admin',
      success(res) {
        let data = res.data
        _this.setData({
          userInfo: data
        })
      }
    })
  },

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

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

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

  },

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

  },

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

  }
})