﻿<template>
    <div class="card device-component">
        <div class="card-header">
            <h3 class="card-title">
                {{device.displayName}}
                <i v-if="device.isOnline" class="text-success ion ion-ios-wifi"></i>
                <i v-else class="text-danger ion ion-ios-wifi"></i>
            </h3>
            <div class="card-tools" v-if="hasDevicePermission()">
                <span @click="visible = true" title="操作"><i class="ion ion-md-settings"></i></span>
            </div>
        </div>
        <div class="card-body">
            <div class="row">
                <div class="col-4 align-self-center">
                    <img class="device-image" :src="device.ioTProduct.image" style="width:48px;" />
                </div>
                <div class="col-8 align-self-center">
                    <div class="row">
                        <span>
                            状态：{{status}}
                        </span>
                    </div>
                </div>
            </div>
        </div>
        <a-modal v-model="visible" :title="device.displayName" :footer="null">
            <img style="height:32px;" v-if="status==='开'" v-on:click="execApi(device.number,'/Socket/Off')" src="/platform/images/on.svg" />
            <img style="height:32px;" v-else v-on:click="execApi(device.number,'/Socket/On')" src="/platform/images/off.svg" />
        </a-modal>
    </div>
</template>
<script>
    export default {
        props: ['device'],
        data: function () {
            return {
                visible: false
            }
        },
        computed: {
            status: function () {
                return getIoTDataValue(this.device, '状态') === '1' ? '开' : '关';
            }
        }
    };
</script>