mui.init({
	pullRefresh: {
		container: '#pullrefresh',
		down: {
			//callback: pulldownRefresh
		},
		up: {
			contentrefresh: '正在加载...',
			callback: pullupRefresh
		}
	}
});
var pageNumber = 0,pagesize = 10;
//上拉加载
function pullupRefresh() {
	++pageNumber;
	var btnArray = ['否', '是'];
	mui.ajax('/iamberry/wechat/rebackStatic/unIncomeOrderCast?dates=' + new Date().getTime(), {
		data: {
			"pageSize": pagesize,
			"pageNumber": pageNumber
		},
		dataType: 'json',
		type: 'post',
		timeout: 15000,
		success: function(dt) {
			//console.log(dt);
			if(dt.status) {
				var chanpin_data = []; //定义一个数组类型存放dt.data.productList
				if(dt.data.list != null) {
					chanpin_data = dt.data.list;
				}

				document.querySelector("#accounts").innerHTML = accDiv(dt.data.unIncomeMoney, 100)
				mui('#pullrefresh').pullRefresh().endPullupToRefresh(chanpin_data.length < pagesize); //参数为true代表没有更多数据了
				var table = document.body.querySelector('.my-tab-view-pull');
				mui(chanpin_data).each(function(index) {
					var li = document.createElement('li');
					li.className = 'mui-table-view-cell ft-12';
					/* li.innerHTML = ''+decodeURI(this.name)+'：¥'+accDiv(this.amount,100)+'元<span class="mui-pull-right"><span id="timer'+((pagesize*pageNumber)+index)+'"></span></span>'; */
					if(this.strDate == '未发货') {
						li.innerHTML = '<table class="my-dl-tb-order"><tr><td><img class="wh-50" src="' + this.img + '"></td><td class="mui-text-left">' + decodeURI(this.name) + '：¥' + accDiv(this.amount, 100) + '元</td><td><span>未发货</span></td></tr></table>';
						table.appendChild(li);
					} else {
						li.innerHTML = '<table class="my-dl-tb-order"><tr><td><img class="wh-50" src="' + this.img + '"></td><td class="mui-text-left">' + decodeURI(this.name) + '：¥' + accDiv(this.amount, 100) + '元</td><td><span id="timer' + ((pagesize * pageNumber) + index) + '"></span></td></tr></table>';
						table.appendChild(li);
						addTimer('timer' + ((pagesize * pageNumber) + index) + '', this.strDate / 1000);
					}

				});
			} else {
				mui.confirm(dt.message, '提示', btnArray, function(e) {
					if(e.index == 1) {
						//console.log("您点击了是");
					}
				});
			}
		},
		error: function(xhr, type, errorThrown) {
			//异常处理；
			errorfn(xhr);
		}
	});
}
mui.ready(function() {
	mui('#pullrefresh').pullRefresh().pullupLoading();
	document.querySelector('.loading-bg').style.display = 'none';
});

var addTimer = function() {
	var list = [],
		interval;

	return function(id, time) {
		if(!interval)
			interval = setInterval(go, 1000);
		list.push({
			ele: document.getElementById(id),
			time: time
		});
	}

	function go() {
		for(var i = 0; i < list.length; i++) {
			list[i].ele.innerHTML = getTimerString(list[i].time ? list[i].time -= 1 : 0);
			if(!list[i].time)
				list.splice(i--, 1);
		}
	}

	function getTimerString(time) {
		d = Math.floor(time / 86400),
			h = Math.floor((time % 86400) / 3600),
			m = Math.floor(((time % 86400) % 3600) / 60),
			s = Math.floor(((time % 86400) % 3600) % 60);
		if(time > 0)
			return "剩余" + d + "天" + h + ":" + m + ":" + s;
		else return "即将入账";
	}
}();

/*  addTimer("timer1", 99999);     
    addTimer("timer2", 66666);     
    addTimer("timer3", 33333); */