var util = require('../../utils/util.js')
var app = getApp();

Page({
  data: {
    g_url: "",
    g_token: "",
    infoNum: "1.0.6",
    g_countName: "",
    g_depName: "",
    g_lgNameId:'',
 
    modelShow: false,

    tips: ""
  },
  onLoad: function (option) {
    var infoName = app.globalData.g_lgName
    var g_countName = app.globalData.g_countName
    var g_depName = app.globalData.g_depName
    var g_lgNameId = app.globalData.g_lgNameId

    this.setData({
      infoName: infoName,
      g_countName: g_countName,
      g_lgNameId: g_lgNameId,
      g_depName: g_depName
    })
  },

  onLogOut: function () {
    app.globalData.g_url = ""
    // wx.removeStorageSync('userinfo')
    // wx.removeStorageSync('usertoken')
    wx.redirectTo({
      url: '../login/login',
    })
  },

  onPasswordModel: function () {
    this.setData({
      modelShow: true,
    })
  },


  sendPassword: function (e) {
    var oldpwd = e.detail.value.oldpwd
    var newpwd = e.detail.value.newpwd
    var surepwd = e.detail.value.surepwd
    var token = wx.getStorageSync('usertoken')

    if (oldpwd == "" || newpwd == "" || surepwd == "") {
      this.setData({
        tips: "内容不能为空",
      })
    } else if (newpwd != surepwd) {
      this.setData({
        tips: "新密码两次内容不一致",
      })
    } else {
      var url = app.globalData.g_url + "/s/mobile/admin/changepassword.html"

      var data = {
        oldpassword: oldpwd,
        newpassword: newpwd,
        token: token
      }


      var send_data = {
        "common":{"returnmap":"0"},
        "data":[
          {
            "name":"checkPassword","type":"v",
            "parammaps":{
              "id":this.data.g_lgNameId,
              "password":oldpwd
             }
          },
          {"name":"updatePwd","type":"e",
          "parammaps":{"password":newpwd,"username":this.data.g_countName}}]}

      util.execDataByConfig(send_data, this.getListSuccess)

    }
  },

  getListSuccess:  function (res) {
    console.log('table数据======>', res)
    if (res.msg !== 'fail') {
      wx.showToast({
        title: "修改密码成功",
        duration: 1500,
        icon: "success"
      })
      this.setData({
        tips: "",
        modelShow: false,
      })
    } else {
      wx.showToast({
        title:  "密码错误，修改失败！",
        icon: 'error',
        duration: 2000,
      })
    }
  },

  cancelModify: function () {
    this.setData({
      tips: "",
      modelShow: false,
    })
  },

  


})