<template>
    <div class="conatiner">

        <el-breadcrumb separator-class="el-icon-arrow-right" class="Breadcrumb">
            <el-breadcrumb-item :replace='true' :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>搜索结果</el-breadcrumb-item>
        </el-breadcrumb>

        <div class="content">
            <div class="content-left">
                <div class="goodsList" v-if="!isNothing">
                    <goods-large :info='item' v-for="item in goodsList" style="margin:0 0 20px;"></goods-large>
                </div>
                <div v-else class="nothing">
                    <img src="../assetsPre/nothingImg.png" alt="">
                    <p>没有匹配到结果哦~<br/>看看热门推荐吧</p>
                </div>

            </div>

            <div class="content-right" v-if="hotList.length>0">
                <div class="right-title">
                    热门推荐
                </div>
                <goods-little v-for="item in hotList" :info='item' style="border-top:1px solid #EAEAEA;padding:15px 0 29px"></goods-little>
            </div>
        </div>
    </div>
</template>

<script>
import goodsLittle from '../components/GoodsLittle'
import goodsLarge from '../components/GoodsLarge'
import { mapState } from "vuex";
export default {
    name: 'home',
    data() {
        return {
            address: 0,
            level: 0,
            time: 0,
            nowIndex: 0,
            bannerList: [],
            hotList: [],
            currentPage: 0,
            flag: true,
            goodsList: [],
            cityList: [],
            district: '',
            credit: '',
            advancedQuery: '',
            timeList: [{
                id: 1,
                name: '0-15分钟',
                key: 'AND_,response_time_,>=_,0_;AND_,response_time_,<_,15'
            }, {
                id: 2,
                name: '15-30分钟',
                key: 'AND_,response_time_,>=_,15_;AND_,response_time_,<_,30'
            }, {
                id: 3,
                name: '30-45分钟',
                key: 'AND_,response_time_,>=_,30_;AND_,response_time_,<_,45'
            }, {
                id: 4,
                name: '45-60分钟',
                key: 'AND_,response_time_,>=_,45_;AND_,response_time_,<_,60'
            }, {
                id: 5,
                name: '60分钟以上',
                key: 'AND_,response_time_,>=_,60'
            }],
            orderType: ['', 'asc', 'desc'],
            orderByStr: '',
            creditOrder: '',
            responseOrder: '',
            reworkOrder: '',
            searchKey: '',
            isNothing:false
        }
    },
    computed: {
        ...mapState(["locationInfo", "serviceType"]),
        locationCity() {
            var city = ''
            if (this.locationInfo) {
                city = this.locationInfo.addressComponent.city.split('市')[0]
                if (!city) {
                    city = this.locationInfo.addressComponent.province.split('省')[0]
                }
            }
            return city
        },
        addressFiliftLocation() {
            var location = {
                width: 46,
                height: 26,
                top: 7,
                left: 0
            }
            if (document.getElementById("filit_address" + this.address)) {
                var width = document.getElementById("filit_address" + this.address).offsetWidth
                var height = document.getElementById("filit_address" + this.address).offsetHeight
                var top = document.getElementById("filit_address" + this.address).offsetTop
                var left = document.getElementById("filit_address" + this.address).offsetLeft
                location = {
                    width: width,
                    height: height,
                    top: top,
                    left: left
                }
            }
            return location
        },
        levelFiliftLocation() {
            var location = {
                width: 46,
                height: 26,
                top: 7,
                left: 0
            }
            if (document.getElementById("filit_level" + this.level)) {
                var width = document.getElementById("filit_level" + this.level).offsetWidth
                var height = document.getElementById("filit_level" + this.level).offsetHeight
                var top = document.getElementById("filit_level" + this.level).offsetTop
                var left = document.getElementById("filit_level" + this.level).offsetLeft
                location = {
                    width: width,
                    height: height,
                    top: top,
                    left: left
                }
            }
            return location
        },
        timeFiliftLocation() {
            var location = {
                width: 46,
                height: 26,
                top: 7,
                left: 0
            }
            if (document.getElementById("filit_time" + this.time)) {
                var width = document.getElementById("filit_time" + this.time).offsetWidth
                var height = document.getElementById("filit_time" + this.time).offsetHeight
                var top = document.getElementById("filit_time" + this.time).offsetTop
                var left = document.getElementById("filit_time" + this.time).offsetLeft
                location = {
                    width: width,
                    height: height,
                    top: top,
                    left: left
                }
            }
            return location
        }
    },
    mounted() {


        setTimeout(() => {
            this.freash()
        }, 500)
    },
    watch: {
        $route() {
            this.freash()
        }
    },
    methods: {
        freash() {
            if (this.$route.query.searchKey) {
                this.searchKey = this.$route.query.searchKey
            }


            var list = [{
                name: '首页',
                href: '/'
            }]
            list.push({
                name: '搜索结果',
                href: this.$route.name
            })
            this.$http.get({
                url: '/storeInfo/page',
                data: {
                    currentPage: 1,
                    pageNumber: 20,
                    hotFlag: 1,
                    useFlag: 'Y'
                }
            }).then(res => {
                if (res.success) {
                    this.hotList = res.data.pp
                }
            }).catch(e => {
                console.log(e)
            })
            this.flag = true
            this.currentPage = 0
            this.isNothing=false
            this.getInfo()
        },
        getInfo() {
            if (!this.flag) {
                return
            }
            else {
                this.flag = false
            }
            if (this.currentPage == 0) {
                this.goodsList = []
            }
            var data = {
                currentPage: this.currentPage,
                pageNumber: 20,
                searchKey: this.searchKey,
                useFlag: 'Y',
                advancedQuery: ''
            }

            console.log(data)




            this.currentPage++
            this.$http.get({
                url: '/storeInfo/page',
                data: data
            }).then(res => {
                if (res.success) {
                    this.goodsList = this.goodsList.concat(res.data.pp)
                    if (res.data.page.currentPage < res.data.page.totalPage) {
                        this.flag = true
                    }
                    if(this.goodsList.length==0){
                        this.isNothing=true
                    }
                    else{
                        this.isNothing=false
                    }
                }
            }).catch(e => {
                console.log(e)
            })
        },
        scrollMenu() {
            if (document.getElementById('container').scrollTop + document.body.clientHeight + 100 >= document.getElementById('container').scrollHeight) {
                this.getInfo()
                console.log('到底了')
            }
        }
    },
    components: {
        goodsLittle, goodsLarge
    }
}
</script>

<style lang="less" scoped>
.swiper {
    width: 1196px;
    height: 420px;
    margin: auto;
}
.Breadcrumb {
    width: 1196px;
    margin: 13px auto 10px;
}

.content {
    width: 1196px;
    overflow: hidden;
    margin: auto;
    min-height: 800px;
    padding-bottom: 20px;

    .content-left {
        width: 925px;
        float: left;

        .goodsList {
            // padding-top: 5px;
            padding-bottom: 20px;
        }

        .nothing {
            margin-top: 130px;
            img {
                width: 167px;
                height: 167px;
                display: block;
                margin: auto;
            }

            p {
                font-size: 14px;
                text-align: center;
                color: rgba(51, 51, 51, 1);
                line-height: 19px;
                margin-top: 24px;
            }
        }
    }

    .content-right {
        width: 211px;
        float: right;
        background-color: #fff;
        border-radius: 4px;
        border: 1px solid rgba(234, 234, 234, 1);
        padding-left: 29px;
        .right-title {
            font-size: 16px;
            font-family: MicrosoftYaHei;
            color: rgba(51, 51, 51, 1);
            line-height: 42px;
        }
    }
}
</style>
