<template>
    <el-dialog title="驳回" :visible.sync="dialogVisible" width="50%" :before-close="close">
        <el-form :model="ruleForm" ref="ruleForm" label-width="100px">
            <el-form-item label="驳回原因" prop="reason">
                <el-input type="textarea" v-model="ruleForm.reason" maxLength="20"></el-input>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="close">取 消</el-button>
            <el-button type="primary" @click="submit" :disabled="submitBtndisabled">确 定</el-button>
        </span>
    </el-dialog>
</template>

<script>
import { couponsExamine } from '@/apps/mobile/api/cardbank/index';
export default {
    data() {
        return {
            dialogVisible: false,
            ruleForm: {
                reason: '',
            },
            submitBtndisabled: false,
            formData: {},
        };
    },
    methods: {
        open(data) {
            console.log(data);
            this.dialogVisible = true;
            this.submitBtndisabled = false;
            this.formData = { ...data };
        },
        close() {
            this.dialogVisible = false;
            this.submitBtndisabled = true;
            this.ruleForm.reason = '';
        },
        submit() {
            if (!this.ruleForm.reason) {
                this.$message({
                    type: 'warning',
                    message: '请填写驳回原因',
                });
                return false;
            }
            let obj = {
                checkFalg: 0,
                reason: this.ruleForm.reason,
                id: this.formData.id,
            };
            console.log(obj);
            couponsExamine(obj)
                .then(res => {
                    console.log(res);
                    if (res.statusCode === '1') {
                        this.$message.success(res.message);
                    } else {
                        this.$message.warning(res.message);
                    }
                    this.$emit('queryListData');
                    this.close();
                })
                .catch(() => {
                    this.submitBtndisabled = false;
                });
        },
    },
};
</script>

