<%@ page import="com.fadu.app.util.SystemCache" %>
<%@ 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>

<link rel="stylesheet" href="${contextPath}/static/assets/css/jquery-ui.css" />
<link rel="stylesheet" href="${contextPath}/static/assets/css/datepicker.css" />
<link rel="stylesheet" href="${contextPath}/static/assets/css/ui.jqgrid.css" />

<style>
    #MyDiv{
        position: absolute;
        top: 50px;
        left: 320px;
        display: none;
        font-size: 20px;
    }
    #MyDiv1{
        position: absolute;
        top: 50px;
        left: 320px;
        display: none;
        font-size: 18px;
    }
    #MyDiv2{
        position: absolute;
        top: 50px;
        left: 320px;
        display: none;
        font-size: 18px;
    }
    #sbdxLawyerInfo{
        position: absolute;
        top: -70px;
        left: 320px;
        display: none;
        font-size: 18px;
    }
    /*a  upload */
    .a-upload {
        padding: 4px 10px;
        height: 30px;
        line-height: 20px;
        position: relative;
        top:7px;
        cursor: pointer;
        color: #888;
        background: #fafafa;
        border: 1px solid #ddd;
        border-radius: 6px;
        overflow: hidden;
        display: inline-block;
        *display: inline;
        *zoom: 1
    }

    .a-upload  input {
        position: absolute;
        font-size: 100px;
        right: 0;
        top: 0;
        opacity: 0;
        filter: alpha(opacity=0);
        cursor: pointer
    }

    .a-upload:hover {
        color: #444;
        background: #eee;
        border-color: #ccc;
        text-decoration: none
    }

</style>

<div style="background: rgba(1,1,2,0.05)">
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" class="input-md" placeholder="搜索关键字" id="keyword"/>
    省：<select id="province">
    <option selected value="" >全部</option>
    <% for(String s:SystemCache.provinceMap.keySet()){ %>
    <option value="<%=s %>" ><%=SystemCache.getProvinceName(s) %></option>
    <%} %>
</select>
    <button type="button" class="btn btn-purple btn-sm" id="searchd">
        <span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
        查询
    </button>
    <button type="button" class="btn btn-purple btn-sm" id="noPhone">
        未打过电话
    </button>
    <button type="button" class="btn btn-purple btn-sm" id="addWeChat">
        已加过微信
    </button>
    <button type="button" class="btn btn-purple btn-sm" id="daoruWeChat">
        导入微信信息
    </button>
    <button type="button" class="btn btn-purple btn-sm" id="daoruPhone">
        导入电话信息
    </button>
    <button type="button" class="btn btn-purple btn-sm" id="daochu">
        导出数据
    </button>
    <button type="button" class="btn btn-danger btn-sm" onclick="fromLawToSb()" id="sbdx">
    更新诉保律师库
    </button>
    <br>
    <br>
</div>

<div class="row">
    <div class="col-xs-12">
        <table id="grid-table"></table>
        <div id="grid-pager"></div>
        <script type="text/javascript">
            var $path_base = "${contextPath}/static";//in Ace demo this will be used for editurl parameter
        </script>
        <!-- PAGE CONTENT ENDS -->
    </div><!-- /.col -->
</div><!-- /.row -->



<%--导入框--%>
<div  id="MyDiv" class="modal-dialog white_content">
    <div class="modal-content">
        <div class="modal-header no-padding">
            <div class="table-header">
                <button onclick="CloseDiv()" type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    <span  class="white">&times;</span>
                </button>
                上传Excel更新微信数据
            </div>
        </div>
        <div class="modal-body" style="overflow-y: scroll;">
            <div id="mod-add-tip" class="red clearfix"></div>
            <form name="xx" action="${contextPath}/sbdx/lawyer/uploadFile"
                  method="post" enctype="multipart/form-data" id="formId"
                  class="pageForm required-validate" >
                <div id="upload">
                    <div>
                        <span for="excelFile">选择文件：</span>
                        <a class="a-upload" id="up1">
                            <input id="excelFile" type="file" name="filename">点击上传
                        </a>
                        <span class="showFileName"></span>
                        <span class="fileerrorTip"></span>
                    </div>
                </div>
            </form>
            <br>
            <div class="modal-footer no-margin-top">
                <div class="text-center">
                    <button onclick="javasrcipt:_submit(); " id="mod-add-submit" type="button" class="btn btn-sm btn-primary">
                        <i class="ace-icon fa fa-floppy-o bigger-160"></i>
                        开始导入
                    </button>
                    <button  onclick="CloseDiv()" class="btn btn-sm" data-dismiss="modal">
                        <i class="ace-icon fa fa-share bigger-160"></i>
                        取消
                    </button>
                </div>
            </div>
        </div><!-- /.modal-content -->

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


