<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>
<script>

</script>
<!-- ajax layout which only needs content area -->
<div class="page-header">
	<h1>
		律师查档
		<small>
			<i class="ace-icon fa fa-angle-double-right"></i>
			实时数据
		</small>
	</h1>
</div><!-- /.page-header -->

<div class="row">
	<div class="col-xs-12">
		筛选人数：<span id="count1" style="font-size: 16px"></span>
		，筛选次数：<span id="count11" style="font-size: 16px"></span>
		| 提交订单数：<span id="count2" style="font-size: 16px"></span>
		，待接单数：<span id="count22" style="font-size: 16px"></span>
		，付款订单数：<span id="count23" style="font-size: 16px"></span>
		| 已取消数：<span id="count3" style="font-size: 16px"></span>
		，已过期数：<span id="count33" style="font-size: 16px"></span>
		</br>
		<input type="text" class="input-sm datapicker" placeholder="选择开始日期" id="startDate"/>
		<input type="text" class="input-sm datapicker" placeholder="选择结束日期" id="endDate"/>
		<button type="button" class="btn btn-primary btn-sm" id="searchd">统计</button>
		<div class="row" style="margin-top: 10px">
			<div class="col-sm-6">
				<div class="widget-box">
					<div class="widget-header">
						<h4 class="widget-title lighter smaller">
							<i class="ace-icon fa fa-comment blue"></i>
							查档筛选
						</h4>

						<div class="widget-toolbar no-border">
							<select class="select" id="needLevelParameter">
								<option value="0" selected = "selected">全部</option>
								<option value="1">强需求</option>
								<option value="2">有需求</option>
								<option value="3">没需求</option>
							</select>
							<button class="btn btn-xs prev_search">
								<i class="ace-icon fa fa-arrow-left"></i>
								上一页
							</button>

							<button class="btn btn-xs next_search">
								下一页
								<i class="ace-icon fa fa-arrow-right"></i>
							</button>

						</div>
					</div>

					<div class="widget-body">
						<div class="widget-main no-padding">
							<!-- #section:pages/dashboard.conversations -->
							<div class="dialogs" id="cd-search"></div>
						</div><!-- /.widget-main -->
					</div><!-- /.widget-body -->
				</div><!-- /.widget-box -->
			</div><!-- /.col -->




		</div><!-- /.row -->


		<!-- PAGE CONTENT ENDS -->
	</div><!-- /.col -->
</div><!-- /.row -->


<div id="modal-search" class="modal fade" tabindex="-1" data-backdrop="static">
	<div class="modal-dialog" style="min-width: 800px;">
		<div class="modal-content">
			<div class="modal-header no-padding">
				<div class="table-header">
					<button type="button" class="close" data-dismiss="modal"
							aria-hidden="true">
						<span class="white">&times;</span>
					</button>
					查询详情
				</div>
			</div>
			<div class="modal-body"	style="max-height: 500px; overflow-y: scroll;">
				<div class="container-fluid">
					<input type="hidden" id="searchLawyerId">
					<table class="table" id="lawyerTab">
						<tr>
							<td>律师信息:</td>
							<td><span id="lawyerPro1"></span></td>
						</tr>
						<tr>
							<td>跟进记录:</td>
							<td colspan="3" id="searchHandleList">

							</td>
						</tr>
						<tr>
							<td>筛选记录:</td>
							<td colspan="3" id="searchList">

							</td>
						</tr>
					</table>
				</div>
			</div>
			<div class="modal-footer no-margin-top">
				<div class="text-right">
					<select class="select" id="needLevel">
						<option value="0"> </option>
						<option value="1">强需求</option>
						<option value="2" selected = "selected">有需求</option>
						<option value="3">没需求</option>
					</select>
					<input type="text" id="followUpSearchContent" style="width: 500px;max-width: 100%;" class="search-query"></input>&emsp;&emsp;
					<button id="submitSearchButton" type="button" class="btn btn-success btn-sm">处理</button>
					<button class="btn btn-sm" data-dismiss="modal">取消</button>
				</div>
			</div>
		</div>

	</div>
	<!-- /.modal-dialog -->
