<template>
    <div class="statistic-analysis-wrap">
        <div class="top-box">
            <div class="left-card">
                <span>语义分析</span>
            </div>
            <div class="right">
                <el-input
                    class="search-box"
					placeholder="关键词搜索"
					v-model="keyword"
					size="medium"
					prefix-icon="el-icon-search"
                    @input="handleSearch"
				/>
            </div>
        </div>
        <div class="main-box">
            <div class="list-wrap" v-infinite-scroll="handleLoadMore" :infinite-scroll-immediate="true">
                <draggable
                    :list="list"
                    :group="{ name: 'component', pull: 'clone', put: false }"
                    class="chart-list-box"
                    animation="300"
                    :sort="false"
                    tag="div"
                >
                    <div class="chart-item" :comp-data="getCompData(item)" v-for="item in list" :key="item.SaCompareId">
                        <div class="title">{{item.Title}}</div>
                        <div class="img" :style="'backgroundImage:url('+item.ResultImg+')'"></div>
                    </div>
                </draggable>
                <tableNoData text="暂无数据" size="mini" v-if="list.length===0&&finished"/>
            </div>
        </div>
    </div>
</template>

<script>
import {semanticInterface} from '@/api/modules/semanticsApi.js';
export default {
    data() {
        return {
            
            keyword:'',
            list:[],
            page:1,
            pageSize:20,
            finished:false,
            loading:false
        }
    },
    created(){
        this.getSemanticList()
    },
    methods: {
        // 生产随机id
        getCompId(type){
            return type+new Date().getTime()
        },

        getCompData(item){
            const obj={
                compId:2,
                compType:'img',
                content:item.ResultImg
            }
            return JSON.stringify(obj)
        },

        handleIsShowMeChange(){
            this.list=[]
            this.page=1
            this.finished=false
            this.getSemanticList()
        },

        handleSearch(){
            this.list=[]
            this.page=1
            this.finished=false
            this.getSemanticList()
        },

        /* 搜索图表分页 */
        async getSemanticList(word) {
            let params = {
                Keyword: this.keyword || "",
                CurrentIndex: this.page,
                PageSize: this.pageSize,
            };
            this.loading=true
            let res = await semanticInterface.compareSearch(params);
            this.loading=false
            if (res.Ret !== 200) return;
            const arr = res.Data.List || [];
            this.list =
                this.page === 1
                ? arr
                : [...this.list, ...arr];
            this.finished =  res.Data.Paging.IsEnd;
        },

        handleLoadMore(){
            if(this.finished||this.loading) return
            this.page++
            this.getSemanticList()
        }
    },
}
</script>

<style lang="scss" scoped>
div{
    box-sizing: border-box;
}
.statistic-analysis-wrap{
    .top-box{
        display: flex;
        justify-content: space-between;
        align-items: center;
        .right{
            .search-box{
                width: 330px;
            }
        }
    }
    .main-box{
        margin-top: 30px;
        height: calc(100vh - 180px);
        border-radius: 4px;
        border: 1px solid var(--gary-gy-5-line, #C8CDD9);
        background: #FFF;
        padding: 20px;
        display: flex;
        flex-direction: column;
        .list-wrap{
            flex: 1;
            overflow-y: auto;

        }
    }
}
.chart-list-box{
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    .chart-item{
                cursor: move;
                padding: 0 10px;
                width: 250px;
                border-radius: 4px;
                border: 1px solid var(--gary-gy-5-line, #C8CDD9);
                background: var(--gary-gy-white, #FFF);
                .title{
                    padding: 10px 0;
                    text-align: center;
                    border-bottom: 1px solid #C8CDD9;
                    overflow: hidden;
                    white-space: nowrap;
                    text-overflow: ellipsis;
                }
                .img{
                    width: 100%;
                    height: 197px;
                    background-size: contain;
                    background-position: center;
                    background-repeat: no-repeat;
                }
            }
}
</style>