<template>
    <view class="container">
        <view class="stay-list" v-if="list.length">
            <view class="stay-item" @tap="gotopage" :data-id="item.icEventId || item.demandRecId" v-for="(item, index) in list" :key="index">
                <view class="date">{{ item.happenTime || item.reportTime }}</view>

                <view class="tit-text">{{ item.eventContent || item.content }}</view>
            </view>
        </view>

        <no-data v-else :isShow="true" />
    </view>
</template>

<script>
import noData from '../../../../components/noData/nodata';
import { icEventOldList, userdemandList } from '../../../../utils/statisticsApi';
export default {
    components: {
        noData
    },
    data() {
        return {
            list: []
        };
    },
    props: {
        stayVal: {
            type: String,
            default: '1'
        }
    },
    mounted() {
        // 处理小程序 ready 生命周期
        this.$nextTick(() => this.ready());
    },
    methods: {
        ready() {
            this.getList();
        },

        getList() {
            if (this.stayVal == '1') {
                this.getEventList();
            } else {
                this.getDemandList();
            }
        },

        getDemandList() {
            userdemandList({
                pageSize: '5',
                pageNo: 1,
                agencyId: '',
                undoneStauts: 'undone'
                // orgId: "1704313950756757506",
                // orgLevel: "agency"
            }).then((res) => {
                res.data.list.forEach((item) => {
                    item.reportTime = this.formatTime(item.reportTime);
                });
                this.setData({
                    list: res.data.list
                });
            });
        },

        formatTime(date) {
            if (date) {
                let _date = new Date(date);
                let M = _date.getMonth() - 0 + 1 > 10 ? _date.getMonth() - 0 + 1 : '0' + (_date.getMonth() - 0 + 1);
                let D = _date.getDate() > 10 ? _date.getDate() : '0' + _date.getDate();
                return M + '-' + D;
            }
            return '';
        },

        getEventList() {
            icEventOldList({
                pageSize: '5',
                pageNo: 1,
                agencyId: '',
                status: 'processing'
            }).then((res) => {
                res.data.list.forEach((item) => {
                    item.happenTime = this.formatTime(item.happenTime);
                });
                this.setData({
                    list: res.data.list
                });
            });
        },

        gotopage(e) {
            if (this.stayVal === '1') {
                uni.navigateTo({
                    url: '/subpages/statistics/pages/event/detail/detail?id=' + e.currentTarget.dataset.id + '&is12345=2'
                });
            } else {
                uni.navigateTo({
                    url: '/subpages/statistics/pages/demand/detail/detail?id=' + e.currentTarget.dataset.id + '&type=1'
                });
            }
        }
    },
    created: function () {},
    watch: {
        stayVal: {
            handler: function () {
                this.getList();
            },

            immediate: true
        }
    }
};
</script>
<style>
.container {
    padding: 0rpx 24rpx;
}
.stay-list{
    width: 100%;
}
.stay-item {
    display: flex;
    align-items: center;
    white-space: nowrap;
    border-bottom: 2px solid #ffffff;
    padding: 30rpx 0;
}
.date {
    flex: 0 0 90rpx;
    width: 90rpx;
    font-size: 30rpx;
    font-weight: 500;
    color: #999999;
    margin-right: 20rpx;
}
.tit-text {
    flex: 0 0 calc(100% - 110rpx);
    width: calc(100% - 110rpx);
    font-size: 30rpx;
    color: #333333;
    text-overflow: ellipsis;
    overflow: hidden;
}
</style>
