<template>
    <div class="news">
        <div class="container">
            <el-row :gutter="20">
                <el-col :span="15">
                    <div style="position:relative">
                        <el-carousel class="banners" height="400px" @change="onCarouselChange">
                            <el-carousel-item v-for="item in banners" :key="item.title">
                                <el-image
                                    class="banner-item"
                                    :src="item.cover"
                                    fit="cover"
                                    @click="$router.push({ name: 'article', query: { id: item.id } })"
                                ></el-image>
                            </el-carousel-item>
                        </el-carousel>
                        <div class="pagination">{{ banners[bannerIndex] ? banners[bannerIndex].title : '' }}</div>
                    </div>
                    <div class="content-left">
                        <div class="dynamic">
                            <span class="title">热点推荐</span>
                            <span class="more" @click="goTab1">更多<img src="../assets/icon_arrow_right.png"/></span>
                        </div>
                        <div class="dynamic_con">
                            <div
                                class="dynamic_list"
                                v-for="n in recommend"
                                :key="n.id"
                                @click="$router.push({ name: 'article', query: { id: n.id } })"
                            >
                                <div class="list_info">
                                    <div class="list_tit">{{ n.title }}</div>
                                    <p>{{ n.content | lable }}</p>
                                </div>
                                <div class="time">{{ n.createdAt }}</div>
                            </div>
                        </div>
                    </div>
                </el-col>
                <el-col :span="9">
                    <div class="content-right">
                        <div class="dynamic" style="border:none">
                            <span class="title">行业动态</span>
                            <span class="more" @click="goTab2">更多<img src="../assets/icon_arrow_right.png"/></span>
                        </div>
                        <div class="hot">
                            <div
                                class="hot_card"
                                v-for="n in news"
                                :key="n.id"
                                @click="$router.push({ name: 'article', query: { id: n.id } })"
                            >
                                <img :src="n.cover" />
                                <div class="hot_con">
                                    {{ n.title }}
                                </div>
                            </div>
                        </div>
                        <!-- <div class="dynamic">
                            <span class="title">通知通告</span>
                            <span class="more" @click="goTab3">更多<img src="../assets/icon_arrow_right.png"/></span>
                        </div>
                        <div
                            class="notice"
                            v-for="n in inform"
                            :key="n.id"
                            @click="$router.push({ name: 'article', query: { id: n.id } })"
                        >
                            <i></i>
                            <div>
                                {{ n.title }}
                            </div>
                        </div> -->
                    </div>
                </el-col>
            </el-row>
        </div>
    </div>
