<template>
    <div>
        <a-modal :visible="visible" @ok="handOK" :confirmLoading="confirmLoading" @cancel="visible=false" width="700px"
            :maskClosable="false" :destroyOnClose="true" :width="900">
            <div slot="title">
                {{type==='add'?'创建':'编辑'}}用户
            </div>
            <div class="modal-box">
                <a-form :form="form" @submit="handOK" layout="horizontal">
                    <a-form-item label="管理员密码：" :label-col="{ span: 3 }" :wrapper-col="{ span: 20 }">
                        <a-input-password v-decorator="[
                             'adminPassword',
                             {rules: [{ required: true, message: '此项为必填!' },
                             ],}
                             ]" />
                    </a-form-item>
                    <a-form-item label="新密码：" :label-col="{ span: 3 }" :wrapper-col="{ span: 20 }">
                        <a-input-password v-decorator="[
                             'newPassword',
                             {rules: [{ required: true, message: '此项为必填!' },
                             { pattern: /^(?=^.{8,}$)(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s)[0-9a-zA-Z!@#$%^&*()]*$/, message: '密码须需包含大小写和数字，且大于八位数字!' },
                             ],}
                             ]" />
                    </a-form-item>
                </a-form>
            </div>
        </a-modal>
    </div>
</template>
<script>
    import { UserResetPassword } from '@/api/api'
    export default {
        data() {
            return {
                confirmLoading: false,
                visible: false,
                form: this.$form.createForm(this),
                type: '',
                record: {},
                detail: '',
            };
        },
        mounted() {

        },
        methods: {
            showModal(record) {
                console.log(record, 'record')
                this.visible = true;
                this.record = record;
            },
            //表单确认
            handOK(e) {
                e.preventDefault();
                this.form.validateFields((err, values) => {
                    if (!err) {
                        this.confirmLoading = true;
                        console.log(values)
                        let data = {
                            userId: this.record.id,
                            ...values
                        }
                        UserResetPassword(data).then(res => {
                            this.$message.success('重置成功！');
                            this.confirmLoading = false;
                            this.visible = false;
                        }).catch(err => {
                            this.confirmLoading = false;
                        })
                    }
                })
            },
        }
    };
</script>
<style scoped>
    .file-row {
        display: flex;
        flex-direction: row;
        align-items: flex-end;
    }
</style>