<!--
 * @Author: 嗨噜客(三亚)<fm453>
 * @Date: 2021-09-06 11:48:18
 * @FilePath: pages/ctms/tabbar/notice/index.vue
 * @Description: 
 * @Email:  393213759@qq.com
 * Copyright (c) 2025 by www.hiluker.cn, All Rights Reserved. 
 -->
<template>
    <view class="container">
        <view v-if="!totalCount" class="content">
            暂时没有消息通知
        </view>

        <uni-collapse v-else v-model="showIndexs">
            <uni-collapse-item :name='"notice-"+index' :title='"（"+(index+1)+"）"+notice.title'
                v-for="(notice,index) in notices" :data-nid="notice.id" :key="index" thumb="./static/logo.png">
                <uni-list>
                    <uni-list-item :title="notice.content" :note="'更新于 : '+notice.updateTime"></uni-list-item>
                </uni-list>
            </uni-collapse-item>
        </uni-collapse>

        <view class="pagination">
            <uni-pagination :show-icon="false" :total="totalCount" :pageSize='psize' v-model='page' title="分页栏"
                @change="newPage" />
        </view>
    </view>
</template>

<script>
    import utils from "@/utils/common.js";
    import ctms from '@/apis/ctms/index.js';
    export default {
        data() {
            return {
                showIndexs: [],
                notices: {},
                totalCount: 0,
                psize: 10,
                page: 1
            }
        },
        onLoad() {
            this.checkNotice()
        },
        onPullDownRefresh() {
            this.page = 1;
            this.checkNotice();
            setTimeout(() => {
                uni.stopPullDownRefresh();
            }, 3000);
        },
        methods: {
            //刷新列表
            checkNotice() {
                var _that = this;
                ctms.notice.list(this.page, this.psize).then(
                    function(res) {
                        if (res) {
                            _that.notices = res.notices;
                            for (var index in res.notices) {
                                if (res.notices[index]['is_show']) {
                                    _that.showIndexs.push('notice-' + index);
                                }
                            }
                            _that.totalCount = res.total;
                        } else {
                            _that.orders = {}
                            _that.totalCount = 0;
                        }
                    }
                );
            },
            //分页器动作
            newPage(e) {
                var page = e.current;
                this.page = page;
                this.checkNotice();
            }
        }
    }
</script>

<style>
    .content {
        text-align: center;
        height: 400upx;
        margin-top: 200upx;
    }
</style>