<!--
 * @Description  : 应用组件
 * @Author       : 熊伟
 * @Date         : 2020-06-16 16:33:46
 * @LastEditTime: 2020-10-10 14:47:23
 * @LastEditors: 李璕
 * @FilePath     : \see-tp-application.vue
 -->

<template>
    <div class="see-tp-application" v-if="isShow">
        <div
            v-if="componentData.applist.length"
            class="application-cont"
        >
            <!-- pc端展示 -->
            <div v-if="componentData.commonVariable.isMobile == 0" class="clearfix">
                <!-- 选择轮播展示 -->
                <div class="swiper-application" v-if="componentData.showType == 'swiper'" >
                    <swiper
                        :options="swiperOption"
                        ref="appSwiper"
                    >
                        <swiper-slide
                            v-for="(item ,index) in componentData.applist"
                            :key="index"
                            class="app-item--pc app-item--pc--swiper"
                        >
                            <div v-if="item.experiencePlatform || item.experiences == 1 || item.experiences == 2 || item.experiences == 3" class="flag">
                                <span class="txt">可体验</span>
                            </div>
                            <div class="app-item__cont">
                                <div
                                    v-if="item.experiencePlatform || item.experiences == 1 || item.experiences == 2 || item.experiences == 3"
                                    class="app-item__cont__cover"
                                >
                                    <div
                                        v-if="item.experiencePlatform == 'ALL' || item.experiencePlatform == 'PC' || item.experiences == 1 || item.experiences == 2"
                                        class="button-exp"
                                        @click="goPcExp(item.experienceUrlPc || item.experience_url_pc)"
                                    >体验pc端</div>
                                    <template v-if="item.experiencePlatform == 'ALL' || item.experiencePlatform == 'WAP' || item.experiences == 1 || item.experiences == 3">
                                        <div class="txt">扫一扫体验移动端</div>
                                        <img :src="item.experienceUrlWap || item.experience_url_wap">
                                    </template>
                                </div>
                                <base-image
                                    class="image"
                                    :src="item.pictureUrl || item.picture_url"
                                ></base-image>
                                <div class="app-item__title">{{item.goodsName || item.goods_name}}</div>
                                <div class="app-item__desc" :title="item.goodsExplain || item.goods_explain">{{item.goodsExplain || item.goods_explain}}</div>
                            </div>
                            <div class="app-item__link">
                                <span class="link" @click="goPcInfo(item.goodsId || item.goods_id)">查看详情 ></span>
                            </div>
                        </swiper-slide>
                    </swiper>
                    <div v-show="componentData.applist.length>swiperOption.slidesPerView" class="swiper-button-next"></div>
                    <div v-show="componentData.applist.length>swiperOption.slidesPerView" class="swiper-button-prev"></div>
                </div>

                <!-- 选择平铺展示 -->
                <div v-if="componentData.showType == 'flow'">
                    <div
                        v-for="(item ,index) in componentData.applist"
                        :key="index"
                        class="app-item--pc app-item--pc--flow"
                    >
                        <div v-if="item.experiencePlatform || item.experiences == 1 || item.experiences == 2 || item.experiences == 3" class="flag">
                            <span class="txt">可体验</span>
                        </div>
                        <div class="app-item__cont">
                            <div v-if="item.experiencePlatform || item.experiences == 1 || item.experiences == 2 || item.experiences == 3" class="app-item__cont__cover">
                                <div
                                    v-if="item.experiencePlatform == 'ALL' || item.experiencePlatform == 'PC' || item.experiences == 1 || item.experiences == 2"
                                    class="button-exp"
                                    @click="goPcExp(item.experienceUrlPc || item.experience_url_pc)"
                                >体验pc端</div>
                                <template v-if="item.experiencePlatform == 'ALL' || item.experiencePlatform == 'WAP' || item.experiences == 1 || item.experiences == 3">
                                    <div class="txt">扫一扫体验移动端</div>
                                    <img :src="item.experienceUrlWap || item.experience_url_wap">
                                </template>
                            </div>
                            <base-image
                                class="image"
                                :src="item.pictureUrl || item.picture_url"
                            ></base-image>
                            <div class="app-item__title">{{item.goodsName || item.goods_name}}</div>
                            <div class="app-item__desc" :title="item.goodsExplain || item.goods_explain">{{item.goodsExplain || item.goods_explain}}</div>
                        </div>
                        <div class="app-item__link">
                            <span class="link" @click="goPcInfo(item.goodsId || item.goods_id)">查看详情 ></span>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 移动端 -->
            <div v-else>
                <div
                    v-for="(item ,index) in componentData.applist"
                    :key="index"
                    class="app-item--mobile"
                >
                    <base-image
                        class="image"
                        :src="item.pictureUrl || item.picture_url"
                    ></base-image>
                    <div class="app-item__cont">
                        <div class="app-item__title">{{item.goodsName || item.goods_name}}</div>
                        <div class="app-item__desc" :title="item.goodsExplain || item.goods_explain">{{item.goodsExplain || item.goods_explain}}</div>
                        <div class="app-item__buttons">
                            <div
                                class="app-item__button app-item__button--fill"
                                @click="goMobileInfo(item.goodsId || item.goods_id)"
                            >查看详情</div>
                            <div
                                v-if="item.experiencePlatform == 'ALL' || item.experiencePlatform == 'WAP' || item.experiences == 1 || item.experiences == 3"
                                class="app-item__button app-item__button--default"
                                @click="goMobileExp(item.goodsId || item.goods_id)"
                            >立即体验</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div
            v-if="componentData.commonVariable.pageType == 'design' && !componentData.applist.length"
            class="cont-empty"
        >应用组件</div>
    </div>
