/*基本参数*/
var json_myScore;
var json_SubjectAndScoreAnalysis;
var json_SubjectAndScoreAnalysis_fufen;
var json_ScoreSectionRank;
var json_moreExam;
var studentReportShowItem;
var payNum;
var total;
var xAxisValue = new Array();
var seriesValue = new Array();
var bodyWidth = window.screen.width;
var nowwidth = bodyWidth * 4 / 15;
var view = null;
var memory_fenshuyuan = '';
var year='';
var datas="";
var isFree="";
$(function() {
	mui.init({
		statusBarBackground: '#f7f7f7'
		//		pullRefresh: {
		//			container: '#pullrefresh',
		//			down: {
		//				style: 'circle', //必选，下拉刷新样式，目前支持原生5+ ‘circle’ 样式
		//				color: '#2BD009', //可选，默认“#2BD009” 下拉刷新控件颜色
		//				height: 1.0 * nowwidth + 'px', //可选,默认50px.下拉刷新控件的高度,
		//				range: 1.0 * nowwidth + 'px', //可选 默认100px,控件可下拉拖拽的范围
		//				offset: '0px',
		//				callback: pulldownRefresh
		//			}
		//		}
	});
	
	window.addEventListener('fanhuishuaxin', function(e) {
		//执行刷新
		location.reload();
		
	});

	/*页面初始化*/
	mui.plusReady(function() {
		//选科推荐点击事件
		$("#xuankeTuijianBtn").on("tap", function() {
			var _this = $(this);
			$("#onloading").show();
		
			$.newAjax({
				url: $.getUrl() + '/appIndex!isOpenQuery.action',
				data: {
					user_id: plus.storage.getItem("xuejihao"),
					ziyuan_num: '60151'
				},
				success: function(d) {
					if (d.code == 200) {
						mui.openWindow({
							url: "xuankeTuijian.html",
							id: 'XuankeTuijian.html',
							extras: {
								examNum: $("#examNum").val(),
								gradeNum: $.getValue("gradeNum")
							},
		
							waiting: {
								autoShow: true, //自动显示等待框，默认为true
								title: '正在加载...', //等待对话框上显示的提示内容
								options: {
									//width: waiting - dialog - widht, //等待框背景区域宽度，默认根据内容自动计算合适宽度
									//height: waiting - dialog - height, //等待框背景区域高度，默认根据内容自动计算合适高度
									//......
								}
							}
						});
		
					} else if (d.code == 501) { //未购买
						var str = getTried();
									
						layer.open({
							title: ["了解更多学情，请购买以下增值服务套餐!", 'margin-top:-0.10rem;background-color:#48C6FF; color:#fff;'],
							content: '<p style="font-size: 0.20rem;">学业评价</p>' +
								'<p style="text-align: left;text-indent:0.30rem">学生在学校和区域所处位置【总分一分一段表／全科等级分布表】、学业水平及偏科情况【学科超越率】、与班级/学校/区域成绩对比、发展动态趋势、历次考试情况、选科推荐（如适用）。</p>' +
								'<p style="font-size: 0.20rem;">学科诊断</p>' +
								'<p style="text-align: left;text-indent:0.30rem">学生在学校和区域所处位置【单科一分一段表／单科等级分布表】、小题诊断、知识点诊断/能力点诊断/题型诊断【如校方标注】、答题卡查询、试卷及参考答案查询【如校方提供】。</p>',
							btn: [str, '取消'],
							shadeClose: false,
							yes: function(index) {
								mui.openWindow({
									url: '../sf/productAll.html',
									id: 'productAll'
								});
							},
							no: function(index) {
								layer.close();
							}
						});
					} else if (d.code == 502) { //已过期
						layer.open({
							title: ["续费", 'background-color:#8DCE16; color:#fff;'],
							content: '请去续费',
							btn: ['确定', '取消'],
							shadeClose: false,
							yes: function(index) {
								mui.openWindow({
									url: '../sf/myProduct.html',
									id: 'myProduct'
								});
							},
							no: function(index) {
								layer.close();
							}
						});
					} else {
						alert(d.msg);
						return;
					}
					$("#onloading").hide();
				}
			});
		});
		//赋分 原始分切换
		$("#fufenSwitchDiv>ul>li").click(function() {
			memory_fenshuyuan = 'refresh';
			if ($(this).hasClass("li-active")) {
				return;
			}
			$(this).addClass("li-active").siblings().removeClass("li-active");
			//得分、正确率 或者 等级 或者 得分+等级
			var studentReportShowType = json_myScore[8][$.getValue("gradeNum")];
			var selectedValue = $(this).attr('value');
			
			//是否展示上线情况
			var isShowSHangxian = json_myScore[11];
			var isfufen=json_myScore[10].isfufen;
			var appZhiyuantianbao=json_myScore[10].appZhiyuantianbao
			if(selectedValue=='1'){
				$("#isFufen").val("1");
				if(studentReportShowType==0){
					var moniScore=''
					var ishave=json_myScore[10].ishave
					var stage=json_myScore[10].stage
					if(ishave==1&&stage==53){ 
						year=json_myScore[10].year
						moniScore=json_myScore[10].score_fufen
						ranking=json_myScore[10].ranking
						var rankingStr=''
						if(null!=ranking){
							rankingStr="("+ranking+")"
						}
						var moniStr="模拟"+year+"年高考预估总分："+moniScore+rankingStr
						// $('#score_val').html(moniStr)
						$('#moniScore').show() 
					}else{
						$('#moniScore').hide()
					}
					
				}else{
					$('#moniScore').hide()
				}
				if(json_myScore[2].length<=0){ 
					$("#totalScore").val(0);
					$("#fullScore").val(0);
					myScore(null,studentReportShowType); /*我的分数*/
				}else{
					$("#totalScore").val(json_myScore[2][0][1]);
					$("#fullScore").val(json_myScore[2][0][2]);
					myScore(json_myScore[2][0],studentReportShowType); /*我的分数*/
				}
				if(appZhiyuantianbao==1&&stage==53){//如果学段为高中学段 （目前不考虑当模拟分、排名为空的时候，金榜路页面的展示）
					// $('#zhiyuantianbao').show() 
					var ranking=json_myScore[10].ranking
					if(null!=ranking){
						$('#zhiyuantianbao').show() 
					}else{
						$('#zhiyuantianbao').hide() 
					}
				}else if(appZhiyuantianbao==0&&stage==53){//如果学段为高中学段 
					$('#zhiyuantianbao').show() 
				}else{
					$('#zhiyuantianbao').hide() 
				}

				if(isFree=='200'){
					if(isShowSHangxian["fufen"]=='T'){
						$("#shangxianqingkuang").show();
					}else{
						$("#shangxianqingkuang").hide();
					}
					
				}else{
					$("#shangxianqingkuang").hide();
				}
				
				setTimeout(function() {
					oneSubScore(json_SubjectAndScoreAnalysis_fufen); /*1--各科目分数*/
					setTimeout(function() {
						afterReadyThings();
					}, 100);
				});
			}else{
				$("#isFufen").val("0");
				$('#moniScore').hide()
				$('#zhiyuantianbao').hide()
				if(json_myScore[0].length<=0){
					$("#totalScore").val(0);
					$("#fullScore").val(0);
					myScore(null,studentReportShowType); /*我的分数*/
				}else{
					$("#totalScore").val(json_myScore[0][0][1]);
					$("#fullScore").val(json_myScore[0][0][2]);
					myScore(json_myScore[0][0],studentReportShowType); /*我的分数*/
				}
				
				if(isFree=='200'){
					if(isShowSHangxian["yuanshi"]=='T'){
						$("#shangxianqingkuang").show();
					}else{
						$("#shangxianqingkuang").hide();
					}
					
				}else{
					$("#shangxianqingkuang").hide();
				}
				
				setTimeout(function() {
					oneSubScore(json_SubjectAndScoreAnalysis); /*1--各科目分数*/
					setTimeout(function() {
						afterReadyThings();
					}, 100);
				});
			}
			
		});
		function createView1() {
			var self = plus.webview.currentWebview(); //历次考试是否传值
			if (self.examNum != null) { //传值，接受并对页面上的隐藏域赋值
				var index = $("#tabDiv .mui-active").index();
				plus.nativeUI.showWaiting("请稍等，正在刷新!");
				StuPersonalScoreAndRank();
			} else { //未传值，去数据库中查询最近的exam
				$.newAjax({
					url: $.getUrl() + "/appIndex!getNewlyExam.action",
					success: function(data) {
						if (data && data != null && data != '') {
							$("#examNum").val(data);
							var index = $("#tabDiv .mui-active").index();
							plus.nativeUI.showWaiting("请稍等，正在刷新!");
							StuPersonalScoreAndRank();
						}
					},
					error: function(XMLHttpRequest, textStatus, errorThrown) {
						var str = XMLHttpRequest.responseText;
					}
				});
			}
		}
		creatreView(createView1, {
			sideX: 0.44 * nowwidth,
			sideY: 1.0 * nowwidth
		})
		bodyWidth = plus.screen.resolutionWidth; //可以通过对比大小来决定bodyWidth和bodyHeight
		bodyHeight = plus.screen.resolutionHeight;
		if (plus.storage.getItem("AccessToken") != undefined) { //登录
			var self = plus.webview.currentWebview(); //历次考试是否传值
			if (self.examNum != null) { //传值，接受并对页面上的隐藏域赋值
				$("#examNum").val(self.examNum);
				$("#header1").show(); /*返回标签*/
			} else { //未传值，去数据库中查询最近的exam
				$.newAjax({
					url: $.getUrl() + "/appIndex!getNewlyExam.action",
					success: function(data) {
						if (data && data != null && data != '') {
							$("#examNum").val(data);

						}
					},
					error: function(XMLHttpRequest, textStatus, errorThrown) {
						var str = XMLHttpRequest.responseText;
					}
				});
				$("#header2").show();
			}

			/*第一模块*/
			StuPersonalScoreAndRank();
		};
	});

});

