<template>
    <view class="index-zhuyonghu">
        <template v-if="devCount.engineeringListLength > 0">
            <view class="canneng-index-title mb20">所有工程设备统计</view>
            <view class="header">
                <view class="header-item" @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" @click="jump('onLineDevs')">
                    <view class="header-item-value">{{ devCount.onLineDevCount || 0 }}</view>
                    <view class="header-item-label">在线设备</view>
                </view>
                <view class="header-item" @click="jump('offLineDevs')">
                    <view class="header-item-value">{{ devCount.offLineDevCount || 0 }}</view>
                    <view class="header-item-label">离线设备</view>
                </view>
                <view class="header-item" @click="jumpMessage">
                    <view class="header-item-value">{{ devCount.alarmCount || 0 }}</view>
                    <view class="header-item-label">告警数量</view>
                </view>
                <view class="header-item" @click="jumpMessage">
                    <view class="header-item-value">{{
                        devCount.eventCount + devCount.runCount + devCount.harmonicCount || 0
                    }}</view>
                    <view class="header-item-label">事件数量</view>
                </view>
                <view class="header-item" @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">当前工程设备统计</view>
		<view class="header">
			<view class="header-item" @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" @click="jump('currentOnLineDevs')">
				<view class="header-item-value">{{ devCount.currentOnLineDevCount || 0 }}</view>
				<view class="header-item-label">在线设备</view>
			</view>
			<view class="header-item" @click="jump('currentOffLineDevs')">
				<view class="header-item-value">{{ devCount.currentOffLineDevCount || 0 }}</view>
				<view class="header-item-label">离线设备</view>
			</view>
		</view> -->
        <view class="canneng-index-title mt20">常用功能</view>
        <view style="padding: 20rpx 20rpx 0">
            <Cn-grid title="" :auto-fill="false">
                <Cn-grid-item src="/static/device2.png" text="设备注册" @click="registerDevice(4)"></Cn-grid-item>
                <Cn-grid-item
                    src="/static/device2.png"
                    text="功能调试"
                    @click="registerDevice(2)"
                    v-if="config.feature"
                ></Cn-grid-item>
                <Cn-grid-item
                    src="/static/device2.png"
                    text="出厂调试"
                    @click="registerDevice(3)"
                    v-if="config.factory"
                ></Cn-grid-item>
                <Cn-grid-item background="#fff" v-if="!config.feature"></Cn-grid-item>
                <Cn-grid-item background="#fff" v-if="!config.factory"></Cn-grid-item>
                <Cn-grid-item background="#fff"></Cn-grid-item>
                <!-- <Cn-grid-item background="#fff"></Cn-grid-item>
                <Cn-grid-item background="#fff"></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>
        <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: true,
            config: {
                feature: true,
                factory: true,
            },
            type: 0,
        }
    },
    props: {
        devCount: {
            type: Object,
            default: {},
        },
    },
    created() {
        this.init()
    },
    methods: {
        init() {
            console.log('工程init')
            let serverConfig = uni.getStorageSync(this.$cacheKey.serverConfig)
            serverConfig && (this.config = serverConfig)
        },
        submitFeedBack() {
            uni.navigateTo({ url: '/pages/home/feedback' })
        },
        registerDevice(type) {
            this.type = type
            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=' + type,
            //                 })
            //             } else {
            //                 uni.navigateTo({
            //                     url: '/pages/engineering/new?from=index&type=' + type,
            //                 })
            //             }
            //         } 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=' + this.type,
            })
            // } else {
            //     uni.navigateTo({
            //         url: '/pages/engineering/new?from=index&type=' + this.type,
            //     })
            // }

            this.$refs.popup.close()
        },
        registerGateway() {
            uni.navigateTo({
                url: '/pages/gateway/new',
            })
        },
        jump(type) {
            uni.navigateTo({
                url: '/pages/device/list?type=' + type,
            })
        },
        jumpMessage() {
            uni.switchTab({
                url: '/pages/index/message1',
            })
        },
        eningerNum() {
            uni.navigateTo({
                url: '/pages/engineering/list',
            })
        },
    },
}
</script>
<style lang="scss"></style>
