<!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"
    />
    <meta name="format-detection" content="telephone=no" />
    <title>index</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/style.css" />
    <link rel="stylesheet" href="../../css/projeck.css" />
  </head>
  <style>
    body,
    html {
      background: #ececee;
    }

    .api_layout {
      /* border-top: 1px solid #37b0e9; */
      padding: 8px 10px;
      -webkit-box-sizing: border-box;
      -moz-box-sizing: border-box;
      box-sizing: border-box;
    }

    .top {
      width: 100%;
      height: 200px;
      position: relative;
    }

    .top img {
      width: 100%;
      height: 100%;
      border-radius: 10px;
    }

    .top p {
      position: absolute;
      right: 8px;
      bottom: 8px;
      font-weight: bold;
      font-size: 15px;
    }

    .content {
      padding: 15px;
      background: white;
      -webkit-box-sizing: border-box;
      -moz-box-sizing: border-box;
      box-sizing: border-box;
      width: 100%;
      /* margin-bottom: 13px; */
      margin-top: 6px;
      position: relative;
      padding-top: 13px;
      box-shadow: 0 3px 29px 0 rgba(59, 74, 116, 0.14);
    }

    .borderRa {
      -webkit-border-radius: 10px;
      -moz-border-radius: 10px;
      border-radius: 10px;
    }

    .con_two {
      display: inline-block;
      height: 100%;
    }

    .content .title {
      text-align: center;
      font-size: 15px;
      color: #222627;
      font-weight: bold;
    }

    .borderRa:after {
      content: '';
      position: absolute;
      top: 50px;
      left: 0;
      width: 100%;
      height: 1px;
      background: #f3f3f3;
    }

    .content .condition {
      display: inline-block;
      width: 100%;
      height: 140px;
      background: white;
      position: relative;
      padding-top: 30px;
    }

    .condition .draught {
      width: 14px;
      height: 14px;
      border-radius: 50%;
      background: #ff3d27;
    }
    .circular-name {
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .circular-name span {
      font-size: 15px;
      margin-left: 5px;
    }
    .content .condition .statistical {
      display: inline-block;
      width: 100%;
    }
    .content .condition .statistical img {
      width: 100%;
      height: 100%;
    }

    .con {
      display: inline-block;
      width: 100%;
      height: 100%;
      padding: 0;
    }

    #tab_bar {
      width: 100%;
      height: 30px;
    }

    #tab_bar ul {
      padding: 0px;
      margin: 0px;
      height: 30px;
      text-align: center;
      border-bottom: 1px solid #f8f8fb;
    }

    #tab_bar li {
      list-style-type: none;
      float: left;
      width: 90px;
      height: 30px;
      line-height: 24px;
      color: #222627;
    }

    .tab_css {
      width: 100%;
      display: none;
      margin-top: 10px;
    }

    .tab_css .head {
      width: 100%;
      height: 40px;
      background: #f3f6fa;
      border-radius: 2px;
      color: #222627;
      display: flex;
      justify-content: space-between;
    }

    .head li {
      list-style: none;
      line-height: 40px;
      width: 25%;
      color: #222627;
      font-size: 13px;
      text-align: center;
    }

    .head li:first-child {
      width: 50%;
    }

    .items {
      padding: 0;
      margin: 0;
      width: 100%;
      border-radius: 2px;
      color: #222627;
    }

    .items .list {
      padding: 10px 0;
      text-align: center;
      display: flex;
      justify-content: space-between;
      position: relative;
      align-items: center;
    }

    .items .list span {
      width: 25%;
      color: #222627;
      font-size: 13px;
    }

    .list span:first-child {
      width: 50%;
      padding: 0 5px;
      box-sizing: border-box;
    }

    .list::after {
      content: '';
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
      height: 1px;
      background: #e8e9ea;
    }

    .list span:nth-child(2) {
      background: #64dcff;
      height: 20px;
      line-height: 20px;
    }
    #contents {
      margin-top: 23px;
    }
  </style>

  <body>
    <div class="api_layout">
      <div class="top">
        <img src="../../image/tou.jpeg" alt="" />
        <p class="time-box"></p>
      </div>
      <div class="content borderRa">
        <p class="title">风机运行状况</p>
        <pseudo:after></pseudo:after>
        <div class="condition">
          <div class="Chart flex-space" id="fanStatus"></div>
          <p
            style="
              margin-top: 20px;
              height: 13px;
              font-size: 14px;
              margin-left: 15px;
              line-height: 13px;
            "
          >
            风量小时趋势
          </p>
          <div class="statistical">
            <div class="" style="width: 100%;">
              <canvas
                id="downWell"
                style="width: 100%; height: 204px;"
              ></canvas>
            </div>
          </div>
        </div>
      </div>
      <div class="content borderRa con_two" style="padding: 15px 5px;">
        <p class="title">风机参数</p>
        <pseudo:after></pseudo:after>
        <div id="contents" class="con">
          <div id="tab_bar">
            <ul>
              <li
                id="tab1"
                onclick="myclick(1)"
                style="
                  color: #3498db;
                  border-bottom: 2px solid #009fe8;
                  font-weight: bold;
                "
              >
                1#风机
              </li>
              <li id="tab2" onclick="myclick(2)">
                2#风机
              </li>
            </ul>
            <div class="" style="width: 100%;">
              <canvas id="downWell" style="width: 100%; height: 10px;"></canvas>
            </div>
          </div>
          <div class="tab_css" id="tab1_content" style="display: block;"></div>
          <div class="tab_css" id="tab2_content"></div>
        </div>
      </div>
    </div>
  </body>
  <script type="text/template" id="fanStatusTemplate">
    <div style="width:50%" class="canvasParent centertT">
      <div class="circular-name">
        <i class="draught" style="background:#{{=it.blower1=='close'?'ff3d27':'00b067'}}"></i>
        <span class="canvasTitle">1#风机</span>
      </div>
     <img src="../../icon/{{=it.blower1=='close'?'ju.png':'status.gif'}}" alt="" style="width: 100px;height: 100px;margin-top: 9px;">
    </div>
    <div class="centertT" style="width:50%">
      <div class="circular-name">
        <div class="draught" style="background:#{{=it.blower2=='close'?'ff3d27':'00b067'}}"></div>
        <span class="canvasTitle">2#风机</span>
      </div>
      <img src="../../icon/{{=it.blower2=='close'?'ju.png':'status.gif'}}" alt="" style="width: 100px;height: 100px;margin-top: 9px;">
    </div>
  </script>
  <script type="text/template" id="fanTemplate">
    <ul class="head">
        <li>参数名称</li>
        <li>数值</li>
        <li>单位</li>
    </ul>
    <ul class="items">
      {{ for (var i = 0;i<it.data.length;i++) { }}
        <li class="list">
            <span>{{=it.data[i].name}}</span>
            <span>{{=it.data[i].value}}</span>
            <span>{{=it.data[i].unit}}</span>
        </li>
      {{ } }}
    </ul>
  </script>
  <script type="text/template" id="fan2Template">
    <ul class="head">
        <li>参数名称</li>
        <li>数值</li>
        <li>单位</li>
    </ul>
    <ul class="items">
      {{ for (var i = 0;i<it.data.length;i++) { }}
        <li class="list">
            <span>{{=it.data[i].name}}</span>
            <span>{{=it.data[i].value}}</span>
            <span>{{=it.data[i].unit}}</span>
        </li>
      {{ } }}
    </ul>
  </script>
  <script type="text/javascript" src="../../script/api.js"></script>
  <script src="../../script/f2.js"></script>
  <script type="text/javascript" src="../../script/doT.min.js"></script>
  <script type="text/javascript" src="../../script/config.js"></script>
  <script type="text/javascript">
    var header = '';
    apiready = function () {
      setInterval(function () {
        $api.html($api.dom('.time-box'), getNowFormatDate());
      }, 1000);
      var info = $api.getStorage('data'),
        token = JSON.parse(info).data.access_token;
      headers = {
        Authorization: 'Bearer ' + token,
      };
      getFanStatus(headers);
      getCanvasData(headers);
      fanData(1);
    };
    // 风机状态
    function getFanStatus(headers) {
      $http.fnReuestDataNologing(
        jinfengUrlRouter.getFanStatus,
        headers,
        'get',
        '',
        function (ret, err) {
          if (ret.code === 0) {
            $apis.html(fanStatus, '#fanStatusTemplate', ret.data);
          }
        }
      );
    }
    // 风量趋势
    function getCanvasData(headers) {
      $http.fnReuestDataNologing(
        jinfengUrlRouter.getFanData,
        headers,
        'get',
        '',
        function (ret, err) {
          if (ret.code === 0) {
            var data = ret.data;
            var chart = new F2.Chart({
              id: 'downWell',
              pixelRatio: window.devicePixelRatio,
            });
            var defs = {
              tem: {
                tickCount: 5,
                min: 0,
                alias: '风量',
              },
            };
            chart.source(data, defs);
            chart.axis('time', {
              label: function label(text, index, total) {
                var textCfg = {};
                if (index === 0) {
                  textCfg.textAlign = 'right';
                } else if (index === total - 1) {
                  textCfg.textAlign = 'center';
                }
                return textCfg;
              },
            });
            chart.tooltip({
              showCrosshairs: true,
            });
            chart.line().position('time*tem').shape('smooth');
            chart.point().position('time*tem').shape('smooth').style({
              stroke: '#fff',
              lineWidth: 1,
            });
            chart.render();
          }
        }
      );
    }
    // #1,#2,风机数据
    function fanData(type) {
      $http.fnReuestDataNologing(
        jinfengUrlRouter.getFanDatas,
        header,
        'post',
        {num: type},
        function (ret, err) {
          if (ret.code === 0) {
            if (type == 1) {
              $apis.html(tab1_content, '#fanTemplate', ret);
            } else {
              $apis.html(tab2_content, '#fan2Template', ret);
            }
          }
        }
      );
    }
    // tab切换
    var myclick = function (v) {
      var llis = document.getElementsByTagName('li');
      for (var i = 0; i < llis.length; i++) {
        var lli = llis[i];
        if (lli == document.getElementById('tab' + v)) {
          lli.style['border-bottom'] = '2px solid #009FE8';
          lli.style.color = '#3498DB';
          lli.style.fontWeight = 'bold';
        } else {
          lli.style['border-bottom'] = 'none';
          lli.style.color = '#273438';
          lli.style.fontWeight = 'normal';
        }
      }
      var divs = document.getElementsByClassName('tab_css');
      for (var i = 0; i < divs.length; i++) {
        var divv = divs[i];
        if (divv == document.getElementById('tab' + v + '_content')) {
          divv.style.display = 'block';
          // console.log(v, 'v');
          fanData(v);
        } else {
          fanData(v);
          divv.style.display = 'none';
        }
      }
    };
  </script>
</html>
