<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="org.wdk.WDKConstant"%>
<%@ page import="org.wdk.WDKCore"%>
<%@ page import="org.wdk.WDK"%>
<%@ page import="com.noblelift.imp.platform.module.portal.source.SessionUser"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
	String WDK_ROOT = WDKCore.WDK_ROOT;
	SessionUser su = (SessionUser)WDK.getSessionUser(request, response);
	WDK.writeSessionUser(out, su);
%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
		
		<base href="<%=basePath%>" target="_self">
		<title>批发零售月趋势查询</title>
		<link rel="stylesheet" type="text/css" href="platform/report/css/report.css">
		<script type="text/javascript" src="<%=WDK_ROOT%>/theme/je/core/js/wdk.js"></script>
		<script type="text/javascript" src="platform/report/js/pf.report.js"></script>
		<script type="text/javascript" src="platform/report/js/pf.chart.js"></script>
		<script type="text/javascript">
	  	<% if(null==su){%>    
	  		$.timeout();
	  	<%}%>
 	     var _data = {
					    header: [{
					        id: 'title',
					        text: '指标'
					    },{
					        id: '2016_5',
					        text: '2016.5'
					    }, {
					        id: '2016_6',
					        text: '2016.6'
					    }, {
					        id: '2016_7',
					        text: '2016.7'
					    }, {
					        id: '2016_8',
					        text: '2016.8'
					    }, {
					        id: '2016_9',
					        text: '2016.9'
					    }, {
					        id: '2016_10',
					        text: '2016.10'
					    }, {
					        id: '2016_11',
					        text: '2016.11'
					    }, {
					        id: '2016_12',
					        text: '2016.12'
					    }, {
					        id: '2017_1',
					        text: '2017.1'
					    }, {
					        id: '2017_2',
					        text: '2017.2'
					    }, {
					        id: '2017_3',
					        text: '2017.3'
					    }, {
					        id: '2017_4',
					        text: '2017.4'
					    }],
					    data: [{
					        'title': '批发销量',
					        '2016_5':412.07,
					        '2016_6':363.85,
					        '2016_7':338.63,
					        '2016_8':305.36,
					          '2017_3':626.87,
					        '2016_9':464.79,
					        '2016_10':698.68,
					        '2016_11':510.9,
					        '2016_12':211.58,
					        '2017_1':2333.94,
					        '2017_2':510.54,
					        '2017_4':792.35
					    }, {
					        'title': '零售销量',
					        '2016_5':552.96,
					        '2016_6':198.00,
					        '2016_7':120.00,
					        '2016_9':232.97,
					        '2016_10':214.45,
					        '2016_11':222.22,
					          '2016_8':205.92,
					        '2016_12':523.34,
					        '2017_1':217.56,
					        '2017_2':291.05,
					        '2017_3':257.12,
					        '2017_4':367.88
					    }]
					};
		var a1 = [{fieldname:'日期',fieldcode:'biz_yearmonth',fieldtype:'dim'}];
	    var a2 =    [{
				        fieldname: '批发销量',
				        fieldcode: 'PL_XL',
				        fieldtype:'metric'
				    }, {
				        fieldname: '零售销量',
				        fieldcode: 'KH_YBH_SL',
				        fieldtype:'metric'
				    }];
				    /*
				    
				    */
	  	//页面初始化
	  	$(function() {
	  		$.orgSelect({
				id:'corp_uuid'
			});
	  		$.monthbox({
	 			id : 'begin_yearmonth',
	 			required : false,
	 			editable : false,
	 			height:25,
	 			tipPosition : 'bottom',
	 			strFormatter : 'yyyy-MM'
	 		});
	 		$('#begin_yearmonth').datebox('setValue','2017-01');
	 		$.monthbox({
	 			id : 'end_yearmonth',
	 			required : false,
	 			editable : false,
	 			height:25,
	 			tipPosition : 'bottom',
	 			strFormatter : 'yyyy-MM'
	 		});
	 		$('#end_yearmonth').datebox('setValue','2017-10');
 			$.productSelect({
				id:'product_uuid'
			});
			//指标计量单位
			$.combo_metric_unit({
				id:'measurement_unit'
				,onLoadSuccess:function(data){
					$.onReadyListener(function(){
						return a1;
					},function(){
						return a2;
					},function(){btn_query();});
				}
			})

			 
			


	  		$(window).resize(function(){
	  			var chart = $.getEchartObj('line_xl');
	  			if(chart){
	  				setTimeout(function(){chart.resize();},500);
	  			}
	  		});
	  	});
 

	  	/**
	  	 * [getFilter description]
	  	 * @return {[type]} [description]
	  	 */
	  	function getFilter(){
	  		var jo = {};
	  		var product_uuid = $.inputpop_getValue({id:'product_uuid'});
	  		if(product_uuid){
	  			jo.product_uuid = product_uuid;
	  		}
	  		var time1 = $('#begin_yearmonth').datebox('getValue');
	  		var time2 = $('#end_yearmonth').datebox('getValue');
	  		if(time1){
	  			jo.biz_yearmonth = time1;
	  			if(time2){
	  				jo.biz_yearmonth = time1+','+time2;
	  			}
	  		}
	  		return jo;
	  	}
	  	/**
	  	 * [createRequestJson 构建查询报表需要的报文]
	  	 * @return {[json]} [返回报文]
	  	 */
	  	function createRequestJson(){
	  		 
	    	var jparam = {};
	    	//构建维度
	    	//var dimList = $.dimension_getValue('dimension');
	    	//加上单位这个维度,单位放最前面
	    	//dimList = [{fieldname:'单位',fieldcode:'county_name'}].concat(dimList);
	    	jparam._FIXEDCOLUMNS = a1;
	    	//构建查询条件
	    	jparam._FILTER = getFilter();
	    	jparam._ACTIVECOLUMNS = a2;
	    	//if(ranges.length>0){
	    		//指标明细的特殊处理
	    	//	ranges = [{fieldname:'本期',fieldcode:'bq',align:'right',width:100}].concat(ranges);
	    	//}
	    	//jparam._RANGE = ranges;
	    	//jparam._METRIC_UNIT = $.combobox_getValue({id:'measurement_unit'});
	    	jparam._TRANSPOSE = 'biz_yearmonth';
	    	//jparam._SERVICE_NAME = 'metric2row_report';
	    	jparam._IS_COLUMN_ROW = true;//指标前置
	    	jparam._METRIC_UNIT = $.combobox_getValue({id:'measurement_unit'});
	    	jparam._TRACEID = $.getUUID();
	    	jparam._ORDERBY = 'biz_yearmonth asc';
	    	return jparam;
	  	}

	  	/**
	  	 * [btn_query 查询操作]
	  	 * @return {[type]} [无]
	  	 */
	  	function  btn_query(){
	    	loading();
		  	var jparam = createRequestJson();
		  	if(!jparam){
		  		loaded();
		  		return;
		  	}

		  	$.report({
	    		id: 'report_context',
				containerid: 'report_gird',
				queryParams: jparam,
				isinit:false,//是否初始化,初始化就不加载数据
				pagination: false,
				view:'front',
				onLoadSuccess: function (_data) {
                	$.line({
			  			id:'line_xl',
			  			title:'批发和零售销量对比分析5',
			  			align:'center',
			  			padding:'0%',
			  			rebuild:true,//是否重画
			  			dimkey:'trans_metric_name',
			  			data:_data
			  		});
                }
	    	});
	  	}
	  
	  	
     
		</script>	
		<style type="text/css">
			.inputgroup:first-child{
				margin-left:10px;
			}
			.inputgroup{
			 	margin-left:10px;
			 	height: 27px;
			 	margin-bottom: 5px;
			 	margin-top: 2px;
			}
			.datagrid-header>td{
				color: #FFF;
			}
		</style>
	</head>
	
	<body class="easyui-layout" data-options="fit:true">
		<div data-options="region:'center',border:false,collapsed:false">
			<div class="easyui-layout" data-options="fit:true">
				<div data-options="region:'north',border:false,collapsed:false" class="row-2" style="padding:10 10px;overflow:hidden;" >
					<form id="search_form">
						<div class="h_layout">
							<div>
								<div class="inputgroup">
									<label>组织选择</label>
									<div>
										<input  id="corp_uuid" name="corp_uuid"/>
									</div>
								</div>
								
								<div class="inputgroup">
									<label>开始年月</label>
									<div>
										<input id="begin_yearmonth" name="begin_yearmonth"/>
									</div>
								</div>
								<div class="inputgroup">
									<label>结束年月</label>
									<div>
										<input id="end_yearmonth" name="end_yearmonth">
									</div>
								</div>
								<div class="inputgroup">
									<label>卷烟选择</label>
									<div>
										<input id="product_uuid" name="product_uuid">
									</div>
								</div>
								<div class="inputgroup">
									<label>计量单位</label>
									<div>
										<input id="measurement_unit" name="measurement_unit" />
									</div>
								</div>
							</div>
							<div style="width:125px;">
								<a class="eapbutton" style="float:right;" onclick="btn_query()"><i class="fa fa-search" aria-hidden="true"></i><span><span>查询</span></span></a>
							</div>
						</div>
					</form>
				</div>

				<div id="report_gird" data-options="region:'center',border:false,collapsed:false" style="padding:10px;overflow-x:hidden;overflow-y: auto; background-color: #FFF;" >
					<div style="padding: 0px 2px;" id="report_context">
					 </div>
					<div id="line_xl" style="height: 500px;margin-top: 20px;">
					</div> 
				</div> 
			</div>
		</div>
	</body>
</html>