<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="standardName">
                                <el-input v-model="queryParams.standardName" placeholder="搜标准名称" clearable style="width: 160px" @keyup.enter="handleQuery" />
                            </el-form-item>
                            <el-form-item label="企业名称" prop="cpyname">
                                <el-input v-model="queryParams.cpyname" placeholder="搜企业名称" clearable style="width: 160px" @keyup.enter="handleQuery" />
                            </el-form-item>
                            <el-form-item label="申报人" prop="createByName">
                                <el-input v-model="queryParams.createByName" placeholder="搜申报人" clearable style="width: 160px" @keyup.enter="handleQuery" />
                            </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.status" @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="standardName" :formatter="colNoData" />
                        <vxe-column title="企业名称" field="cpyname" :formatter="colNoData" />
                        <vxe-column title="申报时间" align="center" width="240">
                            <template #default="{ row }">
                                <span>{{ row.createTime }}</span>
                            </template>
                        </vxe-column>
                        <vxe-column title="申报人" field="createByName" align="center" width="140" />
                        <vxe-column title="点赞数" field="likeCount" align="center" width="70"/>
                        <vxe-column title="分享数" field="shareCount" align="center" width="70" />
                        <vxe-column title="事项状态" width="100">
                            <template #default="{ row }">
                                <DictTag :options="dm_expert_item_list" :value="row?.status"></DictTag>
                            </template>
                        </vxe-column>
                        <vxe-column title="操作" width="100" align="center" fixed="right">
                            <template #default="{ row }">
                                <el-button v-if="!+row?.status" 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="getdeclarationList" />
            </div>
        </div>
    </div>
</template>

<script setup name="choose-check" lang="ts">
import { colNoData } from '@/utils/noData';
import { searchTabs } from '@/views/models';

import {DeclarationRecordList,queryDeclarationRecordCount} from '@/api/leader'
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: {
        status:"0",
        pageNum: 1,
        pageSize: 10,
        res: '0',
        standardName: '',
        cpyname: '',
        createByName:'',
    },
    rules: {}
});

const { queryParams, form } = toRefs(data);
/** 查询审批列表 */
const getdeclarationList = async()=>{
    loading.value = true;
    const res = await DeclarationRecordList(queryParams.value);
    dataList.value = res.rows;
    total.value = res.total;
    loading.value = false;
}

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

/** 重置按钮操作 */
const resetQuery = () => {
    queryFormRef.value?.resetFields();
    queryParams.value.standardName = '';
    queryParams.value.cpyname = '';
    queryParams.value.createByName = '';
    handleQuery();
};

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