<template>
    <view class="index-zhuanzhi">
        <template v-if="devCount.engineeringListLength > 1">
            <view class="canneng-index-title mb20 ml20 canneng-index-title-with-icon">
                <uni-icons custom-prefix="iconfont" type="icon-gongcheng" size="18" color="#376cf3" />
                <text>所有工程设备统计</text>
            </view>
            <view class="header">
                <view class="header-item boxClick" @click="jump('allEngineering')">
                    <view class="header-item-value">{{ devCount.onLineDevCount + devCount.offLineDevCount || 0 }}</view>
                    <view class="header-item-label">设备总数</view>
                </view>
                <view class="header-item boxClick" @click="jump('onLineDevs')">
                    <view class="header-item-value">{{ devCount.onLineDevCount || 0 }}</view>
                    <view class="header-item-label">在线设备</view>
                </view>
                <view class="header-item boxClick" @click="jump('offLineDevs')">
                    <view class="header-item-value">{{ devCount.offLineDevCount || 0 }}</view>
                    <view class="header-item-label">离线设备</view>
                </view>
                <view class="header-item boxClick" @click="jumpMessage(2, false)">
                    <view class="header-item-value">{{ devCount.alarmCount || 0 }}</view>
                    <view class="header-item-label">告警数量</view>
                </view>
                <view class="header-item boxClick" @click="jumpMessage(0, false)">
                    <view class="header-item-value">{{
                        devCount.eventCount + devCount.runCount + devCount.harmonicCount || 0
                    }}</view>
                    <view class="header-item-label">事件数量</view>
                </view>
                <view class="header-item boxClick" @click="eningerNum">
                    <view class="header-item-value">{{ devCount.eningerCount || 0 }}</view>
                    <view class="header-item-label">工程个数</view>
                </view>
            </view>
            <view class="mt20"></view>
        </template>
        <view class="canneng-index-title mb20 ml20 canneng-index-title-with-icon">
            <uni-icons custom-prefix="iconfont" type="icon-zaixianjianceshebei" size="18" color="#376cf3" />
            <text>当前工程设备统计</text>
        </view>
        <view class="header">
            <view class="header-item boxClick" @click="jump('nowEngineering')">
                <view class="header-item-value">{{
                    devCount.currentOnLineDevCount + devCount.currentOffLineDevCount || 0
                }}</view>
                <view class="header-item-label">设备总数</view>
            </view>
            <view class="header-item boxClick" @click="jump('currentOnLineDevs')">
                <view class="header-item-value">{{ devCount.currentOnLineDevCount || 0 }}</view>
                <view class="header-item-label">在线设备</view>
            </view>
            <view class="header-item boxClick" @click="jump('currentOffLineDevs')">
                <view class="header-item-value">{{ devCount.currentOffLineDevCount || 0 }}</view>
                <view class="header-item-label">离线设备</view>
            </view>
            <view class="header-item boxClick" @click="jumpMessage(2, true)">
                <view class="header-item-value">{{ devCount.currentAlarmCount || 0 }}</view>
                <view class="header-item-label">告警数量</view>
            </view>
            <view class="header-item boxClick" @click="jumpMessage(0, true)">
                <view class="header-item-value">{{
                    devCount.currentEventCount + devCount.currentRunCount + devCount.currentHarmonicCount || 0
                }}</view>
                <view class="header-item-label">事件数量</view>
            </view>
            <view class="header-item boxClick" @click="projectNum(true)">
                <view class="header-item-value">{{ devCount.currentProjectCount || 0 }}</view>
                <view class="header-item-label">项目个数</view>
            </view>
        </view>
    </view>
</template>
<script>
export default {
    data() {
        return {
            loading: false,
        }
    },
    props: {
        devCount: {
            type: Object,
            default: {},
        },
    },
    methods: {
        jumpMessage(type, flag) {
            uni.setStorageSync('messageParams', {
                // name: flag ? uni.getStorageSync('engineering').name : '',
                // id: flag ? uni.getStorageSync('engineering').id : '',
                engineeringName: flag ? uni.getStorageSync('engineering').name : '',
                engineeringId: flag ? uni.getStorageSync('engineering').id : '', //工程ID
                projectName: '',
                projectId: '', //項目ID
                deviceName: '',
                deviceId: '', //设备ID
                lineName: '',
                lineId: '', //测点ID
                type: type,
            })
            uni.switchTab({
                url: '/pages/index/message1',
            })
        },
        eningerNum() {
            uni.navigateTo({
                url: '/pages/engineering/list',
            })
        },
        projectWarning() {
            uni.navigateTo({
                url: '/pages/zhuanzhi/warning',
            })
        },
        projectNum(now) {
            console.log(now)
            if (now) {
                let engineering = uni.getStorageSync('engineering')
                uni.navigateTo({
                    url: '/pages/project/list?engineeringName=' + engineering.name + '&engineeringId=' + engineering.id,
                })
            } else {
                uni.navigateTo({
                    url: '/pages/project/list',
                })
            }
        },
        jump(type) {
            uni.navigateTo({
                url: '/pages/device/list?type=' + type,
            })
        },
    },
    created() {},
}
</script>
<style lang="scss">
.index-zhuanzhi {
    .canneng-index-title-with-icon {
        display: inline-flex;
        align-items: center;
        gap: 8rpx;
        font-size: 30rpx;
    }
}
</style>
