<template>
    <div class="pd-16">
        <div class="d-flex mb-16 flex-cln">
            <div class="info-title">报名限制条件</div>
            <div class="bg-#fafafa pd-20" v-if="form?.conditions?.totalCheck == '0' || !form?.conditions?.totalCheck">无</div>
            <div class="bg-#fafafa pd-20 d-flex flex-cln" v-else>
                <div class="pd-5">总参会人数 ≤ {{ form?.conditions?.total }}</div>
                <div class="d-flex">
                    <div>
                        <template v-for="(item, index) in form?.conditions?.levelCheck" :key="index">
                            <div class="d-flex a-c pd-5">
                                <span v-if="+item.check">
                                    所有
                                    <span class="f-w-6">
                                        {{ selectDictLabels(vip_level,item.vipLevel,',') }}
                                    </span>
                                    参会人数 ≤
                                    {{ item.total}}
                                </span>
                            </div>
                        </template>
                    </div>
                    <div>
                        <template v-for="(item, index) in form?.conditions?.cpyCheck" :key="index">
                            <div class="d-flex a-c pd-5">
                                <span v-if="+item.check">
                                    <span class="f-w-6">
                                        {{ selectDictLabels(vip_level,
                                    item.vipLevel,
                                    ',') }}
                                    </span>
                                    限制每家单位人数≤{{ item.total
                                    }}
                                </span>
                            </div>
                        </template>
                    </div>
                </div>
            </div>
        </div>
        <div class="d-flex mb-16 ">
            <div class="info-title">
                <span>参会人员信息</span>
                <span class="f-s-14 c-666">(提交报名:{{ form?.submitCount || 0 }}人 | 审核通过:{{ form?.joinCount || 0 }}人 | 签到:{{form?.signCount || 0}}人 | 领取证书:{{ form?.certCount || 0 }}人)</span>
            </div>
        </div>
        <div class="d-flex j-sb">
            <div><searchTabs v-if="form?.conditions?.totalCheck == '1'" v-model="queryParams.res" @change="handleQuery" :list="tabs" key-label="name" key-count="num" key-value="type"></searchTabs></div>
            <span style="width: 1px;"></span>
            <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="auto">
                <el-form-item label="姓名：" prop="name">
                    <el-input v-model="queryParams.name" placeholder="请输入姓名" clearable style="width: 180px" />
                </el-form-item>
                <el-form-item label="企业名称：" prop="company">
                    <el-input v-model="queryParams.company" placeholder="请输入企业名称" clearable style="width: 180px" />
                </el-form-item>
                <el-form-item label="参会状态：" prop="signupStatus">
                    <el-select v-model="queryParams.signupStatus" placeholder="请选择参会状态" clearable style="width: 180px">
                        <el-option v-for="item in dm_training_signup_status_list" :key="item.value" :label="item.label" :value="item.value" />
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                    <el-button icon="Refresh" @click="resetQuery">重置</el-button>
                    <el-button icon="Download" @click="exportSearch">导出参会人员信息</el-button>
                </el-form-item>
            </el-form>
        </div>
        <vxe-table :loading="loading" border :data="list" min-height="0">
            <!-- 序号 -->
            <vxe-column type="seq" width="60" title="序号" align="center" />
            <vxe-column title="企业名称" field="company" min-width="100" :formatter="colNoData" />
            <vxe-column title="盟员等级" field="vipLevel" min-width="100" :formatter="colNoData" align="center">
                <template #default="{ row }">
                    <div class="d-flex a-c j-c">
                        <DictTag :options="vip_level" :value="row?.signupStatusForPc"></DictTag>
                    </div>
                </template>
            </vxe-column>
            <vxe-column title="姓名" field="name" min-width="100" :formatter="colNoData" />
            <vxe-column title="职务" field="position" min-width="100" :formatter="colNoData" />
            <vxe-column title="联系方式" field="contact" min-width="100" :formatter="colNoData" />
            <vxe-column title="备注" field="remark" min-width="100" :formatter="colNoData" />
            <vxe-column title="报名时间" align="center" field="createTime" min-width="100" :formatter="colNoData" />
            <vxe-column title="报名信息" min-width="100" fixed="right">
                <template #default="{ row }">
                    <div class="c-s-p"><u @click="checkRegostrationInfo(row)">查看报名信息</u></div>
                </template>
            </vxe-column>
            <vxe-column title="参会状态" min-width="100" fixed="right">
                <template #default="{ row }">
                    <DictTag :options="dm_training_signup_status_list" :value="row?.signupStatusForPc"></DictTag>
                </template>
            </vxe-column>
            <vxe-column v-if="form?.conditions?.totalCheck == '1'" title="审核状态" min-width="100" fixed="right">
                <template #default="{ row }">
                    <DictTag :options="cpy_res_status" :value="row?.res"></DictTag>
                </template>
            </vxe-column>
            <vxe-column v-if="form?.conditions?.totalCheck == '1'" title="操作" width="250" align="center" fixed="right">
                <template #default="{ row }">
                    <el-button type="danger" size="small" v-if="row?.res !== '0'" @click="openDialog(row)">重审</el-button>
                    <el-button size="small" type="danger" @click="openDialog(row)" v-else>审核</el-button>
                </template>
            </vxe-column>
        </vxe-table>
        <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
    </div>
    <el-dialog v-model="dialogVisible" title="审核信息" width="500" center>
        <span class="f-s-16 mb-15">请填写审核原因：</span>
        <el-input v-model="dialoginput" type="textarea" :rows="4"></el-input>
        <template #footer>
            <div class="dialog-footer">
                <el-button type="primary" @click="signupApprovals('1')">通过</el-button>
                <el-button type="danger" @click="signupApprovals('2')">不通过</el-button>
            </div>
        </template>
    </el-dialog>
    <registrationInfo v-if="showTemporary" v-model:show="showTemporary" :info="temporaryRegistration"></registrationInfo>
