<template>
    <view class="index-zhuyonghu">
        <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>
            <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('0')">
                <view class="header-item-value">{{ devCount.currentEventCount || 0 }}</view>
                <view class="header-item-label">暂态事件数</view>
            </view>
            <view class="header-item boxClick" @click="jumpMessage('1')">
                <view class="header-item-value">{{ devCount.currentHarmonicCount || 0 }}</view>
                <view class="header-item-label">稳态事件数</view>
            </view>
        </view>
        <view class="canneng-index-title mt20 ml20 canneng-index-title-with-icon">
            <uni-icons type="settings" size="18" color="#376cf3" />
            <text>常用功能</text>
        </view>
        <view style="padding: 20rpx 20rpx 0">
            <Cn-grid title="">
                <Cn-grid-item
                    src="/static/device2.png"
                    class="boxClick"
                    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"
                    class="boxClick"
                    text="问题反馈"
                    @click="submitFeedBack"
                ></Cn-grid-item>
            </Cn-grid>
        </view>
        <uni-popup ref="popup" type="dialog" @maskClick="maskClick">
            <uni-popup-dialog
                mode="base"
                type="info"
                content="请选择设备类型"
                :duration="0"
                confirmText="直连设备"
                cancelText="网关接入"
                cancelColor="#007aff"
                @close="close"
                @confirm="confirm"
            ></uni-popup-dialog>
        </uni-popup>
    </view>
</template>
<script>
export default {
    data() {
        return {
            loading: false,
        }
    },
    props: {
        devCount: {
            type: Object,
            default: {},
        },
    },
    methods: {
        submitFeedBack() {
            uni.navigateTo({ url: '/pages/home/feedback' })
        },
        registerDevice() {
            this.$refs.popup.open()
            // uni.showModal({
            //     title: '提示',
            //     content: '请选择设备类型',
            //     confirmText: '直连设备',
            //     cancelText: '网关接入',
            //     cancelColor: '#007aff',
            //     success: ({confirm, cancel}) => {
            //         if (confirm) {
            //             if (this.devCount.engineeringListLength > 0) {
            //                 uni.navigateTo({
            //                     url: '/pages/device/new?type=4',
            //                 })
            //             } else {
            //                 uni.navigateTo({
            //                     url: '/pages/engineering/new?from=index'
            //                 })
            //             }

            //         } else if (cancel) {
            //             // uni.navigateTo({
            //             //     url: '/pages/gateway/list',
            //             // })
            //             this.$util.toast('功能正在开发，敬请期待')
            //         }
            //     },
            // })
        },
        maskClick() {
            this.$refs.popup.close()
        },
        close() {
            this.$util.toast('功能正在开发，敬请期待')
            this.$refs.popup.close()
        },
        confirm(value) {
            // if (this.devCount.engineeringListLength > 0) {
            uni.navigateTo({
                url: '/pages/device/new?type=4',
            })
            // } else {
            //     uni.navigateTo({
            //         url: '/pages/engineering/new?from=index',
            //     })
            // }

            this.$refs.popup.close()
        },
        registerGateway() {
            uni.navigateTo({
                url: '/pages/gateway/new',
            })
        },
        jump(type) {
            uni.navigateTo({
                url: '/pages/device/list?type=' + type,
            })
        },
        jumpMessage(type) {
            uni.setStorageSync('messageParams', {
                engineeringName: '',
                engineeringId: '', //工程ID
                projectName: '',
                projectId: '', //項目ID
                deviceName: '',
                deviceId: '', //设备ID
                lineName: '',
                lineId: '', //测点ID
                type: type,
            })
            uni.switchTab({
                url: '/pages/index/message1',
            })
        },
    },
}
</script>
<style lang="scss">
.index-zhuyonghu {
    .canneng-index-title-with-icon {
        display: inline-flex;
        align-items: center;
        gap: 8rpx;
        font-size: 30rpx;
    }
}
</style>
