home.html 27.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>云API</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
</head>

<body class="home-view">
    <div class="aui-content aui-margin-b-15 aui-padded-10 aui-padded-t-15">
        <header id="header">
          <h3 class="app-title">罗电物联网用电安全</h3>
          <div class="equipment-switch">
              <p class="aui-pull-left" id="currentDevice">暂无设备</p>
              <p class="aui-pull-right" onclick="choseDevice();"><img style="height:16px;" src="../image/qiehuan-s.png" /><span>切换设备</span></p>
              <div class="aui-clearfix"></div>
          </div>
        </header>
        <div class="equipment-total-info">
          <div class="equipment-total-info-view">
            <ul class="equipment-info-top">
              <li><label class="aui-font-size-14">状态</label><span class="aui-font-size-18" id="deviceStatus">离线</span></li>
              <li><label class="aui-font-size-14">开关</label><span class="aui-font-size-18" id="deviceGate">分闸</span></li>
              <div class="aui-clearfix"></div>
            </ul>
            <ul class="equipment-info-bottom">
              <li onclick="removeDanger()"><label class="aui-font-size-12">消除隐患</label><span><big id="action_count">0</big><em>&nbsp;></em></span></li>
              <li onclick="deviceAlarm()"><label class="aui-font-size-12">历史报警</label><span><big id="warning_count">0</big><em>&nbsp;></em></span></li>
              <li onclick="optionsSet()"><label class="aui-font-size-12">参数设置</label><span><big class="special-item">设定</big><em>&nbsp;></em></span></li>
              <div class="aui-clearfix"></div>
            </ul>
          </div>
        </div>
        <p class="aui-pull-left aui-margin-t-10" id="warnTotal" style="display:none">暂无报警</p>
        <div class="equipment-info-warning" id="warnList" style="display:none">
          <ul id="warnListUl">
          </ul>
        </div>
        <p class="aui-pull-left aui-margin-t-10">操作</p>
        <div class="aui-clearfix"></div>
        <div class="equipment-info-check">
          <ul>
            <li><div onclick="opCommand('&S9+', 4, '分闸');"><img src="../image/fenzha.png" /><p class="aui-ellipsis-1">分闸</p></div></li>
            <li><div onclick="opCommand('&S9+', 2, '消音');"><img src="../image/xiaoyin.png" /><p class="aui-ellipsis-1">消音</p></div></li>
            <li><div onclick="opCommand('&S9+', 16, '复位');"><img src="../image/fuwei.png" /><p class="aui-ellipsis-1">复位</p></div></li>
            <li><div onclick="opCommand('&S9+', 8, '自检');"><img src="../image/zijian.png" /><p class="aui-ellipsis-1">自检</p></div></li>
            <div class="aui-clearfix"></div>
          </ul>
        </div>
        <p class="aui-pull-left">当前设备测量信息</p>
        <div class="aui-clearfix"></div>
        <div class="equipment-info-list">
          <ul>
            <li id="dianliuInfo"><img class="img-normal" src="../image/dianliu.png" /><img class="img-special" src="../image/dianliu-s.png" /><span>电流</span><label class="aui-pull-right" id="dianliuVal">0.0&nbsp;&nbsp;A</label></li>
            <li id="shengyudianliuInfo"><img class="img-normal" src="../image/dianliu.png" /><img class="img-special" src="../image/dianliu-s.png" /><span>剩余电流</span><label class="aui-pull-right" id="shengyudianliuVal">0.0&nbsp;&nbsp;mA</label></li>
            <li id="dianyaInfo"><img class="img-normal" src="../image/dianliu.png" /><img class="img-special" src="../image/dianliu-s.png" /><span>电压</span><label class="aui-pull-right" id="dianyaVal">0.0&nbsp;&nbsp;V</label></li>
            <li id="pinlvInfo"><img class="img-normal" style="margin-left:7px;margin-right:0px;" src="../image/pinlv.png" /><img class="img-special" style="margin-left:7px;margin-right:0px;" src="../image/pinlv-s.png" /><span>频率</span><label class="aui-pull-right" id="pinlvVal">0.0&nbsp;&nbsp;Hz</label></li>
            <li id="xianlanInfo"><img class="img-normal" style="margin-left:18px;margin-right:12px;" src="../image/wendu.png" /><img class="img-special" style="margin-left:18px;margin-right:12px;" src="../image/wendu-s.png" /><span>线缆温度</span><label class="aui-pull-right" id="xianlanVal">0.0&nbsp;&nbsp;</label></li>
            <li id="neibuwendu1Info"><img class="img-normal" style="margin-left:18px;margin-right:12px;" src="../image/wendu.png" /><img class="img-special" style="margin-left:18px;margin-right:12px;" src="../image/wendu-s.png" /><span>内部温区1</span><label class="aui-pull-right" id="neibuwendu1Val">0.0&nbsp;&nbsp;</label></li>
            <li id="neibuwendu2Info"><img class="img-normal" style="margin-left:18px;margin-right:12px;" src="../image/wendu.png" /><img class="img-special" style="margin-left:18px;margin-right:12px;" src="../image/wendu-s.png" /><span>内部温区2</span><label class="aui-pull-right" id="neibuwendu2Val">0.0&nbsp;&nbsp;</label></li>
          </ul>
        </div>
        <div class="aui-bar aui-bar-btn" id="tab">
          <div id="mytab_1" class="aui-bar-btn-item aui-active" onclick="randomSwitchBtn(this,1)">电流
          </div><div id="mytab_2" class="aui-bar-btn-item" onclick="randomSwitchBtn(this,2)">剩余电流
          </div><div id="mytab_3" class="aui-bar-btn-item" onclick="randomSwitchBtn(this,3)">电压
          </div><div id="mytab_4" class="aui-bar-btn-item" onclick="randomSwitchBtn(this,4)">频率
          </div><div id="mytab_5" class="aui-bar-btn-item" onclick="randomSwitchBtn(this,5)">线缆温度
          </div><div id="mytab_6" class="aui-bar-btn-item" onclick="randomSwitchBtn(this,6)">内部温区1
          </div><div id="mytab_7" class="aui-bar-btn-item" onclick="randomSwitchBtn(this,7)">内部温区2</div>
        </div>
        <div class="tab-view-list" id="echarts_view" style="height:15rem;">
            <div id="echarts_1" class="echarts_view_item"></div>
            <div id="echarts_2" class="echarts_view_item"></div>
            <div id="echarts_3" class="echarts_view_item"></div>
            <div id="echarts_4" class="echarts_view_item"></div>
            <div id="echarts_5" class="echarts_view_item"></div>
            <div id="echarts_6" class="echarts_view_item"></div>
            <div id="echarts_7" class="echarts_view_item"></div>
        </div>
    </div>
    <div class="bar-shadow"></div>
