<!--
 * @Description:
 * @Author: 周洋
 * @Date: 2020-07-02 15:54:15
 * @LastEditTime: 2020-10-29 11:16:33
 * @LastEditors: Please set LastEditors
 * @FilePath: \cms-components\see-personnel-special.vue
-->
<template>
    <div class="see-personnel-special" :class="{ 'is-design': isDesign }" v-if="isShow">
        <div class="info-box">
            <div class="avatar">
<!--                <base-image-->
<!--                    class="image"-->
<!--                    :src="curUserInfo.avatar || ''"-->
<!--                ></base-image>-->
                <img :src="curUserInfo.avatar || require('./assets/logo_grey.png')" alt="">
            </div>
            <div class="userinfo">
                <h2>{{ curUserInfo.name || (isDesign ? "姓名" : "") }}</h2>
                <span class="job">{{
                    curUserInfo.job || (isDesign ? "职务" : "")
                }}</span>
                <p class="desc" :title="curUserInfo.desc">
                    {{
                        curUserInfo.desc ||
                        (isDesign ? "人员介绍…不超过100个字符" : "")
                    }}
                </p>
            </div>
        </div>
        <div
            class="carousel"
            :class="{
                'shuffling-layout': playType == 1,
                'tile-layout': playType == 2,
            }"
            @mouseenter="hoverFn"
            @mouseleave="hoverFn"
        >
            <div class="imgs-container">
                <div
                    class="img-item"
                    :class="{ active: activeIndex === index }"
                    v-for="(item, index) in group"
                    @click="changeIndex(index)"
                >
<!--                    <base-image class="image" :src="item.avatar"></base-image>-->
                    <div class="img-item-container">
                        <img :src="item.avatar || require('./assets/logo_grey.png')" alt="">
                    </div>
                    <div class="userinfo">
                        <h3>{{ item.name || (isDesign ? "姓名" : "") }}</h3>
<!--                        <p>{{ item.job || (isDesign ? "职务" : "") }}</p>-->
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import BaseImage from "./components/base-image";
import permissionMixin from "./permission-mixin";
export default {
    name: "see-personnel-special",
    mixins: [permissionMixin],
    props: {
        componentData: {
            required: false,
        },
    },
    components: { BaseImage },
    data() {
        return {
            // 轮播间隔
            interval: 2000,
            // 当前显示的index
            activeIndex: 0,
            // 定时器timer
            timer: null,
            // 是否处于轮播动画执行期间
            isTransitioning: false,
            // 动画时长
            transitionInterval: 500,
            // 是否为瞬间重置定位，在watch中初始化，重定位会取消transition动画
            isResetIndex: false,
        };
    },
    methods: {
        startInterval() {
            if (this.isDesign) return;
            this.timer = setInterval(() => {
                if (this.activeIndex + 1 > this.len - 1) this.activeIndex = 0;
                else this.activeIndex++;
            }, this.interval);
        },
        hoverFn(e) {
            if (this.playType != 1) return;
            if (e.type === "mouseenter") {
                if (this.timer) clearInterval(this.timer);
            } else {
                // this.startInterval();
            }
        },
        changeIndex(index) {
            this.activeIndex = index || 0;
        },
        restart() {
            this.activeIndex = 0;
            if (this.timer) clearInterval(this.timer);
            if (this.playType == 1) this.startInterval();
        },
    },
    created() {},
    mounted() {
        // this.restart();
    },
    beforeDestroy() {
        if (this.timer) clearInterval(this.timer);
    },
    computed: {
        isDesign() {
            return this.componentData.commonVariable.pageType === "design";
        },
        group() {
            return this.componentData.group || [];
        },
        len() {
            return this.group.length;
        },
        translateX() {
            let translateLen =
                this.activeIndex - 4 > 0 ? this.activeIndex - 4 : 0;
            return (translateLen / this.len) * 100;
        },
        curUserInfo() {
            return this.group[this.activeIndex];
        },
        playType() {
            return this.componentData.playType;
        },
    },
    watch: {
        len() {
            this.restart();
        },
        playType(val) {
            this.restart();
        },
        activeIndex(newActiveIndex, oldActiveIndex) {
            // 最后一张取消动画
            if (newActiveIndex === 0 && oldActiveIndex === this.len - 1) {
                this.isResetIndex = true;
                return;
            }
            this.isResetIndex = false;
        },
    },
};
</script>