function tuijianhaoyou(){
	$.newAjax({
		url:plus.storage.getItem("payUrl")+"/youhuiquan/query/IsSettuijianyouhuiquan",
		data:{
			systemid:plus.storage.getItem("systemid"),
		},
		success:function(data){
			
			if(data==1){//有
				$("#yaoqinghaoyou").show();
			}else{
				$("#yaoqinghaoyou").hide();
			}
			
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			
		}
	})
}

/*第一模块（总分、班校区排名）*/
function StuPersonalScoreAndRank() {
	
	tuijianhaoyou();
	
	$.newAjax({
		url: $.getUrl() + "/appIndex!getStuPersonalScoreAndRank.action",
		data: {
			examNum: $("#examNum").val(),
			gradeNum: $.getValue("gradeNum")
		},
		success: function(data) {
			var json = eval(data); //数组   
			datas=json;
			if (data[6]=="1") { //有考试数据
				$("#gradeNum").val(data[12]);
				var html = '';
				json_myScore = json;
				$("body h1").html(json[4]); //标题
				$("#S1Set").val(json[1]);
				
				$("#offCanvasSide").show();

				if(json[5]=='T'){//有赋分
					if(memory_fenshuyuan==''){
						if(json[7]=='0'){//配置文件默认显示原始分
							$("#fufenLi").removeClass("li-active");
							$("#yuanshifenLi").addClass("li-active");
						}else{
							$("#yuanshifenLi").removeClass("li-active");
							$("#fufenLi").addClass("li-active");
						}
					}
					$("#fufenSwitchDiv").show();
				}else{
					$("#fufenLi").removeClass("li-active");
					$("#yuanshifenLi").addClass("li-active");
					$("#fufenSwitchDiv").hide();
				}
				//当前考试没有选科组合时显示选科推荐
				if(json[9]=='T'){
					$("#xuankeTuijianDiv").show();
				}else{
					$("#xuankeTuijianDiv").hide();
				}
				//得分、正确率 或者 等级
				var studentReportShowType = studentReportShowItem = json_myScore[8][$.getValue("gradeNum")];
				var moniScore=''
				var ishave=json_myScore[10].ishave
				var stage=json_myScore[10].stage
				var isfufen=json_myScore[10].isfufen
				var appZhiyuantianbao=json_myScore[10].appZhiyuantianbao
				var isShowShangxian=json_myScore[11];
				
				if(studentReportShowType==0){
					var selectedValue = $("#fufenSwitchDiv").find("li[class='li-active']").eq(0).attr('value');
					if(ishave==1&&stage==53&&selectedValue==isfufen){ 
						year=json_myScore[10].year
						moniScore=json_myScore[10].score_fufen
						ranking=json_myScore[10].ranking
						var rankingStr=''
						if(null!=ranking){
							rankingStr="("+ranking+")"
						}
						var moniStr="模拟"+year+"年高考预估总分："+moniScore+rankingStr
						// $('#score_val').html(moniStr)
						$('#moniScore').show() 
						
					}else{
						$('#moniScore').hide()
					}					
				}else{
					$('#moniScore').hide()
				}
				
				if(selectedValue==isfufen&&isShowShangxian["fufen"]=='T'){
					$('#shangxianqingkuang').show()
				}else if(selectedValue==isfufen&&isShowShangxian["fufen"]=='F'){
					$('#shangxianqingkuang').hide()
				}else{
					if(isShowShangxian["yuanshi"]=='T'){
						$('#shangxianqingkuang').show() 
					}else{
						$('#shangxianqingkuang').hide()
					}
				}
				
				
				if(appZhiyuantianbao==1&&stage==53&&ishave==1){
					var ranking=json_myScore[10].ranking
					if(null!=ranking){
						$('#zhiyuantianbao').show() 
					}else{
						$('#zhiyuantianbao').hide() 
					}
				}else if(appZhiyuantianbao==0&&stage==53){
					$('#zhiyuantianbao').show() 
				}else{
					$('#zhiyuantianbao').hide() 
				}
				
				//全科总title  总分一分一段表、全科正确率分布、全科等级分布
				changeAllSubjectTitle(studentReportShowType);
				
				if( json_myScore[0].length<=0){ 
					$("#totalScore").val(0);
					$("#fullScore").val(0);
					$("#isFabu").val("0");
					myScore(null,studentReportShowType); /*我的分数*/
				}else{
					$("#isFabu").val("1");
					var selectedValue = $("#fufenSwitchDiv").find("li[class='li-active']").eq(0).attr('value');
					if(selectedValue=='1'){
						if(null==json[2]||json[2].length==0){
							$("#totalScore").val(0);
							$("#fullScore").val(0);
							$("#isFabu").val("0");
							myScore(null,studentReportShowType); /*我的分数*/
						}else{
							$("#totalScore").val(json[2][0][1]);
							$("#fullScore").val(json[2][0][2]);
							myScore(json_myScore[2][0],studentReportShowType); /*我的分数*/
						}
					}else{
						$("#totalScore").val(json[0][0][1]);
						$("#fullScore").val(json[0][0][2]);
						myScore(json_myScore[0][0],studentReportShowType); /*我的分数*/
					}
				}
				
				$("#isMoreSchool").val(json[3]); //给隐藏域传值
				localStorage.setItem("isMoreSchool", json[3]);
				if(json[3]=='T'){
					$(".area").show();
				}else{
					$(".area").hide();
					$("#lineChartChangeGradeOption_a").removeAttr("href");//进退步检测，当没有全区的时候，点击样式不起作用
				}
				setTimeout(function() {
					setTimeout(function() {
						SubjectAndScoreAnalysis(); //学科均衡性和成绩排名
						setTimeout(function() {
							setTimeout(function() {
								StuMoreExamScoreList();
								setTimeout(function() {
									afterReadyThings();
								}, 100);
							}, 0);
							$("#onloading").hide();
						}, 100);
					}, 0);
				}, 100);

				/*
				if (json[0][0][7]) { //区成绩存在
					
					if (json[1] == "1") {
						html +=
							"<div style='width:33%'><div style='border-right: 0.01rem solid #E1E1E1;'><div style='text-align:center;'>班排名</div><div style='text-align:center;'><span>" +
							json[0][5] + "/" + json[0][8] + "</span></div><div id='progress' style='margin:auto'><span style='width:" + (
								(1 - (json[0][5] / json[0][8])) * 100) + "%'></span></div></div></div>" +
							"<div style='width:33%'><div style='border-right: 0.01rem solid #E1E1E1;'><div style='text-align:center;'>校排名</div><div style='text-align:center;'><span>" +
							json[0][6] + "/" + json[0][9] + "</span></div><div id='progress' style='margin:auto'><span style='width:" + (
								(1 - (json[0][6] / json[0][9])) * 100) + "%'></span></div></div></div>" +
							"<div style='width:33%'><div><div style='text-align:center;'>区排名</div><div style='text-align:center;'><span>" +
							json[0][7] + "/" + json[0][10] + "</span></div><div id='progress' style='margin:auto'><span style='width:" +
							((1 - (json[0][7] / json[0][10])) * 100) + "%'></span></div></div></div>";
						console.log(html);
					} else {
						//						"<div style='width:33%'><div style='border-right: 1px solid #E1E1E1;'><div>百分等级班</div><div><span>" + json[0][11] +"</span></div><div id='progress'><span style='width:" + json[0][11] + "%'></span></div></div></div>" +
						html +=
							"<div style='width:50%;'><div style='border-right: 0.01rem solid #E1E1E1;'><div style='text-align:center;'>学校超越率</div><div style='text-align:center;'><span>" +
							json[0][12] + "%</span></div><div id='progress'  style='margin:auto'><span style='width:" + json[0][12] +
							"%'></span></div></div></div>" +
							"<div style='width:50%;'><div><div  style='text-align:center;'>全区超越率</div><div style='text-align:center;'><span>" +
							json[0][13] + "%</span></div><div id='progress'  style='margin:auto'><span style='width:" + json[0][13] +
							"%'></span></div></div></div>";
					}

					$("#isMoreSchool").val(json[3]); //给隐藏域传值
					localStorage.setItem("isMoreSchool", json[3]);

					setTimeout(function() {

						// $(".label_2").html(html); //班校区排名
						setTimeout(function() {
							SubjectAndScoreAnalysis(); //学科均衡性和成绩排名
							setTimeout(function() {
								// ScoreSectionRank();
								setTimeout(function() {
									StuMoreExamScoreList();
									setTimeout(function() {
										afterReadyThings();
									}, 100);
								}, 0);
								$("#onloading").hide();
							}, 100);
						}, 0);
					}, 100);
				} else { //没区
					localStorage.setItem("isMoreSchool", json[3]);
					
					if (json[1] == "1") {
						html +=
							"<div style='width:50%'><div style='border-right: 0.01rem solid #E1E1E1;'><div style='text-align:center;'>班排名</div><div style='text-align:center;'><span>" +
							json[0][5] + "/" + json[0][8] + "</span></div><div id='progress' style='margin:auto'><span style='width:" + (
								(1 - (json[0][5] / json[0][8])) * 100) + "%'></span></div></div></div>" +
							"<div style='width:50%'><div><div style='text-align:center;'>校排名</div><div style='text-align:center;'><span>" +
							json[0][6] + "/" + json[0][9] + "</span></div><div id='progress' style='margin:auto'><span style='width:" + (
								(1 - (json[0][6] / json[0][9])) * 100) + "%'></span></div></div></div>";
					} else {
						html +=
							"<div style='width:100%'><div style='border-right: 0.01rem solid #E1E1E1;'><div style='text-align:center;'>学校超越率</div><div style='text-align:center;'><span>" +
							json[0][12] + "%</span></div><div id='progress' style='margin:auto'><span style='width:" + json[0][12] +
							"%'></span></div></div></div>";
					}
					setTimeout(function() {

						// $(".label_2").html(html); //班校排名
						setTimeout(function() {
							SubjectAndScoreAnalysis(); //学科均衡性和成绩排名
							setTimeout(function() {
								// ScoreSectionRank(); //人数统计
								setTimeout(function() {
									StuMoreExamScoreList();
									$(".area").hide();
									setTimeout(function() {
										afterReadyThings();
										$("#onloading").hide();
									}, 100);
								}, 0);

							}, 100);
						}, 0);
					}, 100);
				}
				*/

			} else {
				//第一个模块不能隐藏，填充内容为空
				$("#onloading").hide();
				var html = '';
				html += "<center><div style='height:0.30rem;margin-top:0.30rem'>您还没有参加任何考试</div></center>";
				$("#offCanvasSide").html(html);
				$("#offCanvasSide").show();
				$("#two_li").hide();
			}

		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			$("#onloading").hide();
		}

	});
}