<%--导入框2--%>

<div  id="MyDiv2" class="modal-dialog white_content">
    <div class="modal-content">
        <div class="modal-header no-padding">
            <div class="table-header">
                <button onclick="CloseDiv2()" type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    <span  class="white">&times;</span>
                </button>
                上传Excel更新打电话数据
            </div>
        </div>
        <div class="modal-body" style="overflow-y: scroll;">
            <div id="mod-add-file" class="red clearfix"></div>
            <form name="xx" action="${contextPath}/sbdx/lawyer/uploadPhoneFile"
                  method="post" enctype="multipart/form-data" id="formId2"
                  class="pageForm required-validate" >
                <div id="uploadFile">
                    <div>
                        <span for="excelFile">选择文件：</span>
                        <a class="a-upload" id="up2">
                            <input id="excelFile2" type="file" name="filename2">点击上传
                        </a>
                        <span class="showFileName2"></span>
                        <span class="fileerrorTip2"></span>
                    </div>
                </div>
            </form>
            <br>
            <div class="modal-footer no-margin-top">
                <div class="text-center">
                    <button onclick="javasrcipt:_submit2(); " id="mod-add-submit2" type="button" class="btn btn-sm btn-primary">
                        <i class="ace-icon fa fa-floppy-o bigger-160"></i>
                        开始导入
                    </button>
                    <button  onclick="CloseDiv2()" class="btn btn-sm" data-dismiss="modal">
                        <i class="ace-icon fa fa-share bigger-160"></i>
                        取消
                    </button>
                </div>
            </div>
        </div><!-- /.modal-content -->

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


<%--导出框--%>
<div  id="MyDiv1" class="modal-dialog white_content">
    <div class="modal-content">
        <div class="modal-header no-padding">
            <div class="table-header">
                <button onclick="CloseDiv1()" type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    <span  class="white">&times;</span>
                </button>
                导出数据
            </div>
        </div>
        <div class="modal-body" style="overflow-y: scroll;">
            <div id="mod-add-tip1" class="red clearfix"></div>
            <div>
                <label>选择条件：</label>
                <div id="downLoadDiv">
                    省：<select id="provinceId" onchange="setCity(this)">
                    <option id="dddd" selected value="" >全部</option>
                    <% for(String s: SystemCache.provinceMap.keySet()){ %>
                    <option value="<%=s %>" ><%=SystemCache.getProvinceName(s) %></option>
                    <%} %>
                </select>
                    市：<select id="cityId">
                </select>
                    <br>
                    <br>
                    取出：<input id="downTotle" type="text">&nbsp;&nbsp;条
                </div>
            </div>

            <br>
            <div class="modal-footer no-margin-top">
                <div class="text-center">
                    <button onclick="javasrcipt:downLoadExcel(); "  type="button" class="btn btn-sm btn-primary">
                        <i class="ace-icon fa fa-floppy-o bigger-160"></i>
                        开始导出
                    </button>
                    <button  onclick="CloseDiv1()" class="btn btn-sm" data-dismiss="modal">
                        <i class="ace-icon fa fa-share bigger-160"></i>
                        取消
                    </button>
                </div>
            </div>
        </div><!-- /.modal-content -->

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