</div>

<!-- page specific plugin scripts -->

<!--[if lte IE 8]>
<script src="${contextPath}/static/assets/js/excanvas.js"></script>
<![endif]-->
<script type="text/javascript">
    var page1 = 1;
    var rows1 = 20;
    var needLevel = 0;

    function freshcdSearchs(){
        page1=1;
        getCdTotal();
        getcdSearchs();

    }

    function getcdSearchs(){

        $.getJSON("${contextPath}/sys/cdMonitor/searchStatic?page="+page1+"&rows="+rows1+"&needLevel="+needLevel,function(res){
            var sec='';
            var info='';
            var remark = '';
            $.each(res, function(i,r){
                sec+='<div class="itemdiv dialogdiv">';
                sec+='<div class="user"><img src="${duowenapp_c}'+r.head+'" /></div>';
                sec+='<div class="body">';
                sec+='<div class="time"><i class="ace-icon fa fa-clock-o"></i><span class="green">'+r.time+'</span></div>';
                info=r.lawyerName+'('+r.lawyerPhone+')';
                sec+='<div class="name"><a href="javascript:cdSearchDetail(\''+r.lawyer_id+'\',\''+info+'\');">'+info+'</a></div>';
                remark = r.needLevel;
                if(remark.length > 0){
                    remark = '<font color="red">&emsp;&emsp;' + remark + '</font>';
                }
                sec+='<div class="text">'+r.cdTypeName+' ['+r.cdArea+'] '+remark+' ----' + r.operateType + '</div>';
                sec+='<div class="tools"><a href="javascript:cdSearchDetail(\''+r.lawyer_id+'\',\''+info+'\');" class="btn btn-minier btn-info"><i class="icon-only ace-icon fa fa-search"></i></a></div>';
                sec+='</div></div>';
            });

            $('#cd-search').html(sec);

        });
    }

    $("#searchd").click(function(){
        getCdTotal();
        /* getSsdbSearchs();
         getSsdbApplys();*/
    });



    function getCdTotal(){
        var startDate = $("#startDate").val();
        //默认查询7天记录
        if(startDate==""){
            var date = new Date((+new Date())-7*24*3600*1000);
            startDate = date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();
            $("#startDate").val(startDate);
        }
        var endDate = $("#endDate").val();
        if(endDate ==""){
            var date = new Date((+new Date()));
            endDate = date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();
            $("#endDate").val(endDate);
        }

        var param = "?startDate=" + startDate + "&endDate=" + endDate;
        $.ajax({
            dataType : "json",
            url : "${contextPath}/sys/cdMonitor/getCdStaticTotal" + param,
            type : "get",
            data : {},
            async:true,
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                $("#count1").html(ret.searchTotal);
                $("#count11").html(ret.searchTotalLawyer);
                $("#count2").html(ret.commitTotal);
                $("#count22").html(ret.waiteTotal);
                $("#count23").html(ret.payedTotal);
                $("#count3").html(ret.cancelTotal);
                $("#count33").html(ret.overdueTotal);
            }
        });
    }




    //保存跟进记录
    function saveFollowUpContent(modalId, lawyerId, contentId, type){
        var data = {
            lawyerId : $("#" + lawyerId).val(),
            content : $("#" + contentId).val(),
            needLevel : $('#needLevel').val(),
        };
        $.getJSON("${contextPath}/sys/cdMonitor/saveFollowUpContent",data,function(result){
            if(result.success){
                $("#" + modalId).modal("toggle");
                getcdSearchs();
            }else{
                alert(result.message);
            }
        });
    }

    function cdSearchDetail(lawyerId,info){
        $('#followUpSearchContent').val('');
        $('#lawyerPro1').html(info);
        $.getJSON("${contextPath}/sys/cdMonitor/searchDetail?lawyerId="+lawyerId,function(res){
            var han = '<table class="table"><tr><td></td><td>内容</td><td>操作人</td><td>日期</td></tr>';
            $.each(res.handles, function(i,r){
                han += '<tr>';
                han += '<td>'+(i+1)+'</td>';
                han += '<td>'+r.content+'</td>';
                han += '<td>'+r.operatorName+'</td>';
                han += '<td>'+r.createDate+'</td>';
                han += '</tr>';
            });
            han += '</table>';
            $('#searchHandleList').html(han);
            var sec='<table class="table"><tr><td></td><td>类型</td><td>地区</td><td>日期</td></tr>';
            $.each(res.searchs, function(i,r){
                sec+='<tr>';
                sec+='<td>'+(i+1)+'</td>';
                sec+='<td>'+r.cdTypeName+'</td>';
                sec+='<td>'+r.cdArea+'</td>';
                sec+='<td>'+r.createDate+'</td>';
                sec+='</tr>';
            });
            sec+='</table>';

            $('#searchList').html(sec);

        });
        $('#searchLawyerId').val(lawyerId);
        $("#modal-search").modal("toggle");
    }

    var scripts = [ null,
		"${contextPath}/static/assets/js/jquery-ui.custom.js",
		"${contextPath}/static/assets/js/jquery.sparkline.js",
        "${contextPath}/static/assets/js/date-time/bootstrap-datepicker.js",
        "${contextPath}/static/assets/js/date-time/locales/bootstrap-datepicker.zh-CN.js",
        "${contextPath}/static/assets/js/jqGrid/jquery.jqGrid.js",
        "${contextPath}/static/assets/js/jqGrid/i18n/grid.locale-cn.js",
        "${contextPath}/static/assets/js/jquery-ui.custom.js",
        "${contextPath}/static/js/fs/ssdbMonitor.js?v=2",
        "${contextPath}/static/assets/js/jquery.sparkline.js"
		,null ];



    $('.page-content-area').ace_ajax('loadScripts', scripts, function() {
        // inline scripts related to this page
        jQuery(function($) {
            $(".prev_search").click(function(){
                page1=page1-1;
                if(page1<=0){
                    page1=1;
                    alert('已经到首页！');
                    return;
                }
                getcdSearchs();
            });
            $(".next_search").click(function(){
                page1=page1+1;
                getcdSearchs();
            });


            getcdSearchs();
            getCdTotal();


            $('.sparkline').each(function() {
                var $box = $(this).closest('.infobox');
                var barColor = !$box.hasClass('infobox-dark') ? $box.css('color') : '#FFF';
                $(this).sparkline('html', {
                    tagValuesAttribute : 'data-values',
                    type : 'bar',
                    barColor : barColor,
                    chartRangeMin : $(this).data('min') || 0
                });
            });

            // Android's default browser somehow is confused when tapping on label which will lead to dragging the task
            // so disable dragging when clicking on label
            var agent = navigator.userAgent.toLowerCase();
            if ("ontouchstart" in document && /applewebkit/.test(agent) && /android/.test(agent))
                $('#tasks').on('touchstart', function(e) {
                    var li = $(e.target).closest('#tasks li');
                    if (li.length == 0)
                        return;
                    var label = li.find('label.inline').get(0);
                    if (label == e.target || $.contains(label, e.target))
                        e.stopImmediatePropagation();
                });

            setInterval("freshcdSearchs()", 3*60000);

            $('#submitSearchButton').on('click', function() {
                saveFollowUpContent('modal-search', 'searchLawyerId', 'followUpSearchContent', 0);
            });

            $('#needLevelParameter').change(function(){
                page1 = 1;
                needLevel = $('#needLevelParameter').val();
                getcdSearchs();
            });
        });

        $('.datapicker').datepicker({
            language: 'zh-CN',
            pickTime: false,
            todayBtn: true,
            autoclose: true,
            minView: '2',
            forceParse: false,
            format:"yyyy-mm-dd"
        });
    });


</script>
