var hz_shang = dc("hz_shang");
var wm2 = false;
hz_shang.style.display = 'inline-block';
var barChart = echarts.init(document.getElementById('barChart'));
var types = "7Day";
var getOption = function(chartType) {
	var chartOption = {
		title: {
			subtext: '单位(元)'
		},
		tooltip: {
			trigger: 'axis'
		},
		grid: {
			x: 45,
			x2: 10,
			y: 60,
			y2: 25
		},
		toolbox: {
			show: false,
			feature: {
				saveAsImage: {
					show: true
				}
			}
		},
		calculable: true,
		xAxis: [{
			type: 'category',
			data: ['1日', '2日', '3日', '4日', '5日', '6日', '7日']
		}],
		yAxis: [{
			type: 'value'
		}],
		series: [{
			name: '收入',
			type: 'bar',
			itemStyle: {
				normal: {
					color: function(params) {
						// build a color map as your need.
						var colorList = [
							'#ff67ab', '#ff67ab', '#ff67ab', '#ff67ab', '#ff67ab',
							'#ff67ab', '#ff67ab', '#ff67ab', '#ff67ab', '#ff67ab',
							'#ff67ab', '#ff67ab'
						];
						return colorList[params.dataIndex]
					}
				}
			},
			label: {
				normal: {
					show: true,
					position: 'top'
				}
			},
			data: [0, 0, 0, 0, 0, 0, 0]
		}]
	};
	return chartOption;
};
mui.ready(function() {
	document.querySelector('.loading-bg').style.display = 'none';
	barChart.setOption(getOption('bar'));
	fenxiao_center_data();
	pulldata();
});
mui.each(document.querySelectorAll('#tabbar-chart-bar .mui-control-item'), function(index, el) {
	el.addEventListener('tap', function() {
		switch(index) {
			case 0:
				types = "7Day";
				pulldata()
				break;
			case 1:
				types = "6Mon";
				pulldata()
				break;
			case 2:
				types = "Year";
				pulldata()
				break;
			default:
				break;
		}
	}, false);
});

function pulldata() {
	var btnArray = ['否', '是'];
	mui.ajax(base_path + '/rebackStatic/statisInfo?dates=' + new Date().getTime(), {
		data: {
			"openid": "230",
			"type": types
		},
		dataType: 'json',
		type: 'post', 
		timeout: 15000, 
		success: function(dt) {
			//console.log(dt);
			if(dt.status) {
				var counts = new Array();
				var dates = new Array();
				mui(dt.data).each(function(index) {
					counts[index] = accDiv(this.amount, 100);
					dates[index] = this.strDate;
				});
				// 填入数据
				barChart.setOption({
					xAxis: {
						data: dates
					},
					series: [{
						// 根据名字对应到相应的系列
						name: '收入',
						data: counts
					}]
				});
			} else {

				mui.confirm(dt.message, ' ', btnArray, function(e) {
					if(e.index == 1) {
						location.href = domanUrl + "/iamberry/wechat/drp/indexPage?dates=" + new Date().getTime();
					}
				});
			}
		},
		error: function(xhr, type, errorThrown) {
			//异常处理；
			errorfn(xhr);
		}
	});
}

function fenxiao_center_data() {
	var btnArray = ['否', '是'];
	mui.ajax(base_path + '/placeInfo/showPlaceInfoCenter?dates=' + new Date().getTime(), {
		dataType: 'json',
		type: 'post',
		timeout: 15000,
		success: function(dt) {
			//console.log(dt);
			if(dt.status) {
				document.querySelector('#to_accounts').innerHTML = accDiv(dt.data.unIncomeMoney, 100) + '元';
				document.querySelector('.total_money').innerHTML = accDiv(dt.data.totalMoney, 100) + '元';
				document.querySelector('.tx').innerHTML = '<img class="wechat_tx" src="' + dt.data.headImg + '">';
				if(dt.data.wm2 == "true") {
					wm2 = true;
					document.querySelector(".fenxiao_wm2").style.display = 'inline-block'
					document.querySelector(".fenxiao_share").style.display = 'inline-block'
				}
				document.querySelector('.role_name').innerHTML = dt.data.role;
				document.querySelector('.user_name').innerHTML = dt.data.userName;
				document.querySelector('.wechat_name').innerHTML = dt.data.nickName;

				var shareOpenid = dt.data.shareOpenid;
				var link = domanUrl + "/iamberry/wechat/drp/share2WM?shareOpenid=" + shareOpenid;
				//添加分享
				window.repleFlag = false;
				window.wxFriend = {
					"appId": "",
					"imgUrl": 'http://static.iamberry.com/images/shop/naiji_xuanchuan.jpg',
					"link": link,
					"desc": "家里有了爱贝源智能冲奶机，宝宝喂奶，so easy...", //描述
					"title": "8秒冲奶，宝宝喂奶，让更多的妈妈睡个好觉", //标题
					"netError": "您的网络异常，请刷新重试!如多次刷新无效，请向我们反应 ~",
					"shareTimeSuccess": "分享成功", //分享朋友圈后回调
					"shareTimeCancel": "已取消分享", //取消分享朋友圈后回调
					"shareAppSuccess": "分享成功", //分享好友后回调
					"shareAppCancel": "已取消分享" //取消分享好友后回调
				};
				getConfig();
			} else {
				mui.confirm(dt.message, ' ', btnArray, function(e) {
					if(e.index == 1) {
						//location.reload(true);
						location.href = domanUrl + "/iamberry/wechat/drp/indexPage?dates=" + new Date().getTime();
					}
				});
			}
		},
		error: function(xhr, type, errorThrown) {
			//异常处理；
			errorfn(xhr);
		}
	});
}

//可用余额
function tixian() {
	window.location.href = "/iamberry/wechat/drp/withdrawalsList";
}
//收入记录
function getIncomeRecord() {
	window.location.href = "/iamberry/wechat/drp/UnIncomeOrderList";
}
//查看我的下线
function xialianlist() {
	if(wm2) {
		//有二维码的下线是会员或者微代理
		window.location.href = "/iamberry/wechat/drp/xialianUser2";
	} else {
		window.location.href = "/iamberry/wechat/drp/xialianUser";
	}

}
//分销二维码
function fenxiao_wm2() {
	window.location.href = "/iamberry/wechat/drp/share2WM";
}
//未入账列表
function weiruzhang() {
	if(wm2) {
		window.location.href = "/iamberry/wechat/drp/UnIncomeOrderList";
	} else {
		window.location.href = "/iamberry/wechat/drp/UnIncomeOrderList2";
	}

}
//我要分享
function iwant_share() {
	window.location.href = "/iamberry/wechat/sharePage/upShare?userType=2&isDrp=true";
}