</template>
<script>
import btnMixin from './button-mixin';
import BaseImage from './components/base-image';
import permissionMixin from "./permission-mixin";
import 'swiper/dist/css/swiper.min.css';
import Vue from 'vue'
import VueAwesomeSwiper from 'vue-awesome-swiper'
Vue.use(VueAwesomeSwiper)

export default {
    name: 'see-tp-application',
    mixins: [btnMixin,permissionMixin],
    components: {
        BaseImage
    },
    inject: ["$EventBus"],
    props: {
        isLogin: {
            type: Boolean,
            default: false
        },
        componentData: {
            required: false,
        },
    },
    data() {
        return {
            swiperOption:{
                slidesPerView: 3,
                spaceBetween: 16,
                threshold : 10,
                navigation: {
                    nextEl: '.swiper-button-next',
                    prevEl: '.swiper-button-prev',
                }
            }
        };
    },
    computed: {},
    watch: {},
    created() {
        // if(this.componentData && this.componentData.commonVariable.pageType == "design"){
        //     this.$set(this.swiperOption,'slidesPerView',3)
        // }
    },
    mounted() {

    },
    methods: {
        goPcInfo(goodsId) {
            if(this.componentData.commonVariable.pageType == "design") return;
            window.open("/goods-" +goodsId);
        },
        goMobileInfo(goodsId){
            if(this.componentData.commonVariable.pageType == "design") return;
            this.$router.push({
                path: "/goodsTansfer?goodsId=" + goodsId
            });
        },
        goPcExp(pcUrl) {
            if(this.componentData.commonVariable.pageType == "design") return;
            this.$EventBus.$emit('compGoPcExp',pcUrl);
        },
        goMobileExp(goodsId){
            if(this.componentData.commonVariable.pageType == "design") return;
            this.$emit('goMobileExp',goodsId);
        }
    },
    destroyed() {},
};
</script>