<%--修改框--%>
<div id="sbdxLawyerInfo" class="modal-dialog white_content">
    <div class="modal-content">
        <div class="modal-header no-padding">
            <div class="table-header">
                <button onclick="CloseDiv3()" type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    <span  class="white">&times;</span>
                </button>
                诉保律师详情
            </div>
        </div>
        <div class="modal-body" style="overflow-y: scroll;">
            <div class="red clearfix"></div>
            <div class="row">
                <div class="control-label">
                    <label class="col-sm-3 control-label" >律师姓名:</label>
                    <input type="text"  value="" id="lawyerName">
                </div><br>
                <div class="control-label">
                    <label class="col-sm-3 control-label">律师电话:</label>
                    <input type="text"  value="" id="phone" disabled="disabled">
                </div><br>
                <div class="control-label">
                    <label class="col-sm-3 control-label">是否打过电话:</label>
                    <select id="phoneConn"  class="col-sm-3">
                        <option value="1" >是</option>
                        <option value="0">否</option>
                    </select>
                </div><br><br>
                <div class="control-label">
                    <label class="col-sm-3 control-label">是否有效沟通:</label>
                    <select id="phoneCommu"  class="col-sm-3">
                        <option value="1" >是</option>
                        <option value="0">否</option>
                    </select>
                </div><br><br>
                <div class="control-label">
                    <label class="col-sm-3 control-label">是否加过微信:</label>
                    <select id="isAddWeChat"  class="col-sm-3">
                        <option value="1" >是</option>
                        <option value="0">否</option>
                    </select>
                </div><br><br>
                <div class="control-label">
                    <label class="col-sm-3 control-label" >律师微信号：</label>
                    <input type="text"  value="" id="weChat">
                </div><br>
                <div>
                    <label class="col-sm-3 control-label" >客户经理：</label>
                    <input type="text"  value="" id="manager">
                </div><br>
                <div class="control-label">
                    <label class="col-sm-3 control-label" >客户经理微信号：</label>
                    <input type="text"  disabled="disabled" value="" id="managerWeChat">
                </div><br>
                <div class="control-label">
                    <label class="col-sm-3 control-label">微信号运营人：</label>
                    <input type="text"  disabled="disabled" value="" id="weChatOperator">
                </div>
                <br>
            </div>
            <div class="modal-footer no-margin-top">
                <div class="text-center">
                    <button onclick="updateSbdxLawyer();"  type="button" class="btn btn-sm btn-primary">
                        <i class="ace-icon fa fa-floppy-o bigger-160"></i>
                        保存
                    </button>
                    <button  onclick="CloseDiv3()" class="btn btn-sm" data-dismiss="modal">
                        <i class="ace-icon fa fa-share bigger-160"></i>
                        取消
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">

    var myGrid = null;
    var scripts = [ null,  "${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", null ]

    $('.page-content-area').ace_ajax('loadScripts', scripts, function() {
        jQuery(function ($) {

            var grid_selector = "#grid-table";
            var pager_selector = "#grid-pager";

            /*搜索框  主要对Jquery grid进行刷新 带参数刷新    */
            $("#searchd").click(function(){
                var keyword =encodeURI(encodeURI($("#keyword").val()));
                var type = null;
                var provinceId = $("#province").val();
                myGrid.setGridParam({postData:{keyword:keyword,provinceId:provinceId ,page:1,type : type},
                    url : '${contextPath}/sbdx/lawyer/getSbdxLawyerInfo',page:1}).trigger('reloadGrid');
            });
            /*未打过电话    */
            $("#noPhone").click(function(){
                var keyword =encodeURI(encodeURI($("#keyword").val()));
                var isJd = $("#isJd").val();
                var type = "noPhone";
                myGrid.setGridParam({postData:{keyword:keyword ,page:1,type : type},
                    url : '${contextPath}/sbdx/lawyer/getSbdxLawyerInfo',page:1}).trigger('reloadGrid');
            });
            /*已加过微信    */
            $("#addWeChat").click(function(){
                var keyword =encodeURI(encodeURI($("#keyword").val()));
                var isJd = $("#isJd").val();
                var type = "addWeChat";
                myGrid.setGridParam({postData:{keyword:keyword ,page:1,type : type},
                    url : '${contextPath}/sbdx/lawyer/getSbdxLawyerInfo',page:1}).trigger('reloadGrid');
            });

            $(document).keydown(function (event) {
                var key = window.event ? event.keyCode : event.which;
                if (key == 13) {
                    $("#searchd").click();
                }
            });


            myGrid=	jQuery(grid_selector).jqGrid({
                subGrid : false,
                url : "${contextPath}/sbdx/lawyer/getSbdxLawyerInfo",
                datatype : "json",
                mtype:'POST',//设置http方式为post以解决乱码问题
                colNames : ['姓名', '手机', '律所','省','市',
                   /* '是否打过电话','是否有效沟通',*/'是否加微信','律师微信号',
                    '客户经理','客户经理微信号','微信号运营人','操作'],
                colModel : [{
                    name : 'lawyerName',
                    index : 'lawyerName',
                    width : 120,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'phone',
                    index : 'phone',
                    width : 130,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'lawFirm',
                    index : 'lawFirm',
                    width : 150,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'province',
                    index : 'province',
                    width : 80,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'city',
                    index : 'city',
                    width : 80,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },/*{
                    name : 'phoneConnect',
                    index : 'phoneConnect',
                    width : 100,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'phoneCommu',
                    index : 'phoneCommu',
                    width : 100,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },*/{
                    name : 'addWeChat',
                    index : 'addWeChat',
                    width : 80,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'weChatNumber',
                    index : 'weChatNumber',
                    width : 120,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'managerName',
                    index : 'managerName',
                    width : 120,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'managerWeChat',
                    index : 'managerWeChat',
                    width : 160,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'weChatOperator',
                    index : 'weChatOperator',
                    width : 180,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : '',
                    index : '',
                    label : '操作',
                    width : 70,
                    editable : false,
                    search : false,
                    sortable : false,
                    fixed:true,
                    formatter : optionFormatter
                }],
                //scroll : 1, // set the scroll property to 1 to enable paging with scrollbar - virtual loading of records
                viewrecords : true,
                rowNum : 10,
                rowList : [ 10, 100, 1000 ],
                pager : pager_selector,
                altRows : true,
                height:"auto",//自动根据每页条数弹性调整表格高度
                loadComplete : function() {
                    var table = this;
                    setTimeout(function(){
                        /*styleCheckbox(table);
                        updateActionIcons(table);*/
                        updatePagerIcons(table);
                        enableTooltips(table);
                    }, 0);
                }
            });

            function updatePagerIcons(table) {
                var replacement = {
                    'ui-icon-seek-first' : 'ace-icon fa fa-angle-double-left bigger-140',
                    'ui-icon-seek-prev' : 'ace-icon fa fa-angle-left bigger-140',
                    'ui-icon-seek-next' : 'ace-icon fa fa-angle-right bigger-140',
                    'ui-icon-seek-end' : 'ace-icon fa fa-angle-double-right bigger-140'
                };
                $('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function() {
                    var icon = $(this);
                    var $class = $.trim(icon.attr('class').replace('ui-icon', ''));

                    if ($class in replacement)
                        icon.attr('class', 'ui-icon ' + replacement[$class]);
                })
            }



            function enableTooltips(table) {
                $('.navtable .ui-pg-button').tooltip({
                    container : 'body'
                });
                $(table).find('.ui-pg-div').tooltip({
                    container : 'body'
                });
            };

            function optionFormatter(cellvalue, options, cell) {
                var template = "<button data-toggle='modal' onclick='showdetail1(\""+cell.phone+"\")' class='btn btn-minier btn-yellow'><i class='ace-icon fa fa-hdd-o '></i>详细</button>";
                return template;
            }
        });
    });
    function CloseDiv() {
        $("#MyDiv").hide();
    }
    function CloseDiv1() {
        $("#MyDiv1").hide();
    }
    function CloseDiv2() {
        $("#MyDiv2").hide();
    }
    function CloseDiv3() {
        $("#sbdxLawyerInfo").hide();
    }
    //详细
    function showdetail1(phone){
        $("#sbdxLawyerInfo").show();
        $.ajax({
            dataType : "json",
            url : "${contextPath}/sbdx/lawyer/getLawyerInfo",
            type : "post",
            data : {
                'phone' : phone
            },
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                $("#lawyerName").val(ret.lawyerName);
                $("#phone").val(ret.phone);
                $("#phoneConn").val(ret.phoneConnect);
                $("#phoneCommu").val(ret.phoneCommu);
                $("#isAddWeChat").val(ret.addWeChat);
                $("#weChat").val(ret.weChatNumber);
                $("#manager").val(ret.managerName);
                $("#managerWeChat").val(ret.managerWeChat);
                $("#weChatOperator").val(ret.weChatOperator);
            }
        });
    };
    function buquan() {
        $.ajax({
            dataType : "json",
            url : "${contextPath}/sbdx/lawyer/buquan",
            type : "post",
            data : {
            },
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                alert(ret.isSucc);
                myGrid.trigger("reloadGrid");
            }
        });
    }

    function updateSbdxLawyer(){
        var phone = $("#phone").val();
        var lawyerName = $("#lawyerName").val();
        var phoneConnect = $("#phoneConn").val();
        var phoneCommu = $("#phoneCommu").val();
        var addWeChat = $("#isAddWeChat").val();
        var weChatNumber = $("#weChat").val();
        var managerName = $("#manager").val();
        var managerWeChat = $("#managerWeChat").val();
        var weChatOperator = $("#weChatOperator").val();
        $.ajax({
            dataType : "json",
            url : "${contextPath}/sbdx/lawyer/updateLawyerInfo",
            type : "post",
            data : {
                'phone' : phone,
                'lawyerName' : lawyerName,
                'phoneConnect' : phoneConnect,
                'phoneCommu' : phoneCommu,
                'addWeChat' : addWeChat,
                'weChatNumber' : weChatNumber,
                'managerName' : managerName,
                'managerWeChat' : managerWeChat,
                'weChatOperator' : weChatOperator
            },
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                alert(ret.isSucc);
                $("#sbdxLawyerInfo").hide();
                myGrid.trigger("reloadGrid");
            }
        });
    }