/*第二、三模块（各科目分数、均衡性以及学科对比）*/
function SubjectAndScoreAnalysis() {

	$.newAjax({
		url: $.getUrl() + '/appIndex!getSubjectAndScoreAnalysis.action',
		data: {
			examNum: $("#examNum").val(),
			user_id: plus.storage.getItem("xuejihao"),
			ziyuan_num: '60151'
		},
		success: function(d) {
			var data = d.data;
			$("#two_li").show();
			json_SubjectAndScoreAnalysis = eval(data[0]); //数组  
			json_SubjectAndScoreAnalysis_fufen = eval(data[1]);
			var selectedValue = $("#fufenSwitchDiv").find("li[class='li-active']").eq(0).attr('value');
			if(selectedValue=='1'){
				oneSubScore(json_SubjectAndScoreAnalysis_fufen); /*1--各科目分数*/
			}else{
				oneSubScore(json_SubjectAndScoreAnalysis); /*1--各科目分数*/
			}
			
			isFree=d.code;
			if (d.code == 200) {

				$("#notpay").hide();
				// $("#two_li li .freePaperDiv").hide();
				// $("#two_li li").css("height","1.60rem");//不显示免费答题卡的话调整科目li的高度
				$("#three").show();
				$("#three_2").show();
				
				var isShowShangxian = datas[11];
				if(selectedValue=='1'&&isShowShangxian["fufen"]=='T'){
					$('#shangxianqingkuang').show()
				}else if(selectedValue=='1'&&isShowShangxian["fufen"]=='F'){
					$('#shangxianqingkuang').hide()
				}else{
					if(isShowShangxian["yuanshi"]=='T'){
						$('#shangxianqingkuang').show()
					}else{
						$('#shangxianqingkuang').hide()
					}
				}
				
				
				var classControl = data[2].classControl;
				var gradeControl = data[2].gradeControl;
				var quControl =data[2].quControl;
				
				console.log(classControl);
				console.log(gradeControl);
				
				var control='';
				if(classControl==0){
					$("#lineChartClass_a").hide();
					$("#lineChartClass").hide();
				}else{
					$("#lineChartClass_a").show();
					$("#lineChartClass").show();
				}
				if(gradeControl==0){
					$("#lineChartGrade_a").hide();
					$("#lineChartGrade").hide();
				}else{
					$("#lineChartGrade_a").show();
					$("#lineChartGrade").show();
				}
				if(quControl==0){
					$("#lineChartArea_a").hide();
					$("#lineChartArea").hide();
				}else{
					$("#lineChartArea_a").show();
					$("#lineChartArea").show();
				}
				
				if(classControl==0){
					$("#lineChartClass_a").removeClass("mui-active");
					if(gradeControl==0){
						$("#lineChartGrade_a").removeClass("mui-active");
						if(quControl==0){
							
						}else{
							$("#lineChartArea_a").addClass("mui-active")
						}
					}else{
						$("#lineChartGrade_a").addClass("mui-active")
					}
				}
				 
				$("#oneScoreone").show();
				setTimeout(function() {
					// console.log("1:"+$("#isMoreSchool").val());
					if ($("#isMoreSchool").val() == "T") { //区存在
						percentageSchoolAndArea(json_SubjectAndScoreAnalysis);
					} else {

						percentageOnlyXiao(json_SubjectAndScoreAnalysis);
					}
				
					setTimeout(function() {
						scoreContrast(); /*4--学生成绩对比（班）*/
					}, 100);
				}, 100);
			} else {
				$('#shangxianqingkuang').hide()
				$("#notpay").show();
				if (d.code == 502) {
					$(".xufei").html("续费");
				} else if (d.code == 501) {
					$(".xufei").html(getTried());
				}
			}
		}
	});
}

