$(function() {
	var mySwiper = new Swiper('.swiper-container', {
		pagination: { /* 分页器*/
			el: '.swiper-pagination',
			clickable: true,
		},
		navigation: {
			nextEl: '.swiper-button-next',
			prevEl: '.swiper-button-prev',
		},
		on: {
			init: function() {
				swiperAnimateCache(this); //隐藏动画元素 
				swiperAnimate(this); //初始化完成开始动画
			},
			transitionEnd: function() {
				swiperAnimate(this); //每个slide切换结束时也运行当前slide动画
			},
		}
	})
	Ajax();
	laydate.render({
					elem: '#time1',
					range: '~',
					format: 'yyyy-MM-dd',
					theme: '#114a97',
						done: function(value, date) {
						oneScreen(value && value.split(' ~ ')[0], value && value.split(' ~ ')[1])
						oneSel(value && value.split(' ~ ')[0], value && value.split(' ~ ')[1])
					}
				});
	laydate.render({
					elem: '#time2',
					range: '~',
					format: 'yyyy-MM-dd',
					theme: '#114a97',
						done: function(value, date) {
						twoScreen(value && value.split(' ~ ')[0], value && value.split(' ~ ')[1],$(".areaTwo").val())
					}
				});
	laydate.render({
					elem: '#time3',
					range: '~',
					format: 'yyyy-MM-dd',
					theme: '#114a97',
					done: function(value) {
						threeScreen(value && value.split(' ~ ')[0], value && value.split(' ~ ')[1],$(".areaTwo").val())
					}
			});
})
var myDate = new Date();
var typeSelc;
var oneType;
function turn(aa) {
	if(aa < 10) {
		aa = "0" + aa;
	}
	return aa
}
	// 第三屏 第四屏 发光外框 定时
	(function() {
		var i = 0;
		var length = $(".orderState_ul >li").length;
		var j = 0;
		var length_1 = $(".orderTtype_Con li").length;
		setInterval(function() {
			if(i == length) {
				i = 0;
				$(".orderState_ul >li").removeClass('active');
			}
			$(".orderState_ul >li").eq(i).addClass('active').siblings().removeClass('active');
			if(i == 5) {
				$(".orderState_ul >li").eq(4).removeClass('active');
			}
			i++;

			if(j == length_1) {
				j = 0;
			}
			$(".orderTtype_Con li").eq(j).addClass('active').siblings().removeClass('active');
			j++;
		}, 2000);
	})();
	//第一屏幕 开始
	function oneScreen(sd,ed) {
		if (oneType) {
			typeSelc=oneType;
		}else{
			typeSelc=5;	
		}
		$.ajax({
			type: "get",
			url: huayi.config.callcenter_url + 'WOReport/GetFeedbacklList',
			async: true,
			dataType: 'json',
			data: {
				start: sd,
				end: ed,
				type: typeSelc
			},
			success: function(data) {
				
				if(data.state == "success") {
					var sorceData=data.rows;
					
					var option = {
						tooltip: {
							formatter: "{b} : {c} ({d}%)"
						},
						legend: {
							orient: 'vertical',
							top: 'middle',
							x: 'top',
							left: 10,
							top: 0,
						},
						series: [{
							type: 'pie',
							radius: '70%',
							selectedMode: 'single',
							center: ['50%', '50%'],
							label: {
								normal: {
									show: true,
								}
							},
							itemStyle: {
				                normal: {
						    	    color:'#159FE9',
				                    opacity:0.3,
				                },
				                emphasis: {
				                	opacity:1,				                	opacity:1
			                    }
				           },
							labelLine: {
								normal: {
									show: true,
								}
							},
	
							data: [{
									value: sorceData[0].number,
									name:  sorceData[0].name,
								},
								{
									value: sorceData[1].number,
									name: sorceData[1].name,
								},
								{
									value: sorceData[2].number,
									name: sorceData[2].name,
								},
								{
									value: sorceData[3].number,
									name: sorceData[3].name,
								}
							],
	
						}]
					};
					echartsPie = echarts.init(document.getElementById('oneScreenPie'));
	
					echartsPie.setOption(option);
				}
			},
			error: function(data) {
				console.log(data.message);
			}
		});
	}
	function oneSel(sd,ed){
		$.ajax({
			type: "get",
			url: huayi.config.callcenter_url + 'WOReport/GetFeedbacklList',
			async: true,
			dataType: 'json',
			data: {
				start: sd,
				end: ed
			},
			success: function(data) {
				
				if(data.state == "success") {
					var sorceData=data.rows;
					$(".onescreenText").html(sorceData[4].number);
					$(".twoscreenText").html(sorceData[3].number);
					$(".threescreenText").html(sorceData[2].number);
					$(".fourscreenText").html(sorceData[1].number);
					$(".fivescreenText").html(sorceData[0].number);
				}
			}
		})
	}
	$(".oneScrClick ul li").click(function(){
		oneType=$(this).attr("index")
		oneScreen($('#time1').val() && $('#time1').val().split(' ~ ')[0], $('#time1').val() && $('#time1').val().split(' ~ ')[1]);
	})
	//第二屏
	function twoScreen(start,end) {
		keyWord(start, end)
	}
	//	左侧关键词
	function keyWord(start, end) {
		$.ajax({
			type: "get",
			url: huayi.config.callcenter_url + "WOReport/GetComplainthandlList",
			async: true,
			dataType: 'json',
            data: {
                start: start,
                end: end
			},
			success: function(data) {
				if(data.state.toLowerCase() == 'success') {
					var con = data.rows;
					if (con.length>0) {
						$(".keyW_t").text(con[0].name)
						$('.tagcloud').html('');
						$(con).each(function(k, j) {
							if(k < 9) {
								var strs = '<div index="'+j.Id+'" class="tagcloud_bj">' +
									'<p class="tag_title">' + j.name + '</p>' +
									'<p class="imgs">' + j.number + '</p>' +
									'</div>'
								$('.tagcloud').append(strs);
							}
						})
						$(".tagcloud div:first-child").removeClass("tagcloud_bj");
	                    $(".tagcloud div:first-child").addClass("tagcloud_bjShine");
	                    keyWordDetail(start, end);
					}else{
						$('.tagcloud').html('');
					}
					
				}
			}
		});
	}
	//	右侧部门
	function keyWordDetail(start,end) {
		$.ajax({
			type: "get",
			url: huayi.config.callcenter_url + "WOReport/GetComplainthandlList",
			async: true,
			dataType: 'json',
			data: {
                stime: start,
                endtime: end,
                questionName:$(".quesType").val()
			},
			success: function(data) {
				if(data.state.toLowerCase() == 'success') {
					$('.scroll_table tbody').html('');
					var con = data.rows;
                    $(con).each(function (j, n) {
                        var rate = '';
                        if (n.rate) { rate = n.rate;}
                        var str = '<tr><td>' 
                        + n.name + '</td><td style="width:60px;">' 
                        + n.number + '</td><td style="width:90px;">' 
                        + n.ongesttime + '</td><td style="width:90px;">' 
                        + n.minimumtime + '</td><td style="width:90px;">' 
                        + n.averageTime + '</td><td style="width:75px;">' 
                        + n.median + '</td><td style="width:90px;">' 
                        + n.Overdue + '</td><td style="width:110px;">' 
                        + n.efficiency + '</td></tr>'
						$('.scroll_table tbody').append(str);
					})
					$(".scroll_table").Scroll({
						line: 1,
						speed: 500,
						timer: 2000
					});
				}
			}
		});
	}
	$(".tagcloud").on("click","div",function(){
		$(".tagcloud div").addClass("tagcloud_bj");
		$(".tagcloud div").removeClass("tagcloud_bjShine");
		$(this).removeClass("tagcloud_bj");
		$(this).addClass("tagcloud_bjShine");
        keyWordDetail($('#time2').val() && $('#time2').val().split(' ~ ')[0], $('#time2').val() && $('#time2').val().split(' ~ ')[1]);
	});
	quesTypeSel();
	$(".quesType").change(function() {
        keyWordDetail($('#test6').val() && $('#test6').val().split(' ~ ')[0], $('#test6').val() && $('#test6').val().split(' ~ ')[1],$(".areaFive").val());
	})
	//部门下拉框
	function quesTypeSel() {
		$.getJSON( huayi.config.callcenter_url +"WOReport/GetComplainthandlList", 
			{
                branchcode: $(".areaFive").val()
			},
			function(result) {
			if(result.state.toLowerCase() == "success") {
				goodslist = result.rows;
				$(".depart").empty();
				$('<option value="">请选择部门</option>').appendTo($(".quesType"));
				$(goodslist).each(function(i, n) {
					$('<option value="' + n.name 
					+ '">' + n.name 
					+ '</option>').appendTo($(".quesType"));
				})
			}
		});
	}
	//第三屏
	function threeScreen(start, end) {
		partOne();
		partTwo();
		partThree();
		partFour();
	}
	$(".channelSel").change(function() {
        partFour();
	})
	function Ajax() {
		oneScreen($('#time1').val() && $('#time1').val().split(' ~ ')[0], $('#time1').val() && $('#time1').val().split(' ~ ')[1])
		oneSel($('#time1').val() && $('#time1').val().split(' ~ ')[0], $('#time1').val() && $('#time1').val().split(' ~ ')[1])
		twoScreen($('#time2').val() && $('#time2').val().split(' ~ ')[0], $('#time2').val() && $('#time2').val().split(' ~ ')[1])
		threeScreen();
	}