<style lang="scss">
.clearfix:before,
.clearfix:after {
    content: " ";
    display: table;
}
.clearfix:after {
    clear: both;
}
.see-tp-application {
    width: 100%;
    min-height: 40px;
    .swiper-application {
        position: relative;
        .swiper-button-next {
            right: -30px;
            background-image: url('./assets/arrow-right.svg');
            background-size: 64%;
            &:focus {
                outline: none;
            }
        }
        .swiper-button-prev {
            left: -30px;
            background-image: url('./assets/arrow-left.svg');
            background-size: 64%;
            &:focus {
                outline: none;
            }
        }
    }
    .app-item__title {
        font-size: 20px;
        color: #333;
        width: 100%;
        margin-top: 10px;
        font-weight: 500;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .app-item__desc {
        height: 38px;
        line-height: 20px;
        font-size: 12px;
        color: #999;
        margin-top: 5px;
        text-align: left;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
    }
    .app-item--pc {
        position: relative;
        text-align: left;
        background-color: #fff;
        transition: all 0.2s;
        border-radius: 4px;
        border: 1px solid #ECECEC;
        text-align: center;
        overflow: hidden;
        box-shadow: 0 4px 12px 0 rgba(0,0,0,0.08);
        z-index: 2;
        transition: all .2s;
        transform-origin: bottom center;
        &:hover{
            transform: scale(1.03);
        }
        &.app-item--pc--flow{
            float: left;
            width: calc((100% - 40px) / 3);
            margin-right: 20px;
            &:nth-child(3n){
                margin-right: 0;
            }
            &:nth-child(n+4){
                margin-top: 20px;
            }
            &:hover {
                box-shadow: 0 10px 25px 0 #e1e5ed;
            }
        }
        .flag {
            position: absolute;
            left: 0;
            top: 16px;
            padding: 3px 10px;
            background: #007AFF;
            border-radius: 0 4px 4px 0;
            color: #fff;
            font-size: 14px;
            .txt {
                display: inline-block;
                transform: scale(.9);
            }
        }
        .app-item__cont {
            position: relative;
            padding: 50px 30px 28px;
            cursor: pointer;
            &:hover {
                .app-item__cont__cover {
                    display: flex;
                }
            }
        }
        .image {
            width: 100px;
            height: 100px;
        }
        .app-item__desc {
            margin-top: 15px;
        }
        .app-item__link {
            padding: 12px 0;
            border-top:1px solid #ececec;
            .link {
                color: #3385FF;
                cursor: pointer;
            }
        }
        .app-item__cont__cover {
            position: absolute;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            overflow: hidden;
            background: rgba(0,0,0,.7);
            z-index: 2;
            color: #fff;
            display: none;
            .button-exp {
                width: 96px;
                height: 32px;
                line-height: 32px;
                text-align: center;
                border-radius: 2px;
                font-size: 14px;
                background: #007AFF;
                cursor: pointer;
            }
            .txt {
                margin: 15px 0 8px;
                font-size: 12px;
            }
            img {
                width: 96px;
            }
        }
    }

    .app-item--mobile {
        width: 100%;
        display: flex;
        align-items: center;
        padding: 16px;
        margin-bottom: 16px;
        border: 1px solid #ECECEC;
        border-radius: 6px;
        border-radius: 6px;
        .image {
            width: 84px;
            height: 84px;
            margin-right: 16px;
        }
        .app-item__cont {
            flex: 1;
            overflow: hidden;
        }
        .app-item__buttons {
            margin-top: 6px;
            .app-item__button {
                display: inline-block;
                width: 78px;
                height: 24px;
                line-height: 24px;
                text-align: center;
                border-radius: 3px;
                margin-right: 10px;
                font-size: 12px;
                &.app-item__button--fill {
                    background: #007AFF;
                    border:1px solid #007AFF;
                    color: #fff;
                }
                &.app-item__button--default {
                    background: #fff;
                    border:1px solid #ECECEC;
                    color: #007AFF;
                }
            }
        }
    }
    .cont-empty {
        height: 100px;
        line-height: 100px;
        background: rgba(204,204,204,.15);
        text-align: center;
    }
}
</style>

