<template>
    <el-dialog class="client-data-dialog" title="创建代扣还款单" width="30%" :visible.sync="visible"
               :before-close="handleClose">
        <span>确定要创建代扣还款单？</span>
        <div slot="footer">
            <el-button @click="handleClose">取 消</el-button>
            <el-button type="primary" @click="submitForm('ruleForm')">确 定</el-button>
        </div>
    </el-dialog>
</template>

<script type="text/ecmascript-6">
    export default {
        name: 'AddByhRemindDialog',
        props: {
            dialogVisible: {
                type: Boolean,
                required: true
            },
            creator: {
                type: String
            },
            orderNo: {
                type: String
            },
            periodNo: {
                type: Number
            },
        },

        data() {
            return {
                ui: {
                    submitLoading: false
                },
                visible: this.$props.dialogVisible,

                ruleForm: {
                    orderNo: '',
                    periodNo: '',
                    creator: '',
                },
            }
        },

        created() {
            this.ruleForm = {
                orderNo: this.orderNo,
                periodNo: this.periodNo,
                creator: this.creator,
            }
        },

        methods: {
            /** 提交点击 */
            submitForm() {
                this.$$post('/repayRemind/backedApplyByh', {
                    orderNo: this.ruleForm.orderNo, periodNo: this.ruleForm.periodNo, creator: this.ruleForm.creator
                }).then(res => {
                    if (res.data.code != 1) {
                        this.$message.error(res.data.msg);
                        return
                    }
                    this.handleClose();
                    this.$message({message: '成功', type: 'success'});
                    window.location.reload();
                })
                    .catch(err => {
                        this.$message.error("创建代扣还款单失败");
                    })
            },

            /** 关闭处理 */
            handleClose() {
                this.visible = false;
                setTimeout(() => {
                    this.$emit('update:dialogVisible', false)
                }, 300);
            },
        }
    }
</script>

<style scoped>

</style>
