<template>
    <view>
        <view v-if="dataSource.length">
            <block v-for="(item, index) in dataSource" :key="item.id">
                <view class="search-item" @click="toDetail(item)">
                    {{item.surveyTitle}}
                    <view style="flex:1;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">{{ item.workname }}
                    </view>
                    <image src="../../static/img/eyeopen.svg" style="width: 32rpx;height: 32rpx;margin-right: 10rpx;"
                        mode="">
                    </image>
                    <view class="baddd"></view>
                </view>
            </block>
        </view>
        <empty v-else content="暂无问卷" mrTop="300"></empty>
    </view>
</template>

<script>
    import {
        listEmploymentSurveyManage
    } from '@/api/help.js'
    export default {
        data() {
            return {
                dataSource: [],
                pageNumber: 1,
            }
        },
        created() {
            this.getList("refresh");
        },
        onReachBottom() {
            this.getList();
        },
        onPullDownRefresh() {
            this.getList("refresh");
        },
        methods: {
            toDetail(row) {
                this.navTo(`/pageMy/setUserBase/sub/surveyDetail?id=${row.id}`)
            },
            async getList(type = 'add') {
                if (type === "refresh") {
                    this.pageNumber = 1;
                }
                let params = {
                    size: 10,
                    page: this.pageNumber,
                    status: 1
                }
                let resData = await listEmploymentSurveyManage(params)
                uni.stopPullDownRefresh()
                if (resData.data.code === 200) {
                    const {
                        current,
                        records,
                        total,
                        size
                    } = resData.data.data
                    if (!records.length) {
                        return this.$api.msg("没有更多");
                    }
                    switch (type) {
                        case "add":
                            this.dataSource = [...this.dataSource, ...records];
                            break;
                        case "refresh":
                            this.dataSource = records;
                            break;
                    }
                    this.pageNumber += 1;
                }
            }
        }
    }
</script>

<style scoped>
    .baddd {
        background: #f6f6f6;
        height: 20rpx;
    }

    .search-item {
        display: flex;
        align-items: center;
        font-size: 26rpx;
        border-bottom: 1rpx solid #ddd;
        height: 80rpx;
        line-height: 80rpx;
        padding: 10rpx 30rpx;
    }

    .search-item .type {
        font-size: 20rpx;
        color: #707070;
        background-color: #dddddd;
        border-radius: 15rpx;
        height: 30rpx;
        line-height: 30rpx;
        padding: 0 20rpx;
    }
</style>