const {
  api,
  alertTip,
  imgName,
  getProtocol
} = require('../../lib/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    emailShow: false,
    // qrcodeImg: imgName('qrcode.jpg'),
    email: '',
    protocols: ['用车协议', '押金协议', '租车协议', '用户服务协议', '保险协议', '三电智能协议'],
    others: ['官网', '微信公众号', '微信公众号', '微信公众号'],
    accountShow: false,
  },

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

  },

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

  },
  copyAccount() {
    wx.setClipboardData({
      data: 'KYMCO',
      success() {
        // alertTip('已复制公众号名称')
      }
    })
  },
  gzhLoad(e) {
    console.log(e)
    if (e.detail.status == 0) {
      this.setData({
        accountShow: true
      })
    }
  },
  callServer() {
    wx.makePhoneCall({
      phoneNumber: '13656670870',
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  gzhError(e) {
    console.log('error', e)
  },
  closeEmail() {
    this.setData({
      emailShow: false
    })
  },
  tofeedBack() {
    wx.navigateTo({
      url: '/pages/feedBack/feedBack',
    })
  },
  tofeedBackList() {
    wx.navigateTo({
      url: '/pages/tofeedBackList/tofeedBackList',
    })
  },
  toModifySelf() {
    wx.navigateTo({
      url: '/pages/modifySelf/modifySelf',
    })
  },

  showEmailModel() {
    this.setData({
      emailShow: true
    })
  },
  valueInput(e) {
    this.setData({
      [e.target.id]: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  apiChangeEmail() {
    const {
      email
    } = this.data
    if (!email) {
      alertTip('请输入邮箱号')
      return
    }
    api.post('user/editInfo', {
        email
      })
      .then(res => {
        alertTip(res.message)
        this.closeEmail()

      })
      .catch(err => {
        alertTip(err)
        this.closeEmail()
      })
  },
  onHide: function() {

  },
  readProtocol(e) {
    let id = e.currentTarget.id
    console.log(id)
    getProtocol(id)
      .then(res => {
        console.log(res)
      })
      .catch(err => {
        console.error(err)
        alertTip(err.errMsg || err)
      })
  }
})