<template>
    <div class="p-3">
        <div class="bg-fff flex1 ov-hd d-flex flex-cln" v-show="showSearch">
            <div class="pd-16 border-bottom">
                <div class="f-s-20 c-333 f-w-7 mb-10">抽取专家审核</div>
                <div class="d-flex">
                    <div class="flex1 ov-hd d-flex j-ed">
                        <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="auto">
                            <el-form-item label="发起方" prop="starter">
                                <el-input v-model="queryParams.starter" placeholder="搜发起方" clearable style="width: 180px" @keyup.enter="handleQuery" />
                            </el-form-item>
                            <el-form-item label="事项名称" prop="title">
                                <el-input v-model="queryParams.title" placeholder="搜事项名称" clearable style="width: 180px" @keyup.enter="handleQuery" />
                            </el-form-item>
                            <el-form-item label="时间" prop="dateRange">
                                <div class="d-flex" style="width: 220px">
                                    <DateRange v-model="queryParams.dateRange" v-model:start-date="queryParams.startDate" v-model:end-date="queryParams.endDate" @change="handleQuery"></DateRange>
                                </div>
                            </el-form-item>
                            <el-form-item label="参与方式" prop="joinType">
                                <el-select style="width: 140px" v-model="queryParams.joinType" clearable placeholder="请选择参与方式">
                                    <el-option v-for="item in dm_join_type" :key="item.value" :label="item.label" :value="item.value" />
                                </el-select>
                            </el-form-item>
                            <el-form-item label="搜专家组" prop="queryPersonType">
                                <el-select style="width: 140px" v-model="queryParams.queryPersonType" clearable placeholder="请选择搜专家组">
                                    <el-option v-for="item in dm_person_type" :key="item.value" :label="item.label" :value="item.value" @change="handleQuery" />
                                </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-form-item>
                        </el-form>
                    </div>
                </div>
            </div>

            <div class="d-flex flex1 ov-hd flex-cln pd-16">
                <div class="d-flex j-sb mb-16">
                    <div>
                        <searchTabs v-model="queryParams.res" @change="handleQuery" :list="tabs" key-label="name" key-count="num" key-value="type"></searchTabs>
                    </div>
                </div>
                <div class="flex1 ov-hd">
                    <vxe-table :loading="loading" border :data="dataList" min-height="0" max-height="100%">
                        <vxe-column title="序号" align="center" type="seq" width="50" />
                        <vxe-column title="发起方" field="starter" :formatter="colNoData" />
                        <vxe-column title="事项名称" field="title" :formatter="colNoData" />
                        <vxe-column title="时间">
                            <template #default="{ row }">
                                <span>{{ row.startTime }} 至 {{ row.endTime }}</span>
                            </template>
                        </vxe-column>
                        <vxe-column title="参与方式" width="80">
                            <template #default="{ row }">
                                <DictTag :options="dm_join_type" :value="row?.joinType"></DictTag>
                            </template>
                        </vxe-column>
                        <vxe-column title="联系人" width="80" field="contact" :formatter="colNoData" />
                        <vxe-column title="联系电话" width="110" field="tel" :formatter="colNoData" />
                        <vxe-column title="抽取专家要求" min-width="160">
                            <template #default="{ row }">
                                <div class="d-flex flex-wrap">
                                    <div v-for="(item, index) in row?.personInfo" :key="index" class="pd-4">
                                        <el-tag>{{ selectDictLabel(dm_person_type, item?.personType) }}（{{ item?.personCount }}人）</el-tag>
                                    </div>
                                </div>
                            </template>
                        </vxe-column>
                        <vxe-column title="事项状态" width="100">
                            <template #default="{ row }">
                                <DictTag :options="dm_expert_item_list" :value="row?.res"></DictTag>
                            </template>
                        </vxe-column>
                        <vxe-column title="操作" width="100" align="center" fixed="right">
                            <template #default="{ row }">
                                <el-button v-if="!+row?.res" type="primary" @click="editRow(row)" text>审核</el-button>
                                <el-button v-else type="primary" @click="editRow(row)" text>详情</el-button>
                            </template>
                        </vxe-column>
                    </vxe-table>
                </div>
                <pagination :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
            </div>
        </div>
    </div>
</template>

<script setup name="choose-check" lang="ts">
import { colNoData } from '@/utils/noData';
import { DateRange } from '@/views/models/index';
import { searchTabs } from '@/views/models';
import { expertItemList, expertList, expertPersonCount, expertPersonDelete, expertPersonOff, expertPersonOn, queryChooseCount } from '@/api/authority';
const router = useRouter();
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { dm_join_type, dm_person_type, dm_expert_item_list } = toRefs<any>(proxy?.useDict('dm_join_type', 'dm_person_type', 'dm_expert_item_list'));
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);
const queryFormRef = ref<ElFormInstance>();
const dataList = ref<any[]>([]);
const initFormData = {};
const data = reactive<any>({
    form: { ...initFormData },
    queryParams: {
        pageNum: 1,
        pageSize: 10,
        res: '0',
        startDate: '',
        endDate: '',
        dateRange: []
    },
    rules: {}
});

const { queryParams, form } = toRefs(data);
/** 查询会员信息列表 */
const getList = async () => {
    loading.value = true;
    const res = await expertItemList(queryParams.value);
    dataList.value = res.rows;
    total.value = res.total;
    loading.value = false;
};

/** 搜索按钮操作 */
const handleQuery = () => {
    queryParams.value.pageNum = 1;
    getList();
};

/** 重置按钮操作 */
const resetQuery = () => {
    queryFormRef.value?.resetFields();
    queryParams.value.startDate = '';
    queryParams.value.endDate = '';
    queryParams.value.dateRange = [];
    handleQuery();
};

/** 编辑事项 */
const editRow = (row) => { 
    router.push({ path: 'choose-detail', query: { id: row.id } });
};
// 获取专家统计数量
const tabs = ref([]);
const getExpertPersonCount = async () => {
    const res = await queryChooseCount();
    if (res?.code === 200) {
        tabs.value = res.data;
    }
};
onMounted(() => {
    getExpertPersonCount();
    getList();
});
</script>
