<template>
    <div class="page">
        <div class="top adfac">
            <img src="@/assets/images/agent/arrow_left.png" @click="handleBack">
            <span>{{ questionnaireInfo.questionnaireName }}</span>
        </div>
        <div class="content">
            <div class="c_top adfacjb">
                <div class="ct_l">
                    <div class="cl_title">作答进度</div>
                </div>
                <div class="ct_r adfac">
                    <div class="eb_default" style="margin-left: 20px;" @click="handleReminds">批量提醒</div>
                    <!-- <el-button type="primary" style="margin-left: 20px;" @click="handleMoreSingleReport">批量个人报告</el-button> -->
                    <el-button type="primary" style="margin-left: 20px;" @click="handleTeamReport">生成报告</el-button>
                </div>
            </div>
            <div class="c_texts adfac">
                <div class="cl_pre">公司名称：<span>{{ questionnaireInfo.enterpriseName }}</span></div>
                <div class="cl_pre">团队类型：<span>{{ questionnaireInfo.teamName }}</span></div>
                <div class="cl_pre">发布时间：<span>{{ questionnaireInfo.startTime }}</span></div>
                <div class="cl_pre">截止时间：<span>{{ questionnaireInfo.endTime }}</span></div>
            </div>
            <div class="c_nums adfac">
                <div class="cn_pre">团队人数：<span>{{ questionnaireInfo.userNum }}</span></div>
                <div class="cn_pre">已作答：<span>{{ questionnaireInfo.finishNum }}</span> 人</div>
                <div class="cn_pre">未作答：<span style="color: #E22D48;">{{ questionnaireInfo.userNum-questionnaireInfo.finishNum }}</span> 人</div>
            </div>
            <el-table ref="multipleTable" :data="userList" border cell-class-name="vertical-top-cell" v-loading="loading" empty-text="暂无人员" max-height="672px" style="margin-top: 16px;" @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="55"></el-table-column>
                <el-table-column label="姓名" prop="realName"></el-table-column>
                <el-table-column label="性别" prop="gender">
                    <template #default="{ row }">{{ genderCfg[row.gender]||'' }}</template>
                </el-table-column>
                <el-table-column label="类型" prop="category">
                    <template #default="{ row }">{{ UserCategory.find(u=>u.value===row.category)?.label ||'未知' }}</template>
                </el-table-column>
                <el-table-column label="手机号码" prop="mobile"></el-table-column>
                <el-table-column label="所属部门" prop="dept"></el-table-column>
                <el-table-column label="职位" prop="post"></el-table-column>
                <el-table-column label="级别" prop="level"></el-table-column>
                <!-- <el-table-column label="用户标签" prop="aaa"></el-table-column> -->
                <!-- <el-table-column label="发送人" prop="aaa"></el-table-column> -->
                <!-- <el-table-column label="所属上级" prop="aaa"></el-table-column> -->
                <el-table-column label="状态" prop="status">
                    <template #default="{ row }">
                        <div class="q_status adfac" :class="{'wzd':row.status==='0','yzd':row.status==='1'}">
                            <div class="qs_l"></div>
                            <div class="qs_r">{{ row.status==='0'?'未作答':row.status==='1'?'已作答':'' }}</div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="提交时间" prop="submitTime"></el-table-column>
                <el-table-column label="操作" width="150">
                    <template #default="scope">
                        <!-- <el-button link type="text" size="mini" @click="handleReport(scope.row)" v-if="scope.row.status==='1'">生成报告</el-button> -->
                        <el-button link type="text" size="mini" @click="handleRemind(scope.row)" v-if="scope.row.status==='0'" v-hasPermi="['core:questionnaire:remind']">提醒作答</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <div class="cus_dialog adffcacjc" v-if="reportShow" @click.prevent="closeReportAlert">
            <div class="cus_dialog_content adffcac">
                <div class="cdc_title">生成报告</div>
                <i class="el-icon-close cdc_close" style="font-size: 20px;color: #393939;" @click.stop="closeReportAlert"></i>
                <img src="@/assets/images/agent/report.gif">
                <p>{{ questionnaireInfo.enterpriseName }} - {{ questionnaireInfo.teamName }}</p>
                <p>报告正在生成中，预计需要时间<span>7-10分钟</span></p>
                <p>可去报告管理中查看结果~</p>
                <div class="zt_btn" @click.stop="closeReportAlert">我知道了</div>
            </div>
        </div>
    </div>
</template>