</body>

</html>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="../script/echarts.min.js"></script>
<script type="text/javascript">
    var header = $api.byId('header');
    var imei = '';
    var circled = false;
    var deviceCircleInterval;
    var token='';
    fixStatusBar_API(header);
    apiready = function() {
        loadInfoIndex();
        $('body').scrollTop(0);

        //注册事件
        api.addEventListener({
            name: 'change_device'
        }, function(ret, err){
            if( ret && ret.value.imei ){
                 if(!ret.value.isHome){
                   circled = false;
                   imei = ret.value.imei;
                   if(deviceCircleInterval){
                     clearInterval(deviceCircleInterval);
                   }
                   //$(".echarts_view_item").html('');

                   loadInfoIndex();
                   randomSwitchBtn($api.byId("mytab_1"),1);
                   $("#mytab_1").addClass("aui-active");
                 }

            }
        });

        /** 下拉刷新 */
        api.setRefreshHeaderInfo({
            loadingImg:'../image/loading_more.gif',
            bgColor: 'rgba(255,255,255,1)',
            textColor: '#000',
            textDown: '下拉刷新...',
            textUp: '松开刷新...'
        }, function(ret, err) {
              loadInfoIndex();
              randomSwitchBtn($api.byId("mytab_1"),1);
              $("#mytab_1").addClass("aui-active");
              $('body').scrollTop(0);
              api.refreshHeaderLoadDone();
        });

    }
    var chartTypeArr = ["current","rest_current", "voltage", "rate", "line_temp","temp1", "temp2"];
    var chartTypeUnitArr = ["A", "mA", "V","Hz", "℃", "℃", "℃"];
    var chartNameArr = ["电流", "剩余电流", "电压","频率", "线缆温度", "内部温度1", "内部温度2"];
    function randomSwitchBtn(obj, index){


      var mytab = $api.byId('tab');
        var mytabAct = $api.dom(mytab, '.aui-bar-btn-item.aui-active');
        $api.removeCls(mytabAct, 'aui-active');
        $api.addCls(obj, 'aui-active');

        //$api.html($api.dom($api.byId("echarts_view"), '.echarts_view_item'), 'display:none;');
        $(".echarts_view_item").hide();

        loadDailyChart(index, imei, token, false);
    }
    function removeDanger(){
      api.openWin({ slidBackEnabled:false,
          name: 'removeDanger',
          url: 'removeDanger.html',
          pageParam: {}
      });
    }
    function deviceAlarm(){
      api.openWin({ slidBackEnabled:false,
          name: 'deviceAlarm',
          url: 'deviceAlarm.html',
          pageParam: {}
      });
    }
    function optionsSet(){
      api.openWin({ slidBackEnabled:false,
          name: 'equipment',
          url: 'equipment.html',
          pageParam: {}
      });
    }

    function loadInfoIndex(){
      api.showProgress({
          style: 'default',
          animationType: 'fade',
          title: '加载中...',
          text: '',
          modal: true
      });

      token = $api.getStorage('userToken');
      var userID = $api.getStorage('userID');
      if(token && token != ''){
        //先获取设备列表
        $.ajax({
          url: HOST + '/iot_api/v1/app/bind_list?user_id='+userID,
          type: 'GET',
          dataType: 'json',
          headers: {
              'Content-Type': 'application/json;charset=utf-8',
              'token': token
          },
          success: function(ret) {
            api.hideProgress();
              if (ret) {
                  if (ret.code == 0) {
                      var deviceList = ret.data.list;
                      if(!deviceList || deviceList.length==0){
                        $api.setStorage('devices', JSON.stringify([]));
                        api.alert({
                          title: '添加设备',
                          msg: '暂无设备,请先添加设备...',
                        }, function(ret, err){
                            if( ret ){
                                 openCanner(true);
                            }
                        });

                        // api.confirm({
                        //     title: '添加设备',
                        //     msg: '暂无设备,请先添加设备...',
                        //     buttons: ['确定', '取消']
                        // }, function(ret, err){
                        //     if( ret && ret.buttonIndex==1){
                        //          openCanner(true);
                        //     }else{
                        //       api.closeWidget({
                        //         silent: true
                        //       });
                        //     }
                        // });
                        return false;
                      }else{
                        $api.setStorage('devices', JSON.stringify(deviceList));
                        //确认默认设备
                        var defDev = deviceList[0];
                        if(!defDev.default){
                          for(var i in deviceList){
                            if(i!=0){
                              if(deviceList[i].default){
                                defDev = deviceList[i];
                                break;
                              }
                            }
                          }
                        }
                        imei = defDev.imei;
                        $api.setStorage('defaultDevice', defDev.imei);
                        api.sendEvent({
                            name: 'change_device',
                            extra: {
                                imei: imei,
                                isHome:true
                            }
                        });
                        loadDeviceInfo(defDev.imei, token);
                        loadDailyChart(1, defDev.imei, token, true);
                      }
                  }else{
                    api.toast({
                        msg: '获取设备列表失败',
                        duration: 2000,
                        location: 'bottom'
                    });

                  }
              }
          },
          error: function() {
            api.hideProgress();
            api.toast({
                msg: '获取设备列表失败',
                duration: 2000,
                location: 'bottom'
            });
          }
      });
    }
    }


    function startLoadWarnCount(){
      var userId = $api.getStorage('userID');
      var token = $api.getStorage('userToken');

      if(token && userId && userId != ''){
        $.ajax({
          url: HOST + '/iot_api/v1/app/get_unsloved_warning_count?user_id='+userId,
          type: 'GET',
          dataType: 'json',
          headers: {
              'Content-Type': 'application/json;charset=utf-8',
              'token': token
          },
          success: function(ret) {
              if (ret) {
                  if (ret.code == 0) {
                        api.sendEvent({
                            name: 'warning_count',
                            extra: {
                                total: ret.data
                            }
                        });

                      }

                  }
              },
          error: function() {

          }
      });
      }

    }

    function loadDeviceInfo(imei, token){
      $api.html($api.byId("currentDevice"), "设备编号:"+imei);
      loadDeviceTotalCount(imei, token);
      startLoadWarnCount();
      $.ajax({
        url: HOST + '/iot_api/v1/app/device?imei='+imei,
        type: 'GET',
        dataType: 'json',
        headers: {
            'Content-Type': 'application/json;charset=utf-8',
            'token': token
        },
        success: function(ret) {
            if (ret) {
                if (ret.code == 0) {
                    var deviceInfo = ret.data.device;
                    if(deviceInfo){
                      showDevice(deviceInfo);
                      //初步显示结束之后,进行接下来的回环
                      if(!circled){
                        circleShowDevice(imei, token, function(){
                          //loadDeviceInfo()
                          loadInfoIndex();
                        });
                      }

                    }

                }else{
                  api.toast({
                      msg: '获取设备信息失败,请稍候再试',
                      duration: 4000,
                      location: 'bottom'
                  });

                }
            }
        },
        error: function() {
          api.hideProgress();
          api.toast({
              msg: '获取设备信息失败,请退出重试',
              duration: 4000,
              location: 'bottom'
          });
        }
    });
    }

  function showDevice(info){
    if(info.online){
      $api.html($api.byId("deviceStatus"), '在线');
    }else{
      $api.html($api.byId("deviceStatus"), '离线');
    }

    if(info.gate_status == "1"){
      $api.html($api.byId("deviceGate"), '合闸');
    }else{
      $api.html($api.byId("deviceGate"), '分闸');
    }

    //统计告警信息
    var total = 0;
    $api.html($api.byId("warnListUl"), "");
    var warningStr = "";
    if(info.over_current_warning == "1"){
      total++;
      warningStr += '<li><img src="../image/jingbaotishi.png" /><p class="aui-ellipsis-1">过载报警</p></li>'
    }
    if(info.short_curent_warning == "1"){
      total++;
      warningStr += '<li><img src="../image/jingbaotishi.png" /><p class="aui-ellipsis-1">短路报警</p></li>'
    }
    if(info.rest_current_warning == "1"){
      total++;
      warningStr += '<li><img src="../image/jingbaotishi.png" /><p class="aui-ellipsis-1">漏电报警</p></li>'
    }
    if(info.over_high_voltage_warning == "1"){
      total++;
      warningStr += '<li><img src="../image/jingbaotishi.png" /><p class="aui-ellipsis-1">过压报警</p></li>'
    }
    if(info.over_low_voltage_warning == "1"){
      total++;
      warningStr += '<li><img src="../image/jingbaotishi.png" /><p class="aui-ellipsis-1">欠压报警</p></li>'
    }
    if(info.over_line_temp_warning == "1"){
      total++;
      warningStr += '<li><img src="../image/jingbaotishi.png" /><p class="aui-ellipsis-1">线缆超温报警</p></li>'
    }
    if(info.over_temp1_warning == "1"){
      total++;
      warningStr += '<li><img src="../image/jingbaotishi.png" /><p class="aui-ellipsis-1">产品内部超温</p></li>'
    }
    if(info.fan_error == "1"){
      total++;
      warningStr += '<li><img src="../image/jingbaotishi.png" /><p class="aui-ellipsis-1">风扇异常</p></li>'
    }
    if(info.IGBT_error == "1"){
      total++;
      warningStr += '<li><img src="../image/jingbaotishi.png" /><p class="aui-ellipsis-1">IGBT驱动异常</p></li>'
    }
    if(info.param_error == "1"){
      total++;
      warningStr += '<li><img src="../image/jingbaotishi.png" /><p class="aui-ellipsis-1">参数存储异常</p></li>'
    }
    if(info.sign_error == "1"){
      total++;
      warningStr += '<li><img src="../image/jingbaotishi.png" /><p class="aui-ellipsis-1">信号测量异常</p></li>'
    }
    if(total == 0){
      //未有告警
      $("#warnTotal").hide();
      $("#warnList").hide();
      $api.html($api.byId("warnTotal"), "");
    }else{
      $api.html($api.byId("warnTotal"), "当前共"+total+"条告警");
      $api.html($api.byId("warnListUl"), warningStr);
      $("#warnTotal").show();
      $("#warnList").show();
    }

    //显示设备动态信息
    $api.html($api.byId("dianliuVal"), info.etc_current+"&nbsp;&nbsp;A");
    $api.html($api.byId("shengyudianliuVal"), info.etc_rest_current+"&nbsp;&nbsp;mA");
    $api.html($api.byId("dianyaVal"), info.etc_voltage+"&nbsp;&nbsp;V");
    $api.html($api.byId("pinlvVal"), info.etc_rate+"&nbsp;&nbsp;Hz");
    $api.html($api.byId("xianlanVal"), info.etc_line_temp+"&nbsp;&nbsp;℃");
    $api.html($api.byId("neibuwendu1Val"), info.etc_temp1+"&nbsp;&nbsp;℃");
    $api.html($api.byId("neibuwendu2Val"), info.etc_temp2+"&nbsp;&nbsp;℃");

    if(info.etc_current>info.over_current){
      $("#dianliuInfo").addClass("equipment-item-warning");
    }else{
      $("#dianliuInfo").removeClass("equipment-item-warning");
    }
    if(info.etc_voltage < info.over_low_voltage || info.etc_voltage > info.over_high_voltage){
      $("#dianyaInfo").addClass("equipment-item-warning");
    }else{
      $("#dianyaInfo").removeClass("equipment-item-warning");
    }
    if(info.etc_line_temp > info.over_temp){
      $("#xianlanInfo").addClass("equipment-item-warning");
    }else{
      $("#xianlanInfo").removeClass("equipment-item-warning");
    }
    // if(info.etc_temp1 > info.over_temp){
    //   $("#neibuwendu1Info").addClass("equipment-item-warning");
    // }
    // if(info.etc_temp2 > info.over_temp){
    //   $("#neibuwendu2Info").addClass("equipment-item-warning");
    // }
  }

  function circleShowDevice(imei, token, func){
    circled = true;
    $.ajax({
      url: HOST + '/iot_api/v1/app/sync_device',
      type: 'POST',
      dataType: 'json',
      headers: {
          'Content-Type': 'application/json;charset=utf-8',
          'token': token
      },
      data:JSON.stringify({
        "imei":imei
      }),
      success: function(ret) {
          if (ret) {
              if (ret.code == 0) {
                   // 下面开始每隔1分钟更新一次设备信息
                   deviceCircleInterval = setInterval(function(){
                     loadDeviceInfo(imei, token);
                   }, 60 *1000);
                   if(func){
                     func();
                   }
                  }
              }
          },
      error: function() {
      }
  });
  }

  function loadDeviceTotalCount(imei, token){
    $.ajax({
      url: HOST + '/iot_api/v1/app/get_warning_and_action_count?imei='+imei,
      type: 'GET',
      dataType: 'json',
      headers: {
          'Content-Type': 'application/json;charset=utf-8',
          'token': token
      },
      success: function(ret) {
          if (ret) {
              if (ret.code == 0) {
                    $api.html($api.byId("warning_count"), ret.data.warning_count);
                    $api.html($api.byId("action_count"), ret.data.action_count);
                  }
              }
          },
      error: function() {
      }
  });
  }

  function opCommand(cmd, val, opName){
    api.confirm({
        title: '操作确认',
        msg: '确认执行'+opName+'操作?',
        buttons: ['确定', '取消']
    }, function(ret, err){
        if( ret && ret.buttonIndex == 1){
          var token = $api.getStorage('userToken');
          var userId = $api.getStorage('userID');
          if(token && token != '' && imei != '' && userId && userId != ''){
            api.showProgress({
                style: 'default',
                animationType: 'fade',
                title: '操作请求中...',
                text: '',
                modal: true
            });
            $.ajax({
              url: HOST + '/iot_api/v1/app/set_device',
              type: 'POST',
              dataType: 'json',
              headers: {
                  'Content-Type': 'application/json;charset=utf-8',
                  'token': token
              },
              data:JSON.stringify({
                imei:imei,
                command:cmd,
                value:val.toString(),
                user_id:userId
              }),
              complete:function(){
                api.hideProgress();
              },
              success: function(ret) {
                  if (ret) {
                      if (ret.code == 0) {
                            api.toast({
                                msg: '操作成功',
                                duration: 3000,
                                location: 'bottom'
                            });
                            circled = false;
                            //imei = ret.value.imei;
                            if(deviceCircleInterval){
                              clearInterval(deviceCircleInterval);
                            }
                            //$(".echarts_view_item").html('');
                            loadInfoIndex();
                            randomSwitchBtn($api.byId("#mytab_1"),1);
                            $("#mytab_1").addClass("aui-active");
                            //loadDeviceInfo(imei, token)
                          }else{
                            api.toast({
                                msg: '操作失败,请稍候再试!',
                                duration: 3000,
                                location: 'bottom'
                            });
                          }
                      }else{
                        api.toast({
                            msg: '操作失败,请稍候再试!',
                            duration: 3000,
                            location: 'bottom'
                        });
                      }
                  },
              error: function() {
                api.toast({
                    msg: '操作失败,请稍候再试!',
                    duration: 3000,
                    location: 'bottom'
                });
              }
            });
          }
        }
    });



  }

  function loadDailyChart(index, imei, token, isFirst){
    var chartType = chartTypeArr[index-1];
    var chartTypeUnit = chartTypeUnitArr[index-1];
    var chartName = chartNameArr[index-1];
    if(!isFirst){
      api.showProgress({
          style: 'default',
          animationType: 'fade',
          title: '正在加载中...',
          text: '',
          modal: true
      });

    }
    $.ajax({
      url: HOST + '/iot_api/v1/app/chart_daily?imei='+imei+'&type='+chartType,
      type: 'GET',
      dataType: 'json',
      headers: {
          'Content-Type': 'application/json;charset=utf-8',
          'token': token
      },
      complete:function(){
        if(!isFirst){
          api.hideProgress();
        }
      },
      success: function(ret) {
          if (ret) {
              if (ret.code == 0) {
                    //console.log(JSON.stringify(ret))
                    var targetView = $api.byId("echarts_"+index);
                    $(".echarts_view_item").hide();
                    $api.css(targetView, 'display:block;height:15rem;');
                    var myChart = echarts.init(targetView);
                    var app = {};
                    option = null;
                    option = {
                        title: {
                            left: 'center',
                            text: chartName+'趋势变化图',
                        },
                        grid: {
                             x: 50,
                             y: 50
                        },
                      //   tooltip: {
                      //     trigger: 'axis',
                      //     formatter: function (params) {
                      //         params = params[0];
                      //         return params.axisValue+' '+params.data+chartTypeUnit;
                      //     },
                      //     axisPointer: {
                      //         animation: false
                      //     }
                      // },
                      tooltip: {
                          trigger: 'axis',
                          position: 'top',
                          formatter: function (params) {
                                params = params[0];
                                return params.axisValue+'<br />'+params.marker+params.seriesName+'值 '+params.data+chartTypeUnit;
                            },
                      },
                        xAxis: {
                            type: 'category',
                            boundaryGap: false,
                            data: ret.data.date.map(function(item){
                              return item.substring(11,16)
                            })
                        },
                        yAxis: {
                            type: 'value',
                            boundaryGap: [0, '100%'],
                            axisLabel: {
                                formatter: '{value} '+chartTypeUnit
                            }
                        },
                        series: [{
                            data: ret.data[chartType],
                            name:chartName,
                            type:'line',
                            showSymbol: false,
                            hoverAnimation: false
                        }]
                    };;
                    if (option && typeof option === "object") {
                        myChart.setOption(option, true);
                    }

                    // if(!isFirst){
                    //   var sysType = $api.getStorage('SYSTEMTYPE');
                    //   if (sysType == 'ios') {
                    //     setTimeout(function(){
                    //       api.pageDown();
                    //     },500);
                    //   }
                    // }
                  }
              }
          },
      error: function() {
      }
  });
  }
</script>