//是否已试用
function getTried(){
	var str = "了解详情";
	$.newAjax({
		url: $.getUrl() + '/appIndex!getTried.action',
		data: {
			systemid:plus.storage.getItem("systemid"),
			user_id: plus.storage.getItem("xuejihao")
		},
		success: function(d) {
			if(d.code==200&&d.data=="0"){//显示试用
				str = "试用";
			}
		}
	});
	return str;
}

function scoreContrast() {
	var id = $("#three_2 .mui-control-item.mui-active").attr("id");
	console.log(id);
	if (id == "lineChartClass_a") {
		$("#lineChartGrade").hide();
		$("#lineChartArea").hide();
		scoreContrastClass(json_SubjectAndScoreAnalysis);
	}
	if (id == "lineChartGrade_a") {
		$("#lineChartClass").hide();
		$("#lineChartGrade").show();
		$("#lineChartArea").hide();
		scoreContrastGrade(json_SubjectAndScoreAnalysis);
	}
	if (id == "lineChartArea_a") {
		$("#lineChartClass").hide();
		$("#lineChartGrade").hide();
		$("#lineChartArea").show();
		scoreContrastArea(json_SubjectAndScoreAnalysis);
	}
}

/*第四模块（总分分段统计）*/
function ScoreSectionRank() {
	$.newAjax({
		url: $.getUrl() + '/edei/appIndex!getScoreSectionRank.action',
		data: {
			examNum: $("#examNum").val(),
			user_id: plus.storage.getItem("xuejihao"),
			ziyuan_num: '60151'
		},
		success: function(d) {
			var data = d.data;
			if (d.code == 200) {
				$("#four").show();
				json_ScoreSectionRank = eval(data); //数组       
				scoreSection(); /*7--总分分段统计（班）*/
			}
		}
	});
}

