<template>
    <!-- 资源审核弹窗 -->
    <a-modal :visible="true" :width="width" :maskClosable="false" :destroyOnClose="true" :title="title" :footer="null"
        centered wrapClassName="modal-wrap" @cancel="onClose">
        <div class="action-content">
            <div class="item">
                <div class="item-header">申请信息</div>
                <div class="item-body">暂无</div>
            </div>
            <div class="item">
                <div class="item-header">审核信息</div>
                <div class="item-body">
                    <a-form ref="formRef" :model="form" :rules="rules" :label-col="labelCol" :wrapper-col="wrapperCol">
                        <a-row>
                            <a-col :span="24">
                                <a-form-item label="审核意见" name="opinion" :label-col="{ span: 2 }"
                                    :wrapper-col="{ span: 22 }">
                                    <a-textarea v-model:value="form.opinion" placeholder="" :rows="3" />
                                </a-form-item>
                            </a-col>
                        </a-row>
                        <a-row>
                            <a-col :span="10">
                                <a-form-item label="审核时间" name="passtime">
                                    <a-input v-model:value="form.passtime" style="width: 100%" disabled />
                                </a-form-item>
                            </a-col>
                            <a-col :span="10" :offset="4">
                                <a-form-item label="审核人" name="user">
                                    <a-input v-model:value="form.user" style="width: 100%" disabled />
                                </a-form-item>
                            </a-col>
                        </a-row>
                    </a-form>
                </div>
            </div>
            <div class="item-footer">
                <a-button style="margin-right: 16px;" @click="onClose">取消</a-button>
                <a-button danger style="margin-right: 16px;" @click="onSubmitNo">不通过</a-button>
                <a-button type="primary" @click="onSubmitYes">通过</a-button>
            </div>
        </div>
    </a-modal>
</template>
<script>
import { defineComponent, reactive, ref, onMounted, watch, toRefs, createVNode } from 'vue';
import { message, Modal } from 'ant-design-vue';
import { session } from '/@/utils/Memory';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import moment from 'moment';
import { subminExamineResult } from '/@/api/resource/examine';

const props = {
    bussInfo: {
        type: Object,
        default: {}
    }
}
export default defineComponent({
    name: 'modal',
    components: { ExclamationCircleOutlined },
    props,
    setup(props, { emit }) {
        const data = reactive({
            width: '1000px',
            title: '资源审核',
        })
        const formRef = ref(null)
        const form = reactive({
            bussInfoId: "",
            resId: "",
            userId: session.getItem('userId'),
            opinion: "",
            passtime: moment().format('YYYY-MM-DD HH:mm:ss'),
            user: session.getItem('userInfo').EMPLOYEE.NAME
        })
        const rules = {
            opinion: [{
                required: true,
                message: '请输入审核意见',
                trigger: 'blur'
            }]
        };
        //初始化请求所需数据
        onMounted(() => {
            form.bussInfoId = props.bussInfo.bussInfoId;
            form.resId = props.bussInfo.resId;
        })
        watch(
            () => props.bussInfo,
            (val) => {
                form.bussInfoId = val.bussInfoId;
                form.resId = val.resId;
            },
            {
                deep: true
            }
        )
        // 关闭请求弹窗
        const onClose = (e) => {
            emit('closeModal')
        }
        //通过
        const onSubmitYes = () => {
            formRef.value.validate().then(() => {
                Modal.confirm({
                    title: '审核提示',
                    icon: createVNode(ExclamationCircleOutlined),
                    content: '确定通过该审核？',
                    centered: true,
                    okText: '确定',
                    // okType: 'danger',
                    cancelText: '取消',
                    onOk: (() => {
                        // message.success('调用审核通过')
                        handleSubmit(true)
                    })
                });
            }).catch((error) => {
                console.log('error', error);
            });
        }
        //不通过
        const onSubmitNo = () => {
            formRef.value.validate().then(() => {
                Modal.confirm({
                    title: '审核提示',
                    icon: createVNode(ExclamationCircleOutlined),
                    content: '确定不通过该审核？',
                    centered: true,
                    okText: '确定',
                    okType: 'danger',
                    cancelText: '取消',
                    onOk: (() => {
                        message.info('调用审核不通过')
                        handleSubmit(false)
                    })
                });
            }).catch((error) => {
                console.log('error', error);
            });
        }
        //提交方法
        const handleSubmit = (isPass) => {
            let params = {
                bussInfoId: form.bussInfoId,
                ispass: isPass ? "1" : "0",
                opinion: form.opinion,
                userId: form.userId
            }
            subminExamineResult(params).then(res => {
                // console.log(res);
                if (res.resp_code === 0 && res.resp_msg === '提交成功') {
                    message.success('审核成功')
                } else {
                    message.error('审核失败')
                }
                emit('onSubmit', isPass)
            })
        }

        return {
            formRef,
            form,
            ...toRefs(data),
            rules,
            labelCol: { span: 5 },
            wrapperCol: { span: 19 },
            //func
            onClose,
            onSubmitYes,
            onSubmitNo
        };
    },
});
</script>
<style lang="less" scoped>
.modal-wrap {
    .action-content {
        padding: 20px 50px;

        .item {
            margin-top: 10px;
            margin-bottom: 20px;

            &:first-child {
                margin-top: 0;
            }

            .item-header {
                padding-left: 10px;
                height: 30px;
                display: flex;
                justify-content: space-between;
                align-items: center;
                border-left: 2px solid #0671DD;
                box-sizing: border-box;
            }

            .item-body {
                margin-top: 20px;
                // padding-left: 10px;

                // .submit-btn {
                //     cursor: pointer;
                //     user-select: none;
                // }

                // ::v-deep td{
                //     padding: 5px 5px;
                // }
            }
        }

        .item-footer {
            width: 100%;
            display: flex;
            justify-content: flex-end;
        }
    }
}
</style>