</template>
<script>
export default {
    name: 'news',
    data() {
        return {
            banners: [],
            bannerIndex: 0,
            /* tab: 1002, */
            total: 0,
            page: 1,
            size: 10,
            news: [],
            recommend: [],
            inform: []
        };
    },
    created() {
        this.$http
            .get('/article/all', { query: { mainType: '首页轮播', status: 'PASS' }, sort: 'createdAt,desc' })
            .then(res => {
                this.banners = res.content;
            });

        this.$http
            .get('/article/all', { query: { mainType: '行业动态', status: 'PASS' }, sort: 'createdAt,desc' })
            .then(res => {
                this.news = res.content;
            });

        this.$http
            .get('/article/all', { query: { mainType: '通知通告', status: 'PASS' }, sort: 'createdAt,desc' })
            .then(res => {
                this.inform = res.content;
            });

        this.getData();
    },
    methods: {
        onCarouselChange(e) {
            this.bannerIndex = e;
        },
        getData() {
            this.$http
                .get('/article/all', {
                    sort: 'createdAt,desc',
                    query: { mainType: '热点推荐', status: 'PASS' },
                    size: this.size,
                    page: this.page - 1
                })
                .then(res => {
                    this.recommend = res.content.map(i => {
                        var tmp = document.createElement('DIV');
                        tmp.innerHTML = i.content;
                        i.bref = (tmp.textContent || tmp.innerText || '').trim();
                        return i;
                    });
                    this.total = res.totalElements;
                });
        },
        goTab1() {
            this.$router.push({
                name: 'newsList',
                query: {
                    myTab: 0
                }
            });
        },
        goTab2() {
            this.$router.push({
                name: 'newsList',
                query: {
                    myTab: 1
                }
            });
        },
        goTab3() {
            this.$router.push({
                name: 'newsList',
                query: {
                    myTab: 2
                }
            });
        }
    },
    /* watch: {
        tab() {
            this.page = 1;
            this.getData();
        }
    }, */
    filters: {
        lable: function(str) {
            var tmp = document.createElement('DIV');
            tmp.innerHTML = str;
            str = tmp.innerText.trim();
            return str;
        }
    }
};
</script>
<style lang="less" scoped>
.container {
    width: 1200px;
    margin: 0 auto;
    margin-top: 20px;
}
.banners {
    height: 400px;
    .banner-item {
        width: 100%;
        height: 400px;
    }
}
.pagination {
    position: absolute;
    left: 0;
    bottom: 0;
    right: 0;
    height: 36px;
    line-height: 36px;
    color: white;
    font-size: 14px;
    background: rgba(0, 0, 0, 0.24);
    padding: 0 12px;
    z-index: 2;
    .ellipsis();
}
.content-left {
    background: white;
    // height: 549px;
    margin-top: 20px;
    padding: 0 20px 20px;
    box-sizing: border-box;
    .dynamic {
        height: 56px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        border-bottom: 1px solid #f2f3f5;
        .title {
            width: 80px;
            height: 28px;
            font-size: 20px;
            color: #000000;
            line-height: 28px;
        }
        .more {
            cursor: pointer;
            display: flex;
            height: 18px;
            font-size: 13px;
            color: #939599;
            line-height: 18px;
            img {
                width: 16px;
                height: 16px;
            }
        }
    }
    .dynamic_con {
        .dynamic_list {
            cursor: pointer;
            margin-top: 16px;
            display: flex;
            justify-content: space-between;
            // align-items: center;
            &:hover .list_info p {
                color: #bf1616;
            }
        }

        .list_info {
            .list_tit {
                width: 610px;
                height: 24px;
                font-size: 14px;
                color: #000000;
                line-height: 24px;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
            }
            p {
                width: 610px;
                height: 44px;
                font-size: 13px;
                color: #939599;
                line-height: 22px;
                margin: 5px 0 0;
                overflow: hidden;
                text-overflow: ellipsis;
                display: -webkit-box;
                -webkit-line-clamp: 2;
                -webkit-box-orient: vertical;
            }
        }
        .time {
            width: 70px;
            height: 24px;
            font-size: 13px;
            color: #939599;
            line-height: 24px;
            margin-top: 4px;
        }
    }
}
.content-right {
    background: white;
    padding: 0 20px 30px 20px;
    .dynamic {
        height: 56px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        border-bottom: 1px solid #f2f3f5;
        .title {
            width: 80px;
            height: 28px;
            font-size: 20px;
            color: #000000;
            line-height: 28px;
        }
        .more {
            cursor: pointer;
            display: flex;
            height: 18px;
            font-size: 13px;
            color: #939599;
            line-height: 18px;
            img {
                width: 16px;
                height: 16px;
            }
        }
    }
    .hot {
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
    }
    .hot_card {
        margin-bottom: 20px;
        cursor: pointer;
        img {
            width: 184px;
            height: 110px;
        }
        .hot_con {
            width: 184px;
            height: 40px;
            font-size: 14px;
            color: #000000;
            line-height: 20px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
        }
        &:hover .hot_con {
            color: #bf1616;
        }
    }
    .notice {
        display: flex;
        justify-content: space-between;
        margin-top: 16px;
        cursor: pointer;
        i {
            display: block;
            width: 4px;
            height: 4px;
            background-color: #e3e4e6;
            margin: 10px 0;
            border-radius: 50%;
        }
        div {
            width: 390px;
            // height: 72px;
            font-size: 14px;
            color: #000000;
            line-height: 24px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
        }
        &:hover div {
            color: #bf1616;
        }
    }
}
.pagination-wrapper {
    padding: 30px 0;
    text-align: center;
}
</style>
<style lang="less">
.news {
    .el-carousel__indicators--horizontal {
        bottom: 36px;
    }
}
</style>
