<template>
  <a-modal
    title="修改密码"
    :visible.sync="visible"
    :confirmLoading="confirmLoading"
    width="360px"
    @cancel="visible = false"
    @ok="submit">
    <a-form-model ref="form" :model="form">
      <a-form-model-item
        label="旧密码"
        prop="oldPassword"
        style="width:100%"
        :rules="{
          required: true,
          message: '请输入旧密码'
        }">
        <a-input-password v-model="form.oldPassword" placeholder="请输入旧密码" />
      </a-form-model-item>
      <a-form-model-item
        label="新密码"
        prop="newPassword"
        style="width:100%"
        :rules="{
          required: true,
          message: '请输入新密码'
        }">
        <a-input-password v-model="form.newPassword" placeholder="请输入新密码" />
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>
<script>
import { updatePassword } from '@/api/systemSetting/account'
export default {
  data () {
    return {
      visible: false,
      confirmLoading: false,
      form: {
        oldPassword: '',
        newPassword: ''
      }
    }
  },
  methods: {
    show () {
      this.visible = true
      this.form.oldPassword = ''
      this.form.newPassword = ''
    },
    submit () {
      this.$refs.form.validate(valid => {
        if (!valid) return
        this.confirmLoading = true
        updatePassword(this.form).then(res => {
          this.$message.success('修改成功')
          this.visible = false
        }).finally(() => {
          this.confirmLoading = false
        })
      })
    }
  }

}
</script>
<style lang="scss" scoped>
</style>
