<template>
  <tools-page :need-back='false' title="系统设置"></tools-page>
  <div align="center">
    <http-busy>
      <validator name='v'>
        <div class="app-input lala auto" :class="{'has-error':$v.password.required, 'has-success': !$v.password.required}">
          <label class="control-label">原始密码</label>
          <input type="password" v-model="password"  v-validate:password="{ required: true }">
          <span v-if="$v.password.required" class="center-block">不能为空</span>
        </div>
        <div class="app-input lala auto"
             :class="{'has-error':$v.newpassword.required, 'has-success': !$v.newpassword.required}">
          <label class=" control-label">新密码</label>
          <input type="password"  v-model="newpassword"  v-validate:newpassword='{ required: true }'>
          <span v-if="$v.newpassword.required" class="center-block">不能为空</span>
        </div>
        <div class="app-input lala auto"
             :class="{'has-warning':$v.affirmpassword.required,'has-error':$v.affirmpassword.equalValid && !($v.affirmpassword.required),
          'has-success': !$v.affirmpassword.required && !($v.affirmpassword.equalValid && !($v.affirmpassword.required))}">
          <label class=" control-label">确认密码</label>
          <input type="password" v-model="affirmpassword"  v-validate:affirmpassword="{ required: true, equalValid: newpassword }">
          <!-- <span class="glyphicon glyphicon-ok form-control-feedback" v-if="!$v.affirmpassword.required && !($v.affirmpassword.equalValid && !($v.affirmpassword.required))"></span> -->
          <span v-if="$v.affirmpassword.required" class="center-block">不能为空</span>
          <span v-if="$v.affirmpassword.equalValid && !($v.affirmpassword.required)" class="center-block">两次密码不一致 !!</span>
        </div>
        <!--<div class="row app-btn auto" style="margin-bottom: -5px;">
          <button class="btn btn-primary col-xs-12" @click= "changePass()"><span class="glyphicon glyphicon-zoom-in" style="margin-right: 20px;"></span>修改密码</button>
          &lt;!&ndash; <button class="btn btn-primary col-xs-6" @click="this.$back()"><span class="glyphicon glyphicon-zoom-in" style="margin-right: 20px;"></span>取消</button> &ndash;&gt;
        </div>-->
        <div class="row app-btn" style="margin-bottom: -5px;">
          <button class="btn btn-primary col-xs-12" style="height: 34px" @click= "changePass()"><span class="glyphicon glyphicon-zoom-in" style="margin-right: 20px;"></span>修改密码</button>
        </div>
      </validator>
    </http-busy>
    <div style="height:50px;"></div>
  </div>
</template>

<script>
import Vue from 'vue'

export default {
  title: '系统设置',
  data() {
    return {
        password: '',
        newpassword: '',
        affirmpassword: ''
    }
  },
  methods: {
    changePass() {
      let deliver = {ename:Vue.user.ename,password:this.password,newpassword:this.newpassword,affirmpassword:this.affirmpassword}
      let res = this.$resetpost(`${this.$androidUtil.getProxyUrl()}/api/af-safecheck/logic/EditPassword`, {data:deliver})
      if (res.code == 200) {
        this.password = ''
        this.newpassword = ''
        this.affirmpassword = ''
        HostApp.alert("密码修改成功！")
      }else{
        HostApp.alert("密码修改失败！")
      }
    },
    callback(result) {
      if(!Vue.param)
        Vue.param = {}
      result = result.data.data
      result.forEach(function(param) {
        let key = param['name']
        //console.log(key)
        Vue.param[key] = param['f_paramvalues']
        //console.log(JSON.stringify(param['f_paramvalues']))
      })
      HostApp.__callback__ = null
    },
    /*updateParam() {
      HostApp.__callback__ = this.callback
      if(Vue.android) {
        this.$androidUtil.bzLogic('更新参数', {data: {action: 'post', url: Vue.url + 'db/hql', data: 'select distinct p from param p left join fetch p.f_paramvalues'}})
      }
    }*/
  }
}
</script>
