    <template>
      <div class="app-container calendar-list-container">
        <el-form :rules="rules" ref="addForm" :model="JlAdminUser" label-position="left" label-width="80px"
                  style='width: 100% ;margin-left:20px'>
                <el-row :gutter="24" style="margin-bottom: 15px;" align="center">
                  <el-col :xs="23" :sm="23" :md="12" :lg="6" :xl="6">
                    <div class="grid-content bg-purple" >
                      <el-form-item  :label="$t('modifyinfo.opwd')" prop="opwd" style="width: 100%;">
                        <div class="block">
                      <el-input type="password" v-model="JlAdminUser.password"> </el-input>
                        </div>
                      </el-form-item>
                    </div>
                  </el-col>
                </el-row>
                <el-row :gutter="24" style="margin-bottom: 15px;" align="center">
                  <el-col :xs="23" :sm="23" :md="12" :lg="6" :xl="6">
                    <div class="grid-content bg-purple">
                      <el-form-item  :label="$t('modifyinfo.npwd')" prop="npwd" style="width: 100%;">
                        <div class="block">
                      <el-input type="password" v-model="JlAdminUser.npwd"> </el-input>
                        </div>
                      </el-form-item>
                    </div>
                  </el-col>
                </el-row>
                <el-row :gutter="24" style="margin-bottom: 15px;" align="center">
                  <el-col :xs="23" :sm="23" :md="12" :lg="6" :xl="6">
                    <div class="grid-content bg-purple">
                      <el-form-item  :label="$t('modifyinfo.npwd2')" prop="npwd2" style="width: 100%;">
                        <div class="block">
                      <el-input type="password" v-model="JlAdminUser.npwd2"> </el-input>
                        </div>
                      </el-form-item>
                    </div>
                  </el-col>
                </el-row>
                <el-row :gutter="24" style="margin-bottom: 15px;">
                <el-col :span="1"><div>&nbsp;</div></el-col>
                <el-col :xs="23" :sm="23" :md="12" :lg="6" :xl="6">
                  <div >
                    <el-button  type="primary" @click="modifyPassword">{{$t('table.confirm')}}</el-button>
                    <el-button @click="handleref()">{{$t('navbar.reset')}}</el-button>
                  </div>
                </el-col>
                <el-col :span="6"><div>&nbsp;</div></el-col>
              </el-row>
            </el-form>
        <el-dialog title="Reading statistics" :visible.sync="dialogPvVisible">
          <el-table :data="pvData" border fit highlight-current-row style="width: 100%">
            <el-table-column prop="key" label="Channel"></el-table-column>
            <el-table-column prop="pv" label="Pv"></el-table-column>
          </el-table>
          <span slot="footer" class="dialog-footer" >
            <el-button type="primary" @click="dialogPvVisible = false">{{$t('table.confirm')}}</el-button>
          </span>
        </el-dialog>
      </div>
    </template>
    <script>
      import { createArticle, JlAdminupdate } from '@/api/article'
      import waves from '@/directive/waves' // 水波纹指令
      import { parseTime } from '@/utils'
      import crypto from 'crypto'
      // arr to obj ,such as { CN : "China", US : "USA" }
      export default {
        name: 'passwordmodify',
        directives: {
          waves
        },
        data() {
          return {
            tableKey: 0,
            list: null,
            total: null,
            page: 1,
            limit: 10,
            queryType: 'list',
            listLoading: true,
            JlAdminUser: {
              id: null,
              password: null,
              npwd: null,
              npwd2: null
            },
            sortOptions: [{ label: 'ID Ascending', key: '+id' }, { label: 'ID Descending', key: '-id' }],
            showReviewer: false,
            ethnicgroupptions: '',
            provinceoptions: '',
            dialogFormVisible: false,
            dialogStatus: '',
            dialogPvVisible: false,
            pvData: [],
            rules: {
              password: [{ required: true, message: '请录入原始密码！', trigger: 'blur' }],
              npwd: [{ required: true, message: '请录入新密码！', trigger: 'blur' }],
              npwd2: [{ required: true, message: '请录入确认密码！', trigger: 'blur' }]
            },
            downloadLoading: false
          }
        },
        created() {
          this.getList()
        },
        methods: {
          getList() {
          },
          modifyPassword() {
            this.JlAdminUser.id = this.$store.state.user.id
            if (this.JlAdminUser.npwd !== this.JlAdminUser.npwd2) {
              this.$message({
                message: '二次输入密码不一致！',
                type: 'warning'
              })
            } else {
              this.$refs['addForm'].validate((valid) => {
                if (valid) {
                  var md5password = crypto.createHash('md5')
                  md5password.update(this.JlAdminUser.password)
                  this.JlAdminUser.password = md5password.digest('hex')
                  var md5npwd = crypto.createHash('md5')
                  md5npwd.update(this.JlAdminUser.npwd)
                  this.JlAdminUser.npwd = md5npwd.digest('hex')
                  var md5npwd2 = crypto.createHash('md5')
                  md5npwd2.update(this.JlAdminUser.npwd2)
                  this.JlAdminUser.npwd2 = md5npwd2.digest('hex')
                  JlAdminupdate(this.JlAdminUser).then(response => {
                    if (response.data === 1) {
                      createArticle().then(() => {
                        this.dialogFormVisible = false
                        this.$notify({
                          title: '成功',
                          message: '修改成功！',
                          type: 'success',
                          duration: 2000
                        })
                      })
                      this.handleref()
                    } else if (response.data === 2) {
                      this.$message({
                        message: '原始密码错误！',
                        type: 'warning'
                      })
                    }
                  })
                }
              })
            }
          },
          handleref() {
            this.JlAdminUser.password = null
            this.JlAdminUser.npwd = null
            this.JlAdminUser.npwd2 = null
          },
          formatJson(filterVal, jsonData) {
            return jsonData.map(v => filterVal.map(j => {
              if (j === 'timestamp') {
                return parseTime(v[j])
              } else {
                return v[j]
              }
            }))
          }
        }
      }
    </script>
    <style>
    .el-form--label-left .el-form-item__label{
      text-align:right
    }
    .el-rate{
      line-height: 0;
      margin-top:8px;
    }
    .el-checkbox.el-checkbox {
        margin-left: 30px;
    }
    </style>