
function ciy_chart_farm1_r1(opdata) {
    this.func = ['farm_r1'];
    this.lastdata = {};
    this.resize = function () {
    }
    this.setdata = function (funame, data) {
        if (!data)
            return;
        this.lastdata[funame] = data;
        var html = '';
        html += '<div>';
        if(data.cameras.length > 0){
            var offline = 0;
            for(var i in data.cameras){
                if(data.cameras[i].lasttimes < data.time - 86400*7)
                    offline++;
            }
            if(offline == 0)
                html += '<div style="background: #076a01;" title="共'+data.cameras.length+'台">完美</div>';
            else if(offline < data.cameras.length / 4)
                html += '<div style="background: #009f38;" title="7日离线设备'+offline+'台，共'+data.cameras.length+'台">正常</div>';
            else if(offline < data.cameras.length / 2)
                html += '<div style="background: #d1c100;" title="7日离线设备'+offline+'台，共'+data.cameras.length+'台">告警</div>';
            else
                html += '<div style="background: #d15700;" title="7日离线设备'+offline+'台，共'+data.cameras.length+'台">严重</div>';
        }else
            html += '<div style="background: #686868;">无</div>';
        html += '<span>视频监控设备</span></div>';

        html += '<div>';
        if(data.iotrbs.length > 0){
            var errcnt = 0;
            for(var i in data.iotrbs){
                if(data.iotrbs[i].ioterrtype > 0)
                    errcnt++;
            }
            if(errcnt == 0)
                html += '<div style="background: #076a01;" title="无未处理数据">完美</div>';
            else if(errcnt < data.iotrbs.length / 4)
                html += '<div style="background: #009f38;" title="有'+errcnt+'条异常">正常</div>';
            else if(offline < data.iotrbs.length / 2)
                html += '<div style="background: #d1c100;" title="有'+errcnt+'条异常">告警</div>';
            else
                html += '<div style="background: #d15700;" title="有'+errcnt+'条异常">严重</div>';

        }else
            html += '<div style="background: #686868;">无</div>';
        html += '<span>环境监测设备</span></div>';

        html += '<div><div style="background: #686868;">无</div><span>网关设备</span></div>';

        
        $5('.ciy_chart_farm1_r1', opdata.container).html(html);
    }
    this.distory = function () {
    }

    opdata.container.append(`
    <div class="ciy_chart_farm1_r1 cehide" style="display: flex;flex-wrap: wrap;">
    </div>
    `);

    var style = document.createElement("style");
    style.innerHTML = `
    .ciy_chart_farm1_r1>div {
        display: flex;
        padding-bottom: 1em;
        width: 50%;
        font-size: 0.9em;
    }
    
    .ciy_chart_farm1_r1>div>div {
        color: #ffffff;
        width: 3em;
        padding: 0.3em 0;
        text-align: center;
        border-radius: 5px 0 0 5px;
    }
    
    .ciy_chart_farm1_r1>div>span {
        display: block;
        background: #00000099;
        margin-right: 0.5em;
        padding: 0.3em 0 0.3em 0.6em;
        flex: 1;
        border-radius: 0 5px 5px 0;
    }
    `;
    window.document.head.appendChild(style);
}