mui.init({
	pullRefresh: {
		container: '#pullrefresh',
		down: {},
		up: {
			contentrefresh: '正在加载...',
			callback: pullupRefresh
		}
	}
});
var pageNumber = 0,
	pagesize = 10;

function pullupRefresh() {
	pageNumber += 1;
	var btnArray = ['否', '是'];
	$.ajax(base_path + '/rebackStatic/unIncomeOrderCast2?dates=' + new Date().getTime(), {
		data: {
			"pageSize": pagesize,
			"pageNumber": pageNumber,
			"openid": getParam("openid")
		},
		dataType: 'json',
		type: 'post',
		timeout: 15000,
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		success: function(dt) {
			if(dt.isRedirect) {
				location.href = dt.redirectURL;
			} else {
				console.log(dt);
				if(dt.status) {
					var chanpin_data = [];
					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);
					var table = document.body.querySelector('.my-tab-view-pull');
					mui(chanpin_data).each(function(index) {
						var li = document.createElement('li');
						if(this.roleName != "门店" && this.roleName != "母婴店") {
							li.setAttribute("href", base_path + "/drp/UnIncomeOrderList?openid=" + this.openid)
						}
						li.className = 'mui-table-view-cell ft-12';
						li.innerHTML = '<table class="my-dl-tb-order"><tr><td style="width:70px;"><img class="wh-50" src="' + this.img + '"></td><td>' + decodeURI(this.name) + '</td><td class="mui-text-left" style="color:blue">' + this.roleName + '</td><td>¥' + accDiv(this.amount, 100) + '元</td></tr></table>';
						table.appendChild(li);
					});
					mui('body').on('tap', '.my-tab-view-pull .mui-table-view-cell', function() {
						var ref = this.getAttribute("href");
						if(ref != null) {
							location.href = this.getAttribute("href")
						}
					})
				} else {
					mui.confirm(dt.message, '提示', btnArray, function(e) {
						if(e.index == 1) {}
					})
				}
			}
		},
		error: function(xhr, type, errorThrown) {
			errorfn(xhr)
		}
	})
};
mui.ready(function() {
	mui('#pullrefresh').pullRefresh().pullupLoading();
	getCartNum();
	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 += 1) {
			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 "即将入账"
		}
	}
}();