<!--
 * @Description: 卡片组-人员组件
 * @Author: 周洋
 * @Date: 2020-06-30 14:08:16
 * @LastEditTime: 2020-10-10 14:46:48
 * @LastEditors: 李璕
 * @FilePath: \cms-components\see-personnel.vue
-->
<template>
    <div
        v-if="isShow"
        class="see-personnel"
        :class="{ 'is-pc': !isMobile, 'is-mobile': isMobile }"
    >
        <div
            class="control left"
            :class="{ 'not-allowed': curIndex == 0 }"
            @click="changeIndex('left')"
            v-show="
                componentData.group &&
                componentData.group.length > 3 &&
                componentData.playType == 1
            "
        ></div>
        <div
            class="document-view"
            :class="{
                'shuffling-layout': componentData.playType == 1,
                'tile-layout': componentData.playType == 2,
            }"
        >
            <ul class="document-container" :style="translateX">
                <li
                    class="document-item"
                    v-for="(item, index) in componentData.group"
                    :key="index"
                >
                    <div class="document-item__img">
                        <base-image
                            class="image"
                            :src="item.avatar"
                        ></base-image>
                    </div>
                    <h2 :title="item.name">
                        {{ item.name || (isDesign ? "姓名" : "") }}
                    </h2>
                    <h3 :title="item.job">
                        {{ item.job || (isDesign ? "职务" : "") }}
                    </h3>
                    <p class="document-item__desc" :title="item.desc">
                        {{
                            item.desc ||
                            (isDesign ? "人员介绍…不超过50个字符" : "")
                        }}
                    </p>
                </li>
            </ul>
        </div>
        <div
            class="control right"
            :class="{
                'not-allowed':
                    Math.abs(curIndex) === componentData.group.length - 4,
            }"
            @click="changeIndex('right')"
            v-show="
                componentData.group &&
                componentData.group.length > 4 &&
                componentData.playType == 1
            "
        ></div>
    </div>
</template>

<script>
import BaseImage from "./components/base-image";
import permissionMixin from "./permission-mixin";
export default {
    name: "see-personnel",
    mixins: [permissionMixin],
    props: {
        componentData: {
            required: false,
        },
    },
    components: { BaseImage },
    data() {
        return {
            curIndex: 0,
        };
    },
    methods: {
        changeIndex(sign) {
            if (sign === "left") {
                if (this.curIndex === 0) return;
                else ++this.curIndex;
            } else if (sign === "right") {
                if (
                    Math.abs(this.curIndex) ===
                    this.componentData.group.length - 4
                )
                    return;
                else --this.curIndex;
            }
        },
    },
    created() {},
    mounted() {},
    computed: {
        isMobile() {
            return this.componentData.commonVariable.isMobile;
        },
        isDesign() {
            return this.componentData.commonVariable.pageType === "design";
        },
        translateX() {
            return {
                transform: `translateX(calc(((100% - 60px) / 4 + 20px) * ${this.curIndex}))`,
            };
        },
    },
    watch: {},
};
</script>

<style lang='scss' scoped>
ul,
li {
    list-style: none;
    padding: 0;
    margin: 0;
}
.document-item {
    border-radius: 4px;
    text-align: center;
    padding: 30px;
    flex-grow: 0;
    flex-shrink: 0;
    width: calc((100% - 30px) / 4);
    background: #ffffff;
    border: 1px solid #ececec;
    box-shadow: 0 4px 12px 0 rgba(0,0,0,0.08);
    &:not(:last-child) {
        margin-right: 16px;
    }
    &__img {
        width: 72px;
        height: 72px;
        border-radius: 50%;
        margin: 0 auto 10px;
        overflow: hidden;
        text-align: center;
        background: #cccccc;
        .image {
            width: 100%;
            height: 100%;
        }
    }
    h2 {
        font-size: 16px;
        color: #333333;
        line-height: 20px;
        font-weight: bold;
        margin-bottom: 3.5px;
        width: 100%;
        overflow: hidden;
        -ms-text-overflow: ellipsis;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    h3 {
        font-size: 12px;
        color: #999;
        line-height: 16px;
        margin-bottom: 10px;
        width: 100%;
        overflow: hidden;
        -ms-text-overflow: ellipsis;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    &__desc {
        margin-bottom: 0;
        text-align: left;
        font-size: 12px;
        color: #666;
        line-height: 18px;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 3;
    }
}
.not-allowed {
    cursor: default !important;
    opacity: 0.35;
    pointer-events: none;
}
.is-mobile {
    .document-view {
        width: 100%;
        .document-container {
            display: flex;
            flex-wrap: wrap;
            transform: translateX(0) !important;
            .document-item {
                margin: 0;
                width: calc(50% - 5px);
                padding: 19px 16px;
                &:nth-child(2n-1) {
                    margin-right: 10px;
                }
                &:nth-child(n + 3) {
                    margin-top: 10px;
                }
                &__img {
                    width: 56px;
                    height: 56px;
                    margin-bottom: 10px;
                }
                h2 {
                    font-size: 14px;
                }
                &__desc,
                h3 {
                    font-size: 10px;
                }
            }
        }
    }
}
.is-pc {
    position: relative;
    .control {
        width: 27px;
        height: 44px;
        background-size: 17px 17px;
        background-repeat: no-repeat;
        background-position: center;
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        cursor: pointer;
        z-index: 100;
    }
    .left {
        left: -30px;
        background-image: url("./assets/arrow-left.svg");
    }
    .right {
        right: -30px;
        background-image: url("./assets/arrow-right.svg");
    }
    .shuffling-layout {
        width: 100%;
        margin: 0 auto;
        overflow: hidden;
        .document-container {
            display: flex;
            flex-wrap: nowrap;
            transition: all ease-in-out 0.5s;
        }
    }
    .tile-layout {
        width: 100%;
        overflow: inherit;
        .document-container {
            display: flex;
            flex-wrap: wrap;
            transform: translateX(0) !important;
            .document-item {
                transition: all 0.2s;
                &:nth-child(4n) {
                    margin-right: 0;
                }
                &:nth-child(n + 5) {
                    margin-top: 10px;
                }
                &:hover {
                    box-shadow: 0 10px 25px 0 #e1e5ed;
                }
            }
        }
    }
}
</style>
