<template>
    <div class="page">
        <el-table :data="dataList" border cell-class-name="vertical-top-cell" v-loading="loading" empty-text="暂无问卷管理" max-height="578px" style="margin-top: 18px;">
            <el-table-column label="序号" width="50">
                <template #default="scope">
                    {{ scope.$index + 1 }}
                </template>
            </el-table-column>
            <el-table-column label="问卷名称" prop="title"></el-table-column>
            <el-table-column label="问卷类型" prop="">
                <template #default="scope">{{ typeCfg[scope.row.type]||'' }}</template>
            </el-table-column>
            <el-table-column label="团队名称" prop="teamName"></el-table-column>
            <el-table-column label="问卷状态" prop="">
                <template #default="scope">{{ statusCfg[scope.row.status]||'' }}</template>
            </el-table-column>
            <el-table-column label="创建时间" prop="createDate"></el-table-column>
        </el-table>
        <el-row style="display: flex;justify-content: center;">
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="queryParams.page"
                :page-sizes="[5, 10, 20, 50]"
                :page-size="10"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
                v-show="total > 0">
            </el-pagination>
        </el-row>
    </div>
</template>

<script setup name="">
    const props = defineProps({
        userId:{
            typeof:'String',
            default:''

        }
    });
    import { ref, getCurrentInstance, onMounted } from 'vue'
    const { proxy } = getCurrentInstance();
    import { 
        getQuestionniareManagerList
    } from '@/api/agent/indexTwo.js'
    
    const queryParams = ref({
        page: 1,
        limit: 10,
        userId:''
    })
    const typeCfg = ref({
        0: '我发布的',
        1: '我收到的'
    })
    const statusCfg = ref({
        '-1': '已失效',
        0: '待完成',
        1: '已完成'
    })
    const dataList = ref([])
    const total = ref(0)
    const loading = ref(false)
    
    const handleSizeChange = (val) => {
        queryParams.value.limit = val;
        getList();
    }

    const handleCurrentChange = (val) => {
        queryParams.value.page = val;
        getList();
    }
    const getList = async () => {
        let query = JSON.parse(JSON.stringify(queryParams.value));
        loading.value = true;
        const res = await getQuestionniareManagerList(query);
        dataList.value = res.data.list;
        total.value = res.data.total;
        loading.value = false;
    }

    onMounted(() => {
        queryParams.value.userId = props.userId;
        getList();
    })
</script>

<style scoped lang="scss">
    
</style>