<!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>消息</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/toast.css">
    <link rel="stylesheet" href="../../css/projeck.css">
    <style>
        body,html{
            background: #fff;
        }
        .api_news_item .news_img{
            background: none;
            background-color: #009fe8;
            -webkit-border-radius: 50%;
            -moz-border-radius: 50%;
            border-radius: 50%;
            font-size: 12px;
            line-height: 15px;
            text-align: center;
            padding: 8px 10px;
            box-sizing: border-box;
            color: #fff;
        }
        .api_layout{
            padding-bottom: 30px;
        }
    </style>
</head>
<body>
<div class="api_layout">
    <div class="api_news_items api_news_public">
        <p class="api_title_text">公共：</p>
        <ul class="api_news_item" id="pulicList">

        </ul>
    </div>
    <div class="api_news_items api_news_office">
        <p class="api_title_text">机关部室：</p>
        <ul class="api_news_item" id="depList">

        </ul>
    </div>
</div>
</body>
</html>
<script type="text/template" id="templatePublic">
    {{~it:value:index}} {{?value.departmentId == 'root'}}
    <li onclick="openQRcodeInfo('{{=value.departmentId}}','{{=value.messageFlag}}')">
        <span class="news_img">{{=value.departmentName.substring(0,4)}}</span>
        <div class="api_titles">
            <span class="api_news_title">{{=value.departmentName}}</span>
            <p>
                <i class="api_ico"></i>
                {{=value.desc}}
            </p>
        </div>
        <span class="api_date">{{=value.time}}</span>
        {{?value.messageCount != 0}}
        <span class="api_news_num">{{=value.messageCount}}</span>
        {{?}}
        <span class="api_ceil"></span>
    </li>
    {{?}} {{~}}
</script>
<script type="text/template" id="templateDep">
    {{~it:value:index}} {{?value.departmentId != 'root'}}
    <li onclick="openQRcodeInfo('{{=value.departmentId}}','{{=value.messageFlag}}')">
        <span class="news_img">{{=value.departmentName.substring(0,4)}}</span>
        <div class="api_titles">
            <span class="api_news_title">{{=value.departmentName}}</span>
            <p>
                <i class="api_ico"></i>
                {{=value.desc}}
            </p>
        </div>
        <span class="api_date">{{=value.time}}</span>
        {{?value.messageCount != 0}}
        <span class="api_news_num">{{=value.messageCount}}</span>
        {{?}}
        <span class="api_ceil"></span>
    </li>
    {{?}} {{~}}
</script>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/doT.min.js"></script>
<!-- <script src="../../script/aui-toast.js" charset="utf-8"></script> -->
<!-- <script src="../../script/fastclick.min.js" charset="utf-8"></script> -->
<script src="../../script/config.js" charset="utf-8"></script>
<script type="text/javascript">
    var skip = 0,jobNum = "";
    var toast = new auiToast();
    apiready = function () {
        var info = $api.getStorage('data');
            jobNum = JSON.parse(info).data.user.staff_num;
        $http.fnReuestData(UrlRouter.findMessageApi+jobNum,'','get','',newsDatas);
        setCustomRefreshHeader(jobNum);
        api.addEventListener({
            name: 'myEvent'
        }, function(ret, err) {
            $http.fnReuestData(UrlRouter.findMessageApi+jobNum,'','get','',newsDatas);
        });
    }
    function setCustomRefreshHeader(jobNum) {
        api.setRefreshHeaderInfo({
            bgColor: '#f2f2f2',
            textColor: '#000',
            textDown: '下拉刷新...',
            textUp: '松开刷新...'
        }, function(ret, err) {
            $http.fnReuestData(UrlRouter.findMessageApi+jobNum,'','get','',newsDatas);
            api.sendEvent({
                name: 'newsBroadcast'
            });
        });
    }
    function newsDatas(ret,err){
        if (ret) {
          if (ret.code === '200') {
              getChangMessageList();//已读二维码和记录
              $apis.html(pulicList,'#templatePublic',ret.data);
              $apis.html(depList,'#templateDep',ret.data);
              api.refreshHeaderLoadDone();
              $event.removeTips('tips');
              toast.hide();
          }else {
              toast.hide();
              api.toast({
                  msg: '获取信息失败',
                  duration: 2000,
                  location: 'top'
              });
          }
        } else {
            toast.hide();
            $event.tips('body','加载失败，请假差网络！');
        }
    }
    // 详情
    function openQRcodeInfo(id,Flag) {
        $event.openWin('QRcodeLisr','../Qrcode/QRcodeList',{depID:id,messageFlag:Flag},'');
    }

    // 已读消息 二维码
    function getChangMessageList() {
      $http.fnReuestData(UrlRouter.getChangMessageList+jobNum,'','get','');
    }
</script>