</template>
<script setup name="MeetingDetailInfo" lang="ts">
import { ref, onMounted } from 'vue';
import { signupCount, trainingMembers, signupApproval, exportTrainingMembers } from '@/api/training';
import { searchTabs } from '@/views/models';
import { colNoData } from '@/utils/noData';
import registrationInfo from './registration-info.vue';
import { debounce } from 'lodash';
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { cpy_res_status, dm_training_signup_status_list, vip_level } = toRefs<any>(proxy?.useDict('cpy_res_status', 'dm_training_signup_status_list', 'vip_level'));
// 获取详情
const props = defineProps({
    form: {
        type: Object,
        default: () => ({})
    }
});
const showTemporary = ref(false);
const dialogVisible = ref(false);
const dialoginput = ref();
const currentRow = ref();
const temporaryRegistration = ref();
const checkRegostrationInfo = (row) => {
    temporaryRegistration.value = row;
    showTemporary.value = true;
};
const openDialog = (row) => {
    currentRow.value = row; // 保存当前行数据
    dialogVisible.value = true;
};
const query = useRoute().query;

const queryParams = ref<any>({
    pageNum: 1,
    pageSize: 10,
    trainingId: query?.id || ''
});
const loading = ref(false);
const total = ref(0);
const list = ref<any>([]);
const tabs = ref([]);
const getExpertPersonCount = async () => {
    const res = await signupCount(query?.id);
    if (res?.code === 200) {
        tabs.value = res.data;
    }
};
const getList = async () => {
    loading.value = true;
    const res = await trainingMembers(queryParams.value);
    if (!res || res.code !== 200) return;
    list.value = res.rows;
    total.value = res.total;
    loading.value = false;
};
const signupApprovals = async (type: string) => {
    const res = await signupApproval({
        targetId: currentRow.value.id,
        res: type,
        msg: dialoginput.value
    });
    dialogVisible.value = false;
    handleQuery();
};
const handleQuery = () => {
    queryParams.value.pageNum = 1;
    getList();
};
const queryFormRef = ref<ElFormInstance>();
const resetQuery = () => {
    queryFormRef.value?.resetFields();
    handleQuery();
};
const exportSearch = debounce(() => {
    const params = {
        ...queryParams.value
    };
    delete params.pageNum;
    delete params.pageSize;
    exportTrainingMembers(params);
}, 500);
onMounted(() => {
    getList();
    getExpertPersonCount();
});
</script>
<style scoped lang="scss">
.tabs-item {
    margin-right: 20px;
    padding: 8px 20px;
    font-size: 14px;
    border-color: #d7d7d7;
    border-style: solid;
    border-width: 1px 1px 0 1px;
    cursor: pointer;
    user-select: none;

    &.checked {
        color: #fff;
        border-color: var(--el-color-primary);
        background-color: var(--el-color-primary);
    }
}

.border-botttom {
    border-bottom: 1px solid #d7d7d7;
}
</style>
