<template>
    <el-dialog title="批量添加白名单" :visible.sync="dialogVisible" width="800px" @close="handleClose">
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-form-item label="钱包地址" prop="addresss">
                <el-input v-model="form.addresss" type="textarea" :autosize="{ minRows: 5, maxRows: 16 }"
                    placeholder="钱包地址（用换行符分隔）"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" :loading="loading" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
import { batchInsertMmWalletWhiteList } from '@/api/admin/mm-wallet-white-list'

export default {
    name: "BatchAdd",
    props: {
        dialogVisible: {
            type: Boolean,
            default: false
        }
    },
    data() {
        return {
            // dialogVisible: false,
            loading: false,
            form: {

            },
            rules: {
                addresss: [{ required: true, message: '请输入地址', trigger: 'blur' }]
            }
        }
    },
    methods: {
        handleClose(done) {
            this.$emit('update:dialogVisible', false)
            this.$emit("close");
            done();
        },
        submitForm() {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    this.loading = true;

                    batchInsertMmWalletWhiteList(this.form).then(response => {
                        if (response.code === 200) {
                            this.$message.success('批量添加成功');
                            this.handleClose();
                        } else {
                            this.$message.error(response.message);
                        }
                    }).catch(error => {
                        console.log(error);
                        // this.$message.error('批量添加失败');
                    }).finally(() => {
                        this.loading = false;
                    });
                }
            });
        },
        cancel() {
            this.handleClose();
        }
    }
}
</script>