<template>
    <view style="position: relative">
        <!-- 稳态 -->
        <view class="transientBox">
            <view class="statistics pd20">
                <view class="box" :class="{ boxClick: item.label == '稳态数量' }" v-for="item in list">
                    <text class="num">{{ item.value }}</text>
                    <text class="label">{{ item.label }}</text>
                </view>
            </view>
        </view>
        <!-- 卡片 -->
        <scroll-view
            scroll-y="true"
            @refresherrefresh="refresherrefresh"
            :refresher-triggered="triggered"
            refresher-enabled="true"
            class="event-list"
            :style="{ height: 'calc(100vh - ' + (navHeight + height) + 'px)', overflow: 'auto' }"
        >
            <!-- 循环渲染事件项 -->
            <uni-card
                class="event-item"
                :class="item.type"
                v-for="(item, index) in store.data"
                :key="index"
                @click="jump(item)"
            >
                <!-- 头部：图标 + 信息 + 操作 -->
                <view class="event-header">
                    <view class="event-icon">
                        <!-- 动态图标：根据类型切换 -->
                        <uni-icons
                            custom-prefix="iconfont"
                            type="icon-kouanjiancedian"
                            size="40"
                            color="#E6A23C"
                        ></uni-icons>
                        <view class="badge1" v-if="item.isRead == 0"> </view>
                    </view>
                    <view class="event-info">
                        <view class="event-title">
                            <text class="event-id">{{ item.lineName }}</text>
                        </view>
                        <view class="event-desc">
                            <text>工程名称：{{ item.engineeringName }}</text>
                            <text>项目名称：{{ item.projectName }}</text>
                            <text>设备名称：{{ item.devName }}</text>
                            <!-- <text>统计日期：{{ item.statisticsDate }}</text> -->
                        </view>
                    </view>
                    <view class="event-action">
                        <uni-icons type="search" size="25"></uni-icons>
                    </view>
                </view>
                <!-- 详情区域 -->
                <view class="event-detail">
                    <text>{{ item.statisticsDate }}发生 {{ item.overLimitDesc }} </text>
                </view>
            </uni-card>

            <uni-load-more
                v-if="store.status == 'loading' || (store.data && store.data.length > 0)"
                :status="store.status"
            ></uni-load-more>
            <Cn-empty v-else style="top: 20%"></Cn-empty>
        </scroll-view>
    </view>
</template>
<script>
import list from '@/common/js/list'
export default {
    components: {},
    props: {
        navHeight: {
            type: Number,
            default: 0,
        },
        selectValue: {
            type: Object,
            // default: () => {},
        },
    },
    mixins: [list],
    data() {
        return {
            height: 0,
            list: [
                { value: 0, label: '稳态数量' },
                { value: 0, label: '越限天数' },
                { value: 0, label: '越限测点数' },
            ],
            triggered: true,
            status: 'noMore', //more加载前  loading加载中 noMore加载后
        }
    },
    mounted() {
        uni.createSelectorQuery()
            .select('.transientBox')
            .boundingClientRect((rect) => {
                //
                // #ifdef H5
                this.height = rect.height
                // #endif
                // #ifdef APP-PLUS
                this.height = rect.height
                // #endif
            })
            .exec()
    },

    methods: {
        //           "devId": "",
        //   "engineerId": "",
        //   "lineId": "",
        //   "projectId": "",
        //   "time": ""
        // 查詢
        init() {
            this.store = this.DataSource('/cs-harmonic-boot/csHarmonic/queryHarmonicList')
            this.store.params.pageSize = 10000
            this.store.params.engineerId = this.selectValue.engineeringId
            this.store.params.projectId = this.selectValue.projectId
            this.store.params.devId = this.selectValue.deviceId
            this.store.params.lineId = this.selectValue.lineId
            this.store.params.time = this.selectValue.date
            this.store.loadedCallback = () => {
                this.list[0].value = this.store.copyData.harmonicNums
                this.list[1].value = this.store.copyData.overDays
                this.list[2].value = this.store.copyData.overLineNums
                this.loading = false
            }
            this.store.reload()
        },

        jump(item) {
            let str = JSON.stringify(item).replace(/%/g, '百分比')
            item.status = '1'

            uni.navigateTo({ url: '/pages/message1/comp/steadyStateDetails?detail=' + encodeURIComponent(str) })
        },
        // 下拉
        refresherrefresh() {
            this.triggered = true
            uni.startPullDownRefresh()
            setTimeout(() => {
                this.triggered = false
            }, 500)
        },
    },

    computed: {},

    watch: {
        selectValue: {
            handler(val, oldVal) {
                if (Object.keys(val).length === 0) return
                this.init()
            },
            deep: true,
            immediate: true,
        },
    },
}
</script>

<style lang="scss" scoped>
@import './index.scss';

.box:first-child {
    flex: 1.3 !important;
}
/* 列表容器 */
.event-list {
    /* 头部：图标 + 信息 + 操作 */
    .event-header {
        display: flex;
        align-items: center;
        margin-bottom: 10rpx;
    }

    /* 图标区域（按类型区分背景色） */
    .event-icon {
        background-color: #e6a23c20;
    }

    .event-tags {
        font-size: 24rpx;
    }
}
/deep/ .uni-scroll-view-refresher {
    display: none;
}
</style>