function scoreSection() {
	for (var i = 0; i < json_ScoreSectionRank.length - 1; i++) { //设置值
		xAxisValue[i] = new Array();
		seriesValue[i] = new Array();
		for (var j = 0; j < json_ScoreSectionRank[i].length; j++) {
			xAxisValue[i][j] = json_ScoreSectionRank[i][j][4]; //区间分段
			seriesValue[i][j] = json_ScoreSectionRank[i][j][7]; //累计人数
		}
	}
	var id = $("#four .mui-control-item.mui-active").attr("id");
	if (id == "lineChartTotalCLass_a") {
		$("#lineChartTotalGrade").hide();
		$("#lineChartTotalGrade").next().hide();
		$("#lineChartTotalArea").hide();
		$("#lineChartTotalArea").next().hide();
		scoreSectionClass(json_ScoreSectionRank, xAxisValue, seriesValue);
	}
	if (id == "lineChartTotalGrade_a") {
		$("#lineChartTotalCLass").hide();
		$("#lineChartTotalCLass").next().hide();
		$("#lineChartTotalGrade").show();
		$("#lineChartTotalGrade").next().show();
		$("#lineChartTotalArea").hide();
		$("#lineChartTotalArea").next().hide();
		scoreSectionGrade(json_ScoreSectionRank, xAxisValue, seriesValue);
	}
	if (id == "lineChartTotalArea_a") {
		$("#lineChartTotalCLass").hide();
		$("#lineChartTotalCLass").next().hide();
		$("#lineChartTotalGrade").hide();
		$("#lineChartTotalGrade").next().hide();
		$("#lineChartTotalArea").show();
		$("#lineChartTotalArea").next().show();
		scoreSectionArea(json_ScoreSectionRank, xAxisValue, seriesValue);
	}
}
var checkedValues = [];
/*第五模块(进退步检测)*/
function StuMoreExamScoreList() {
	//1.获取最近的examNum
	var newExamNum = [];
	$.newAjax({
		url: $.getUrl() + '/edei/appIndex!getExams.action',
		success: function(data) {
			if (data && data != null && data != '') {
				var json = eval(data);
				if (json.length > 1) {
					if (json[0].examNum == $("#examNum").val()) { //本次考试即为最新的考试
						newExamNum.push(json[1].examNum);
						newExamNum.push($("#examNum").val());
					} else {
						newExamNum.push($("#examNum").val());
						newExamNum.push(json[0].examNum);
					}
				} else {
					newExamNum.push($("#examNum").val());
				}
			}
		}
	});
	checkedValues = newExamNum;
	// console.log("checkedValues:"+checkedValues);
	$.newAjax({
		url: $.getUrl() + '/edei/appIndex!getStuMoreExamScoreList.action',
		traditional: true,
		data: {
			examNum: newExamNum,
			user_id: plus.storage.getItem("xuejihao"),
			ziyuan_num: '60151'
		},
		success: function(d) {
			var data = d.data;
			if (d.code == 200) {
				$("#five_div").show();
				$("#five").show();
				$("#moreExam").show();
				json_moreExam = eval(data); //数组    

				//					var html = "";
				//					for(var i = 0; i < json_moreExam.length; i++) {
				//						html += json_moreExam[i][1][0].ext2 + "<br/>";
				//					}
				//					$("#moreExamContent").html(html);
				moreExam(); //10.个人多次考试成绩变化趋势-标准分（校）
			}
		},
		error: function(data) {
			//				alert("error:"+data.status);
		}
	});
}

function moreExam() {
	var id = $("#five .mui-control-item.mui-active").attr("id");
	if (id == "lineChartChangeGradeOption_a") {
		$("#lineChartChangeGradeOption").show();
		$("#lineChartChangeAreaOption").hide();
		moreExamGrade(json_moreExam);
	}
	if (id == "lineChartChangeAreaOption_a") {
		$("#lineChartChangeGradeOption").hide();
		$("#lineChartChangeAreaOption").show();
		//		alert(json_moreExam);
		moreExamArea(json_moreExam);
	}
}

/*页面加载完之后调用的方法*/
function pulldownRefresh() {
	setTimeout(function() {
		StuPersonalScoreAndRank();
		mui('#pullrefresh').pullRefresh().endPulldownToRefresh(); //refresh completed
	}, 1500);
}

function afterReadyThings() {
	pinjieThings();
}

