<style>
  .form-signin {
    max-width: 500px;
    padding: 15px;
    margin: 0 auto;
  }
  .form-signin .form-signin-heading,
  .form-signin .checkbox {
    margin-bottom: 10px;
  }
  .form-signin .checkbox {
    font-weight: normal;
  }
  .form-signin .form-control {
    position: relative;
    height: auto;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    padding: 10px;
    margin: 5px 0px 5px 0px;
    font-size: 16px;
  }
  .form-signin .form-control:focus {
    z-index: 2;
  }
  .form-signin input {
    margin-bottom: -1px;
    border-bottom-right-radius: 0;
    border-bottom-left-radius: 0;
  }
  .form-signin input[type="password"] {
    margin-bottom: 10px;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
  }
</style>

<template>
  <div class="app-bg" style="background: #4C637B;">
    <validator name='v'>
      <form class="form-signin" novalidate @submit.prevent="signIn()">
        <div>
          <!-- <img src="../../assets/logo1.png" class="center-block img-responsive"></img> -->
        </div>
        <h2 class="form-signin-heading text-center" style="color: #fff;">手机抄表系统</h2>
        <h4 class="form-signin-heading text-center" style="color: #fff;">欢迎使用手机抄表系统</h4>
        <!-- <h5 class="form-signin-heading text-center" @click="backupDatabase">当前版本：0.{{version}}</h5> -->
        <input id="ename" style="margin-top: 100px;" class="form-control" placeholder="请输入用户名" autofocus v-model="model.ename" v-validate:ename='{ required: true }'  @focus="noPage()" @blur="haspage()">
        <input type="password"  id="inputPassword" class="form-control" placeholder="请输入密码" v-model="model.password" v-validate:password='{ required: true }' @focus="noPage()" @blur="haspage()">
        <button class="btn btn-lg btn-danger btn-block" type="submit" style="color: #fff; ">登录</button>
      </form>
    </validator>
    <div class="login-footer login-footer_fixed-bottom" v-if='showversion'>
      <p class="login-footer__links">
        <a href="javascript:home();" class="login-footer__link"></a>
      </p>
      <p class="login-footer__text">Copyright @ v1.0.0 手机抄表</p>
    </div>
  </div>
</template>
<script>
  import Vue from 'vue'

  export default {
    title: '登录系统',
    data () {
      return {
        model: {
          ename: '',
          password: ''
        },
        showversion: true
      }
    },
    methods: {
      noPage () {
        this.showversion = false
      },
      haspage () {
        this.showversion = true
      },
      backupDatabase () {
        HostApp.backupDatabase()
      },
      load () {
        if (this.model.ename === '' || this.model.password === '') {
          HostApp.alert('登录失败, 用户名或密码不能为空！')
          return
        }
        this.$resetpost(Vue.ProxyUrl + '/rs/logic/phonelogin', {data: this.model}, {resolveMsg: null, rejectMsg: null}).then((ret) => {
          console.log(ret.data)
          if (ret.data.state === 0) {
            this.$goto('readmeter-home')
            Vue.user = ret.data.data
          } else {
            HostApp.alert('登录失败 ' + ret.data.msg)
          }
        })
      },
      signIn () {
        this.login = true
        // 模拟手机，定时提取

        // 获取登录加载数据
        this.load()
      },
      isJSON (str) {
        if (typeof str == 'string') {
          try {
            var obj = JSON.parse(str)
            if (typeof obj == 'object' && obj ) {
              return true
            } else {
              return false
            }
          } catch (e) {
            console.log('error：'+str+'!!!'+e);
            return false
          }
        }
        console.log('It is not a string!')
      },
      isAndroidDevice() {
        try {
          HostApp
          Vue.AndroidPlugin.isAndroid = true
          Vue.ProxyUrl = Vue.AndroidPlugin.getProxyURL()
          console.log("ProxyUrl---------------->>>>>>>"+Vue.ProxyUrl)
          // Vue.ProxyUrl = 'http://192.168.30.63:8080/'
        } catch (e) {
          console.log("捕获到异常"+e.message)
          Vue.AndroidPlugin.isAndroid = false
          //如果是非安卓环境，config中配置的链接地址肯定是不能用的，所以改成空的即可
          Vue.ProxyUrl = ''
          console.log("ProxyUrl---------------->>>>>>>"+Vue.ProxyUrl)
        }
      },
    },
   ready(){
      this.isAndroidDevice()
   }
  }
</script>
<style scoped>
  .login-footer_fixed-bottom {
    height: auto;
    position: fixed;
    bottom: .52em;
    left: 0;
    right: 0;
  }
  .login-footer {
    color: #999;
    font-size: 14px;
    text-align: center;
  }
  .login-footer__link {
    color: #586C94;
  }
</style>