/*导入*/

    //导入框显示
    $("#daoruWeChat").click(function () {
        var file = document.getElementById("excelFile");
        // for IE, Opera, Safari, Chrome
        if (file.outerHTML) {
            file.outerHTML = file.outerHTML;
        } else { // FF(包括3.5)
            file.value = "";
        }
        $(".showFileName").html("");
        $(".fileerrorTip").html("");
        $("#MyDiv").show();
    });

    //导入框2显示
    $("#daoruPhone").click(function () {
        var file = document.getElementById("excelFile2");
        // for IE, Opera, Safari, Chrome
        if (file.outerHTML) {
            file.outerHTML = file.outerHTML;
        } else { // FF(包括3.5)
            file.value = "";
        }
        $(".showFileName2").html("");
        $(".fileerrorTip2").html("");
        $("#MyDiv2").show();
    });

    //导出框显示
    $("#daochu").click(function () {
        $("#provinceId").val("");
        $("#cityId").html("");
        $("#downTotle").val("");
        $("#MyDiv1").show();
    });

    //导入提交表单
    function _submit() {
        //遍历所的有文件
        var files = document.getElementsByName("filename");
        if (files[0].value === "") {
            alert("上传有误，请检查是否上传文件或者检查文件类型！!");
            return false;
        }else{
            $('#formId').submit();
        }
    }

    //导入提交表单
    function _submit2() {
        //遍历所的有文件
        var files = document.getElementsByName("filename2");
        if (files[0].value === "") {
            alert("上传有误，请检查是否上传文件或者检查文件类型！!");
            return false;
        }else{
            $('#formId2').submit();
        }
    }


    $("#up1").on("change","input[type='file']",function(){
        var filePath=$(this).val();
        //alert(filePath);
        if(filePath.indexOf("xlsx")!==-1){
            $(".fileerrorTip").html("").hide();
            var arr=filePath.split('\\');
            var fileName=arr[arr.length-1];
            $(".showFileName").html(fileName);
        }else{
            $(".showFileName").html("");
            $(".fileerrorTip").html("上传有误！请上传后缀名为xlsx的文件").show();
            return false
        }
    });

    $("#up2").on("change","input[type='file']",function(){
        var filePath=$(this).val();
        //alert(filePath);
        if(filePath.indexOf("xlsx")!==-1){
            $(".fileerrorTip2").html("").hide();
            var arr=filePath.split('\\');
            var fileName=arr[arr.length-1];
            $(".showFileName2").html(fileName);
        }else{
            $(".showFileName2").html("");
            $(".fileerrorTip2").html("上传有误！请上传后缀名为xlsx的文件").show();
            return false
        }
    });
    function setCity(obj){
        var val = obj.value;
        var sec = document.getElementById('cityId');
        sec.innerHTML = "<option value=''>全部</option>";
        if(val !== ''){
            //ajax
            $.getJSON("${contextPath}/util/getCitysByProvince?provinceId="+val,function(result){
                $.each(result, function(i, v){
                    sec.innerHTML+="<option value='"+v.value+"'>"+v.name+"</option>";
                });
            });
        }
    };
    function downLoadExcel() {
        var provinceId = $("#provinceId").val();
        var cityId = $("#cityId").val();
        var downTotle = $("#downTotle").val();
        var url = '${contextPath}/sbdx/lawyer/downLoadExcel?provinceId=' + provinceId +
            "&cityId="+cityId + "&downTotle="+downTotle ;
        console.info(url);
        window.open(url);
    }
    function fromLawToSb() {
        $.ajax({
            dataType : "json",
            url : "${contextPath}/sbdx/lawyer/updateSbdx",
            type : "post",
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                alert(ret.isSucc);
                myGrid.trigger("reloadGrid");
            }
        });
    }


</script>
