mui.init({
	pullRefresh: {
		container: '#pullrefresh',
		down: {
			style: 'circle', //必选，下拉刷新样式，目前支持原生5+ ‘circle’ 样式
			color: '#2BD009', //可选，默认“#2BD009” 下拉刷新控件颜色
			height: '50px', //可选,默认50px.下拉刷新控件的高度,
			range: '100px', //可选 默认100px,控件可下拉拖拽的范围
			offset: '0px', //可选 默认0px,下拉刷新控件的起始位置
			auto: true, //可选,默认false.首次加载自动上拉刷新一次
			callback: reloadNews //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
		},
		up: {
			contentrefresh: '正在加载...',
			callback: pullupRefresh
		}
	},
});
/**
 * 下拉刷新具体业务实现
 */
function reloadNews() {
	pageNo = 1;
	var table = document.body.querySelector('.mui-table-view');
	table.innerHTML = "";
	addData();
}

var pageNo = 1;
var folder_id = 0;
/**
 * 上拉加载具体业务实现
 */
function pullupRefresh() {
	addData();
}

function addData() {
	var url = API.API_URL();
	var obj = {
		method: "adviceList",
		pageNo: pageNo,
		pageSize: APP.PageSize,
		p: '{}'
	};
	app.ajax(obj, function(data) {
		//服务器返回响应
		console.log(JSON.stringify(data))
		var totalRow = data.totalRow;
		var totalPage = data.totalPage;
		var list = data.list;
		var table = document.body.querySelector('.mui-table-view');
		for(var i = 0, len = list.length; i < len; i++) {
			var username = list[i].username;
			var create_time = list[i].create_time;
			var content = list[i].content
			var replay_content = "";
			var replay_name = "";
			var replay_time = "";
			if(list[i].replay_time){
				replay_time = list[i].replay_time;
			}
			if(list[i].replay_name){
				replay_name = list[i].replay_name;
			}
			if(list[i].replay_content){
				replay_content = list[i].replay_content;
			}
			var li = document.createElement('li');
			li.className = 'mui-table-view-cell mui-media';			
			var html = '<div class="column">'
	                +' <h1>'+content+'</h1>'
	                +' <div class="revert">管理员回复：<span>'+replay_content+'</span></div>'
	                +' <ul>'
	                +' 	<li class="pull_r user"><img src="../../images/User.png" class="pull_l"><a href="" class="pull_l">'+username+'</a></li>'
	                +'     <li class="pull_r time"><img src="../../images/Clock.png" class="pull_l"><a href="" class="pull_l">'+create_time+'</a></li>'
	                +'     <li class="cleafix"></li>'
	                +' </ul>'
	            	+' </div>';           
			li.innerHTML = html;
			table.appendChild(li);
		}
		if(totalPage == 0 || totalPage == 1) {
			mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
		} else {
			mui('#pullrefresh').pullRefresh().endPullupToRefresh(totalPage == pageNo); //参数为true代表没有更多数据了。
		}

		if(pageNo == 1) {
			mui('#pullrefresh').pullRefresh().endPulldown();
		}
		pageNo = pageNo + 1;
		if(totalPage == 0) {
			$(".mui-scroll").html("<div style='text-align:center;padding-top:10px;'>暂无数据</div>")
		}
	});
}

mui.plusReady(function() {
	
});