function pinjieThings() {
	$("#two_li li a").on("tap", function() { /*科目点击事件*/
		var sjt = $(this);
		$("#onloading").show();

		$.newAjax({
			url: $.getUrl() + '/appIndex!getSubjectAndScoreAnalysis.action',
			data: {
				examNum: $("#examNum").val(),
				user_id: plus.storage.getItem("xuejihao"),
				ziyuan_num: '60151'
			},
			success: function(d) {
				var data = d.data;
				console.log(data[2].classControl);
				if (d.code == 200) {
					var selectedValue = $("#fufenSwitchDiv").find("li[class='li-active']").eq(0).attr('value');
					mui.openWindow({
						// url: "../oneSub/oneSubAnalysis/oneSubAnalysis.html",
						// id: 'oneSubAnalysis.html',
						url: "../oneSub/oneSubAnalysis/JiaoXueZhenDuan.html",
						id: 'JiaoXueZhenDuan.html',
						extras: {
							examNum: $("#examNum").val(), //考试编号
							examName: $("h1").html(),
							subjectNum: sjt.attr("subjectNum"),//.find("a")
							subjectName: sjt.attr("name"),
							totalScore: sjt.attr("totalScore"),
							isMoreSchool: $("#isMoreSchool").val(),
							S1Set: $("#S1Set").val(),
							fenshuyuan:selectedValue, //0：原始分  1：赋分
							studentReportShowItem:sjt.attr("studentReportShowItem"),
							classControl:data[2].classControl,
							gradeControl:data[2].gradeControl,
							quControl:data[2].quControl,
						},

						waiting: {
							autoShow: true, //自动显示等待框，默认为true
							title: '正在加载...', //等待对话框上显示的提示内容
							options: {
								//width: waiting - dialog - widht, //等待框背景区域宽度，默认根据内容自动计算合适宽度
								//height: waiting - dialog - height, //等待框背景区域高度，默认根据内容自动计算合适高度
								//......
							}
						}
					});

				} else if (d.code == 501) { //未购买
					var str = getTried();	
					var str2=str;		
					if(str=='了解详情'){
						str2='购买';
					}		
							
					layer.open({
						title: ["了解更多学情，请购买以下增值服务套餐!", 'margin-top:-0.10rem;background-color:#48C6FF; color:#fff;'],
						content: '<p style="font-size: 0.20rem;">学业评价</p>' +
							'<p style="text-align: left;text-indent:0.30rem">学生在学校和区域所处位置【总分一分一段表/全科等级分布表】、学业水平及偏科情况【学科超越率】、与班级/学校/区域成绩对比、发展动态趋势、历次考试情况、选科推荐（如适用）。</p>' +
							'<p style="font-size: 0.20rem;">学科诊断</p>' +
							'<p style="text-align: left;text-indent:0.30rem">学生在学校和区域所处位置【单科一分一段表/单科等级分布表】、小题诊断、知识点诊断/能力点诊断/题型诊断【如校方标注】、答题卡查询、试卷及参考答案查询【如校方提供】。</p>',
						btn: [str2, '取消'],
						shadeClose: false,
						yes: function(index) {
							
							var btnArray = ['取消', '确定'];
							
							mui.confirm('如果需要查询的考试不存在，或者成绩未发布，建议等成绩全部发布后，再'+str2+'增值服务套餐！是否继续？', '提示', btnArray, function(e) { 
								if(e.index == 1) {
									mui.openWindow({
										url: '../sf/productAll.html',
										id: 'productAll'
									});
								}
							})
							
						},
						no: function(index) {
							layer.close();
						}
					});
				} else if (d.code == 502) { //已过期
					layer.open({
						title: ["续费", 'background-color:#8DCE16; color:#fff;'],
						content: '请去续费',
						btn: ['确定', '取消'],
						shadeClose: false,
						yes: function(index) {
							
							var btnArray = ['取消', '确定'];
							
							mui.confirm('如果需要查询的考试不存在，或者成绩未发布，建议等成绩全部发布后，再续费增值服务套餐！是否继续？', '提示', btnArray, function(e) { 
								if(e.index == 1) {
									mui.openWindow({
										url: '../sf/myProduct.html',
										id: 'myProduct'
									});
								}
							})
							
						},
						no: function(index) {
							layer.close();
						}
					});
				} else {
					alert(d.msg);
					return;
				}
				$("#onloading").hide();
			}
		});
	});
	
	//跳转到查看试卷页面
	$("#two_li li .freePaperDiv").on("tap", function() {
		var sjt = $(this).prevAll("a");
		mui.openWindow({
			url: '../oneSub/ownPapers/ownPapers.html',
			id: 'ownPapers.html',
			extras: {
				exampaperNum: sjt.attr("examPaperNum"),
				examName: $("h1").html(),
				subjectName: sjt.attr("name"),
				hideYuantidaan: "1",
				examNum: $("#examNum").val()
			}
		});
	});
	
}

//$("#notpay button").click(function() { /*首页*/
$("#notpay button").on("tap", function() { /*首页*/		
		var str = $(this).html();
		var str2=str;
		if(str=='了解详情'){
			str2='购买';
		}
		
		layer.open({
			title: ["了解更多学情，请购买以下增值服务套餐!", 'margin-top:-0.10rem;background-color:#48C6FF; color:#fff;'],
			content: '<p style="font-size: 0.20rem;">学业评价</p>' +
				'<p style="text-align: left;text-indent:0.30rem">学生在学校和区域所处位置【总分一分一段表/全科等级分布表】、学业水平及偏科情况【学科超越率】、与班级/学校/区域成绩对比、发展动态趋势、历次考试情况、选科推荐（如适用）。</p>' +
				'<p style="font-size: 0.20rem;">学科诊断</p>' +
				'<p style="text-align: left;text-indent:0.30rem">学生在学校和区域所处位置【单科一分一段表/单科等级分布表】、小题诊断、知识点诊断/能力点诊断/题型诊断【如校方标注】、答题卡查询、试卷及参考答案查询【如校方提供】。</p>',
			btn: [str2, '取消'],
			shadeClose: false,
			yes: function(index) {
				
				var btnArray = ['取消', '确定'];
				mui.confirm('如果需要查询的考试不存在，或者成绩未发布，建议等成绩全部发布后，再'+str2+'增值服务套餐！是否继续？', '提示', btnArray, function(e) { 
					if(e.index == 1) {
						
						if (str == "了解详情" || str == "试用") {
							mui.openWindow({
								url: '../sf/productAll.html',
								id: 'productAll'
							});
						} else {
							mui.openWindow({
								url: '../sf/myProduct.html',
								id: 'myProduct'
							});
						}
					}
				})
				
			},
			no: function(index) {
				layer.close();
			}
		});

		
	
});

$("#oneScoreone button").click(function() { /*一分一段表*/
	var isFabu=$("#isFabu").val();
		if(isFabu=='0'){
			mui.alert("总分未发布！！");
		}else{
			var index = $(this).index();
			var totalScore=$("#totalScore").val();
			totalScore=parseInt(totalScore);
			var selectedValue = $("#fufenSwitchDiv").find("li[class='li-active']").eq(0).attr('value');
			mui.openWindow({
				url: 'oneScoreOne.html',
				extras: {
					subjectNum: "-1",
					index: index,
					totalScore:totalScore,
					examNum: $("#examNum").val(), //考试编号
					fenshuyuan:selectedValue, //0：原始分  1：赋分
					studentReportShowItem: studentReportShowItem,
					fullScore:$('#fullScore').val()
				},
				id: 'oneScoreOne.html'
			});
		}
});

