<template>
    <div class="users">
        <el-form :inline="true" :model="formData" :rules="rules" ref="formData" class="option">
            <el-row>
                <el-row>
                    <el-form-item label="审批意见:" prop="status">
                        <el-radio v-model="formData.status" label="PASS">批准</el-radio>
                        <el-radio v-model="formData.status" label="REJECT">驳回</el-radio>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="信息内容:" prop="reason">
                        <el-input
                                v-model="formData.reason"
                                type="textarea"
                                show-word-limit
                                :rows="5"
                                maxlength="300"
                                placeholder="请输入"
                        >
                        </el-input>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-col :offset="10">
                        <el-form-item>
                            <el-button @click="cancel('formData')">取消</el-button>
                            <el-button type="primary" @click="save('formData')">确定</el-button>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-row>
        </el-form>
    </div>
</template>

<script>
    import {approvelJob, saveJob} from '@/api/job'

    export default {
        name: 'ApproveStatusV2',
        props: {
            id: {
                type: Number,
                required: true
            }
        },
        data() {
            return {
                loading: false,
                formData: {
                    status: undefined,
                    reason: undefined
                },
                rules: {
                    status: [
                        {required: true, message: '请选择审核状态', trigger: 'blur'}
                    ],
                    reason: [
                        {required: true, message: '请输入信息内容', trigger: 'change'}
                    ]
                }
            }
        },
        methods: {
            cancel(formName) {
                this.$refs[formName].resetFields();
                this.$emit("changeApproveVisible");
            },
            save(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        approvelJob(this.id, this.formData).then(res => {
                            // console.log(res)
                            this.$message.success('审核完成');
                            this.$emit("changeApproveVisible");
                        }).catch(error => {
                            this.$message.warning('当前用户无权限');
                        })
                    } else {
                        this.$message.warning('必填项没填写');
                        return false;
                    }
                });
            }

        }
    }
</script>