var orderChartsTitle = '<span class="charts-title order" onclick="onloadOrderChart(1)">今日</span>';
orderChartsTitle += '<span class="charts-title order black" onclick="onloadOrderChart(2)">昨日</span>';
orderChartsTitle += '<span class="charts-title order black" onclick="onloadOrderChart(3)">本周</span>';
orderChartsTitle += '<span class="charts-title order black" onclick="onloadOrderChart(4)">本月</span>';
//orderChartsTitle += '<span class="charts-title-ordernum">订单总数<i>0</i></span>';

var weixinChartsTitle = '<span class="charts-title fans" onclick="onloadWeiXinFansChart(1)">今日</span>';
weixinChartsTitle += '<span class="charts-title fans black" onclick="onloadWeiXinFansChart(2)">昨日</span>';
weixinChartsTitle += '<span class="charts-title fans black" onclick="onloadWeiXinFansChart(3)">本周</span>';
weixinChartsTitle += '<span class="charts-title fans black" onclick="onloadWeiXinFansChart(4)">本月</span>';
var chart,salesStatistical,weixinChart,weixinStatistical,weixinTimeStatistical,weixinOption;
$(function() {
	// 加载页面Title以及用户名称
	// 1--获取当前时间
	/*
	 * var title; var myDate = new Date(); var dayHour = myDate.getHours(); if
	 * (parseInt(dayHour) >= 0 && parseInt(dayHour) < 12) { title = "早上好，"; }
	 * else if (parseInt(dayHour) >= 12 && parseInt(dayHour) < 18) { title =
	 * "下午好，"; } else if (parseInt(dayHour) >= 18 && parseInt(dayHour) < 24) {
	 * title = "晚上好，"; } $("#Stitle").text(title);
	 */
	// 临时隐藏面包屑和选项卡，后期会对后台首页进行整体界面修改 2016年11月15日 09:32:21 王永杰
	// 销售统计
	onloadOrderChart(1);
	onloadWeiXinFansChart(1);
	// 关注人数统计
	var focusNumberStatistical = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
	chart = new Highcharts.Chart({
		chart : {
			type : 'column',
			renderTo : 'orderCharts'
		},
		title : {
			text : orderChartsTitle,
			align : "left",
			useHTML : true
		},
		lang : {
			printChart : "打印",
			downloadPNG : "导出PNG格式图片",
			downloadJPEG : "导出JPEG格式图片",
			downloadPDF : "导出PDF格式图片",
			downloadSVG : "导出SVG格式图片"
		},
		xAxis : {
			type : 'category',
			labels : {
				rotation : -45,
				style : {
					fontSize : '13px',
					fontFamily : 'Verdana, sans-serif'
				}
			}
		},
		yAxis : {
			min : 0,
			title : {
				text : '订单统计'
			}
		},
		legend : {
			enabled : false
		},
		credits : {
			enabled : false,// 默认值，如果想去掉版权信息，设置为false即可
			text : PLATFORM_NAME, // 显示的文字
			href : '#', // 链接地址
		},
		series : [ {
			name : '订单统计',
			data : salesStatistical,
			dataLabels : {
				enabled : false,
				color : '#FFFFFF',
				align : 'right',
				format : '{point.y:.1f}', // one decimal
				y : 0, // 10 pixels down from the top
				style : {
					fontSize : '12px',
					fontFamily : 'Verdana, sans-serif'
				}
			}
		} ]
	});

	var focusChartsTitle = '<span class="charts-title">今日</span>';
	focusChartsTitle += '<span class="charts-title black">昨日</span>';
	focusChartsTitle += '<span class="charts-title black">本周</span>';
	focusChartsTitle += '<span class="charts-title black">本月</span>';
	/*focusChartsTitle += '<span class="charts-title-ordernum">关注用户总数<i>0</i></span>';
	focusChartsTitle += '<span class="charts-title-ordernum">浏览用户总数<i>0</i></span>';*/
	weixinTimeStatistical = [ '00:00', '01:00', '02:00', '03:00', '04:00',
								'05:00', '06:00', '07:00', '08:00', '09:00',
								'10:00', '11:00', '12:00', '13:00', '14:00',
								'15:00', '16:00', '17:00', '18:00', '19:00',
								'20:00', '21:00', '22:00', '23:00' ];
	weixinChart = new Highcharts.Chart("focusCharts",{
	//$('#focusCharts').highcharts({
				/*chart : {
					type : 'spline',
					renderTo : 'focusCharts'
				},*/
				title : {
					text : weixinChartsTitle,
					align : "left",
					useHTML : true
				},
				xAxis : {
					categories : weixinTimeStatistical
				},
				lang : {
					printChart : "打印",
					downloadPNG : "导出PNG格式图片",
					downloadJPEG : "导出JPEG格式图片",
					downloadPDF : "导出PDF格式图片",
					downloadSVG : "导出SVG格式图片"
				},
				yAxis : {
					title : {
						text : ''
					},
					plotLines : [ {
						value : 0,
						width : 1,
						color : '#808080'
					} ]
				},
				tooltip : {
				// valueSuffix : '°C'
				},
				legend : {
					enabled : false
				},
				credits : {
					enabled : false,// 默认值，如果想去掉版权信息，设置为false即可
					text : '牛酷商城', // 显示的文字
					href : '#', // 链接地址
				},
				exporting : {
					allowHTML : true,
					buttons : {
						contextButton : {
						// text : '导出'
						}
					}
				},
				series : [ {
					name : '今日',
					data : weixinStatistical
				}
				/*
				 * , { name : '昨日', data : [ -0.2, 0.8, 5.7, 11.3, 17.0, 22.0,
				 * 24.8, 24.1, 20.1, 14.1, 8.6, 2.5 ] }, { name : '本周', data : [
				 * -0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9,
				 * 1.0 ] }, { name : '本月', data : [ 3.9, 4.2, 5.7, 8.5, 11.9,
				 * 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8 ] }
				 */
				]
			});
});
$(function(){
	onloadUserInfo();
	onloadGoodsCount();
	onloadOrderCount();
	onloadSalesStatistics();
	onloadConsultCount();
});
/**
 * 加载 店铺 会员 信息
 */
