<!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/swiper.css">
    <link rel="stylesheet" type="text/css" href="../../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
    <link rel="stylesheet" href="../../css/projeck.css">
    <style>
        body {
            /*background: #fff;*/
            background: url("../../image/top.png") no-repeat;
            background-size: 100%;
            /*padding-top: 40px;*/
        }

        .aui-grid-label {
            font-size: 14px !important;
            width: 90%;
            margin: auto;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .swiper-slide {
            height: 200px
        }
        .swiper-slide a{
          width: 100%;
        }
        .swiper-slide img{
            -webkit-border-radius: 10px;
            -moz-border-radius: 10px;
            border-radius: 10px;
            width: 100%;
            height: 200px;
            object-fit: cover;
        }

        .api_swiper_wrap .swiper-pagination-fraction {
            bottom: 1px;
        }

        .api_page_text {
            bottom: 0;
        }

        .api_grids {
            padding: 0 20px 0 10px;
        }

        .api_grids .aui-col-xs-3 {
            font-size: 12px;
            display: inline-block;
            height: 42px;
            line-height: 42px;
            text-align: center;
            color: #009fe8;
            border: 1px solid #009fe8;
            border-radius: 10px;
            width: auto;
            padding: 0;
            margin-bottom: 20px;
        }

        .api_grids .aui-grid-label {
            margin-top: 0;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .height_duty {
            height: 45px;
            overflow: hidden;
            -webkit-box-sizing: border-box;
            -moz-box-sizing: border-box;
            box-sizing: border-box;
        }

        .aui-grid [class*=aui-col-] {
            padding: 0
        }

        .api_intelligence {
            margin-top: 20px;
        }
    </style>
</head>

<body>
    <div class="api_layout" id="api_layout">
        <div>
            <div class="duty">
                <p class="duty_title"><span id="duty_title"></span> <i class="duty_icon icon"></i></p>
                <div class="height_duty" id="box">
                    <p class="duty_content" id="ul1"></p>
                    <p class="duty_content" id="ul2"></p>
                </div>
            </div>
            <!--banner-->
            <div class="api_swiper_wrap">
                <div class="swiper-container">
                    <div class="swiper-wrapper" id="age_list">

                    </div>
                    <div class="swiper-pagination swiper-pagination-fraction" id="api_page"></div>
                </div>
            </div>
            <!--新闻-->
            <div class="api_news" id="api_newsList"></div>
            <!--智慧-->
            <div class="api_intelligence">
                <section class="aui-grid" id="api_grid">
                    <div class="aui-row" style="padding:0 10px;" id="imgNav">

                </div>
            </section>
        </div>
        <div class="api_line"></div>
        <!-- 基层区队 -->
        <div id="DistrictTeam"></div>
    </div>
</body>

</html>
<!-- 轮播 -->
<script type="text/template" id="template">
    {{~it:value}}
    <div class="swiper-slide" onclick="openUrlBanner('{{=value.jumpURL}}')">
        <a href="javascript:;">
            <img src="{{=value.imgURL}}" alt="">
        </a>
        <div class="api_page_text">
            <p class="api_banner_info">{{=value.title}}</p>
        </div>
    </div>
    {{~}}
</script>
<!-- 新闻 -->
<script type="text/template" id="templateNews">
    <h1 class="api_title">
      新闻动态
      <i class="icon News_icon"></i>
      <span class="api_more" onclick="openNewsList('')">更多</span>
  </h1>
    <ul class="api_newsList">
        {{~it:value}}
        <li onclick="openURl('{{=value.detail_url}}','{{=value.title}}')">
            <img src="{{=value.main_img}}" alt="">
            <p>{{=value.title}}</p>
        </li>
        {{~}}
    </ul>
    <div class="api_line"></div>
</script>
<!-- 智慧枣泉煤矿 -->
<!-- 3 -->
<script type="text/template" id="templateNav">
    {{~it:value}}
    <div class="aui-col-xs-4 item" onclick="openURl('{{=value.link}}','{{=value.title}}');">
        <img src="{{=value.icon}}" alt="">
        <div class="aui-grid-label">{{=value.title}}</div>
    </div>
    {{~}}
</script>
<!-- 4 -->
<script type="text/template" id="templateNav_Four">
    {{~it:value}}
    <div class="aui-col-xs-3 item" onclick="openURl('{{=value.link}}','{{=value.title}}');">
        <img src="{{=value.icon}}" alt="">
        <div class="aui-grid-label">{{=value.title}}</div>
    </div>
    {{~}}
</script>
<!-- 区队 -->
<script type="text/template" id="templateDistrict">
    {{ for (var i = 0;i
    <it.length;i++) { }} <div class="api_office">
        <h1 class="api_title" style="margin-bottom: 13px">
            {{=it[i].title}}
            <img src="{{=i%2 == 0?'../../image/icon01.png':'../../image/edit.png'}}" alt="">
        </h1>
        <section class="aui-grid api_grids">
            <div class="aui-row">
                {{ for (var j =0 ;j
                <it[i].children.length;j++) { }} <div class="aui-col-xs-3 api_col" onclick="openURl('{{=it[i].children[j].link}}','{{=it[i].children[j].title}}');">
                    <div class="aui-grid-label">{{=it[i].children[j].title}}</div>
            </div>
            {{ } }}
            </div>
        </section>
        </div>
        {{ } }}
</script>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/swiper.min.js"></script>
<script src="../../script/doT.min.js" charset="utf-8"></script>
<script src="../../script/config.js" charset="utf-8"></script>
<script type="text/javascript">
    var toast = new auiToast(),
        isFlat = true,
        userId = "",
        departmentId = "",
        headers ={},
        token = '';
    $apis.swiper('.swiper-container', true, 'fraction');
    apiready = function() {
        api.closeFrame({
            name: 'frame3'
        });
        var info = $api.getStorage('data')
        userId = JSON.parse(info).data.user.staff_num;
        token = JSON.parse(info).data.access_token;
        headers = {
            "Authorization": "Bearer " + token
        };
        departmentId = JSON.parse(info).data.user.section_id;
        // 监听app从后台返回前台刷新
        api.addEventListener({
            name: 'resume'
        }, function(ret, err) {
            getBannerData()
            getNewsData()
            getNoticeData()
            getImgNavData()
            getDistrictteamData()
        });
        // 每次打开app刷新一次
        if (isFlat) {
            getBannerData()
            getNewsData()
            getNoticeData()
            getImgNavData()
            getDistrictteamData()
            isFlat = false;
        }
        // banner
        getBannerCache();
        // 公告
        getNoticeDataCache();
        //news
        getNewsDataCache();
        //图片nav
        getImgNavDataCache();
        //区队
        getDistrictteamDataCache();
        // 下拉刷新
        setCustomRefreshHeader();
    };
    // 下拉刷新
    function setCustomRefreshHeader() {
        api.setRefreshHeaderInfo({
            bgColor: '#f2f2f2',
            textColor: '#000',
            textDown: '下拉刷新...',
            textUp: '松开刷新...'
        }, function(ret, err) {
            getBannerData()
            getNewsData()
            getNoticeData()
            getImgNavData()
            getDistrictteamData()
        });
    }

    function flexWidth() {
        var cols = document.getElementsByClassName('api_col');
        for (var i = 0; i < cols.length; i++) {
            cols[i].style.width = (api.frameWidth / 4 - 19) + 'px';
            cols[i].style.marginLeft = 10 + 'px'
        }
    }
    // openUrlBanner
    function openUrlBanner(urls, titles) {
        $event.openWin('openURlId1', 'openUrlBanner', {
            url: urls,
            title: titles
        }, '');
    }
    // openURl
    function openURl(urls, titles) {
        var appU = urls.split('//');
        if (appU && appU[1] == 'app:') {
            $event.openWin('organization_win', appU[2], '', '');
        } else {
            var name, value, info = [],
                Qrurl = urls;
            var str = Qrurl;
            var num = str.indexOf("?");
            str = str.substr(num + 1);
            var arr = str.split("&");
            for (var i = 0; i < arr.length; i++) {
                num = arr[i].indexOf("=");
                if (num > 0) {
                    name = arr[i].substring(0, num);
                    value = arr[i].substr(num + 1);
                    this[name] = value;
                    info.push(value)
                }
            }
            if (info[2] != "" && info[2]) {
                $event.openWin('browseQrcode_win', '../browseQrcode/browseQrcode_win', {
                    pageId: info[2],
                    title: titles
                }, '');
                var data = {
                    "pageId": info[2],
                    "userId": userId,
                    "status": "CREATE"
                }
                // addPageUserTime
                api.ajax({
                    url: UrlRouter.getAddPageUserTime,
                    method: 'post',
                    headers: headers,
                    data: {
                        body: data
                    }
                },function(ret, err){
                    if (ret) {
                      api.sendEvent({
                          name: 'pageUserTimeDefault',
                          extra: {
                              id: ret.data.id,
                              createDate: ret.data.createDate
                          }
                      });
                    } else {
                        console.log(err);
                    }
                });
            } else {
                $event.openWin('openURlId', 'openUrl', {
                    url: urls,
                    title: titles
                }, '');
            }
        }
    }
    // banner
    function getBannerData() {
        $http.requestData(UrlRouter.bannerApi, 'get', '')
            .then(ret => {
                if (ret.code === 0) {
                    $apis.html(age_list, '#template', ret.data.data);
                    $apis.writeFile($apis.CACHE_DIR('banner'), ret.data.data);
                    mySwiper.destroy(true, true);
                    $apis.swiper('.swiper-container', true, 'fraction');
                    mySwiper.init();
                } else if (ret.code === 401) {
                    api.alert({
                        title: '提示',
                        msg: '登录过期，重新登录',
                    }, function(ret, err) {
                        var index = ret.buttonIndex;
                        if (index == 1) {
                            $api.clearStorage();
                            api.setStatusBarStyle({
                                color: 'rgba(0,0,0,0)',
                                style: 'light'
                            });
                            api.closeWin({
                                name: 'index'
                            });
                        }
                    });
                }
            })
            .catch(err => {})
    }

    function getBannerCache() {
        $apis.readFile($apis.CACHE_DIR('banner'), function(ret, err) {
            if (ret.status) {
                $apis.html(age_list, '#template', JSON.parse(ret.data));
                mySwiper.destroy(true, true);
                $apis.swiper('.swiper-container', true, 'fraction');
                mySwiper.init();
            }else{
              getBannerData()
            }
        });
    }
    // 新闻
    function getNewsDataCache() {
        $apis.readFile($apis.CACHE_DIR('news'),function (ret,err) {
            if( ret.status ){
                $apis.html(api_newsList,'#templateNews',JSON.parse(ret.data));
            }else{
                getNewsData()
            }
        })
    }

    function getNewsData() {
        $http.requestData(UrlRouter.nwesApi, 'get', '')
            .then(ret => {
                if (ret.code === 0) {
                    api.refreshHeaderLoadDone();
                    $apis.html(api_newsList, '#templateNews', ret.data.data);
                    $apis.writeFile($apis.CACHE_DIR('news'), ret.data.data);
                }
            })
            .catch(err => {})
    }
    //公告
    function getNoticeDataCache() {
        $apis.readFile($apis.CACHE_DIR('Notice'), function(ret, err) {
            if (ret.status) {
                if (JSON.parse(ret.data).message == "暂无公告") {
                    $api.html($api.byId('duty_title'), JSON.parse(ret.data).title);
                    $api.html($api.dom('#ul1'), JSON.parse(ret.data).message);
                } else {
                    $api.html($api.byId('duty_title'), JSON.parse(ret.data).title);
                    $api.html($api.dom('#ul1'), JSON.parse(ret.data).content);
                    textRoll(200);
                }
            } else {
                getNoticeData()
            }
        })
    }

    function getNoticeData() {
        $http.requestData(UrlRouter.NoticeApi, 'get', '')
            .then(ret => {
                if (ret.code === 0) {
                    if (ret.data.message == "暂无公告") {
                        $api.html($api.byId('duty_title'), ret.data.title);
                        api.refreshHeaderLoadDone();
                        $api.html($api.dom('#ul1'), ret.data.message);
                        $apis.writeFile($apis.CACHE_DIR('Notice'), ret.data)
                    } else {
                        $api.html($api.byId('duty_title'), ret.data.title);
                        $api.html($api.dom('#ul1'), ret.data.content);
                        $apis.writeFile($apis.CACHE_DIR('Notice'), ret.data)
                    }
                }
            })
            .catch(err => {})
    }
    textRoll(200);
    // 图片导航
    function getImgNavDataCache() {
        $apis.readFile($apis.CACHE_DIR('ImgNav'), function(ret, err) {
            if (ret.status) {
                if (JSON.parse(ret.data).index_link_num == 3) {
                    $apis.html(imgNav, '#templateNav', JSON.parse(ret.data).data);
                } else {
                    $apis.html(imgNav, '#templateNav_Four', JSON.parse(ret.data).data);
                }
            } else {
                getImgNavData()
            }
        })
    }

    function getImgNavData() {
        $http.requestData(UrlRouter.ImgApi, 'get', '')
            .then(ret => {
                if (ret.code === 0) {
                    api.refreshHeaderLoadDone();
                    if (ret.data.index_link_num == 3) {
                        $apis.html(imgNav, '#templateNav', ret.data.data);
                    } else {
                        $apis.html(imgNav, '#templateNav_Four', ret.data.data);
                    }
                    $apis.writeFile($apis.CACHE_DIR('ImgNav'), ret.data);
                }
            })
            .catch(err => {})
    }
    // 区队
    function getDistrictteamDataCache() {
        $apis.readFile($apis.CACHE_DIR('District'), function(ret, err) {
            if (ret.status) {
                $apis.html(DistrictTeam, '#templateDistrict', JSON.parse(ret.data));
                flexWidth();
            } else {
                getDistrictteamData()
            }
        })
    }

    function getDistrictteamData() {
        $http.requestData(UrlRouter.DistrictteamApi, 'get', '')
            .then(ret => {
                if (ret.code === 0) {
                    api.refreshHeaderLoadDone();
                    $apis.html(DistrictTeam, '#templateDistrict', ret.data);
                    $apis.writeFile($apis.CACHE_DIR('District'), ret.data);
                    flexWidth();
                }
            })
            .catch(err => {})
    }
    // 文字无缝滚动
    function textRoll(t) {
        var ul1 = document.getElementById("ul1");
        var ul2 = document.getElementById("ul2");
        var box = document.getElementById("box");
        var timer = '';
        if (ul1.offsetHeight > box.offsetHeight) {
            ul2.innerText = ul1.innerText;
        }
        box.scrollTop = 0;
        timer = setInterval(rollStart, t);
    }

    function rollStart() {
        if (document.getElementById("box").scrollTop > document.getElementById("ul1").scrollHeight) {
            document.getElementById("box").scrollTop = 0;
        } else {
            document.getElementById("box").scrollTop++;
        }
    }
    // open新文列表
    function openNewsList(urls) {
        $event.openWin('openNews', 'openNews', {
            url: urls
        }, '');
    }
</script>
