<template>
  <el-form ref="form" :model="form" :rules="rules" label-width="100px">
    <el-form-item :label="$t('center.security.oldpwd')" prop="oldpwd">
      <el-col :span="4">
        <el-input v-model="form.oldpwd" show-password type="password"
                  :placeholder="$t('input_please',{keyword:$t('center.security.oldpwd')})"/>
      </el-col>
    </el-form-item>
    <el-form-item :label="$t('center.security.newpwd')" prop="newpwd">
      <el-col :span="4">
        <el-input v-model="form.newpwd" show-password type="password"
                  :placeholder="$t('input_please',{keyword:$t('center.security.newpwd')})"/>
      </el-col>
    </el-form-item>
    <el-form-item :label="$t('center.security.confirmpwd')" prop="confirmpwd">
      <el-col :span="4">
        <el-input v-model="form.confirmpwd" show-password type="password"
                  :placeholder="$t('input_confirm',{keyword:$t('center.security.newpwd')})"/>
      </el-col>
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="onSubmit">{{$t('button.submit')}}</el-button>
    </el-form-item>
  </el-form>
</template>

<script lang="ts">
  import Vue from 'vue'

  export default Vue.extend({
    name: 'security',
    data() {
      return {
        form: {
          oldpwd: '',
          newpwd: '',
          confirmpwd: ''
        },
        rules: {
          oldpwd: [
            {
              required: true,
              message: this.$t('input_please', { keyword: this.$t('center.security.oldpwd') }),
              trigger: 'blur'
            },
            { min: 3, max: 5, message: this.$t('center.security.rules.password',{min:3,max:5}), trigger: 'blur' }
          ],
          newpwd: [
            {
              required: true,
              message: this.$t('input_please', { keyword: this.$t('center.security.newpwd') }),
              trigger: 'blur'
            },
            { min: 3, max: 5, message: this.$t('center.security.rules.password',{min:3,max:5}), trigger: 'blur' }
          ],
          confirmpwd: [
            {
              required: true,
              message: this.$t('input_confirm', { keyword: this.$t('center.security.newpwd') }),
              trigger: 'blur'
            },
            { min: 3, max: 5, message: this.$t('center.security.rules.password',{min:3,max:5}), trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      onSubmit() {
        this.$refs.form.validate((valid: boolean)=>{
          if (valid) {
            this.$alert(this.$t('center.security.tip.ok').toString())
          } else {
            console.log('error submit!!');
            return false;
          }
        })

      }
    }
  })
</script>