function onloadUserInfo(){
	$.ajax({
		type : "post",
		url : admin_main+"/Index/getUserInfo",
		async : true,
		success : function(data) {
			$(".user_name").html(data['user_name']);
			$(".last-login-time span").html(data['last_login_time']);
			$(".last-login-ip span").html(data['last_login_ip']);
		}
	});
}
function onloadGoodsCount(){
	$.ajax({
		type : "post",
		url : admin_main+"/Index/getGoodsCount",
		async : true,
		success : function(data) {
//			alert(JSON.stringify(data));
			if(data['all']!=null){
				$(".goods_all_count").html(data['all']+'/不限');
			}
			//$(".goods_audit_count").html();
			//$(".goods_sale_count").html(data['sale']);
			//$(".goods_shelf_count").html(data['shelf']);
			exeryTimePut("goods_sale_count", parseInt(data['sale']));
			exeryTimePut("goods_audit_count", parseInt(data['audit']));
			exeryTimePut("goods_shelf_count", parseInt(data['shelf']));
		}
	});
}
function onloadOrderCount(){
	$.ajax({
		type : "post",
		url : admin_main+"/Index/getOrderCount",
		async : true,
		success : function(data) {
			/*$(".daifukuan").html(data['daifukuan']);
			$(".daifahuo").html(data['daifahuo']);
			$(".yifahuo").html(data['yifahuo']);
			$(".yishouhuo").html(data['yishouhuo']);
			$(".yiwancheng").html(data['yiwancheng']);
			$(".yiguanbi").html(data['yiguanbi']);
			$(".tuikuanzhong").html(data['tuikuanzhong']);
			$(".yituikuan").html(data['yituikuan']);
			$(".charts-title-ordernum i").html(data['all']);*/
			exeryTimePut("daifukuan",data['daifukuan']);
			exeryTimePut("daifahuo",data['daifahuo']);
			exeryTimePut("yifahuo",data['yifahuo']);
			exeryTimePut("yishouhuo",data['yishouhuo']);
			exeryTimePut("yiwancheng",data['yiwancheng']);
			exeryTimePut("yiguanbi",data['yiguanbi']);
			exeryTimePut("tuikuanzhong",data['tuikuanzhong']);
			exeryTimePut("yituikuan",data['yituikuan']);
			exeryTimePut("charts-title-ordernum",data['all']);
		}
	});
}
function onloadSalesStatistics(){
	$.ajax({
		type : "post",
		url : admin_main+"/Index/getSalesStatistics",
		async : true,
		success : function(data) {
			$(".yesterday_goods").html(data['yesterday_goods']);
			$(".month_goods").html(data['month_goods']);
			$(".yesterday_money").html(data['yesterday_money']);
			$(".month_money").html(data['month_money']);
		}
	});
}


function onloadOrderChart(e) {
	
	$(".order").addClass('black');
	$(".order").eq(e-1).removeClass('black');
	$.ajax({
		type : "post",
		url : admin_main+"/Index/getOrderChartCount",
		data : {'date':e},
		async : true,
		success : function(data) {
			
//			salesStatistical = [ [ '00:00', 10 ], [ '01:00', 20 ], [ '02:00', 30 ],
//				         			[ '03:00', 40 ], [ '04:00', 50 ], [ '05:00', 60 ], [ '06:00', 70 ],
//				         			[ '07:00', 80 ], [ '08:00', 90 ], [ '09:00', 100 ],
//				         			[ '10:00', 110 ], [ '11:00', 120 ], [ '12:00', 130 ] ];
			salesStatistical = data;
			var series = chart.series;
			while (series.length > 0) {
				series[0].remove(false);
			}
			chart.addSeries({
				name : "订单数量",
				data : salesStatistical
			}, false);
			chart.redraw();
		}
	});
}
	
//定时器	
function exeryTimePut(tag_name, num){
	if(num > 0){
		var number = 1;
		$('body').everyTime('0.01s','B',function(){
			$("."+tag_name).text(number);
			number++;
			//do something...
		},num);		
	}
}
//咨询回复
function onloadConsultCount(){
	$.ajax({
		type : "post",
		url : admin_main+"/Index/getConsultCount",
		async : true,
		success : function(data) {
			exeryTimePut("goods_consult_count",data);
		}
	});
}
/**
 * fans关注图标数据
 * @param e
 */
function onloadWeiXinFansChart(e) {
	
	$(".fans").addClass('black');
	$(".fans").eq(e-1).removeClass('black');
	$.ajax({
		type : "post",
		url : admin_main+"/Index/getWeiXinFansChartCount",
		data : {'date':e},
		async : true,
		success : function(data) {	
			var timeOut = "关注人数";
			if(e == 1){
				timeOut = "今日";
			}else if(e == 2){
				timeOut = "昨日";
			}else if(e == 3){
				timeOut = "本周";
			}else if(e == 4){
				timeOut = "本月";
			}
			
			weixinTimeStatistical = data[0];
			weixinChart.update({
				xAxis : {
					categories : weixinTimeStatistical
				},
				series : [ {
					name : timeOut,
					data : data[1]
				}]
			})
		}
	});
}
