<template>
    <div>
        <el-form ref="vipForm"
                 :model="vipForm"
                 class="vipForm"
                 label-width="110px">
            <el-alert title="已拒绝" show-icon center v-if="vipForm.auditStatus == 'REJECT'" :closable="false" class="alert" type="error"></el-alert>
            <el-alert title="已同意" show-icon center v-if="vipForm.auditStatus == 'PASS'" :closable="false" class="alert" type="success"></el-alert>
            <el-form-item label="开始时间">
                <el-input disabled v-model.trim="vipForm.createTime"></el-input>
            </el-form-item>
            <el-form-item label="老师姓名">
                <el-input disabled v-model.trim="vipForm.userName"></el-input>
            </el-form-item>
            <el-form-item label="线上课数">
                <el-input disabled v-model.trim="vipForm.onlineClassesNum"></el-input>
            </el-form-item>
            <el-form-item label="线上课单价">
                <el-input disabled v-model.trim="vipForm.onlineClassesUnitPrice"></el-input>
            </el-form-item>
            <el-form-item label="线上课课酬">
                <el-input disabled v-model.trim="vipForm.onlineTeacherSalary"></el-input>
            </el-form-item>
            <el-form-item label="线下课数">
                <el-input disabled v-model.trim="vipForm.offlineClassesNum"></el-input>
            </el-form-item>
            <el-form-item label="线下课单价">
                <el-input disabled v-model.trim="vipForm.offlineClassesUnitPrice"></el-input>
            </el-form-item>
            <el-form-item label="线下课课酬">
                <el-input disabled v-model.trim="vipForm.offlineTeacherSalary"></el-input>
            </el-form-item>
            <el-form-item label="科目名">
                <el-input disabled v-model.trim="vipForm.subjectName"></el-input>
            </el-form-item>
            <el-form-item label="活动名称">
                <el-input disabled v-model.trim="vipForm.vipGroupActivityName"></el-input>
            </el-form-item>
            <el-form-item label="商品价格">
                <el-input disabled v-model.trim="vipForm.totalPrice"></el-input>
            </el-form-item>
            <el-form-item label="原因" prop="memo" :rules="[{ required: true, message: '请输入原因', trigger: 'blur' }]">
                <el-input type="textarea" :disabled="vipForm.auditStatus !== 'ING'" v-model.trim="vipForm.memo"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer" v-permission="'vipGroupManage/vipApplyAudit'" v-if="vipForm.auditStatus === 'ING'">
            <el-button type="primary" @click="onSubmit('vipForm', 'PASS')">确 定</el-button>
            <el-button type="danger" @click="onSubmit('vipForm', 'REJECT')">拒 绝</el-button>
        </div>
    </div>
</template>

<script>
import { getVipGroupDetailForAudit } from '@/api/vipSeting'
import { vipApplyAudit } from '@/api/journal'
export default {
    props: ['dialogDetail'],
    data() {
        return {
            vipForm: {},
        }
    },
    mounted() {
        this.__init()
    },
    methods: {
        async __init() {
            let { memo } = this.dialogDetail
            memo = memo ? JSON.parse(memo) : null
            if(!memo) { // 判断是否有参数
                this.$message.error('参数有误')
                return
            }
            await getVipGroupDetailForAudit({  vipGroupId: memo.vipGroupId }).then(res => {
                let result = res.data
                if (res.code == 200) {
                    this.vipForm = result
                }
            })
        },
        async onSubmit(formName, type) {
            const params = {
                vipGroupId: this.vipForm.id,
                reason: this.vipForm.memo,
                auditStatus: type,
            }
            this.$refs[formName].validate(async (valid) => {
                if(valid) {
                    const str = type == 'PASS' ? '同意' : '拒绝'
                    this.$confirm(`您确定${str}申请吗?`, '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(async () => {
                        await vipApplyAudit(params).then(res => {
                            if (res.code == 200) {
                                this.$message.success('处理成功')
                                this.$listeners.close()
                            } else {
                                this.$message.error(res.msg)
                            }
                        })
                    }).catch(() => {
                        //
                    })
                }
            })
        }
    }
}
</script>

<style lang="less" scoped>
.dialog-footer{
    margin-top: 20px;
    display: block;
    text-align: right;
}
.alert {
   margin-bottom: 10px;
}
</style>
