<template>
    <div>
        <Row type="flex" justify="center" align="middle" class="code-row-bg">
            <Col span="10" >
                <Form ref="form" :model="formData" :rules="formRule" :label-width="100">
                    <Col span="24">
                        <Form-item label="用户名"  prop="name">
                            <Input v-model="formData.name">
                            </Input>
                        </Form-item>
                    </Col>
                    <Col span="24">
                        <Form-item label="新密码"  prop="password">
                            <Input v-model="formData.password">
                            </Input>
                        </Form-item>
                    </Col>
                    <!--<Col span="24">
                        <Form-item label="授权"  prop="impower">
                            <Input v-model="formData.impower">
                            </Input>
                        </Form-item>
                    </Col>-->
                    <Col span="2" offset="20">
                        <Button type="primary" long @click="handleSubmit">提交</Button>
                    </Col>
                </Form>
            </Col>
        </Row>
    </div>
</template>
<script>
import { changewebuserpasswd } from '@/api/user'
export default {
  name: 'changepasswd',
  data () {
    return {
      formData: {
        name: '',
        password: '',
        /** 通过授权验证是否可改密码 */
        impower: ''
      },
      formRule: {
        name: [
          { type: 'string', required: true, message: '用户名必填', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '密码必填', trigger: 'blur' },
          { type: 'string', min: 6, message: '至少六位数', trigger: 'blur' }
        ]
        /* impower: [
          { required: true, message: '授权必填', trigger: 'blur' }
        ] */
      }
    }
  },
  methods: {
    handleSubmit () {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          changewebuserpasswd(this.formData).then(res => {
            const data = res.data
            if (data.code !== 200) {
              this.$Message.error(data.msg)
            } else {
              this.$Message.success('操作成功!')
            }
          })
        }
      })
    }
  }
}
</script>
