<template>
    <view class="trajectory">
        <view class="title">访问轨迹</view>
        <time-axis v-for="item in trajectoryList" :key="item.userID">
            <template #title>
                <text>{{ item.accessTime }}(停留时长{{ item.accessDuration }})</text>
            </template>
            <template #content>
                <view class="time-axis-content" @click="handleLink(item)">
                    <image
                        :src="fileType(item)"
                        class="axis-product"
                        mode=""
                    ></image>
                    <view class="axis-product-info">
                        <view class="product-title">【{{ item.pageType | pageTypeChange }}】</view>
                        <view class="product-info" v-if="item.title">{{ item.title }}</view>
                    </view>
                </view>
            </template>
        </time-axis>
    </view>
</template>

<script>
import TimeAxis from './time-axis.vue'
export default {
    props: {
        trajectoryList: {
            type: Array,
            default: () => []
        }
    },
    components: {
        TimeAxis
    },
    filters: {
        pageTypeChange(val) {
            const obj = {
                '6': '商品',
                '11': '文章',
                '8': '搜索记录',
                '69': '文件',
                '70': '图片',
                '71': '视频'
            }
            return obj[val]
        },
    },
    data() {
        return {}
    },
    methods: {
        handleLink(item) {
            if (Number(item.pageType) >= 69) {
                uni.setStorageSync('databaseurl', item.pagePath)
                uni.navigateTo({
                    url: `/pages/h5/article/path?databaseurl=1`
                })
            }
        },
        fileType(item) {
            if (item.titleImage) return item.titleImage
            if (item.title) {
                return item.title?.indexOf('.pdf') !== -1
                    ? 'https://static.caimei365.com/app/mini-database/H5-pdf.png'
                    : item?.indexOf('.docx') !== -1
                    ? 'https://static.caimei365.com/app/mini-database/H5-doc.png'
                    : 'https://static.caimei365.com/app/mini-database/H5-ppt.png'
            }
            else return '../../../../static/temp/icon-new@2x.png'
        }
    }
}
</script>

<style lang="scss">
.trajectory {
    margin: 24rpx auto;
    width: 702rpx;
    background-color: #fff;
    border-radius: 16rpx;
    padding: 40rpx 32rpx;
    box-sizing: border-box;
    .title {
        color: #333333;
        font-size: 28rpx;
        font-weight: bold;
        margin-bottom: 30rpx;
    }
}
.axis-product {
    width: 136rpx;
    height: 136rpx;
    object-fit: contain;
}
.axis-product-info {
    display: flex;
    flex-direction: column;
    height: 136rpx;
    width: 426rpx;
    color: #333333;
    font-size: 26rpx;
    margin-left: 24rpx;
    .product-info {
        margin-top: 16rpx;
        overflow: hidden;
        -webkit-line-clamp: 2;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        height: 73rpx;
        width: 426rpx;
    }
}
.time-axis-content {
    display: flex;
    align-items: center;
}
</style>
