<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="news.aspx.cs" Inherits="xxpeixun.app.news" %>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>新闻公告——<%=xxsoft_check.check.getseting("systitle") %></title>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <link rel="stylesheet" href="../weui/css/weui.css"/>
    <link rel="stylesheet" href="../weui/css/weuix.css"/>

    <script src="../weui/js/zepto.min.js"></script>
    <script src="../weui/js/zepto.weui.js"></script>
    <script src="../weui/js/iscroll-lite.js" type="text/javascript"></script>
    <script src="../weui/js/php.js"></script>

</head>

<body ontouchstart>
<div class="weui-header bg-blue"> 
  <div class="weui-header-left"> <a class="icon icon-109 f-white" href="javascript:history.go(-1);">返回</a>  </div>
   <h1 class="weui-header-title">新闻公告</h1>
    <div class="weui-header-right"><a class="icon icon-112 f-white" href="exit.aspx"></a></div> 
    </div>
     <div class="weui-tab" id="t1" style="height:44px;">
        <div class="weui-navbar">
        </div>
    </div>

    <div class="weui-panel weui-panel_access">
        <div class="weui-cells" id="rank-list"> 
       </div>
       <script id="tpl" type="text/html">
            <@  for(var i in data) {   @>
             <a class="weui-cell weui-cell_access" href="newsview.aspx?id=<@=data[i].id @>">
            <div class="weui-cell__bd">
                <p><@=data[i].title@></p>
            </div>
            <div class="weui-cell__ft"><@=data[i].addtime@></div>
        </a>
            <@ } @>
        </script>
        <div class="weui-panel__ft">
            <a href="javascript:void(0);" class="weui-cell weui-cell_access weui-cell_link">
                <div class="weui-cell__bd" id="getmore">查看更多<i id="loading" class="weui-loading"></i></div>

            </a>
        </div>
    </div>
    <br>
    <br>
  
    <script>
        $('#loading').hide();
        var pagesize=20;//每页数据条数
        function ajaxpage(page,tfl){
            $.ajax({
                type: "post",
                url: 'news.aspx?action=list',
                data: { "page": page, "limit": pagesize,"tfenlei":tfl},
                dataType: 'json',
                timeout: 10000,
                beforeSend: function (xhr) {
                    $('#loading').show();
                },
                success: function (data) {
                    $('#loading').hide();
                    $("#rank-list").append(tpl(document.getElementById('tpl').innerHTML, data));
                    //$("#rank-list").append(temp);
                    var maxpage = Math.ceil(data.count / pagesize);
                    sessionStorage['maxpage'] = maxpage;

                    if (page == maxpage) {
                        $("#getmore").html("没有更多数据了"); return false;
                    }
                },
                error: function (xhr) {
                    alert('ajax出错');
                }
            });
        }
        
        $(function(){
            var page = 2;
            var maxpage;
            var tfenlei=sessionStorage['tfenlei'];
            $('#getmore').on('click', function() {
                maxpage = sessionStorage['maxpage'];
                if(page<=maxpage) {
                    ajaxpage(page,tfenlei);
                    page++;
                }
            });
            ajaxpage(1,tfenlei);
        })
        $(function () {
            $.ajax({
                type: "post",
                url: 'news.aspx?action=fenlei',
                dataType: 'json',
                success: function (data) {
                    for (var i = 0; i < data.data.length; i++) {
                        $('.weui-navbar').append("<div class='weui-navbar__item' onclick=setsession('" + data.data[i].fenlei + "')>" + data.data[i].fenlei + "</div>");
                    }
                    $('#t1').tab({
                        defaultIndex: 0,
                        activeClass: 'tab-green',
                        onToggle: function (index) {
                        }
                    })
                },
                error: function (xhr) {
                    alert('ajax出错');
                }
            });
        });
        function setsession(str) {
            sessionStorage['tfenlei'] = str;
            $("#rank-list").html("");
            ajaxpage(1, str);
        }
</script>
</body>
</html>

