<template>
    <view class="index-zhuyonghu">
        <div class="header">
            <div class="header-item">
                <div class="header-item-value">{{ devCount.onLineCount || 0 }}</div>
                <div class="header-item-label">正常设备</div>
            </div>
            <div class="header-item" @click="jump('alarmLineDevs')">
                <div class="header-item-value">{{ devCount.alarmLineCount || 0 }}</div>
                <div class="header-item-label">报警设备</div>
            </div>
            <div class="header-item" @click="jump('offLineDevs')">
                <div class="header-item-value">{{ devCount.offLineCount || 0 }}</div>
                <div class="header-item-label">离线设备</div>
            </div>
        </div>
        <view style="padding: 20rpx 20rpx 0">
            <Cn-grid title="常用功能">
                <Cn-grid-item src="/static/device2.png" text="设备注册" @click="registerDevice"></Cn-grid-item>
                <!-- <Cn-grid-item src="/static/gateway2.png" text="网关注册" @click="registerGateway"></Cn-grid-item> -->
                <Cn-grid-item src="/static/feedback2.png" text="提交反馈" @click="submitFeedBack"></Cn-grid-item>
            </Cn-grid>
        </view>
    </view>
</template>
<script>
export default {
    data() {
        return {
            loading: false,
        }
    },
    props: {
        devCount: {
            type: Object,
            default: {},
        },
    },
    methods: {
        submitFeedBack() {
            uni.navigateTo({ url: '/pages/home/feedback' })
        },
        registerDevice() {
            uni.showModal({
                title: '提示',
                content: '请选择设备类型',
                confirmText: '直连装置',
                cancelText: '网关接入',
                cancelColor: '#007aff',
                success: ({ confirm, cancel }) => {
                    if (confirm) {
                        uni.navigateTo({
                            url: '/pages/device/new',
                        })
                    } else if (cancel) {
                        uni.navigateTo({
                            url: '/pages/gateway/list',
                        })
                    }
                },
            })
        },
        registerGateway() {
            uni.navigateTo({
                url: '/pages/gateway/new',
            })
        },
        jump(type) {
            switch (type) {
                case 'alarmLineDevs':
                    uni.navigateTo({
                        url:
                            '/pages/device/list?type=alarmLineDevs&projectList=' +
                            encodeURIComponent(JSON.stringify(this.devCount.alarmLineDevs)),
                    })
                    break
                case 'offLineDevs':
                    uni.navigateTo({
                        url:
                            '/pages/device/list?type=offLineDevs&projectList=' +
                            encodeURIComponent(JSON.stringify(this.devCount.offLineDevs)),
                    })
                    break

                default:
                    break
            }
        },
    },
}
</script>
<style lang="scss"></style>
