<script setup name="ReportEnSearchList">
import {ref,reactive} from 'vue'
import apiReportEn from '@/api/reportEn'
import { showToast } from 'vant'
import moment from 'moment'
import { useRouter } from 'vue-router'

const router=useRouter()

const keyword=ref('')
const listState = reactive({
    list:[],
    page:1,
    pageSize:20,
    finished:false,
    loading:false
})
async function getList(){
    const res=await apiReportEn.getList({
        CurrentIndex:listState.page,
        PageSize:listState.pageSize,
        KeyWord:keyword.value
    })
    if(res.Ret===200){
        listState.loading=false
        if(!res.Data){
            listState.finished=true
            return
        }
        
        listState.finished=res.Data.Paging.IsEnd
        const arr=res.Data.List||[]
        listState.list=[...listState.list,...arr]
    }
}
function onLoad(){
    listState.page++
    getList()
}

function handleSearch(){
    if(!keyword.value){
        showToast('请输入关键词')
        return
    }
    listState.page=1
    listState.list=[]
    listState.finished=false
    getList()
}

function goDetail(item){
    router.push({
        path:"/reportEn/detail",
        query:{
            id:item.Id
        }
    })
}
</script>

<template>
    <div class="report-search-page">
        <div class="search-box">
            <van-search 
                shape="round"
                placeholder="请输入报告标题或创建人"
                v-model="keyword"
                @search="handleSearch"
            />
        </div>
        <img v-if="listState.list.length==0&&listState.finished&&keyword" class="list-empty-img" src="https://hzstatic.hzinsights.com/static/ETA_mobile/empty_img.png" alt="">
        <template v-if="keyword">
        <van-list
            v-model:loading="listState.loading"
            :finished="listState.finished"
            :finished-text="listState.list.length>0?'没有更多了':'暂无报告'"
            :immediate-check="false"
            @load="onLoad"
        >
            <ul class="list-wrap">
                <li 
                    v-for="item in listState.list"
                    :key="item.Id"
                    class="item" 
                    @click="goDetail(item)"
                >
                    <h2 :class="['van-ellipsis title',item.Title.startsWith('【')?'inline-title':'']">{{item.Title}}</h2>
                    <p class="van-multi-ellipsis--l2 des">{{item.Abstract}}</p>
                    <div class="bot-info">
                        <div>
                            <span style="margin-right:10px">{{moment(item.ModifyTime).format('YYYY-MM-DD HH:mm:ss')}}</span>
                            <span>(第{{item.Stage}}期)</span>
                        </div>
                        <div>{{item.ClassifyNameFirst}}</div>
                    </div>
                </li>
            </ul>
        </van-list>
        </template>
    </div>
</template>

<style lang="scss" scoped>
.list-wrap{
    padding: 30px 34px;
    .item{
        padding: 20px;
        margin-bottom: 20px;
        border: 1px solid $border-color;
        box-shadow: 0px 3px 12px rgba(52, 75, 120, 0.08);
        border-radius: 8px;
        .title{
            font-size: 32px;
            line-height: 44px;
            margin: 0;
        }
        .inline-title{
            margin-left: -14px;
        }
        .des{
            margin-top: 10px;
            margin-bottom: 20px;
            font-size: 28px;
            color: $font-grey;
            min-height: 60px;
        }
        .bot-info{
            display: flex;
            justify-content: space-between;
            color: $font-grey;
            font-size: 28px;
            .active-status{
                color: $font-success;
            }
        }
    }
}
.report-search-page{
    .search-box{
        position: sticky;
        top: 0;
        z-index: 99;
        background-color: #fff;
    }
}
@media screen and (min-width:$media-width){
    .list-wrap{
        padding: 30px;
        .item{
            padding: 20px;
            margin-bottom: 20px;
            border-radius: 4px;
            .title{
                font-size: 16px;
                line-height: 22px;
            }
            .inline-title{
                margin-left: -14px;
            }
            .des{
                margin-top: 5px;
                margin-bottom: 10px;
                font-size: 14px;
                min-height: 30px;
            }
            .bot-info{
                font-size: 14px;
            }
        }
    }
    .report-search-page{
        .search-box{
            top: 60px;
        }
    }
}
</style>