<script setup name="">
    import { ref, getCurrentInstance, onMounted, nextTick } from 'vue'
    const { proxy } = getCurrentInstance();
    import { getQuestionnaireSchedule,genTeamReportById,genPersonReport } from '@/api/agent/index.js'
    const { UserCategory} = proxy.useDict("UserCategory");
    
    const genderCfg = { 0: '男', 1: '女', 2: '保密' }
    const questionnaireInfo = ref({})
    const multipleSelection = ref([])
    const userList = ref([{status:1},{status:0}])
    const loading = ref(false)
    const reportShow = ref(false)

    const handleBack = () => {
        proxy.$router.go(-1)
    }
    const handleSelectionChange = (val) => {
        multipleSelection.value = val;
    }
    const handleCancel = () => {
        multipleSelection.value = [];
        proxy.$refs.multipleTable.clearSelection();
    }
    const handleReminds = () => {
        if(!multipleSelection.value.length) return proxy.$message({ type: 'warning', message: '请勾选需要提醒的人员' })
        proxy.$confirm('是否确认发送通知提醒？?', '警告', {
            confirmButtonText: '确定',
            confirmButtonColor:'#761E6A',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => {
            
        })
    }
    const handleMoreSingleReport = () => {
        if(!multipleSelection.value.length) return proxy.$message({ type: 'warning', message: '请勾选需要生成报告的人员' })
        genPersonFn(multipleSelection.value.map(u=>u.id))
    }

    const handleTeamReport = () => {
        genTeamReportById(questionnaireInfo.value.id).then(res => {
            if(res.code!==0) return proxy.$message.error(res.msg)
            reportShow.value = true
        })
    }


    const handleReport = (row) => {
        genPersonFn([row.id])
    }
    const genPersonFn = (ids) => {
        genPersonReport(ids).then(res => {
            if(res.code!==0) return proxy.$message.error(res.msg)
            reportShow.value = true
        })
    }

    const handleRemind = (row) => {
        proxy.$confirm('是否确认发送通知提醒？?', '警告', {
            confirmButtonText: '确定',
            confirmButtonColor:'#761E6A',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => {
            
        })
    }

    const getList = () => {
        loading.value = true;
        getQuestionnaireSchedule(questionnaireInfo.value.id).then(res => {
            if(res.code!==0) return proxy.$message({ type: 'error', message: res.msg })
            userList.value = res.data;
        }).finally(()=>{
            loading.value = false
        })
    }

    const closeReportAlert = () => {
        reportShow.value = false;
    }

    onMounted(()=>{
        questionnaireInfo.value = proxy.$route.query;
        nextTick(()=>{
            getList()
        })
    })
</script>

<style scoped lang="scss">
    :v-deep .el-dialog__wrapper{
        background: rgba(0,0,0,.3) !important;
    }
    ::v-deep .el-dialog__title{
        font-weight: bold !important;
    }
    ::v-deep .el-dialog{
        margin-top: 15vh !important;
    }

    .page{
        background: #FAFAFA;
        
        .top{
            width: 100%;
            height: 64px;
            background: #FFFFFF;
            border-bottom: 1px solid #F3F4F6;
            img{
                width: 36px;
                height: 36px;
                margin-left: 16px;
                cursor: pointer;
            }
            span{
                font-family: PingFangSC, PingFang SC;
                font-weight: 400;
                font-size: 14px;
                color: #252525;
                line-height: 14px;
                margin-left: 27px;
            }
        }

        .content{
            width: calc(100% - 24px);
            height: calc(100vh - 88px);
            margin: 12px;
            background: #FFFFFF;
            border-radius: 6px 6px 0px 0px;
            border: 1px solid #F3F4F6;
            padding: 32px 24px;
            box-sizing: border-box;
            overflow-y: auto;

            .c_top{
                .ct_l{
                    .cl_title{
                        font-family: PingFang-SC, PingFang-SC;
                        font-weight: bold;
                        font-size: 16px;
                        color: #252525;
                        line-height: 16px;
                    }
                }
                .ct_r{
                    p{
                        font-family: PingFang-SC, PingFang-SC;
                        font-weight: bold;
                        font-size: 16px;
                        color: #808080;
                        line-height: 16px;
                        span{
                            color: #252525;
                        }
                    }
                }
            }
            .c_texts{
                margin-top: 20px;
                .cl_pre{
                    width: 25%;
                    font-family: PingFang-SC, PingFang-SC;
                    font-weight: 400;
                    font-size: 14px;
                    color: #808080;
                    line-height: 16px;
                    span{
                        color: #252525;
                        margin-left: 10px;
                    }
                }
            }

            .c_nums{
                width: 100%;
                height: 68px;
                background: rgba(118,30,106,0.06);
                border-radius: 6px;
                margin-top: 37px;
                padding: 0 25px;
                box-sizing: border-box;
                .cn_pre{
                    font-family: PingFang-SC, PingFang-SC;
                    font-weight: bold;
                    font-size: 14px;
                    color: #808080;
                    margin-right: 153px;
                    span{
                        font-family: DINAlternate, DINAlternate;
                        font-size: 22px;
                        color: #1D2129;
                        line-height: 28px;
                    }
                }
            }
        }

        .q_status{
            .qs_l{
                width: 10px;
                height: 10px;
                border-radius: 50%;
            }
            .qs_r{
                font-family: PingFangSC, PingFang SC;
                font-weight: 400;
                font-size: 14px;
                line-height: 16px;
                margin-left: 12px;
            }

            &.wzd{
                .qs_l{
                    background: #E22D48;
                }
                .qs_r{
                    color: #E22D48;
                }
            }
            &.yzd{
                .qs_l{
                    background: #009191;
                }
                .qs_r{
                    color: #009191;
                }
            }
        }
    }

    .cus_dialog_content{
        width: 400px;
        background: linear-gradient( 180deg, #FDF2FB 0%, #FFFFFF 100%);
        border-radius: 6px;
        padding: 36px 68px;
        box-sizing: border-box;
        position: relative;
        .cdc_title{
            font-family: PingFang-SC, PingFang-SC;
            font-weight: bold;
            font-size: 16px;
            color: #252525;
            line-height: 16px;
            text-align: center;
        }
        .cdc_close{
            position: absolute;
            right: 30px;
            top: 36px;
            cursor: pointer;
        }
        img{
            width: 100%;
        }
        p{
            font-family: PingFangSC, PingFang SC;
            font-weight: 400;
            font-size: 14px;
            color: #393939;
            line-height: 24px;
            text-align: center;
            span{
                color: #F31616;
            }
        }
        .zt_btn{
            margin-top: 40px;
        }
    }
</style>