<template>
    <view class="container activity">
        <tui-skeleton v-if="isRequest" loadingType="2"></tui-skeleton>
        <view class="activity-content" v-if="activityList.length > 0">
            <view
                class="activity-list"
                v-for="(activity, index) in activityList"
                :key="index"
                @click="NavigatorPath(activity)"
            >
                <view class="activity-list-pic">
                    <image class="activity-image" :src="activity.listImage" mode=""></image>
                </view>
                <view class="activity-list-msg">
                    <view class="activity-title">{{ activity.name }}</view>
                    <view class="activity-numbe"
                        >商品数：<text class="color">{{ activity.productCount }}</text>
                    </view>
                    <view class="activity-times">
                        <text class="label">活动时间：</text>
                        <text class="color">{{ activity.beginTime }} ~ {{ activity.endTime }}</text>
                    </view>
                </view>
            </view>
        </view>
        <view v-else class="activity-content-empty">
            <view class="empty-container">
                <image
                    class="empty-container-image"
                    :src="StaticUrl + 'icon-empty-activity.png'"
                    mode="aspectFit"
                ></image>
                <text class="error-text">您还没有活动哟~</text> <text class="error-text">可联系采美帮您设置活动~</text>
            </view>
        </view>
        <template v-if="activityList.length >= 6">
            <tui-loadmore :index="3" :visible="loadmore"></tui-loadmore>
            <tui-nomore :text="loadingText" :visible="!loadmore" backgroundColor="#ff457b"></tui-nomore>
        </template>
    </view>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
    data() {
        return {
            StaticUrl: this.$Static,
            activityList: [],
            hasNextPage: false,
            listQuery: {
                userId: 0,
                pageNum: 1,
                pageSize: 10
            },
            isRefresh: false,
            isRequest: true,
            loadmore: false // 正在加载更多
        }
    },
    computed: {
        ...mapGetters(['userId']),
        loadingText() {
            return this.hasNextPage ? '上拉加载更多' : '没有更多了'
        }
    },
    onLoad() {
        this.listQuery.userId = this.userId
        this.getActivityAreaList()
    },
    methods: {
        getActivityAreaList() {
            this.loadmore = true
            //初始化活动列表数据
            this.ProductService.GetProductActivityAreaList(this.listQuery)
                .then(response => {
                    const data = response.data
                    this.hasNextPage = data.hasNextPage
                    if (this.isRefresh) {
                        this.activityList = data.list
                    } else {
                        this.activityList = [...this.activityList, ...data.list]
                    }
                    this.loadmore = false
                    this.isRequest = false
                })
                .catch(error => {
                    this.$util.msg(error.msg, 2000)
                })
                .finally(() => {
                    if (this.isRefresh) {
                        setTimeout(() => {
                            uni.stopPullDownRefresh()
                        }, 500)
                        this.isLoadMore = false
                    }
                })
        },
        NavigatorPath(item) {
            this.$api.navigateTo(`/pages/user/activity/activity?activityId=${item.activityId}&name=${item.name}`)
        }
    },
    //下拉刷新
    onPullDownRefresh() {
        this.isRefresh = true
        this.listQuery.pageNum = 1
        this.activityList = []
        this.getActivityAreaList()
    },
    // 加载更多
    onReachBottom() {
        if (this.hasNextPage) {
            this.getActivityAreaList()
        }
    }
}
</script>

<style lang="scss">
page {
    height: auto !important;
    background-color: $color-system;
}
.activity-content {
    width: 100%;
    height: auto;
    box-sizing: border-box;
    padding: 24rpx;
    .activity-list {
        width: 100%;
        height: 228rpx;
        box-sizing: border-box;
        padding: 24rpx 20rpx;
        background-color: #ffffff;
        border-radius: 16rpx;
        margin-bottom: 24rpx;
        .activity-list-pic {
            width: 180rpx;
            height: 180rpx;
            float: left;
            box-sizing: border-box;
            border: 1px solid #e1e1e1;
            border-radius: 8rpx;
            .activity-image {
                width: 178rpx;
                height: 178rpx;
                display: block;
                border-radius: 8rpx;
            }
        }
        .activity-list-msg {
            width: 460rpx;
            height: 100%;
            float: right;
            position: relative;
            .activity-title {
                width: 100%;
                height: auto;
                line-height: 36rpx;
                text-overflow: ellipsis;
                overflow: hidden;
                display: -webkit-box;
                -webkit-line-clamp: 2;
                line-clamp: 2;
                -webkit-box-orient: vertical;
                font-size: $font-size-26;
                color: #333333;
                text-align: justify;
                float: left;
            }
            .activity-numbe {
                width: 100%;
                height: 28rpx;
                float: left;
                margin-top: 4rpx;
                text-align: left;
                line-height: 28rpx;
                font-size: $font-size-24;
                color: #999999;
                .color {
                    color: #666666;
                }
            }
            .activity-times {
                width: 100%;
                height: 44rpx;
                position: absolute;
                bottom: 0;
                left: 0;
                font-size: 18rpx;
                color: #666666;
                line-height: 44rpx;
                .label {
                    display: inline-block;
                    float: left;
                }
                .color {
                    display: inline-block;
                    float: left;
                    color: $color-system;
                }
            }
        }
    }
}
.activity-content-empty {
    position: relative;
}
</style>