$(".topPopover").on("tap", function() { /*历次考试*/

	$.newAjax({
		url: $.getUrl() + '/edei/appIndex!getExams.action',
		success: function(data) {
			var json = eval(data);
			if (json.length > 1) {
				var html = "";
				for (var i = 0; i < json.length; i++) {
					// if (json[i].examNum != $("#examNum").val()) {
						html += "<li class='mui-table-view-cell' name='exam_li'  val=" + json[i].examNum +
							" onclick='examEvent(this)'><div><div id='biaoti'><input type='hidden' value='2' id='examNum'/>" + json[i].examName +
							"</div><div class='mui-clearfix'><div id='moni'>" + json[i].examTypeName + "</div>" +
							"</div></div></li>";
					// }
				}
				$("#top_ul").html(html);
			} else {
				$("#top_ul").html("<li class='mui-table-view-cell'>当前没有进行比较的考试</li>");
			}
		}
	});

	//	$("#topPopover").dialog({
	//		"bg": "#ffffff"
	//	});
});

function examEvent(obj) { /*历次考试的点击事件*/
	mui.openWindow({
		url: '../totalScore/exam.html',
		extras: {
			examNum: $(obj).attr('val')
		},
	});

}

$(".middlePopover").on("tap", function() { /*进退步检测*/
	$.newAjax({
		url: $.getUrl() + '/edei/appIndex!getExams.action',
		success: function(data) {
			var json = eval(data);
			if (json.length > 1) {
				var json = eval(data);
				var html = "";
				var examName = "";
				for (var i = 0; i < json.length; i++) {
					if (json[i].examName.length > 18) {
						examName = json[i].examName + "<br/>";
						//						examName = json[i].examName.substring(0, 16);
					} else {
						examName = json[i].examName;
					}
					if (json[i].examNum == $("#examNum").val()) {
						html += "<li style='display:none;border:0;'><input value=" + json[i].examNum +
							" type='checkbox' checked='checked' disabled='disabled'></li>";
					} else {
						html += "<li class='mui-table-view-cell'><span id='middlePopover_checkbox'><input value=" + json[i].examNum +
							" type='checkbox' class='input_check' id='check" + json[i].examNum + "' disabled='disabled'><label for='check" + json[i].examNum +
							"'></label></span><span>" + examName + "</span></li>";
					}
				}
				$("#middlePopover ul div:eq(0)").html(html);
				for (var i = 0; i < checkedValues.length; i++) {
					if (checkedValues[i] != $("#examNum").val()) {
						$("#middlePopover ul input[type='checkbox'][value='" + checkedValues[i] + "']").prop("checked", true);
					}
				}
			} else {
				$("#middlePopover ul div:eq(0)").html("<li class='mui-table-view-cell'>当前没有进行比较的考试</li>");
				$("#ensure").hide();
			}
			$("#middlePopover ul div:eq(0) li").on("tap", function() {
				var check=$(this).find("input");
				var checkStatus=check.is(':checked');
				if(checkStatus){
					check.prop('checked',false);
				}else{
					check.prop("checked",true);
				}
			});
		}
	});
	//	$("#middlePopover").dialog({
	//		"bg": "#ffffff"
	//	});
});

$("#ensure").on("tap", function() { /*进退步检测考试选择*/
	mui('.mui-scroll-wrapper').scroll(0, 100000);
	checkedValues = [];
	var checkedContent = [];
	// checkedValues.push($("#examNum").val());
	// $.each($("#middlePopover input[class='input_check']:checked"), function() {
	$.each($("#middlePopover input:checked"), function() {
		checkedValues.push($(this).val());
	});
	// console.log(checkedValues);
	checkedValues.reverse();
	// console.log(checkedValues);
	//	$("#middlePopover").hideDialog();
	mui('#middlePopover').popover('hide');
	if (checkedValues.length > 10){
		mui.alert("最多选择10次考试");
		return false;
	}else if (checkedValues.length >= 2) {
		$.newAjax({
			url: $.getUrl() + '/edei/appIndex!getStuMoreExamScoreList.action',
			traditional: true,
			data: {
				examNum: checkedValues,
				user_id: plus.storage.getItem("xuejihao"),
				ziyuan_num: '60151'
			},
			success: function(d) {
				var data = d.data;
				if (d.code == 200) {
					$("#five_div").show();
					$("#five").show();
					$("#moreExam").show();

					var html = "";
					json_moreExam = eval(data); //数组       
					for (var i = 0; i < json_moreExam.length; i++) {
						html += json_moreExam[i][1][0].ext2 + "<br/>";
					}
					$("#moreExamContent").html(html);
					//10.个人多次考试成绩变化趋势-标准分（校）
					var changeScore = $(".changeScore.mui-active").attr("id");
					if (changeScore == "lineChartChangeGradeOption_a") {
						$("#lineChartChangeGradeOption").show();
						$("#lineChartChangeAreaOption").hide();
						moreExamGrade(json_moreExam);
					} else {
						$("#lineChartChangeAreaOption").show();
						$("#lineChartChangeGradeOption").hide();
						moreExamArea(json_moreExam);
					}
				}
			}
		});
	} else {
		mui.alert("您未选择考试");
	}
});

