<template>
    <div class="about">
        <banner></banner>

        <bread-page>
            <div class="intro" id="intro">
                <divider-title>
                    <template> 平台 </template>
                    <template #prim>简介</template>
                    <template #sub>Platform Overview</template>
                </divider-title>

                <div class="text" v-html="connect"></div>
            </div>
        </bread-page>

        <div class="history" ref="history" id="history">
            <divider-title>
                <template>发展</template>
                <template #prim>历程</template>
                <template #sub>Development process</template>
            </divider-title>
            <div class="content">
                <swiper
                    class="imgLine"
                    ref="imgSwiper"
                    :options="imgOptions"
                    @slideChange="slideChange"
                    @touchStart="touchStart"
                    @touchEnd="touchEnd"
                >
                    <swiper-slide v-for="(item, index) in historys" :key="index">
                        <img class="img-slide" :src="item.img" object-fit="scale-down" />
                    </swiper-slide>
                    <div class="img-pagination" slot="pagination"></div>
                    <div class="img-button-prev" slot="button-prev"></div>
                    <div class="img-button-next" slot="button-next"></div>
                </swiper>
                <div class="title" ref="historyTitle">
                    <div class="time">
                        <span>{{ formatTime(activeHistory.time, 'YYYY') }}</span>
                        <span>年</span>
                        <span>{{ formatTime(activeHistory.time, 'MM月') }}</span>
                    </div>
                    <div v-html="activeHistory.title"></div>
                </div>
                <swiper class="timeLine" ref="timeSwiper" :options="boxOptions">
                    <swiper-slide v-for="(item, index) in historys" :key="index">
                        <div class="time-item">
                            <div class="text1">
                                <span>{{ formatTime(item.time, 'YYYY') }}</span>
                                <span>年</span>
                                <span>{{ formatTime(item.time, 'MM月') }}</span>
                            </div>
                            <div class="text2" v-html="item.title"></div>
                        </div>
                    </swiper-slide>
                    <div class="time-pagination" slot="pagination"></div>
                </swiper>
            </div>
        </div>

        <div class="center-content honor-content" id="honor">
            <divider-title>
                <template>资质</template>
                <template #prim> 荣誉</template>
                <template #sub>Qualification honor</template>
            </divider-title>

            <swiper ref="honor" class="honor" :options="honorOptions">
                <swiper-slide v-for="(item, index) in honors" :key="index">
                    <img :src="item.img" alt="" />
                    <div class="name">{{ item.title }}</div>
                </swiper-slide>
                <div class="honor-pagination" slot="pagination"></div>
            </swiper>
        </div>

        <div class="connect" id="connect">
            <div class="center-content">
                <divider-title>
                    <template>联系</template>
                    <template #prim>我们</template>
                    <template #sub>contact us</template>
                </divider-title>

                <div class="connect-content">
                    <map-container></map-container>

                    <div class="text">
                        <div>
                            <i class="iconfont iconfont-footer_icon_dianhua"></i>
                            <span>{{ phone }}</span>
                        </div>
                        <div>
                            <i class="iconfont iconfont-footer_icon_youjian"></i>
                            <span>{{ email }}</span>
                        </div>
                        <div>
                            <i class="iconfont iconfont-footer_icon_dizhi"></i>
                            <span>{{ address }}</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import Banner from '../components/Banner.vue';
