<template>
    <div class="conatiner">
        <el-carousel class="swiper" :class="[bannerList.length==1?'noButton':'']" height="420px" :interval="4000">
            <template v-for="item in bannerList">
                <el-carousel-item @click="goBanner(item.url)" :style="{backgroundImage:'url('+item.imageUrl+')'}">
                    <a v-if="item.url" :href="item.url"></a>
                </el-carousel-item>
            </template>

        </el-carousel>
        <el-breadcrumb v-if="serviceType.length>0" separator-class="el-icon-arrow-right" class="Breadcrumb">
            <el-breadcrumb-item :replace='true' :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>{{serviceType[nowIndex].shortName}}</el-breadcrumb-item>
        </el-breadcrumb>

        <div class="content">
            <div class="content-left">
                <div class="flift-content">
                    <div class="flift-title">筛选条件</div>

                    <div class="flift-item">
                        <div class="flift-name">
                            区域：
                        </div>
                        <div class="flift-list">
                            <div id='filit_address0' :class="{isActive:(address==0)}" @click="address=0">全部</div>
                            <div id='filit_address1' :class="{isActive:(address==1)}" v-if="this.locationCity" @click="address=1">定位所在地:{{this.locationCity}}</div>
                            <div v-for="(item,index) in cityList" :class="{isActive:(address==(index+2))}" :id='"filit_address"+(index+2)' @click="address=(index+2)">{{item.districtName}}</div>
                            <div class="box" :style="{width:addressFiliftLocation.width+'px',height:addressFiliftLocation.height+'px',top:addressFiliftLocation.top+'px',left:addressFiliftLocation.left+'px'}"></div>
                        </div>
                    </div>

                    <div class="flift-item">
                        <div class="flift-name">
                            信誉等级:
                        </div>
                        <div class="flift-list">
                            <div id='filit_level0' :class="{isActive:(level==0)}" @click="level=0">全部</div>
                            <div :id='"filit_level"+(index+1)' v-for="(item,index) in creditList" :class="{isActive:(level==(index+1))}" @click="level=(index+1)">{{item.credit}}</div>
                            <!-- <div id='filit_level2' :class="{isActive:(level==2)}" @click="level=2">B</div>
                            <div id='filit_level3' :class="{isActive:(level==3)}" @click="level=3">C</div>
                            <div id='filit_level4' :class="{isActive:(level==4)}" @click="level=4">D</div>
                            <div id='filit_level5' :class="{isActive:(level==5)}" @click="level=5">E</div> -->
                            <div class="box" :style="{width:levelFiliftLocation.width+'px',height:levelFiliftLocation.height+'px',top:levelFiliftLocation.top+'px',left:levelFiliftLocation.left+'px'}"></div>
                        </div>
                    </div>

                    <div class="flift-item">
                        <div class="flift-name">
                            响应时间:
                        </div>
                        <div class="flift-list">
                            <div id='filit_time0' :class="{isActive:(time==0)}" @click="time=0">全部</div>
                            <div :id='"filit_time"+item.id' :class="{isActive:(time==item.id)}" @click="time=item.id" v-for="item in timeList">{{item.name}}</div>
                            <div class="box" :style="{width:timeFiliftLocation.width+'px',height:timeFiliftLocation.height+'px',top:timeFiliftLocation.top+'px',left:timeFiliftLocation.left+'px'}"></div>
                        </div>
                    </div>
                    <div class="flift-item">
                        <div class="flift-name">
                            排序:
                        </div>
                        <div class="flift-list">
                            <div style="padding-right:15px;" @click="creditOrder=(creditOrder==1?2:1)">
                                信誉等级
                                <i class="el-icon-caret-top top-icon" :class="{isActive:creditOrder==1}"></i>
                                <i class="el-icon-caret-bottom bottom-icon" :class="{isActive:creditOrder==2}"></i>
                            </div>
                            <div style="padding-right:15px;" @click="responseOrder=(responseOrder==1?2:1)">
                                响应时间
                                <i class="el-icon-caret-top top-icon" :class="{isActive:responseOrder==1}"></i>
                                <i class="el-icon-caret-bottom bottom-icon" :class="{isActive:responseOrder==2}"></i>
                            </div>
                            <div style="padding-right:15px;" @click="reworkOrder=(reworkOrder==1?2:1)">
                                返片率
                                <i class="el-icon-caret-top top-icon" :class="{isActive:reworkOrder==1}"></i>
                                <i class="el-icon-caret-bottom bottom-icon" :class="{isActive:reworkOrder==2}"></i>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="goodsList">
                    <goods-large :info='item' v-for="item in goodsList"></goods-large>
                </div>

            </div>

            <div class="content-right" v-if="hotList.length>0">
                <div class="right-title">
                    热门{{serviceType[this.nowIndex].serviceType}}
                </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: '',
            queryId: 0,
            creditList: []
        }
    },
    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() {

        this.$http.get({
            url: '/creditRating/all'
        }).then(res => {
            if (res.success) {
                this.creditList = res.data;
            }
        });

        this.$http.get({
            url: '/districtInfo/all',
            data: {
            }
        }).then(res => {
            if (res.success) {
                this.cityList = res.data
            }
        }).catch(e => {
            console.log(e)
        })

        setTimeout(() => {
            this.freash()
        }, 500)
    },
    watch: {
        "$route.query"() {
            console.log(this.$route.query.serviceId)
            if (this.$route.query.serviceId) {
                if (this.nowIndex != parseInt(this.$route.query.serviceId) - 1) {
                    this.freash()
                }

            }


        },
        address() {
            if (this.address == 0) {
                this.district = ''
            }
            else if (this.address == 1) {
                this.district = this.locationCity
            }
            else {
                this.district = this.cityList[this.address - 2].districtName
            }
            this.currentPage = 0
            this.flag = true
            this.getInfo()
        },
        level() {
            if (this.level == 0) {
                this.credit = ''
            }
            else {
                this.credit = this.creditList[this.level - 1].credit
            }
            // else if (this.level == 2) {
            //     this.credit = 'B'
            // }
            // else if (this.level == 3) {
            //     this.credit = 'C'
            // }
            // else if (this.level == 4) {
            //     this.credit = 'D'
            // }
            // else if (this.level == 5) {
            //     this.credit = 'E'
            // }
            this.currentPage = 0
            this.flag = true
            this.getInfo()
        },
        time() {
            if (this.time == 0) {
                this.advancedQuery = ''
            }
            else {
                this.timeList.forEach(item => {
                    if (item.id == this.time) {
                        this.advancedQuery = item.key
                    }
                })
            }

            this.currentPage = 0
            this.flag = true
            this.getInfo()
        },
        creditOrder() {
            this.currentPage = 0
            this.flag = true
            this.getInfo()
        },
        responseOrder() {
            this.currentPage = 0
            this.flag = true
            this.getInfo()
        },
        reworkOrder() {
            this.currentPage = 0
            this.flag = true
            this.getInfo()
        },
    },
    methods: {
        freash() {
            if (this.$route.query.serviceId) {
                this.nowIndex = parseInt(this.$route.query.serviceId) - 1
            }

            document.title = this.serviceType[this.nowIndex].shortName

            this.address = 0
            this.level = 0
            this.time = 0

            this.creditOrder = ''
            this.responseOrder = ''
            this.reworkOrder = ''

            this.$http.get({
                url: '/bannerInfo/all',
                data: {
                    location: this.nowIndex + 8
                }
            }).then(res => {
                if (res.success) {
                    this.bannerList = res.data
                }
            }).catch(e => {
                console.log(e)
            })
            var list = [{
                name: '首页',
                href: '/'
            }]
            list.push({
                name: this.serviceType[this.nowIndex].shortName,
                href: this.$route.name
            })
            // this.$store.commit('updateHrefHistory', list)


            this.$http.get({
                url: '/storeInfo/page',
                data: {
                    currentPage: 1,
                    pageNumber: 20,
                    serviceType: this.serviceType[this.nowIndex].id,
                    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.getInfo()
        },
        getInfo() {
            if (!this.flag) {
                return
            }
            else {
                this.flag = false
            }
            if (this.currentPage == 0) {
                this.goodsList = []
            }
            var data = {
                currentPage: this.currentPage,
                pageNumber: 20,
                serviceType: this.serviceType[this.nowIndex].id,
                useFlag: 'Y',
                advancedQuery: ''
            }
            if (this.$route.query.littleId) {
                data.subclass = this.$route.query.littleId
            }




            if (this.district) {
                data.advancedQuery += 'AND_,citye_,like_,' + JSON.parse(JSON.stringify(this.district))
            }

            if (this.credit) {
                data.credit = this.credit
            }

            if (this.advancedQuery) {
                if (data.advancedQuery) {
                    data.advancedQuery += '_;'
                }
                data.advancedQuery += JSON.parse(JSON.stringify(this.advancedQuery))
            }

            console.log(this.advancedQuery)

            data.orderByStr = ''


            if (this.creditOrder) {
                data.orderByStr += 'credit_,' + this.orderType[this.creditOrder]
            }

            if (this.responseOrder) {
                if (data.orderByStr) {
                    data.orderByStr += '_;'
                }
                data.orderByStr += 'response_time_,' + this.orderType[this.responseOrder]
            }

            if (this.reworkOrder) {
                if (data.orderByStr) {
                    data.orderByStr += '_;'
                }
                data.orderByStr += 'rework_rate_,' + this.orderType[this.reworkOrder]
            }



            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
                    }
                }
            }).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;

    .content-left {
        width: 925px;
        float: left;
        .flift-content {
            background: rgba(255, 255, 255, 1);
            border-radius: 4px;
            border: 1px solid rgba(234, 234, 234, 1);
            .flift-title {
                font-size: 14px;
                font-family: MicrosoftYaHei;
                color: rgba(51, 51, 51, 1);
                line-height: 19px;
                padding: 9px 17px 4px;
                border-bottom: 1px solid rgba(234, 234, 234, 1);
            }

            .flift-item {
                overflow: hidden;
                .flift-name {
                    width: 70px;
                    padding-right: 13px;
                    font-size: 12px;
                    font-family: MicrosoftYaHei;
                    color: rgba(51, 51, 51, 1);
                    line-height: 40px;
                    text-align: right;
                    float: left;
                }
                .flift-list {
                    width: 826px;
                    float: left;
                    font-size: 0;
                    padding-top: 7px;
                    position: relative;
                    div {
                        padding: 5px 11px;
                        font-size: 12px;
                        font-family: MicrosoftYaHei;
                        color: #333;
                        line-height: 16px;
                        display: inline-block;
                        margin-bottom: 7px;
                        margin-right: 10px;
                        cursor: pointer;
                        z-index: 2;
                        position: relative;

                        &.isActive {
                            color: #fff;
                        }
                    }

                    .box {
                        width: 45px;
                        height: 22px;
                        background: rgba(11, 158, 192, 1);
                        border-radius: 2px;
                        position: absolute;
                        left: 0;
                        top: 10px;
                        padding: 0;
                        transition: all ease-in-out 0.3s;
                        z-index: 1;
                    }

                    .top-icon {
                        position: absolute;
                        top: 5px;
                        right: 0;
                        color: #d6d6d6;

                        &.isActive {
                            color: #0b9ec0;
                        }
                    }

                    .bottom-icon {
                        position: absolute;
                        bottom: 2px;
                        right: 0;
                        color: #d6d6d6;

                        &.isActive {
                            color: #0b9ec0;
                        }
                    }
                }

                &:not(:last-child) {
                    .flift-list {
                        border-bottom: 1px solid #eaeaea;
                    }
                }
            }
        }

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

    .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>