/*切换的点击事件*/
/*第三模块（第一个滑动学科均衡性）*/
$("#barChartArea_a").on("tap", function() {
	$("#barChartArea").show();
	$("#barChartSchool").hide();
	percentageArea(json_SubjectAndScoreAnalysis);
});
$("#barChartSchool_a").on("tap", function() {
	$("#barChartArea").hide();
	$("#barChartSchool").show();
	percentageSchool(json_SubjectAndScoreAnalysis);
});
/*第三模块（第二个滑动学科对比）*/
$("#lineChartClass_a").on("tap", function() {
	$("#lineChartClass").show();
	$("#lineChartGrade").hide();
	$("#lineChartArea").hide();
	scoreContrastClass(json_SubjectAndScoreAnalysis);
});
$("#lineChartGrade_a").on("tap", function() {
	$("#lineChartClass").hide();
	$("#lineChartGrade").show();
	$("#lineChartArea").hide();
	scoreContrastGrade(json_SubjectAndScoreAnalysis);
});
$("#lineChartArea_a").on("tap", function() {
	$("#lineChartClass").hide();
	$("#lineChartGrade").hide();
	$("#lineChartArea").show();
	scoreContrastArea(json_SubjectAndScoreAnalysis);
});
/*第四模块（总分分段统计）*/
$("#lineChartTotalCLass_a").on("tap", function() {
	$("#lineChartTotalCLass").show();
	$("#lineChartTotalCLass").next().show();
	$("#lineChartTotalGrade").hide();
	$("#lineChartTotalGrade").next().hide();
	$("#lineChartTotalArea").hide();
	$("#lineChartTotalArea").next().hide();
	scoreSectionClass(json_ScoreSectionRank, xAxisValue, seriesValue);
});
$("#lineChartTotalGrade_a").on("tap", function() {
	$("#lineChartTotalCLass").hide();
	$("#lineChartTotalCLass").next().hide();
	$("#lineChartTotalGrade").show();
	$("#lineChartTotalGrade").next().show();
	$("#lineChartTotalArea").hide();
	$("#lineChartTotalArea").next().hide();
	scoreSectionGrade(json_ScoreSectionRank, xAxisValue, seriesValue);
});
$("#lineChartTotalArea_a").on("tap", function() {
	$("#lineChartTotalCLass").hide();
	$("#lineChartTotalCLass").next().hide();
	$("#lineChartTotalGrade").hide();
	$("#lineChartTotalGrade").next().hide();
	$("#lineChartTotalArea").show();
	$("#lineChartTotalArea").next().show();
	scoreSectionArea(json_ScoreSectionRank, xAxisValue, seriesValue);
});

/*第五模块（进退步检测）*/
$("#lineChartChangeGradeOption_a").on("tap", function() {
	$("#lineChartChangeGradeOption").show();
	/*$("#lineChartChangeGradeOption").next().show();*/
	$("#lineChartChangeAreaOption").hide();
	
	setTimeout(function(){
		if($("#isMoreSchool").val()=="F"){
			console.log("222");
			$(this).addClass("mui-active");
			console.log($(this).attr("class"));
		}
	},1000);
	
	
	// console.log($("#moreExam div:eq(0) a[class='mui-active']").length);
	
	/*$("#lineChartChangeAreaOption").next().hide();*/
	moreExamGrade(json_moreExam);
});

$("#lineChartChangeAreaOption_a").on("tap", function() {
	$("#lineChartChangeAreaOption").show();
	/*$("#lineChartChangeGradeOption").next().show();*/
	$("#lineChartChangeGradeOption").hide();
	/*$("#lineChartChangeAreaOption").next().hide();*/
	moreExamArea(json_moreExam);
});

function xiangqing() {
	layer.open({
		title: ["关于模拟高考分数的详解", 'margin-top:-0.10rem;background-color:#48C6FF; color:#fff;'],
		content: '<p style="font-size: 0.20rem;">当前分数模拟本校'+year+'年高考分数。这个分数可在优自愿APP里模拟填报。点击模拟高考分数可以购买优自愿的志愿卡。(根据本校'+year+'年高考的百分等级分推算出的此次考试所对应的'+year+'年的高考分数）</p>',
		btn: ['确定'],
		shadeClose: false,
		no: function(index) {
			layer.close();
		}
	});
}

function shangxian(){
	mui.openWindow({
		url: '../totalScore/shangxian.html',
		extras: {
			examNum:$("#examNum").val(),
			gradeNum:$("#gradeNum").val(),
			isFufen:$("#isFufen").val(),
		},
		id: 'shangxian'
	});
}

function shangpin(){
	var appZhiyuantianbao=json_myScore[10].appZhiyuantianbao
	var url=''
	if(appZhiyuantianbao==0){
		url='../shop/zhiyuanka.html'
	}else{
		url='../shop/shopmain.html'
	}
	mui.openWindow({
		url: url,
		extras: {
			examNum:$("#examNum").val(),
			gradeNum:$("#gradeNum").val(),
		},
		id: 'productAll'
	});
} 

function cankaoSchool(){

	mui.openWindow({
		url: '../totalScore/cankaoSchool.html',
		extras: {
			examNum:$("#examNum").val(),
			gradeNum:$("#gradeNum").val(),
		},
		id: 'shangxian'
	});
}


//点击主页面邀请好友领红包图片跳转
function yaoqinghaoyou(){
	$.newAjax({
		url: plus.storage.getItem('payUrl') + "/dingdan/getUserIsBuyTaocan",
		data: {
			systemid: plus.storage.getItem('systemid'),
			user_id: plus.storage.getItem("xuejihao"),
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			// console.log(XMLHttpRequest.status);
			mui.alert("收费服务器关闭或异常，请联系管理员！");
		},
		success: function(d) {
			if(d.code==200){
				if(d.data=='0'){//新用户（未购买过）
					// mui.alert("您不满足活动条件，暂时无法推荐好友！（购买过增值服务的用户可以推荐好友）");
					mui.openWindow({
						url: "../yaoqing/TuiJianHaoYouOfNewUser.html",
						id: 'TuiJianHaoYouOfNewUser.html'
					});
				}else if(d.data=='1'){//老用户（已购买）
					mui.openWindow({
						url: "../yaoqing/TuiJianHaoYou.html",
						id: 'TuiJianHaoYou.html'
					});
				}
			}
		},
	});
}

function openvideo(){
	var studentReportShowType = studentReportShowItem = json_myScore[8][$.getValue("gradeNum")];
	var he = document.body.clientHeight;
	var he2=he*0.7
	var str='<div style="text-align: center;"><video src="http://qiniu.51baxue.com/video/jiazhang_score.mp4" style="height:'+he2+'px" controls="controls" autoplay></video></div>'
	if(studentReportShowType==2){
		str='<div style="text-align: center;"><video src="http://qiniu.51baxue.com/video/jiazhang_dengji.mp4" style="height:'+he2+'px" controls="controls" autoplay></video></div>'
	}
	layer.open({
		title: ["数据解读", 'margin-top:-0.10rem;background-color:#48C6FF; color:#fff;'],
		content: str,
		btn: ['关闭'],
		shadeClose: false,
		no: function(index) {
			layer.close();
		}
	});
}