<style lang='scss' scoped>
.see-personnel-special{
    display: flex;
}
.info-box {
    display: flex;
    width: 60%;
    align-items: center;
    .avatar {
        border-radius: 50%;
        position: relative;
        margin-left: 20px;
        &::before {
          content: "";
          width: 150px;
          height: 100%;
          background: url("./assets/avatar-bg.png") no-repeat center center;
          background-size: 100% 100%;
          position: absolute;
          left: 0;
          top: 0;
          z-index: -1;
        }
        .image {
            width: 250px;
            height: 100%;
        }
        img{
          border-radius: 50%;
          height: 150px;
          object-fit: cover;
          width: 150px;
          max-width: unset;
        }
    }
    .userinfo {
        width: 420px;
        max-width: calc(100% - 150px);
        margin-left: 20px;
        h2 {
            font-size: 28px;
            color: #333333;
            font-weight: bold;
            line-height: 28px;
            margin-bottom: 8px;
        }
        .job {
            display: inline-block;
            font-size: 12px;
            color: #999999;
            padding-bottom: 19px;
            margin-bottom: 22px;
            position: relative;
            &::after {
                content: "";
                width: 36px;
                height: 4px;
                background: linear-gradient(270deg, #00B2FF 0%, #007AFF 100%);;
                position: absolute;
                left: 0;
                bottom: -3px;
            }
        }
        .desc {
            font-size: 16px;
            color: #666666;
            line-height: 24px;
            overflow: hidden;
            text-overflow: ellipsis;
            display:-webkit-box; //作为弹性伸缩盒子模型显示。
            -webkit-box-orient:vertical; //设置伸缩盒子的子元素排列方式--从上到下垂直排列
            -webkit-line-clamp:3; //显示的行
        }
    }
}
.carousel {
    position: relative;
    display: flex;
    justify-content: flex-end;
    width: 100%;
    .imgs-container {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        width: 90%;
        margin-top: 10px;
        .img-item {
            width: 33.3%;
            cursor: pointer;
            transition: all 0.2s;
            display: flex;
            flex-direction: column;
            position: relative;
            align-items: center;
            text-align: center;
            /*border: 1px solid rgba(0, 0, 0, 0.1);*/
            /*&::before {*/
            /*    content: "";*/
            /*    width: 100%;*/
            /*    height: 100%;*/
            /*    position: absolute;*/
            /*    z-index: 10;*/
            /*    left: 0;*/
            /*    top: 0;*/
            /*    !*background: rgba(0, 0, 0, 0.2);*!*/
            /*}*/
            .image {
                width: 100%;
            }
            .img-item-container {
                width: 75px;
                height: 75px;
                img {
                    border-radius: 50%;
                    object-fit: cover;
                    width: 100%;
                    height: 100%;
                }
            }
            .userinfo {
                width: 100%;
                /*height: 100%;*/
                /*position: absolute;*/
                /*z-index: 11;*/
                /*left: 0;*/
                /*top: 0;*/
                h3 {
                    font-size: 14px;
                    margin: 10px 0 0 0;
                    overflow:hidden; //超出的文本隐藏
                    text-overflow:ellipsis; //溢出用省略号显示
                    white-space:nowrap; //溢出不换行
                    font-weight: 300;
                    /*color: #ffffff;*/
                    /*line-height: 20px;*/
                    /*margin-top: 160px;*/
                    /*margin-bottom: 4px;*/
                }
                p {
                    font-size: 12px;
                    color: #ffffff;
                    opacity: 0.5;
                }
            }
        }
        .active {
            .img-item-container {
                img {
                    box-shadow: 0px 8px 20px 0px rgba(0,0,0,0.1);
                    transform: scale(1.05);
                }
            }
            h3 {
              font-weight: 700 !important;
            }
            /*transform: scale(1.06) translateY(-6px);
            /*z-index: 100;
            border: none;
            &::before {
                content: none;
            }
            .userinfo {
                display: none;
            }*/
        }
    }
}
.is-design {
    .avatar {
        width: 150px;
        height: 150px;
    }
}
</style>
<style lang='scss' >
@media screen and (max-width: 960px) {
    .see-personnel-special {
        .info-box {
            padding: 30px !important;
            /*.avatar {*/
            /*    width: 120px !important;*/
            /*    height: 120px !important;*/
            /*}*/
            /*.userinfo {*/
            /*    margin-left: 20px !important;*/
            /*}*/
        }
    }
}
</style>