import DividerTitle from '../components/DividerTitle.vue';
import BreadPage from '../components/page/BreadPage.vue';
import { Swiper, SwiperSlide, directive } from 'vue-awesome-swiper';
import MapContainer from '../components/MapContainer.vue';
export default {
    components: { Banner, BreadPage, DividerTitle, Swiper, SwiperSlide, MapContainer },
    directives: {
        swiper: directive
    },
    data() {
        return {
            connect: '',
            historys: [],
            boxOptions: {
                direction: 'vertical',
                slidesPerView: 'auto',
                centeredSlides: true,
                pagination: {
                    type: 'progressbar',
                    el: '.time-pagination'
                },
                navigation: {
                    nextEl: '.img-button-next',
                    prevEl: '.img-button-prev'
                },
                mousewheel: true,
                releaseOnEdges: true,
                autoplay: {
                    autoplay: false,
                    delay: 5000,
                    stopOnLastSlide: false,
                    disableOnInteraction: false,
                    pauseOnMouseEnter: true
                }
            },
            imgOptions: {
                slidesPerView: 'auto',
                spaceBetween: 40,
                updateOnImagesReady: true,
                setWrapperSize: true,
                autoHeight: true,
                init: false,
                pagination: {
                    el: '.img-pagination',
                    type: 'fraction'
                },
                normalizeSlideIndex: true
            },
            honorOptions: {
                slidesPerView: 3,
                spaceBetween: 40,
                pagination: {
                    el: '.honor-pagination',
                    type: 'progressbar'
                }
                // autoplay: {
                //     delay: 3000,
                //     stopOnLastSlide: false,
                //     disableOnInteraction: false
                // }
            },
            active: 0,
            honors: [],
            address: '',
            email: '',
            phone: '',
            timer: null
        };
    },
    computed: {
        imgSwiper() {
            return this.$refs.imgSwiper.$swiper;
        },
        timeSwiper() {
            return this.$refs.timeSwiper.$swiper;
        },
        activeHistory() {
            if (this.historys.length > this.active) {
                return [...this.historys][this.active];
            } else {
                return {
                    time: ''
                };
            }
        }
    },
    watch: {
        $route() {
            this.scrollEvent();
        }
    },
    mounted() {
        this.$http
            .get('/sysConfig/get/CONVERGENCE')
            .then(res => {
                this.connect = res.value;
                return this.$http.get('/sysConfig/get/PROCESS');
            })
            .then(res => {
                this.historys = JSON.parse(res.value);
                this.$nextTick(() => {
                    this.imgSwiper.init();
                    this.timeSwiper.update();
                    this.imgSwiper.controller.control = this.timeSwiper;
                    this.timeSwiper.controller.control = this.imgSwiper;
                    if (!this.timeSwiper.autoplay.running) {
                        this.timeSwiper.autoplay.start();
                    }
                    // setTimeout(() => {
                    //     this.imgSwiper.updateSize();
                    // }, 500);
                });
                return this.$http.get('/sysConfig/get/HONOR');
            })
            .then(res => {
                this.honors = JSON.parse(res.value);
                this.$nextTick(() => {
                    this.$refs.honor.$swiper.update();
                    if (!this.$refs.honor.$swiper.autoplay.running) {
                        this.$refs.honor.$swiper.autoplay.start();
                    }
                });

                this.$nextTick(() => {
                    this.scrollEvent();
                });
            });

        this.$http.get('/sysConfig/get/ADDRESS').then(res => {
            this.address = res.value;
        });
        this.$http.get('/sysConfig/get/EMAil').then(res => {
            this.email = res.value;
        });
        this.$http.get('/sysConfig/get/PHONE').then(res => {
            this.phone = res.value;
        });
    },
    methods: {
        scrollEvent() {
            if (this.$route.hash) {
                this.$nextTick(() => {
                    let top = document.getElementById(this.$route.hash.replace(/#/, '')).offsetTop;
                    window.scrollTo({
                        top: top - 100,
                        behavior: 'smooth'
                    });
                });
            }
        },
        touchStart() {
            if (this.timeSwiper.autoplay.running) {
                this.timeSwiper.autoplay.stop();
            }
        },
        touchEnd() {
            if (!this.timeSwiper.autoplay.running) {
                this.timeSwiper.autoplay.start();
            }
        },
        slideChange() {
            this.$nextTick(() => {
                this.active = this.imgSwiper.activeIndex;
            });

            let childs = this.$refs.historyTitle.children;

            childs[0].className = childs[0].className + ' animate__animated animate__lightSpeedInRight';
            childs[1].className = childs[1].className + ' animate__animated animate__flipInX animate__delay-1s';
            if (this.timer) {
                clearTimeout(this.timer);
            }
            this.timer = setTimeout(() => {
                childs[0].className = childs[0].className.replace(/ animate__animated animate__lightSpeedInRight/g, '');
                childs[1].className = childs[1].className.replace(
                    / animate__animated animate__flipInX animate__delay-1s/g,
                    ''
                );
            }, 2000);
        }
    }
};
</script>

<style lang="less" scoped>
.intro {
    box-shadow: 0px 3px 20px 0px rgba(0, 0, 0, 0.07);
    margin: 0 50px;
    padding: 0 120px 50px;
    .page-title {
        padding: 50px;
    }

    .text {
        font-size: 14px;
        color: #292c33;
        line-height: 26px;
        text-indent: 30px;
    }
}

.history {
    position: relative;
    padding-top: 1px;
    margin-top: 70px;
    .content {
        position: relative;
        background: #f8f8f8;
        box-shadow: 0px 3px 12px 0px rgba(0, 0, 0, 0.07);
        padding: 80px 0 300px;
        height: 700px;
        box-sizing: border-box;
        @media screen and (max-width: 1300px) {
            height: 500px;
        }
    }
    .center-content {
        padding: 100px 50px 60px;
        position: relative;
        z-index: 2;
    }
    .page-title {
        padding: 50px 100px 80px;
    }

    .left {
        width: 600px;
        right: 50%;
        position: relative;
        padding-top: 172px;
    }
    .title {
        font-size: 20px;
        font-weight: bold;
        color: #393939;
        line-height: 30px;
        position: absolute;
        top: 80px;
        right: calc(50% + 200px);
        width: 320px;
        padding-left: 30px;
        z-index: 3;
        background-color: rgba(255, 255, 255, 0.4);
        padding: 10px;
        &::before {
            content: '';
            width: 2px;
            position: absolute;
            left: 0px;
            top: 10px;
            bottom: 10px;
            background-color: @prim;
        }

        .time {
            span {
                vertical-align: middle;
                &:first-child {
                    font-size: 24px;
                    font-family: Impact;
                    line-height: 40px;
                }

                &:nth-child(2) {
                    font-size: 22px;
                    font-weight: bold;
                    line-height: 30px;
                    padding: 0 6px 0 2px;
                }
            }
        }
    }

    .timeLine {
        width: 340px;
        height: 50%;
        padding: 20px;
        box-sizing: border-box;
        background-color: fade(@warn, 70%);
        position: absolute;
        right: calc(50% - 100px);
        bottom: 90px;

        /deep/ .swiper-slide {
            height: auto;
            padding: 10px 0 20px;
        }

        .time-item {
            font-size: 14px;
            color: #ffffff;
            line-height: 24px;
            padding-left: 30px;
            position: relative;
            .text1 {
                position: relative;
                span {
                    vertical-align: middle;
                    &:first-child {
                        font-family: Impact;
                        color: #ffffff;
                        line-height: 30px;
                    }

                    &:nth-child(2) {
                        font-size: 18px;
                        font-weight: bold;
                        color: #ffffff;
                        line-height: 30px;
                        margin-right: 6px;
                    }
                }

                &::before {
                    content: '';
                    width: 11px;
                    height: 11px;
                    background: #ffffff;
                    position: absolute;

                    position: absolute;
                    left: -29px;
                    top: 11px;
                    border-radius: 100%;
                }
            }

            &::before {
                content: '';
                width: 15px;
                height: 15px;
                border: 1px solid #ffffff;
                position: absolute;
                left: -2px;
                top: 8px;
                border-radius: 100%;
            }

            &::after {
                content: '';
                width: 0px;
                height: 110%;
                border-left: 1px dashed #fff;
                position: absolute;
                left: 6px;
                top: 28px;
            }
        }

        /deep/ .swiper-slide {
            &:last-child {
                .time-item {
                    &::after {
                        content: none;
                    }
                }
            }
        }

        /deep/ .swiper-pagination-progressbar {
            left: auto;
            right: 20px;
            height: calc(100% - 60px);
            top: 30px;
            width: 2px;
            .swiper-pagination-progressbar-fill {
                background-color: #fff;
            }
        }
    }
}

.imgLine {
    position: absolute;
    z-index: 1;
    left: 50%;
    right: 0;
    top: 80px;
    padding-bottom: 100px;
    width: 50vw;
    @media screen and (max-width: 1300px) {
        width: 650px;
    }
    .img-slide {
        height: 400px;
        width: auto;
        display: block;

        @media screen and (max-width: 1300px) {
            width: auto;
            height: 200px;
        }
    }

    /deep/ .swiper-slide {
        width: auto;
    }
}
.img-pagination {
    position: absolute;
    left: 320px;
    bottom: 0;
    font-size: 20px;
    color: #bcc1cc;
    line-height: 24px;
    .flex();
    /deep/ .swiper-pagination-current {
        color: @prim;
        font-size: 20px;
        font-family: Impact;
        padding: 0 5px;
        min-width: 40px;
        text-align: center;
    }

    /deep/ .swiper-pagination-total {
        font-size: 16px;
        font-family: Impact;
        color: #bcc1cc;
        padding: 0 5px;
        text-align: center;
        min-width: 30px;
        align-self: flex-end;
        line-height: 20px;
    }
}
.honor-content {
    margin-top: 100px;
    .page-title {
        padding: 50px 50px 40px;
    }
}
.honor-pagination {
    position: absolute;
    bottom: 0;
    top: auto;
    width: 120px;
    left: 50%;
    transform: translateX(-50%);
}

.img-button-prev,
.img-button-next {
    position: absolute;
    bottom: 0;
    width: 24px;
    height: 24px;
    z-index: 10;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--swiper-navigation-color, var(--swiper-theme-color));

    &::after {
        font-family: iconfont;
        font-size: 24px;
        text-transform: none !important;
        letter-spacing: 0;
        text-transform: none;
        font-variant: initial;
        line-height: 1;
    }

    &.swiper-button-disabled {
        color: #bcc1cc;
    }
}
.img-button-prev {
    left: 200px;
    right: auto;
    &::after {
        content: '\e62f';
    }
}
.img-button-next {
    left: 500px;
    right: auto;
    &::after {
        content: '\e630';
    }
}

.honor {
    padding-bottom: 40px;
    img {
        width: 100%;
        height: 280px;
        display: block;
    }

    .name {
        font-size: 14px;
        color: #393939;
        line-height: 24px;
        text-align: center;
        padding: 20px;
    }
}

.about {
    background-color: #fff;
    padding-bottom: 0px;
}

.connect {
    height: 700px;
    background-color: #f8f8f8;
    margin-top: 120px;

    .connect-content {
        .flex();

        .text {
            font-size: 14px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #525866;
            line-height: 24px;
            margin-left: 60px;

            div {
                vertical-align: middle;
                &:not(:last-child) {
                    margin-bottom: 30px;
                }
                span {
                    vertical-align: middle;
                }

                i {
                    font-size: 20px;
                    margin-right: 10px;
                    vertical-align: middle;
                }
            }
        }
        position: relative;

        &::after {
            content: '';
            width: 60px;
            height: 60px;
            background-color: fade(@prim, 12);
            position: absolute;
            top: 0;
            right: 50px;
        }

        &::before {
            width: 30px;
            height: 30px;
            background-color: @prim;
            content: '';
            position: absolute;
            right: 120px;
            top: 70px;
        }
    }
}
</style>
