<%@ 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/ui.jqgrid.css"/>

<style>
    .hr-line-dashed {
        background-color: #ffffff;
        border-top: 1px dashed #e7eaec;
        color: #ffffff;
        height: 1px;
        margin: 20px 0;
    }
</style>

<div id="mod-add" class="modal fade" tabindex="-1" data-backdrop="static">
    <div class="modal-dialog">
        <form id="AddForm">
            <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="overflow-y: scroll;">
                    <div id="mod-add-tip" class="red clearfix"></div>
                    <div class="form-group">
                        <label for="mod-add-name">公司全称</label>
                        <input type="text" id="mod-add-name" class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label for="mod-add-loginName">公司简称（登录名）</label>
                        <input type="text" id="mod-add-loginName" class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label for="mod-add-clearing-institution-name">结算机构名称</label>
                        <input type="text" id="mod-add-clearing-institution-name" class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label for="mod-add-loginName">公司类型</label>
                        <select class="form-control" id="mod-add-companyType">
                            <option value="1">保险公司</option>
                            <option value="0">担保公司</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="mod-add-password">密码</label>
                        <input type="password" id="mod-add-password" class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label for="mod-add-password2">确认密码</label>
                        <input type="password" id="mod-add-password2" class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label for="mod-add-contact">跟单对接人姓名</label>
                        <input type="text" id="mod-add-contact" class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label for="mod-add-tel">跟单对接人手机</label>
                        <input type="text" id="mod-add-tel" class="form-control"/>
                    </div>
                    <div class="form-group" style="display: none">
                        <label for="mod-add-commision">平台返佣</label>
                        <div class="input-group">
                            <input type="text" id="mod-add-commision" class="form-control" value="0"/>
                            <span class="input-group-addon">%</span>
                        </div>
                    </div>
                    <div class="form-group" style="display: none">
                        <label for="mod-add-commisionLawyer">律师返佣</label>
                        <div class="input-group">
                            <input type="text" id="mod-add-commisionLawyer" class="form-control" value="0"/>
                            <span class="input-group-addon">%</span>
                        </div>
                    </div>
                    <div class="form-group" style="display: none">
                        <label for="mod-add-sort">合作排序(0表示不是战略合作)</label>
                        <input type="text" id="mod-add-sort" class="form-control" value="1"/>
                    </div>
                    <div class="form-group" style="display: none">
                        <label for="mod-add-text0">战略合作公司宣传语1(不能有|符号)</label>
                        <input type="text" id="mod-add-text0" class="form-control"/>
                    </div>
                    <div class="form-group" style="display: none">
                        <label for="mod-add-text1">战略合作公司宣传语2(不能有|符号)</label>
                        <input type="text" id="mod-add-text1" class="form-control"/>
                    </div>
                    <div class="form-group" style="display: none">
                        <label for="mod-add-text2">战略合作公司宣传语3(不能有|符号)</label>
                        <input type="text" id="mod-add-text2" class="form-control"/>
                    </div>
                    <div class="form-group" style="display: none">
                        <label for="mod-add-commisionLawyer" class="no-padding-left col-sm-2 control-label">线下支付</label>
                        <div class="col-sm-10 text-left input-group">
                            <input type="radio" name="mod-add-pay_offLine" value="1" checked="checked"/>是
                            <input type="radio" name="mod-add-pay_offLine" value="0"/>否
                        </div>
                    </div>
                    <div class="form-group" style="display: none">
                        <label for="mod-add-commisionLawyer" class="no-padding-left col-sm-2 control-label">微信</label>
                        <div class="col-sm-10 text-left input-group">
                            <input type="radio" name="mod-add-pay_weixin" value="1"/>是
                            <input type="radio" name="mod-add-pay_weixin" value="0" checked="checked"/>否
                        </div>
                    </div>
                    <div class="form-group" style="display: none">
                        <label for="mod-add-commisionLawyer" class="no-padding-left col-sm-2 control-label">支付宝</label>
                        <div class="col-sm-10 text-left input-group">
                            <input type="radio" name="mod-add-pay_alipay" value="1"/>是
                            <input type="radio" name="mod-add-pay_alipay" value="0" checked="checked"/>否
                        </div>
                    </div>
                    <div class="form-group" style="display: none">
                        <label for="mod-add-advance-div" class="no-padding-left col-sm-3 control-label">是否多问垫付保费</label>
                        <div class="col-sm-9 text-left input-group">
                            <input type="radio" name="mod-add-advance" value="1"/>是
                            <input type="radio" name="mod-add-advance" value="0" checked="checked"/>否
                        </div>
                    </div>
                    <div class="form-group" id="mod-add-containTax-div" style="display: none">
                        <label class="no-padding-left col-sm-2 control-label">是否含税</label>
                        <div class="col-sm-10 text-left">
                            <select class="select" id="mod-add-containTax">
                                <option value="0">否</option>
                                <option value="1">是</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="modal-footer no-margin-top">
                    <div class="text-center">
                        <button 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 class="btn btn-sm" data-dismiss="modal">
                            <i class="ace-icon fa fa-share bigger-160"></i>
                            取消
                        </button>
                    </div>
                </div>
            </div><!-- /.modal-content -->
        </form>
    </div><!-- /.modal-dialog -->
</div>


<div class="well well-sm">

    <input type="text" class="input-sm" placeholder="搜索关键字" id="keyword"/>
    <select class="select" id="companyState">
        <option value="">状态</option>
        <option value="0">未提交</option>
        <option value="1">申请中</option>
        <option value="3" selected>认证成功</option>
        <option value="2">认证失败</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>
    <shiro:hasPermission name='${ROLE_KEY}:ssdbCompany:add'>
        <button style="float:right" type="button" class="btn btn-danger btn-sm" data-toggle='modal' onclick='add()'>
            <span class="ace-icon fa fa-edit icon-on-right bigger-110"></span>
            新增公司
        </button>
    </shiro:hasPermission>
    <!-- <button style="float:right" type="button" class="btn btn-success btn-sm" data-toggle='modal' onclick='setServices()'>
       <span class="ace-icon fa fa-edit icon-on-right bigger-110"></span>
                         设置服务标签
    </button>  -->
</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="modal-table" class="modal fade" tabindex="-1" data-backdrop="static">
    <div class="modal-dialog" style="min-width: 920px;">
        <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" id="modal-table-body">

            </div>
        </div>
    </div>
</div>

<%--新增区间--%>
<div id="modal-AddParamQJ" class="modal fade" tabindex="-1" data-backdrop="static">
    <div class="modal-dialog">
        <form id="AddParamQJ">
            <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="overflow-y: scroll;">
                    <div id="mod-AddParamQJ-companyId" class="red clearfix"></div>
                    <div class="form-group">
                        <label for="mod-AddParamQJ-startValue">开始金额</label>
                        <input type="number" id="mod-AddParamQJ-startValue" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" class="form-control"/>
                    </div>

                    <div class="form-group">
                        <label for="mod-AddParamQJ-endValue">结束金额</label>
                        <input type="number" id="mod-AddParamQJ-endValue" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label for="mod-AddParamQJ-rat">费率</label>
                        <input type="number" id="mod-AddParamQJ-rat" class="form-control"/>
                        <span class="input-group-addon">%</span>
                    </div>
                    <div class="modal-footer no-margin-top">
                        <div class="text-center">
                            <button id="mod-AddParamQJ-submit" type="button" class="btn btn-sm btn-primary">
                                <i class="ace-icon fa fa-floppy-o bigger-160"></i>
                                保存
                            </button>
                            <button class="btn btn-sm" data-dismiss="modal">
                                <i class="ace-icon fa fa-share bigger-160"></i>
                                取消
                            </button>
                        </div>
                    </div>
                </div>
            </div><!-- /.modal-content -->
        </form>
    </div>
</div>

<%--新增法院--%>
<div id="modal-Addcourt" class="modal fade" tabindex="-1" data-backdrop="static">
    <div class="modal-dialog">
        <form id="Addcourt">
            <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="overflow-y: scroll;">
                    <div id="mod-Addcourt-companyId" class="red clearfix"></div>

                    <div class="form-group">
                        <label for="mod-Addcourt-courtName">法院</label>
                        <input type="text"  id="mod-Addcourt-courtName" class="form-control"  />
                    </div>

                    <div class="form-group">
                        <label for="mod-Addcourt-deliver">配送方式</label>
                        <select id="mod-Addcourt-deliver">
                            <option value="">请选择</option>
                            <option value="1">上门配送</option>
                            <option value="2">快递配送</option>
                        </select>
                    </div>

                    <div class="modal-footer no-margin-top">
                        <div class="text-center">
                            <button id="mod-Addcourt-submit" type="button" class="btn btn-sm btn-primary">
                                <i class="ace-icon fa fa-floppy-o bigger-160"></i>
                                保存
                            </button>
                            <button class="btn btn-sm" data-dismiss="modal">
                                <i class="ace-icon fa fa-share bigger-160"></i>
                                取消
                            </button>
                        </div>
                    </div>
                </div>
            </div><!-- /.modal-content -->
        </form>
    </div>
</div>

<%--新增收款账号--%>
<div id="modal-AddAccount" class="modal fade" tabindex="-1" data-backdrop="static">
    <div class="modal-dialog">
        <form id="AddAccount">
            <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="overflow-y: scroll;">
                    <div id="mod-AddAccount-companyId" class="red clearfix"></div>

                    <div class="form-group">

                        <tr class="warning">
                            <td>省：</td>
                            <td>
                                <select id="areaProvince" onchange="setAreaCity(this);"><option value=''>全部</option></select>
                            </td>
                        </tr>
                        <tr>
                            <td>市：</td>
                            <td><select id="areaCity" onchange="getCounty(this)"></select></td>
                        </tr>
                    </div>

                    <div class="form-group">
                        <label for="mod-AddAccount-accountName">收款账户名</label>
                        <input type="text"  id="mod-AddAccount-accountName" class="form-control"  />
                    </div>

                    <div class="form-group">
                        <label for="mod-AddAccount-accountNum">收款账户</label>
                        <input type="text"  id="mod-AddAccount-accountNum" class="form-control"  />
                    </div>

                    <div class="form-group">
                        <label for="mod-AddAccount-accountBank">开户行</label>
                        <input type="text"  id="mod-AddAccount-accountBank" class="form-control"  />
                    </div>

                    <div class="modal-footer no-margin-top">
                        <div class="text-center">
                            <button id="mod-AddAccount-submit" type="button" class="btn btn-sm btn-primary">
                                <i class="ace-icon fa fa-floppy-o bigger-160"></i>
                                保存
                            </button>
                            <button class="btn btn-sm" data-dismiss="modal">
                                <i class="ace-icon fa fa-share bigger-160"></i>
                                取消
                            </button>
                        </div>
                    </div>
                </div>
            </div><!-- /.modal-content -->
        </form>
    </div>
</div>

<%--新增收件信息--%>
<div id="modal-AddReceipt" class="modal fade" tabindex="-1" data-backdrop="static">
    <div class="modal-dialog">
        <form id="AddReceipt">
            <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="overflow-y: scroll;">
                    <div id="mod-AddReceipt-companyId" class="red clearfix"></div>

                    <div class="form-group">

                        <tr class="warning">
                            <td>省：</td>
                            <td>
                                <select id="areaProvinceTwo" onchange="setAreaCityTwo(this);"><option value=''>全部</option></select>
                            </td>
                        </tr>
                        <tr>
                            <td>市：</td>
                            <td><select id="areaCityTwo" onchange="getCountyTwo(this)"></select></td>
                        </tr>
                    </div>

                    <div class="form-group">
                        <label for="mod-AddReceipt-contact">收件人</label>
                        <input type="text"  id="mod-AddReceipt-contact" class="form-control"  />
                    </div>

                    <div class="form-group">
                        <label for="mod-AddReceipt-phone">收件人联系号码</label>
                        <input type="text"  id="mod-AddReceipt-phone" class="form-control"  />
                    </div>

                    <div class="form-group">
                        <label for="mod-AddReceipt-address">收货地址</label>
                        <input type="text"  id="mod-AddReceipt-address" class="form-control"  />
                    </div>

                    <div class="modal-footer no-margin-top">
                        <div class="text-center">
                            <button id="mod-AddReceipt-submit" type="button" class="btn btn-sm btn-primary">
                                <i class="ace-icon fa fa-floppy-o bigger-160"></i>
                                保存
                            </button>
                            <button class="btn btn-sm" data-dismiss="modal">
                                <i class="ace-icon fa fa-share bigger-160"></i>
                                取消
                            </button>
                        </div>
                    </div>
                </div>
            </div><!-- /.modal-content -->
        </form>
    </div>
</div>


<!-- 阿里云OSS -->
<script type="text/javascript" src="${contextPath}/static/js/contract/promise-6.1.0.js"></script>
<script type="text/javascript" src="http://gosspublic.alicdn.com/aliyun-oss-sdk-4.3.0.min.js"></script>
<script type="text/javascript" src="${contextPath}/static/js/contract/ace.fileinput.js"></script>
<script type="text/javascript" src="${contextPath}/static/js/contract/uuid.js"></script>
<script type="text/javascript" src="${contextPath}/static/js/contract/picupload.js?v=2"></script>
<script type="text/javascript" src="${contextPath}/static/assets/js/lazyload/jquery.lazyload.js"></script>
<!-- page specific plugin scripts -->
<script type="text/javascript">
    var bucket = '${oss_bucket_b}';
    var contextPath = '${contextPath}';
    var logoUrl = '${oss_bucket_b_url}';
    var logoThum = '${oss_bucket_b_url_img}';
    var myGrid = null;
    var url_b = '${duowenapp_b}';
    var companyId = '';
    var areaProvinceName = '';
    var areaCityName = '';

    var scripts = [null, "${contextPath}/static/assets/js/jqGrid/jquery.jqGrid.js", "${contextPath}/static/assets/js/jqGrid/i18n/grid.locale-cn.js",
        "${contextPath}/static/js/contract/promise-6.1.0.js",
        "http://gosspublic.alicdn.com/aliyun-oss-sdk-4.3.0.min.js",
        "${contextPath}/static/js/contract/ace.fileinput.js",
        "${contextPath}/static/js/contract/uuid.js",
        "${contextPath}/static/js/contract/picupload.js",
        "${contextPath}/static/assets/js/lazyload/jquery.lazyload.js",
        "${contextPath}/static/js/network.js",
        null];

    var hiddenModalBody = '';
    $(function () {
        hiddenModalBody += '<div class="row">'
            + '<label class="col-sm-2 control-label">公司LOGO:</label>'
            + '<div class="col-sm-2 text-right" id="company-Logo"></div>'
            + '<label class="col-sm-2 control-label">公司宣传图:</label>'
            + '<div class="col-sm-2 text-right" id="company-Pic"></div>'
            + '<label class="col-sm-2 control-label">公司营业执照:</label>'
            + '<div class="col-sm-2 text-right" id="company-Cert"></div>'
            + '</div>'
            + '<div class="row">'
            + '<label class="col-sm-2 control-label">保函样式:</label>'
            + '<div class="col-sm-2 text-right" id="company-Example1"></div>'
            + '<label class="col-sm-2 control-label">保单样式:</label>'
            + '<div class="col-sm-2 text-right" id="company-Example2"></div>'
            + '<label class="col-sm-2 control-label">合同/投保单:</label>'
            + '<div class="col-sm-2 text-right" id="company-Example3"></div>'
            + '</div>'
            + '<div class="row">'
            + '<label class="col-sm-2 control-label">诉讼前申请文件:</label>'
            + '<div class="col-sm-2 text-right" id="company-SuitBefore"></div>'
            + '<label class="col-sm-2 control-label">诉讼中申请文件:</label>'
            + '<div class="col-sm-2 text-right" id="company-SuitAfter"></div>'
            + '<label class="col-sm-2 control-label">客服电话:</label>'
            + '<div class="col-sm-2 text-right" id="company-Tel"></div>'
            + '</div>'
            + '<div class="row">'
            + '<label class="col-sm-2 control-label">公司简介:</label>'
            + '<div class="col-sm-10 text-right" id="company-Info"></div>'
            + '</div>'
            + '<div class="hr-line-dashed"></div>';
        hiddenModalBody += '<div class="row">'
            + '<div class="col-sm-12 text-left"><h5>服务承诺</h5></div>'
            + '</div>'
            + '<div class="row">'
            + '<label class="col-sm-2 control-label">审核承诺:</label>'
            + '<div class="col-sm-2 text-right" id="company-CheckTime"></div>'
            + '<label class="col-sm-2 control-label">确认收款承诺:</label>'
            + '<div class="col-sm-2 text-right" id="company-ConfirmTime"></div>'
            + '<label class="col-sm-2 control-label">出函承诺:</label>'
            + '<div class="col-sm-2 text-right" id="company-SendTime"></div>'
            + '</div>'
            + '<div class="row">'
            + '<label class="col-sm-3 control-label">发票(保单)配送方式:</label>'
            + '<div class="col-sm-3 text-right" id="company-Deliver2"></div>'
            + '<label class="col-sm-6 control-label"></label>'
            + '</div>'
            + '<div class="hr-line-dashed"></div>';
        hiddenModalBody += '<div class="row">'
            + '<div class="col-sm-12 text-left"><h5>保费比例</h5></div>'
            + '</div>'
            + '<div class="row">'
            + '<label class="col-sm-2 control-label no-padding-right">房产:</label>'
            + '<div class="col-sm-2 text-right no-padding-left" id="company-s101"></div>'
            + '<label class="col-sm-2 control-label no-padding-right">银行账户类:</label>'
            + '<div class="col-sm-2 text-right no-padding-left" id="company-s102"></div>'
            + '<label class="col-sm-2 control-label no-padding-right">土地使用权:</label>'
            + '<div class="col-sm-2 text-right no-padding-left" id="company-s103"></div>'
            + '</div>'
            + '<div class="row">'
            + '<label class="col-sm-2 control-label no-padding-right">非上市公司股权:</label>'
            + '<div class="col-sm-2 text-right no-padding-left" id="company-s104"></div>'
            + '<label class="col-sm-2 control-label no-padding-right">应收债权:</label>'
            + '<div class="col-sm-2 text-right no-padding-left" id="company-s105"></div>'
            + '<label class="col-sm-2 control-label no-padding-right">车辆:</label>'
            + '<div class="col-sm-2 text-right no-padding-left" id="company-s201"></div>'
            + '</div>'
            + '<div class="row">'
            + '<label class="col-sm-2 control-label no-padding-right">船舶:</label>'
            + '<div class="col-sm-2 text-right no-padding-left" id="company-s202"></div>'
            + '<label class="col-sm-2 control-label no-padding-right">不易腐朽损坏货物:</label>'
            + '<div class="col-sm-2 text-right no-padding-left" id="company-s203"></div>'
            + '<label class="col-sm-2 control-label no-padding-right">机器设备:</label>'
            + '<div class="col-sm-2 text-right no-padding-left" id="company-s204"></div>'
            + '</div>'
            + '<div class="row">'
            + '<label class="col-sm-2 control-label no-padding-right">商标专利:</label>'
            + '<div class="col-sm-2 text-right no-padding-left" id="company-s205"></div>'
            + '<label class="col-sm-2 control-label no-padding-right">上市公司股票:</label>'
            + '<div class="col-sm-2 text-right no-padding-left" id="company-s301"></div>'
            + '<label class="col-sm-2 control-label no-padding-right">非固定收益基金账户:</label>'
            + '<div class="col-sm-2 text-right no-padding-left" id="company-s302"></div>'
            + '</div>'
            + '<div class="row">'
            + '<label class="col-sm-2 control-label no-padding-right">易腐朽损坏货物:</label>'
            + '<div class="col-sm-2 text-right no-padding-left" id="company-s303"></div>'
            + '<label class="col-sm-2 control-label no-padding-right">诉讼前折扣:</label>'
            + '<div class="col-sm-2 text-right no-padding-left" id="company-suitBefore"></div>'
            + '<label class="col-sm-2 control-label no-padding-right">诉讼中折扣:</label>'
            + '<div class="col-sm-2 text-right no-padding-left" id="company-suitAfter"></div>'
            + '</div>'
            + '<div class="row" id="modalBodyLastDiv">'
            + '<label class="col-sm-2 control-label no-padding-right">最低保费:</label>'
            + '<div class="col-sm-2 text-right no-padding-left" id="company-minFee"></div>'
            + '<label class="col-sm-8 control-label"></label>'
            + '</div>';

        $("#areaProvince").change(function(){
            areaProvinceName = $(this).find("option:selected").text();
        })
        $("#areaCity").change(function (){
            areaCityName = $(this).find("option:selected").text();
        })
    });

    function showdetail(id) {
        var html = "";
        $('#modal-table-body').html("");
        $.ajax({
            dataType: "json",
            url: "${contextPath}/sys/ssdbCompany/getCompanyDetailTwo",
            type: "post",
            data: {
                'companyId': id
            },
            success: function (ret) {
                companyId = ret.companyId;
                //公司基本信息
                var companyVO = ret.companyVO;
                //公司参数
                var paramVO = ret.paramVO;
                //费率返点信息
                var paramQJVOList = ret.paramQJVOList;
                //法院
                var courtVOList = ret.companyCourtVOList;
                //收款
                var accoutVOList = ret.companyAccoutVOList;
                //投保单
                var receiptVOList = ret.companyReceiptVOList;

                //基本信息
                html += '<div class="col-sm-12 text-left" style="margin-bottom: 15px;color: #555;height: 30px;background-color:#55555542; "><strong>基本信息</strong></div>';
                html += '<div class="row">';
                html += '<div class="form-group col-sm-7">登录名：<input type="text" id="loginName" value="'+companyVO.loginName+'"></div>';
                html += '</div>';
                html += '<div class="row">';
                html += '<div class="form-group col-sm-7">密码：<input type="password" id="password" ></div>';
                html += '</div>';
                html += '<div class="row">';
                html += '<div class="form-group col-sm-7">注册状态：<select id="companyStateTwo"><option value=0>未提交</option><option value=1>申请中</option><option value=2>认证失败</option><option value=3>认证成功</option></select></div>'
                html += '</div>';
                html += '<div class="row">';
                html += '<div class="form-group col-sm-7">公司全称：<input type="text"  id="name" value="'+companyVO.name+'"></div>';
                html += '</div>';
                html += '<div class="row">';
                html += '<div class="form-group col-sm-7">对接人姓名：<input type="text" id="contact" value="'+companyVO.contact+'"></div>';
                html += '</div>';
                html += '<div class="row">';
                html += '<div class="form-group col-sm-7">对接人手机：<input type="text" id="tel" value="'+companyVO.tel+'"></div>';
                html += '</div>';
                html += '<div class="row">';
                html += '<div class="form-group col-sm-7">佣金比例：<input type="number" id="commision" value="'+(companyVO.commision * 100)+'">%</div>';
                html += '</div>';
                html += '<button class="btn btn-primary btn-white checkbox-inline btnSty" type="button" onclick="updateSsdbCompany(\'' + companyId + '\')">保存</button>';

                html += '<br/>';
                //费率返点设置
                html += '<div class="col-sm-12 text-left" style="margin-bottom: 15px;color: #555;height: 30px;background-color:#55555542; "><strong>费率返点设置</strong></div>';
                html += '<div class="row">';
                html += '<div class="form-group col-sm-7">设置保全金额区间对应的费率：<button class="btn btn-primary btn-white checkbox-inline btnSty" type="button" onclick="showSaveParamQJVOList(\'' + companyId + '\')">新增区间</button></div>';
                html += '</div>';
                console.log(paramQJVOList.length);
                for(var i = 1;i<=paramQJVOList.length;i++){
                    html += '<div class="row" id="paramQj'+i+'">';
                    html +='<input type ="hidden" class = "paramQJId" value="'+paramQJVOList[i-1].id+'" />'
                    html += '<div class="form-group col-sm-6">区间'+i+'：<input type="number" class="startValue" value="'+paramQJVOList[i-1].startValue+'">&nbsp;';
                    html += '<input type="number" class="endValue" value="'+paramQJVOList[i-1].endValue+'"></div>&nbsp;';
                    if(paramQJVOList[i-1].rat){
                        html += '<div class="form-group col-sm-4" id="paramQJrat"'+i+'>费率：<input type="number" class="rat" value="'+(paramQJVOList[i-1].rat*100).toFixed(2)+'">%</div>&nbsp;';
                    }else{
                        html += '<div class="form-group col-sm-4" id="paramQJrat"'+i+'>费率：<input type="number" class="rat" value="'+0+'">%</div>&nbsp;';
                    }
                    html+= '<button class="btn btn-primary btn-white checkbox-inline btnSty" type="button" onclick="deleteParamQJVOList(\'' + paramQJVOList[i-1].id + '\')">删除</button> </div>';
                }
                html += '<button class="btn btn-primary btn-white checkbox-inline btnSty" type="button" onclick="updateParamQj(\'' + companyId + '\')">保存</button>';
                html += '<br/>';
                //服务时效设置
                html += '<div class="col-sm-12 text-left" style="margin-bottom: 15px;color: #555;height: 30px;background-color:#55555542; "><strong>服务时效设置</strong></div>';
                html += '<div class="row">';
                html += '<div class="form-group col-sm-5">审核时效：<input type="text" id="checkHours" value="'+paramVO.checkHours+'">个工作时</div>';
                html += '<div class="form-group col-sm-5">出函时效：<input type="text" id="sendHours" value="'+paramVO.sendHours+'">个工作时</div>';
                html += '</div>';
                html += '<button class="btn btn-primary btn-white checkbox-inline btnSty" type="button" onclick="updateParam(\'' + paramVO.id + '\')">保存</button>';
                html += '<br/>';
                //法院设置
                html += '<div class="col-sm-12 text-left" style="margin-bottom: 15px;color: #555;height: 30px;background-color:#55555542; "><strong>法院设置</strong></div>';
                html += '<div class="row">';
                html += '<button class="btn btn-primary btn-white checkbox-inline btnSty" type="button" onclick="showSaveCourt(\'' + companyId + '\')">添加法院</button></div>';
                html += '<div class="row">';
                html += '<div class="form-group col-sm-12" >';
                html += '<table class="tab" border="1" style="width: 900px;">' +
                    '<tr style="background-color: #ccc"><th>省</th><th>市</th><th>法院</th><th>配送方式</th><th>操作</th></tr>';
                if(courtVOList){
                    for(var i = 0;i<courtVOList.length;i++){
                        html += '<tr><td>'+notNull(courtVOList[i].province)+'</td><td>'+notNull(courtVOList[i].region)+'</td><td>'+notNull(courtVOList[i].name)+'</td><td>'+notNull(courtVOList[i].deliver1Value)+'</td><td><button  onclick="updateCourtDeliver(\'' + courtVOList[i].id + '\',\'' + courtVOList[i].deliver1 + '\')" class="btn btn-minier btn-info"><i class="ace-icon fa fa-pencil-square-o"></i>修改配送方式</button>|<button  onclick="deleteCourt(\'' + courtVOList[i].id  + '\')" class="btn btn-minier btn-info"><i class="ace-icon fa fa-pencil-square-o"></i>删除</button></td></tr>';
                    }
                }

                html +='</table></div></div>';
                html +='<br/>';

                //收款设置
                html += '<div class="col-sm-12 text-left" style="margin-bottom: 15px;color: #555;height: 30px;background-color:#55555542; "><strong>收款设置</strong></div>';
                html += '<div class="row">';
                html += '<button class="btn btn-primary btn-white checkbox-inline btnSty" type="button" onclick="showSaveAccount(\'' + companyId + '\')">添加收款账号</button></div>';
                html += '<div class="row">';
                html += '<div class="form-group col-sm-12" >';
                html += '<table class="tab" border="1" style="width: 900px;">' +
                    '<tr style="background-color: #ccc"><th>地址</th><th>收款账户名</th><th>收款账户</th><th>开户行</th><th>操作</th></tr>';
                if(accoutVOList){
                    for(var i = 0;i<accoutVOList.length;i++){
                        html += '<tr><td>'+notNull(accoutVOList[i].areaFullName)+'</td><td>'+notNull(accoutVOList[i].accountName)+'</td><td>'+notNull(accoutVOList[i].accountNum)+'</td><td>'+notNull(accoutVOList[i].accountBank)+'</td><td><button  onclick="deleteAccount(\'' + accoutVOList[i].id  + '\')" class="btn btn-minier btn-info"><i class="ace-icon fa fa-pencil-square-o"></i>删除</button></td></tr>';
                    }
                }

                html +='</table></div></div>';
                html +='<br/>';
                html += '<div class="row">';
                html += '——————————————————————————————————————————————————————————————————————';
                html += '</div>';
                html += '<div class="row">';
                html += '<div class="form-group" style="margin-left: 30px;">付款要求：</div>';
                html += '</div>';
                var text = paramVO.paymentContent;
                if(!text){
                    text = "";
                }
                html += '<div class = "row">' +
                    '<div class="form-group" style="margin-left: 30px;">'+
                    '<textarea id="modal-refund-paymentContent" rows="4" cols="60" ></textarea></div>'+
                    '</div>';
                html += '<button class="btn btn-primary btn-white checkbox-inline btnSty" type="button" onclick="updatePaymentContent(\'' + paramVO.id + '\')">保存</button>';
                html +='</br>';

                //投保单设置
                html += '<div class="col-sm-12 text-left" style="margin-bottom: 15px;color: #555;height: 30px;background-color:#55555542; "><strong>投保单设置</strong></div>';
                html += '<div class="row">';
                html += '<div class="form-group col-sm-6">投保单是否需回寄：<select id="isPostBack"><option value="0">不需要</option><option value="1">需要</option></select></div>';
                html += '<div class="form-group col-sm-6">是否开通自动填写投保单：<select id="isAutoFill"><option value="0">否</option><option value="1">是</option></select></div>';
                html += '</div>';
                html += '<div class="row">';
                html += '<div class="form-group" style="margin-left: 30px;"> 投保单要求：</div>';
                html += '</div>';
                var orderContent = paramVO.orderContent;
                if(!orderContent){
                    orderContent = "";
                }
                html += '<div class = "row">' +
                    '<div class="form-group" style="margin-left: 30px;">'+
                    '<textarea id="modal-refund-orderContent" rows="4" cols="60"></textarea></div>'+
                    '</div>';
                html += '<button class="btn btn-primary btn-white checkbox-inline btnSty" type="button" onclick="updateOrderContent(\'' + paramVO.id + '\')">保存</button>';
                html +='</br>';
                html += '<div class="row">';
                html += '——————————————————————————————————————————————————————————————————————';
                html += '</div>';

                html += '<div class="row">';
                html += '<button class="btn btn-primary btn-white checkbox-inline btnSty" type="button" onclick="showSaveReceipt(\'' + companyId + '\')">添加收件信息</button></div>';
                html += '<div class="row">';
                html += '<div class="form-group col-sm-12" >';
                html += '<table class="tab" border="1" style="width: 900px;">' +
                    '<tr style="background-color: #ccc"><th>省</th><th>市</th><th>机构</th><th>收件人</th><th>收件人联系号码</th><th>收货地址</th><th>操作</th></tr>';
                if(receiptVOList){
                    for(var i = 0;i<receiptVOList.length;i++){
                        html += '<tr><td>'+notNull(receiptVOList[i].provinceValue)+'</td><td>'+notNull(receiptVOList[i].cityValue)+'</td><td>'+notNull(receiptVOList[i].companyName)+'</td><td>'+notNull(receiptVOList[i].contact)+'</td><td>'+notNull(receiptVOList[i].phone)+'</td><td>'+notNull(receiptVOList[i].address)+'</td><td><button  onclick="deleteReceipt(\'' + receiptVOList[i].id  + '\')" class="btn btn-minier btn-info"><i class="ace-icon fa fa-pencil-square-o"></i>删除</button></td></tr>';
                    }
                }

                html +='</table></div></div>';
                html +='<br/>';

                // html += '<div class="form-group col-sm-3">手机号：'+notNull(user.lawyerPhone)+'</div>';
                // html += '<div class="form-group col-sm-3">省：'+notNull(user.province)+'</div>';
                // html += '<div class="form-group col-sm-3">市：'+notNull(user.city)+'</div></div>';
                // html += '<div class="row"><div class="form-group col-sm-3">注册状态：<select id="selector"><option value="0">未注册</option><option value="1">已注册</option>  </select></div>';
                // html += '<div class="form-group col-sm-3">客户经理微信号昵称：'+user.weChatOperator+'</div>';
                // html += '<div class="form-group col-sm-3">客户经理微信号：'+user.weChatNum+'</div>';
                // html += '<div class="form-group col-sm-3">互动状态：<select id="selectinteractiveState"><option value="0">未激活</option><option value="1">已激活</option> <option value="2">已加微信</option><option value="3">已删微信</option> </select></div></div>';
                // html += '<div class="row">';
                // html += '<button class="btn btn-primary btn-white checkbox-inline btnSty" type="button" onclick="updateSbdxLawyer(\'' + user.id + '\')">保存</button></div>';
                //
                $("#modal-table").modal("toggle");
                $("#modal-table-body").html(html);
                if(companyVO.companyState) {
                    $("#companyStateTwo").find("option").eq(companyVO.companyState).attr("selected",true);
                }
                if(paramVO.isPostBack != null){
                    $("#isPostBack").find("option").eq(paramVO.isPostBack).attr("selected",true);
                }
                if(paramVO.isAutoFill != null){
                    $("#isAutoFill").find("option").eq(paramVO.isAutoFill).attr("selected",true);
                }
                $("#modal-refund-paymentContent").val(text);
                $("#modal-refund-orderContent").val(orderContent);
                $(".btnSty").css("margin-bottom","5px");
                $(".btnSty").css("margin-left","20px");
                $(".tab td").css("text-align","center");
                $(".tab th").css("text-align","center");
                // if(user.registeredState) {
                //     $("#selector").find("option").eq(1).attr("selected",true);
                // }
                //
                // if(user.interactiveState){
                //     $("#selectinteractiveState").find("option").eq(parseInt(user.interactiveState)).attr("selected",true);
                // }
                // $(".btnSty").css("margin-bottom","5px");
                // $(".btnSty").css("margin-left","20px");
                // $(".tab td").css("text-align","center");
                // $(".tab th").css("text-align","center");
            }
        });
    }


    //删除公司投保单收货地址信息
    function deleteReceipt(id){
        if(confirm("确定要删除选中数据吗?")){
            $.ajax({
                dataType: "json",
                url: "${contextPath}/sys/ssdbCompany/deleteSsdbCompanyReceipt",
                type: "post",
                data: {
                    id:id
                },
                complete: function (ret) {
                    var ret = eval("(" + ret.responseText + ")");
                    if (ret.success) {
                        alert("操作成功");
                        $("#modal-table").modal("toggle");
                        myGrid.trigger("reloadGrid");
                    } else {
                        alert(ret.message);
                    }
                }
            });
        }
    }

    //删除公司收款账户
    function deleteAccount(id){
        if(confirm("确定要删除选中数据吗?")){
            $.ajax({
                dataType: "json",
                url: "${contextPath}/sys/ssdbCompany/deleteSsdbCompanyAccount",
                type: "post",
                data: {
                    id:id
                },
                complete: function (ret) {
                    var ret = eval("(" + ret.responseText + ")");
                    if (ret.success) {
                        alert("操作成功");
                        $("#modal-table").modal("toggle");
                        myGrid.trigger("reloadGrid");
                    } else {
                        alert(ret.message);
                    }
                }
            });
        }
    }

    //删除公司法院
    function deleteCourt(id){
        if(confirm("确定删除该法院吗?")){
            $.ajax({
                dataType: "json",
                url: "${contextPath}/sys/ssdbCompany/deleteSsdbCompanyCourt",
                type: "post",
                data: {
                    id:id
                },
                complete: function (ret) {
                    var ret = eval("(" + ret.responseText + ")");
                    if (ret.success) {
                        alert("操作成功");
                        $("#modal-table").modal("toggle");
                        myGrid.trigger("reloadGrid");
                    } else {
                        alert(ret.message);
                    }
                }
            });
        }
    }

    //修改配送方式
    function updateCourtDeliver(id,state){
        var deliver1 = 0;
        var deliver2 = 0;
        if(state == 0){
            if(confirm("确定把配送方式改为上门配送吗?")){
                deliver1 = 1;
                $.ajax({
                    dataType: "json",
                    url: "${contextPath}/sys/ssdbCompany/updateSsdbCompanyCourt",
                    type: "post",
                    data: {
                        id:id,
                        deliver1:deliver1,
                        deliver2:deliver2
                    },
                    complete: function (ret) {
                        var ret = eval("(" + ret.responseText + ")");
                        if (ret.success) {
                            alert("操作成功");
                            $("#modal-table").modal("toggle");
                            myGrid.trigger("reloadGrid");
                        } else {
                            alert(ret.message);
                        }
                    }
                });
            }
        }else{
            if(confirm("确定把配送方式改为快递配送吗?")){
                deliver2 = 1;
                $.ajax({
                    dataType: "json",
                    url: "${contextPath}/sys/ssdbCompany/updateSsdbCompanyCourt",
                    type: "post",
                    data: {
                        id:id,
                        deliver1:deliver1,
                        deliver2:deliver2
                    },
                    complete: function (ret) {
                        var ret = eval("(" + ret.responseText + ")");
                        if (ret.success) {
                            alert("操作成功");
                            $("#modal-table").modal("toggle");
                            myGrid.trigger("reloadGrid");
                        } else {
                            alert(ret.message);
                        }
                    }
                });
            }
        }
    }


    //修改投保单要求
    function updateOrderContent(id){
        var isPostBack = $("#isPostBack").val();
        var isAutoFill = $("#isAutoFill").val();
        var orderContent = $("#modal-refund-orderContent").val();
        $.ajax({
            dataType: "json",
            url: "${contextPath}/sys/ssdbCompany/updateSsdbCompanyParam",
            type: "post",
            data: {
                id:id,
                isPostBack:isPostBack,
                isAutoFill:isAutoFill,
                orderContent:orderContent
            },
            complete: function (ret) {
                var ret = eval("(" + ret.responseText + ")");
                if (ret.success) {
                    alert("操作成功");
                    $("#modal-table").modal("toggle");
                    myGrid.trigger("reloadGrid");
                } else {
                    alert(ret.message);
                }
            }
        });
    }

    //修改付款要求
    function updatePaymentContent(id){
        var paymentContent = $("#modal-refund-paymentContent").val();
        if(!paymentContent){
            alert("付款要求不能为空");
            return;
        }
        $.ajax({
            dataType: "json",
            url: "${contextPath}/sys/ssdbCompany/updateSsdbCompanyParam",
            type: "post",
            data: {
                id:id,
                paymentContent:paymentContent
            },
            complete: function (ret) {
                var ret = eval("(" + ret.responseText + ")");
                if (ret.success) {
                    alert("操作成功");
                    $("#modal-table").modal("toggle");
                    myGrid.trigger("reloadGrid");
                } else {
                    alert(ret.message);
                }
            }
        });

    }

    //修改时效
    function updateParam(id){
        var checkHours = $("#checkHours").val();
        var sendHours = $("#sendHours").val();
        $.ajax({
            dataType: "json",
            url: "${contextPath}/sys/ssdbCompany/updateSsdbCompanyParam",
            type: "post",
            data: {
                id:id,
                checkHours:checkHours,
                sendHours:sendHours
            },
            complete: function (ret) {
                var ret = eval("(" + ret.responseText + ")");
                if (ret.success) {
                    alert("操作成功");
                    $("#modal-table").modal("toggle");
                    myGrid.trigger("reloadGrid");
                } else {
                    alert(ret.message);
                }
            }
        });
    }

    function deleteParamQJVOList(id){
        if(confirm("确定要删除吗？")){
            $.ajax({
                dataType: "json",
                url: "${contextPath}/sys/ssdbCompany/deleteSsdbCompanyParamQJ",
                type: "post",
                data: {
                    id:id
                },
                complete: function (ret) {
                    var ret = eval("(" + ret.responseText + ")");
                    if (ret.success) {
                        alert("删除成功");
                        $("#modal-table").modal("toggle");
                        myGrid.trigger("reloadGrid");
                    } else {
                        alert(ret.message);
                    }
                }
            });
        }

    }

    /*对象构造器，就是一个普通函数*/
    function paramQj(id,startValue,endValue,rat,companyId){
        /*定义对象的属性*/
        this.id = id;
        this.startValue = startValue;
        this.endValue = endValue;
        this.rat = rat;
        this.companyId = companyId;
    }

    function updateParamQj(companyId){
        var paramQj = [];
        //循环Id以paramQj开头的标签
        $("[id^='paramQj']").each(function(i){

            paramQj[i] = new Object();
            paramQj[i].id = $(this).find("[class='paramQJId']").val();
            paramQj[i].startValue = $(this).find("[class='startValue']").val();
            paramQj[i].endValue = $(this).find("[class='endValue']").val();
            var rat =  $(this).find("[class='rat']").val();

            rat = keepTwoDecimal(rat/100);
            paramQj[i].rat =rat;
            paramQj[i].companyId = companyId;
            console.log(paramQj[i]);
        });
        if(paramQj.length == 0){
            alert("信息不能为空");
            return;
        }

        //转json格式
        var json = JSON.stringify(paramQj);
        $.ajax({
            dataType: "json",
            url: "${contextPath}/sys/ssdbCompany/updateSsdbCompanyParamQJ",
            type: "post",
            data: {
                stringJson:json
            },
            complete: function (ret) {
                var ret = eval("(" + ret.responseText + ")");
                if (ret.success) {
                    alert("操作成功");
                    $("#modal-table").modal("toggle");
                    myGrid.trigger("reloadGrid");
                } else {
                    alert(ret.message);
                }
            }
        });
        console.log(json);
       

    }

    function keepTwoDecimal(num) {
        var result = parseFloat(num);
        if (isNaN(result)) {
            alert('传递参数错误，请检查！');
            return false;
        }
        result = Math.round(num * 100) / 100;
        return result;
    }

    function notNull(str){
        if(str){
            return str;
        }else{
            return "未录入"
        }
    }

    function doRenzhen(type) {

        $.ajax({
            dataType: "json",
            url: "${contextPath}/sys/ssdbCompany/renzhen",
            type: "post",
            data: {
                id: $("#mod-check-id").val(),
                type: type,
                reason: $("#mod-check-fail").val(),
            },
            complete: function (ret) {
                if (ret.success) {
                    $("#mod-check").modal("toggle");
                    myGrid.trigger("reloadGrid");
                } else {
                    alert(ret.message);
                }
            }
        });
    }

    function tuishen(id) {
        if (confirm('确定退回申请状态吗?')) {
            $.ajax({
                dataType: "json",
                url: "${contextPath}/sys/ssdbCompany/tuishen",
                type: "post",
                data: {
                    id: id,
                },
                complete: function (ret) {
                    if (ret.success) {
                        myGrid.trigger("reloadGrid");
                    } else {
                        alert(ret.message);
                    }
                }
            });
        }
    }

    //显示添加收件信息页
    function showSaveReceipt(companyId){
        $("#modal-AddReceipt").modal("toggle");
        $("#mod-AddReceipt-companyId").val(companyId);
        initAreaProvinceTwo();
    }

    //显示添加收款账号页
    function showSaveAccount(companyId){
        $("#modal-AddAccount").modal("toggle");
        $("#mod-AddAccount-companyId").val(companyId);
        initAreaProvince();
    }

    function showSaveCourt(){
        $("#modal-Addcourt").modal("toggle");
        $("#mod-Addcourt-companyId").val(companyId);
    }

    //显示新增保全金额区间对应的费率页面
    function showSaveParamQJVOList(companyId){
        $("#modal-AddParamQJ").modal("toggle");
        $("#mod-AddParamQJ-companyId").val(companyId);
    }

    //保存公司基本信息
    function updateSsdbCompany(companyId){
        //登录名
        var loginName = $("#loginName").val();
        //公司状态
        var companyStateTwo = $("#companyStateTwo").val();
        //公司对接人
        var contact = $("#contact").val();
        //对接人联系号码
        var tel = $("#tel").val();
        //佣金比率
        //公司全称
        var name = $("#name").val();
        var commision = $("#commision").val();
        var password = $("#password").val();
        if(!loginName || !companyStateTwo||!name){
            alert("请完善信息！");
            return;
        }

        $.ajax({
            dataType: "json",
            url: "${contextPath}/sys/ssdbCompany/updateSsdbCompany",
            type: "post",
            data: {
                id:companyId,
                loginName: loginName.trim(),
                companyState: companyStateTwo,
                contact: contact.trim(),
                tel: tel.trim(),
                commision:(commision/100),
                password:password,
                name:name
            },
            complete: function (ret) {
                var ret = eval("(" + ret.responseText + ")");
                if (ret.success) {
                    alert("修改成功");
                    $("#modal-table").modal("toggle");
                    myGrid.trigger("reloadGrid");
                } else {
                    alert(ret.message);
                }
            }
        });

    }

    function renzhen(id) {
        $("#mod-check-id").val(id);
        $("#mod-check").modal("toggle");
    }

    function customRate(id) {
        document.getElementById('modal-customRate-form').reset();
        $('#mod-cr-companyId').val(id);
        $.getJSON('${contextPath}/sys/ssdbCompany/getRateParam?companyId=' + id, function (result) {
            if (result.noCompanyParam) {
                alert("该公司自定义费率不存在,可重新配置");
            }
            $("input[name='minBd']").val(result.minBd);
            //$("input[name='commisionDiff']").val(result.commisionDiff);
            $("input[name='minCommision1']").val(result.minCommision1);
            $("input[name='minFee1']").val(result.minFee1);
            $("input[name='minCommision2']").val(result.minCommision2);
            $("input[name='minFee2']").val(result.minFee2);
            $("input[name='minCommision3']").val(result.minCommision3);
            $("input[name='minFee3']").val(result.minFee3);
            $("input[name='minCommision4']").val(result.minCommision4);
            $("input[name='minFee4']").val(result.minFee4);
            //$("input[name='bfDiff']").val(result.bfDiff);
            $("#mod-cr-pcInputHid").val(result.pc);
            $("#mod-cr-pcSel").val(result.pc);
            $("#modal-customRate").modal("toggle");
        });

        loadRateInterval();
        loadSpecailRateInterval();
    }

    function customRateNew(id) {
        document.getElementById('modal-customRate-formNew').reset();
        $('#mod-cr-companyIdNew').val(id);
        $.getJSON('${contextPath}/sys/ssdbCompany/getRateParamNew?companyId=' + id, function (result) {
            console.log(result)
            if (result.noCompanyParam) {
                alert("该公司自定义费率不存在,可重新配置");
            }
            $("input[name='minBdNew']").val(result.minBd);
            $("input[name='minCommisionNew']").val(result.minCommisionNew);
            $("input[name='minFeeNew']").val(result.minFeeNew);
            $("#mod-cr-pcInputHidNew").val(result.pc);
            $("#mod-cr-pcSelNew").val(result.pc);
            $("#modal-customRateNew").modal("toggle");
        });
        loadRateIntervalNew();
    }

    function addServices(id) {
        $('#mod-addServices-companyId').val(id);
        $.getJSON('${contextPath}/sys/ssdbCompany/getCompanyLabel?companyId=' + id, function (result) {
            var html_sb = '';
            var html_ps = '';
            for (var i in result) {
                if (result[i].labelType == 0) {
                    //html_sb += '<label><input type="checkbox" value="'+ result[i].labelContent+'"">'+result[i].labelContent+'</label>'
                    html_sb += '<div class="form-group col-sm-6">';
                    if (result[i].isUser == 0) {
                        html_sb += '   <label><input type="checkbox" name="mod-addServices-check" value="' + result[i].id + '"">' + result[i].labelContent + '</label>'
                    } else {
                        html_sb += '   <label><input type="checkbox" checked="true" name="mod-addServices-check" value="' + result[i].id + '"">' + result[i].labelContent + '</label>'
                    }
                    html_sb += '</div>';
                } else if (result[i].labelType == 1) {
                    html_ps += '<div class="form-group col-sm-6">';
                    if (result[i].isUser == 0) {
                        html_ps += '   <label><input type="checkbox" name="mod-addServices-check" value="' + result[i].id + '"">' + result[i].labelContent + '</label>'
                    } else {
                        html_ps += '   <label><input type="checkbox" checked="true" name="mod-addServices-check" value="' + result[i].id + '"">' + result[i].labelContent + '</label>'
                    }
                    html_ps += '</div>';
                }
            }
            $("#mod-addServices-sbList").html(html_sb);
            $("#mod-addServices-psList").html(html_ps);
        });
        $("#modal-addServices").modal("toggle");
    }

    $('#modal-addServices-submit').click(function (event) {
        var obj = document.getElementsByName('mod-addServices-check');
        var sid = '';
        for (var i = 0; i < obj.length; i++) {
            if (obj[i].checked) {
                sid += obj[i].value + ','; //如果选中，将value添加到变量s中
            }
        }
        if (sid != null) {
            $.ajax({
                dataType: "json",
                url: "${contextPath}/sys/ssdbCompany/saveCompanyLabel",
                type: "post",
                data: {
                    sid: sid,
                    companyId: $('#mod-addServices-companyId').val()
                },
                complete: function (ret) {
                    if (ret.success) {
                        alert("保存成功!");
                        $("#modal-addServices").modal("toggle");
                        myGrid.trigger("reloadGrid");
                    } else {
                        alert(ret.message);
                    }
                }
            });
        }
    });

    function setServices() {
        $.getJSON('${contextPath}/sys/ssdbCompany/getDwLabel', function (result) {
            // alert(JSON.stringify(result))
            //加载诉保服务  loadSbServices();
            //加载配送服务  loadPsServices();
            var html_sb = '';
            var html_ps = '';
            var count_sb = 0;
            for (var i in result) {
                if (result[i].labelType == 0) {
                    count_sb++;
                    html_sb += '<div class="form-group">';
                    html_sb += '     <div class="row">';
                    html_sb += '        <label class="col-sm-2 control-label">服务' + count_sb + ':</label>';
                    html_sb += '        <div class="col-sm-5"></div>';
                    html_sb += '        <div class="col-sm-2"><button class="btn btn-white" onclick="deleteService(\'' + result[i].id + '\')" type="button">删除服务</button></div>';
                    html_sb += '     </div>';
                    html_sb += '     <div class="row">';
                    html_sb += '        <label class="col-sm-2 control-label">服务标签:</label>';
                    html_sb += '        <div class="col-sm-1"> <a href="' + result[i].labelIcon + '" target="_blank"><img width="30" height="30" src="' + result[i].labelIcon + '" /></a></div>';
                    html_sb += '        <div class="col-sm-2"><button class="btn btn-white" onclick="reUploadPic(\'' + result[i].id + '\')" type="button">重新上传</button></div>';
                    html_sb += '     </div>';
                    html_sb += '     <div class="row">';
                    html_sb += '        <label class="col-sm-2 control-label">服务文案:</label>';
                    html_sb += '        <div class="col-sm-4"><div class="input-group"><input name="' + result[i].id + '-sb" type="text" class="form-control" value="' + result[i].labelContent + '"></div></div>';
                    html_sb += '     </div>';
                    html_sb += '</div>';
                    html_sb += '<div class="hr-line-dashed"></div>';
                } else if (result[i].labelType == 1) {
                    //count_ps++;
                    html_ps += '<div class="form-group">';
                    //html_ps += '     <label class="col-sm-2 control-label">服务'+count_ps+':</label>';
                    html_ps += '     <div class="row">';
                    html_ps += '        <label class="col-sm-2 control-label">服务文案:</label>';
                    html_ps += '        <div class="col-sm-5"><div class="input-group"><input name="' + result[i].id + '-ps" type="text" class="form-control" value="' + result[i].labelContent + '"></div></div>';
                    html_ps += '         <div class="col-sm-2"><button class="btn btn-white" onclick="deleteService(\'' + result[i].id + '\')" type="button">删除服务</button></div>';
                    html_ps += '     </div>';
                    html_ps += '</div>';
                }
            }
            $("#mod-service-sbList").html(html_sb);
            $("#mod-service-psList").html(html_ps);

        });
        $("#modal-service").modal("toggle");
    }

    function reUploadPic() {
        $("#mod-pic").modal("toggle");
    }

    $('#mod-pic-submit').click(function (event) {
        alert('开始上传图片');
        $("#mod-pic").modal("toggle");
    });

    $('#mod-sb-addButton').click(function (event) {
        $("#mod-service-sb").modal("toggle");
    });

    $('#mod-ps-addButton').click(function (event) {
        $("#mod-service-ps").modal("toggle");
    });

    function deleteService(id) {
        $.ajax({
            dataType: "json",
            url: "${contextPath}/sys/ssdbCompany/deleteDwLabel",
            type: "post",
            data: {
                id: id
            },
            complete: function (ret) {
                if (ret.success) {
                    $("#modal-service").modal("toggle");
                    myGrid.trigger("reloadGrid");
                } else {
                    alert(ret.message);
                }
            }
        });
    }

    function add() {
        $("#AddForm")[0].reset();
        $("#mod-add-tip").html('');
        $("#mod-add").modal("toggle");
    }

    function edit(id, name, loginName, tel, contact, companyState, commision, commisionLawyer, companyType,
                  containTax, payChannel, sort, textInfo, pc, fsRemarks, advance, commisionDiff, minCommision,
                  clearingInstitutionName, serviceCostProportion, serviceCostRemark, appointTime) {
        if (fsRemarks == "null" || fsRemarks == null) {
            $("#mod-edit-companyInfo").html("无");
        } else {
            $("#mod-edit-companyInfo").html(fsRemarks);
        }

        $("#mod-edit-tip").html('');
        $("#mod-edit-title").html(name + '-编辑');
        $("#mod-edit-id").val(id);
        $("#mod-edit-password").val('');
        $("#mod-edit-name").val(name);
        $("#mod-edit-loginName").val(loginName);
        $("#mod-edit-tel").val(tel);
        $("#mod-edit-contact").val(contact);
        $("#mod-edit-companyState").val(companyState);
        $("#mod-edit-commision").val(parseInt(commision * 100));
        $("#mod-edit-commisionLawyer").val(parseInt(commisionLawyer * 100));
        $("#mod-edit-companyType").val(companyType);
        $("#mod-edit-sort").val(sort);
        $("#mod-edit-containTax").val(containTax);
        if (commisionDiff == null || commisionDiff == 'null') {// 废弃字段，设置一个数字,以免保存报错.
            commisionDiff = 0;
        }
        console.info(commisionDiff);
        $("#mod-edit-commisionDiff").val(commisionDiff);
        $("#mod-edit-minCommision").val(minCommision);
        $("#mod-edit-clearing-institution-name").val(clearingInstitutionName);
        $("#mod-edit-service-cost-proportion").val(serviceCostProportion);
        $("#mod-edit-service-cost-remark").val(serviceCostRemark);
        $("#mod-edit-service-appoint-time").val(appointTime);

        var texts = textInfo.split("|");
        if (texts.length != 3) {
            texts = ['', '', ''];
        }
        for (var i = 0; i < 3; i++) {
            $('#mod-edit-text' + i).val(texts[i]);
        }
        var channels = payChannel.split("");
        $("input[name='mod-edit-pay_offLine'][value='" + channels[0] + "']").attr("checked", true);
        $("input[name='mod-edit-pay_weixin'][value='" + channels[1] + "']").attr("checked", true);
        $("input[name='mod-edit-pay_alipay'][value='" + channels[2] + "']").attr("checked", true);
        $("input[name='mod-edit-advance'][value='" + advance + "']").attr("checked", true);
        $("#mod-edit").modal("toggle");
        loadPic('service-cooperative-agreements', $("#mod-edit-id").val());
    }

    function isNotNaturalNumber(obj) {
        var reg = /^[0-9]+$/;
        return !reg.test(obj);
    }

    function isNotNumber(obj) {
        var reg = /^(\-|\+)?\d+(\.\d+)?$/;
        return !reg.test(obj);
    }

    function initAreaProvince(){
        $.getJSON("${contextPath}/sys/cdPrice/getProvince",function(result){
            $.each(result, function(i, v){
                $("#areaProvince").append("<option value='"+v.code+"'>"+v.name+"</option>");
            });
        });
    }

    function initAreaProvinceTwo(){
        $.getJSON("${contextPath}/sys/cdPrice/getProvince",function(result){
            $.each(result, function(i, v){
                $("#areaProvinceTwo").append("<option value='"+v.code+"'>"+v.name+"</option>");
            });
        });
    }

    function setAreaCityTwo(obj){
        var val = obj.value;
        var sec = document.getElementById('areaCityTwo');
        sec.innerHTML = "<option value=''>全部</option>";
        if(val != ''){
            //ajax
            $.getJSON("${contextPath}/sys/cdPrice/getAreas?parentCode="+val,function(result){
                $.each(result, function(i, v){
                    sec.innerHTML+="<option value='"+v.code+"'>"+v.name+"</option>";
                });
            });
        }
    }

    function setAreaCity(obj){
        var val = obj.value;
        var sec = document.getElementById('areaCity');
        sec.innerHTML = "<option value=''>全部</option>";
        if(val != ''){
            //ajax
            $.getJSON("${contextPath}/sys/cdPrice/getAreas?parentCode="+val,function(result){
                $.each(result, function(i, v){
                    sec.innerHTML+="<option value='"+v.code+"'>"+v.name+"</option>";
                });
            });
        }
    }

    function getCheckBoxHtml(value, text){
        return "<input type=checkbox name=county value='" + value + "' />" + text + "&nbsp;&nbsp;";
    }

    function getCountyTwo(obj){
        var val = obj.value;
        var text = $(obj).find("option:selected").text();
        $("#tdCounty").html("").append(getCheckBoxHtml(val, text));
        if(val != ''){
            $.getJSON("${contextPath}/sys/cdPrice/getAreas?parentCode="+val,function(result){
                $.each(result, function(i, v){
                    $("#tdCounty").append(getCheckBoxHtml(v.code, v.name));
                });
            });
        }
    }

    function getCounty(obj){
        var val = obj.value;
        var text = $(obj).find("option:selected").text();
        $("#tdCounty").html("").append(getCheckBoxHtml(val, text));
        if(val != ''){
            $.getJSON("${contextPath}/sys/cdPrice/getAreas?parentCode="+val,function(result){
                $.each(result, function(i, v){
                    $("#tdCounty").append(getCheckBoxHtml(v.code, v.name));
                });
            });
        }
    }

    var scripts = [null, "${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 () {

        $("#mod-AddReceipt-submit").on("click",function(e){
            var companyId = $("#mod-AddReceipt-companyId").val();
            var areaProvince = $("#areaProvinceTwo").val();
            var areaCity = $("#areaCityTwo").val();
            var contact = $("#mod-AddReceipt-contact").val();
            var phone = $("#mod-AddReceipt-phone").val();
            var address = $("#mod-AddReceipt-address").val();
            if(!areaProvince ||!areaCity ){
                alert("请选择地区");
                return;
            }
            if(!contact ||!phone ||!address){
                alert("请完善信息");
                return;
            }

            $.ajax({
                dataType: "json",
                url: "${contextPath}/sys/ssdbCompany/saveSsdbCompanyReceipt",
                type: "post",
                data: {
                    companyId:companyId,
                    provinceId: areaProvince,
                    cityId: areaCity,
                    contact:contact,
                    phone:phone,
                    address:address
                },
                complete: function (ret) {
                    var ret = eval("(" + ret.responseText + ")");
                    if (ret.success) {
                        alert("添加成功");
                        $("#mod-AddReceipt-companyId").val("");
                        $("#mod-AddReceipt-contact").val("");
                        $("#mod-AddReceipt-phone").val("");
                        $("#mod-AddReceipt-address").val("");
                        $("#areaCity").html("");
                        $("#modal-AddReceipt").modal("toggle");
                        $("#modal-table").modal("toggle");
                        myGrid.trigger("reloadGrid");
                    } else {
                        alert(ret.message);
                    }
                }
            });

        })

        $("#mod-AddAccount-submit").on("click",function(e){
            var accountName = $("#mod-AddAccount-accountName").val();
            var accountNum = $("#mod-AddAccount-accountNum").val();
            var accountBank = $("#mod-AddAccount-accountBank").val();
            var companyId = $("#mod-AddAccount-companyId").val();
            var areaProvince = $("#areaProvince").val();
            var areaCity = $("#areaCity").val();
            if(!areaProvince ||!areaCity ){
                alert("请选择地区");
                return;
            }
            if(!accountName ||!accountNum||!accountBank ){
                alert("请完善信息");
                return;
            }
            var areaFullName = areaProvinceName+areaCityName;
            $.ajax({
                dataType: "json",
                url: "${contextPath}/sys/ssdbCompany/saveSsdbCompanyAccount",
                type: "post",
                data: {
                    companyId:companyId,
                    accountName: accountName,
                    accountNum: accountNum,
                    accountBank:accountBank,
                    areaCode:areaProvince,
                    areaFullName:areaFullName
                },
                complete: function (ret) {
                    var ret = eval("(" + ret.responseText + ")");
                    if (ret.success) {
                        alert("添加成功");
                        $("#mod-AddAccount-companyId").val("");
                        $("#mod-AddAccount-accountName").val("");
                        $("#mod-AddAccount-accountNum").val("");
                        $("#mod-AddAccount-accountBank").val("");
                        $("#areaCity").html("");
                        $("#modal-AddAccount").modal("toggle");
                        $("#modal-table").modal("toggle");
                        myGrid.trigger("reloadGrid");
                    } else {
                        alert(ret.message);
                    }
                }
            });

        })

        $("#mod-Addcourt-submit").on("click",function(e){
            var companyId = $("#mod-Addcourt-companyId").val();
            var courtName = $("#mod-Addcourt-courtName").val();
            var deliver = $("#mod-Addcourt-deliver").val();
            if(!courtName || !deliver){
                alert("请完善信息");
                return;
            }
            $.ajax({
                dataType: "json",
                url: "${contextPath}/sys/ssdbCompany/saveSsdbCompanyCourt",
                type: "post",
                data: {
                    companyId:companyId,
                    courtName: courtName,
                    deliver: deliver
                },
                complete: function (ret) {
                    var ret = eval("(" + ret.responseText + ")");
                    if (ret.success) {
                        alert("添加成功");
                        $("#mod-Addcourt-companyId").val("");
                        $("#mod-Addcourt-courtName").val("");
                        $("#mod-Addcourt-deliver").val("");
                        $("#modal-Addcourt").modal("toggle");
                        $("#modal-table").modal("toggle");
                        myGrid.trigger("reloadGrid");
                    } else {
                        alert(ret.message);
                    }
                }
            });
        })

        $("#mod-AddParamQJ-submit").on("click",function(e){
            var companyId = $("#mod-AddParamQJ-companyId").val();
            var startValue = $("#mod-AddParamQJ-startValue").val();
            var endValue = $("#mod-AddParamQJ-endValue").val();
            var rat = $("#mod-AddParamQJ-rat").val();
            if(!rat || !endValue || ! startValue){
                alert("请完善信息");
                return;
            }
            $.ajax({
                dataType: "json",
                url: "${contextPath}/sys/ssdbCompany/saveSsdbCompanyParamQJ",
                type: "post",
                data: {
                    companyId:companyId,
                    startValue: startValue.trim(),
                    endValue: endValue,
                    rat:(rat/100)
                },
                complete: function (ret) {
                    var ret = eval("(" + ret.responseText + ")");
                    if (ret.success) {
                        alert("添加成功");
                        $("#mod-AddParamQJ-startValue").val("");
                        $("#mod-AddParamQJ-startValue").val("");
                        $("#mod-AddParamQJ-endValue").val("");
                        $("#mod-AddParamQJ-rat").val("");
                        $("#modal-AddParamQJ").modal("toggle");
                        $("#modal-table").modal("toggle");
                        myGrid.trigger("reloadGrid");
                    } else {
                        alert(ret.message);
                    }
                }
            });
        })

        $("#mod-add-submit").on("click", function (e) {
            var p1 = $("#mod-add-password").val();
            var p2 = $("#mod-add-password2").val();
            if ($("#mod-add-name").val() == "") {
                alert("请输入公司全称！");
                return;
            }
            if ($("#mod-add-loginName").val() == "") {
                alert("请输入公司简称（登录名）！");
                return;
            }
            if ($("#mod-add-clearing-institution-name").val() == "") {
                alert("请输入结算机构名称！");
                return;
            }
            if (p1 == "" || p2 == "" || p1 != p2) {
                alert("请输入密码，并且密码一致！");
                return;
            }
            var texts = ['', '', ''];
            for (var i = 0; i < 3; i++) {
                texts[i] = $('#mod-add-text' + i).val();
            }
            var payChannel = "" + $("input[name='mod-add-pay_offLine']:checked").val() + $("input[name='mod-add-pay_weixin']:checked").val() + $("input[name='mod-add-pay_alipay']:checked").val();
            var sort = $('#mod-add-sort').val();
            if (isNotNaturalNumber(sort)) {
                alert('合作排序只能为自然数');
                return;
            }
            $.ajax({
                dataType: "json",
                url: "${contextPath}/sys/ssdbCompany/add",
                type: "post",
                data: {
                    name: $("#mod-add-name").val(),
                    loginName: $("#mod-add-loginName").val(),
                    password: $("#mod-add-password").val(),
                    tel: $("#mod-add-tel").val(),
                    contact: $("#mod-add-contact").val(),
                    commision: $("#mod-add-commision").val() / 100,
                    commisionLawyer: $("#mod-add-commisionLawyer").val() / 100,
                    companyType: $("#mod-add-companyType").val(),
                    payChannel: payChannel,
                    containTax: $("#mod-add-containTax").val(),
                    advance: $("input[name='mod-add-advance']:checked").val(),
                    clearingInstitutionName: $("#mod-add-clearing-institution-name").val(),
                    sort: sort,
                    textInfo: texts.join('|')
                },
                complete: function (ret) {
                    if (ret.success) {
                        $("#mod-add").modal("toggle");
                        myGrid.trigger("reloadGrid");
                    } else {
                        alert(ret.message);
                    }
                }
            });

        });

        $("#mod-edit-submit").on("click", function (e) {
            if ($("#mod-edit-loginName").val() == "") {
                alert("请输入公司简称（登录名）！");
                return;
            }
            var texts = ['', '', ''];
            for (var i = 0; i < 3; i++) {
                texts[i] = $('#mod-edit-text' + i).val();
            }
            var payChannel = "" + $("input[name='mod-edit-pay_offLine']:checked").val() + $("input[name='mod-edit-pay_weixin']:checked").val() + $("input[name='mod-edit-pay_alipay']:checked").val();
            var sort = $('#mod-edit-sort').val();
            if (isNotNaturalNumber(sort)) {
                alert('合作排序只能为自然数');
                return;
            }
            if (isNotNaturalNumber($("#mod-edit-service-appoint-time").val()) || $("#mod-edit-service-appoint-time").val() < 1 || $("#mod-edit-service-appoint-time").val() > 31) {
                alert('服务费约定回款时间（每月号数）只能是数字!号数为1~31号之间');
                return;
            }
            if (isNotNumber($("#mod-edit-service-cost-proportion").val())) {
                alert('服务费比例输入格式不正确，请检查!');
                return;
            }
            $.ajax({
                dataType: "json",
                url: "${contextPath}/sys/ssdbCompany/edit",
                type: "post",
                data: {
                    id: $("#mod-edit-id").val(),
                    name: $("#mod-edit-name").val(),
                    loginName: $("#mod-edit-loginName").val(),
                    password: $("#mod-edit-password").val(),
                    tel: $("#mod-edit-tel").val(),
                    contact: $("#mod-edit-contact").val(),
                    commision: $("#mod-edit-commision").val() / 100,
                    commisionLawyer: $("#mod-edit-commisionLawyer").val() / 100,
                    companyType: $("#mod-edit-companyType").val(),
                    payChannel: payChannel,
                    advance: $("input[name='mod-edit-advance']:checked").val(),
                    containTax: $("#mod-edit-containTax").val(),
                    sort: sort,
                    textInfo: texts.join('|'),
                    commisionDiff: $("#mod-edit-commisionDiff").val(),
                    minCommision: $("#mod-edit-minCommision").val(),
                    clearingInstitutionName: $("#mod-edit-clearing-institution-name").val(),
                    serviceCostProportion: $("#mod-edit-service-cost-proportion").val(),
                    serviceCostRemark: $("#mod-edit-service-cost-remark").val(),
                    appointTime: $("#mod-edit-service-appoint-time").val(),
                },
                complete: function (ret) {
                    if (ret.success) {
                        $("#mod-edit").modal("toggle");
                        myGrid.trigger("reloadGrid");
                    } else {
                        alert(ret.message);
                    }
                }
            });

        });

        // inline scripts related to this page
        jQuery(function ($) {
            var grid_selector = "#grid-table";
            var pager_selector = "#grid-pager";

            // resize to fit page size
            $(window).on('resize.jqGrid', function () {
                $(grid_selector).jqGrid('setGridWidth', $(".page-content").width());
            })
            // resize on sidebar collapse/expand
            var parent_column = $(grid_selector).closest('[class*="col-"]');
            $(document).on('settings.ace.jqGrid', function (ev, event_name, collapsed) {
                if (event_name === 'sidebar_collapsed' || event_name === 'main_container_fixed') {
                    // setTimeout is for webkit only to give time for DOM changes and then redraw!!!
                    setTimeout(function () {
                        $(grid_selector).jqGrid('setGridWidth', parent_column.width());
                    }, 0);
                }
            });

            myGrid = jQuery(grid_selector).jqGrid({
                subGrid: false,
                url: "${contextPath}/sys/ssdbCompany/getCompany",
                datatype: "json",
                postData: {
                    'companyState': $("#companyState").val()
                },
                height: '99%',
                colModel: [{
                    name: 'loginName',
                    label: '登录名',
                    width: 100,
                }, {
                    name: 'name',
                    label: '公司全称',
                    width: 200,
                }, {
                    name: 'contact',
                    label: '对接人',
                    width: 150,
                }, {
                    name: 'tel',
                    label: '对接人电话',
                    width: 80,
                }, {
                    name: 'checkHours',
                    label: '审核时效',
                    width: 80,
                }, {
                    name: 'sendHours',
                    label: '出函时效',
                    width: 80,
                }, {
                    name: 'companyState',
                    label: '状态',
                    width: 80,
                    formatter: defaultState,
                },{
                    name: 'id',
                    index: '',
                    label: '操作',
                    width: 80,
                    editable: false,
                    search: false,
                    sortable: false,
                    formatter: optionFormatter
                }],
                //scroll : 1, // set the scroll property to 1 to enable paging with scrollbar - virtual loading of records
                sortname: "name",
                sortorder: "asc",
                viewrecords: true,
                rowNum: 10,
                rowList: [10, 20, 30],
                pager: pager_selector,
                altRows: true,
                //toppager : true,
                //multiselect : true,
                //multikey : "ctrlKey",
                //multiboxonly : true,
                loadComplete: function () {
                    var table = this;
                    setTimeout(function () {
                        //styleCheckbox(table);
                        //updateActionIcons(table);
                        updatePagerIcons(table);
                        enableTooltips(table);
                    }, 0);
                },
                //editurl : "${contextPath}/sys/ssdbCompany/saveCompany",
                //caption : "用户管理列表",
                //autowidth : true,

            });

            function optionFormatter(cellvalue, options, cell) {
                var template = "<button data-toggle='modal' onclick='showdetail(\"" + cellvalue + "\")' class='btn btn-minier btn-yellow'><i class='ace-icon fa fa-hdd-o '></i>查看详细</button>";
                return template;
            }

            function defaultCompanyType(cellvalue, options, rowObject) {
                if (cellvalue == 1)
                    return "保险公司";
                if (cellvalue == 0)
                    return "担保公司";
                return "";
            }

            function defaultState(cellvalue, options, rowObject) {
                if (cellvalue == 1)
                    return "<font color='red'>" + rowObject.companyStateName + "</font>";
                return rowObject.companyStateName;
            }

            function defaultCommision(cellvalue, options, rowObject) {
                return parseInt(cellvalue * 100) + "%";
            }

            function defaultCommisionLawyer(cellvalue, options, rowObject) {
                return parseInt(cellvalue * 100) + "%";
            }

            $("#searchd").click(function () {
                var keyword = encodeURI(encodeURI($("#keyword").val()));
                var companyState = $("#companyState").val();
                myGrid.setGridParam({
                    postData: {'keyword': keyword, 'companyState': companyState},
                    url: '${contextPath}/sys/ssdbCompany/getCompany',
                    page: 1
                }).trigger('reloadGrid');
            });

            $(window).triggerHandler('resize.jqGrid');// trigger window resize to make the grid get the correct size

            jQuery(grid_selector).jqGrid('navGrid', pager_selector, {
                edit: false,
                editicon: 'ace-icon fa fa-pencil blue',
                add: false,
                addicon: 'ace-icon fa fa-plus-circle purple',
                del: false,
                delicon: 'ace-icon fa fa-trash-o red',
                search: false,
                searchicon: 'ace-icon fa fa-search orange',
                refresh: false,
                refreshicon: 'ace-icon fa fa-refresh blue',
                view: false,
            });

            // replace icons with FontAwesome icons like above
            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'
                });
            }

            // var selr = jQuery(grid_selector).jqGrid('getGridParam','selrow');

            $(document).one('ajaxloadstart.page', function (e) {
                $(grid_selector).jqGrid('GridUnload');
                $('.ui-jqdialog').remove();
            });

            $("#mod-cr-addButton").on("click", function (e) {
                document.getElementById('mod-add1-form').reset();
                $('#mod-add1').modal('toggle');
            });

            $("#mod-cr-addButtonNew").on("click", function (e) {
                document.getElementById('mod-add1-formNew').reset();
                $('#mod-addNew').modal('toggle');
            });

            $("#mod-ncr-addButton").on("click", function (e) {
                document.getElementById('mod-add2-form').reset();
                $('#mod-add2').modal('toggle');
            });

            $("#mod-add1-submit").on("click", function (e) {
                submitRateInterval(0);
            });
            $("#mod-add1-submitNew").on("click", function (e) {
                submitRateInterval(1);
            });

            $("#mod-add2-submit").on("click", function (e) {
                addSpecialRateInterval();
            });

            $("#modal-customRate-submit").on("click", function (e) {
                submitCustomRate();
            });

            $("#modal-customRate-submitNew").on("click", function (e) {
                submitCustomRateNew();
            });


            $('#mod-cr-pcSel').change(function () {
                var v = $(this).children('option:selected').val();
                $('#mod-cr-pcInputHid').val(v);
            });
            $('#mod-cr-pcSelNew').change(function () {
                var v = $(this).children('option:selected').val();
                $('#mod-cr-pcInputHidNew').val(v);
            });
        });
    });


    function isNotBlank(obj) {
        var result = true;
        if (obj == undefined || obj == null || obj == 'null' || obj.length < 1) {
            result = false;
        }
        return result;
    }

    function checkDouble(s) {
        var reg = /\d+(\.\d+)?/;
        return !reg.test(s);
    }

    function deleteRateInterval(id,isNew) {
        if (confirm("确定删除吗?")) {
            $.getJSON('${contextPath}/sys/ssdbCompany/deleteRateInterval?ids=' + id, function (result) {
                if (result.success) {
                    if(isNew==1){
                        loadRateIntervalNew();
                    }else{
                        loadRateInterval();
                    }
                }
            });
        }
    }

    //标的区间数据
    function loadRateInterval() {
        var id = $('#mod-cr-companyId').val();
        $.getJSON('${contextPath}/sys/ssdbCompany/getRateInterval?companyId=' + id, function (result) {
            var html = '';
            var htmlC = '';
            var ids = '';
            var arr = null;
            $.each(result, function (i, v) {
                arr = new Array();
                htmlC = '';
                $.each(v.rats, function (j, r) {
                    htmlC += '<div class="hr-line-dashed"></div>';
                    htmlC += '<div class="form-group">';
                    htmlC += '	<label class="col-sm-2 control-label">费率' + (j + 1) + '</label>';
                    htmlC += '	<div class="col-sm-10">';
                    htmlC += '		<div class="row">';
                    htmlC += '			<div class="col-sm-3"><div class="input-group"><input name="' + r.id + '-rs" type="text" class="form-control" value="' + r.ratStart + '" placeholder="输入费率比例 "><span class="input-group-addon">%</span></div></div>';
                    htmlC += '			<div class="col-sm-3"><div class="input-group" style="display: none"><input name="' + r.id + '-re" type="text" class="form-control" value="' + r.ratEnd + '" placeholder="输入费率比例 "><span class="input-group-addon">%</span></div></div>';
                    htmlC += '			<label class="col-sm-3 control-label">律师返现</label>';
                    htmlC += '			<div class="col-sm-3"><div class="input-group"><input name="' + r.id + '-lc" type="text" class="form-control" value="' + r.commision + '" placeholder="输入律师返现 "><span class="input-group-addon">%</span></div></div>';
                    htmlC += '		</div>';
                    htmlC += '	</div>';
                    htmlC += '</div>';
                    arr.push(r.id);
                });
                if (arr.length > 0) {
                    ids = arr.join();
                    html += '<div class="hr-line-dashed"></div>';
                    html += '<div class="form-group">';
                    html += '	<label class="col-sm-2 control-label">标的区间' + (i + 1) + '</label>';
                    html += '	<div class="col-sm-10">';
                    html += '		<div class="row">';
                    html += '			<div class="col-sm-3"><input name="bdRatIdsS' + ids + '" type="text" class="form-control" value="' + v.bdStart + '"></div>';
                    html += '			<div class="col-sm-3"><input name="bdRatIdsE' + ids + '" type="text" class="form-control" value="' + v.bdEnd + '" placeholder="无上限"></div>';
                    html += '			<div class="col-sm-2"><button class="btn btn-white" onclick="deleteRateInterval(\'' + ids + '\')" type="button">删除</button></div>';
                    html += '			<div class="col-sm-4"></div>';
                    html += '		</div>';
                    html += '	</div>';
                    html += '</div>';
                    html += htmlC;
                }
            });
            $("#mod-cr-qjList").html(html);
        });
    }
    function loadRateIntervalNew() {
        var id = $('#mod-cr-companyIdNew').val();
        console.log(id)
        $.getJSON('${contextPath}/sys/ssdbCompany/getRateIntervalNew?companyId=' + id, function (result) {
            console.log(result)
            var html = '';
            var htmlC = '';
            var ids = '';
            var arr = null;
            $.each(result, function (i, v) {
                arr = new Array();
                htmlC = '';
                $.each(v.rats, function (j, r) {
                    htmlC += '<div class="hr-line-dashed"></div>';
                    htmlC += '<div class="form-group">';
                    htmlC += '	<label class="col-sm-2 control-label">费率</label>';
                    htmlC += '	<div class="col-sm-10">';
                    htmlC += '		<div class="row">';
                    htmlC += '			<div class="col-sm-3"><div class="input-group"><input name="' + r.id + '-rs" type="text" class="form-control" value="' + r.ratStart + '" placeholder="输入费率比例 "><span class="input-group-addon">%</span></div></div>';
                    htmlC += '			<div class="col-sm-3"><div class="input-group" style="display: none"><input name="' + r.id + '-re" type="text" class="form-control" value="' + r.ratEnd + '" placeholder="输入费率比例 "><span class="input-group-addon">%</span></div></div>';
                    htmlC += '			<label class="col-sm-3 control-label">返点</label>';
                    htmlC += '			<div class="col-sm-3"><div class="input-group"><input name="' + r.id + '-lc" type="text" class="form-control" value="' + r.commision + '" placeholder="输入律师返现 "><span class="input-group-addon">%</span></div></div>';
                    htmlC += '		</div>';
                    htmlC += '	</div>';
                    htmlC += '</div>';
                    arr.push(r.id);
                });
                if (arr.length > 0) {
                    ids = arr.join();
                    html += '<div class="hr-line-dashed"></div>';
                    html += '<div class="form-group">';
                    html += '	<label class="col-sm-2 control-label">标的区间</label>';
                    html += '	<div class="col-sm-10">';
                    html += '		<div class="row">';
                    html += '			<div class="col-sm-3"><input name="bdRatIdsS' + ids + '" type="text" class="form-control" value="' + v.bdStart + '"></div>';
                    html += '			<div class="col-sm-3"><input name="bdRatIdsE' + ids + '" type="text" class="form-control" value="' + v.bdEnd + '" placeholder="无上限"></div>';
                    html += '			<div class="col-sm-2"><button class="btn btn-white" onclick="deleteRateInterval(\'' + ids + '\',1)" type="button">删除</button></div>';
                    html += '			<div class="col-sm-4"></div>';
                    html += '		</div>';
                    html += '	</div>';
                    html += '</div>';
                    html += htmlC;
                }
            });
            $("#mod-cr-qjListNew").html(html);
        });
    }


    function submitCustomRate() {
        console.log($("#modal-customRate-form").serialize())
        $.getJSON('${contextPath}/sys/ssdbCompany/saveCustomRate', $("#modal-customRate-form").serialize(), function (result) {
            if (result.success) {
                alert('提交成功！');
                $("#modal-customRate").modal("toggle");
            } else
                alert(result.message);
        });
    }
    function submitCustomRateNew() {
        console.log($("#modal-customRate-formNew").serialize())
        $.getJSON('${contextPath}/sys/ssdbCompany/saveCustomRateNew', $("#modal-customRate-formNew").serialize(), function (result) {
            if (result.success) {
                alert('提交成功！');
                $("#modal-customRateNew").modal("toggle");
            } else
                alert(result.message);
        });
    }

    function submitRateInterval(isNew) {
        if(isNew==1){
            var obj = {
                'add-bd-startNew': ['标的(始)', 'bds'],
                'add-rat1-startNew': ['费率(始)', 'r1s'],
                'add-lawRat1New': ['律师返现', 'lr1'],
            };
        }else{
            var obj = {
                'add-bd-start': ['标的(始)', 'bds'],
                'add-rat1-start': ['费率1(始)', 'r1s'],
                'add-rat1-end': ['费率1(终)', 'r1e'],
                'add-lawRat1': ['律师返现', 'lr1'],
                'add-rat2-start': ['费率2(始)', 'r2s'],
                'add-rat2-end': ['费率2(终)', 'r2e'],
                'add-lawRat2': ['律师返现', 'lr2'],
                'add-rat3-start': ['费率3(始)', 'r3s'],
                'add-rat3-end': ['费率3(终)', 'r3e'],
                'add-lawRat3': ['律师返现', 'lr3'],
                'add-rat4-start': ['费率4(始)', 'r4s'],
                'add-rat4-end': ['费率4(终)', 'r4e'],
                'add-lawRat4': ['律师返现', 'lr4'],
            };
        }

        var data = {};
        var v = null;
        var a = null;
        for (var key in obj) {
            v = $('input[name="' + key + '"]').val();
            a = obj[key];
            if (v.length < 1) {
                if (key.indexOf("end") != -1) {
                    v = $('input[name="' + key.replace(/end/g, "start") + '"]').val()
                } else {
                    alert(a[0] + '不能为空');
                    return;
                }
            }
            if (checkDouble(v)) {
                alert(a[0] + '只能为浮点数');
                return;
            }
            data[a[1]] = v;
        }
        var url;
        if(isNew==1){
            v = $('input[name="add-bd-endNew"]').val();
            url = "${contextPath}/sys/ssdbCompany/addRateIntervalNew"
            data['companyId'] = $('#mod-cr-companyIdNew').val();
            a = [['费率1', 'r1s'], ['费率1', 'r1e'], ['费率2(始)', 'r2s'], ['费率2(终)', 'r2e'], ['费率3(始)', 'r3s'], ['费率3(终)', 'r3e'], , ['费率4(始)', 'r4s'], ['费率4(终)', 'r4e']];

        }else{
            v = $('input[name="add-bd-end"]').val();
            url = "${contextPath}/sys/ssdbCompany/addRateInterval"
            data['companyId'] = $('#mod-cr-companyId').val();
            a = [['费率1(始)', 'r1s'], ['费率1(终)', 'r1e'], ['费率2(始)', 'r2s'], ['费率2(终)', 'r2e'], ['费率3(始)', 'r3s'], ['费率3(终)', 'r3e'], , ['费率4(始)', 'r4s'], ['费率4(终)', 'r4e']];

        }

        if (v.length > 0 && checkDouble(v)) {
            alert('标的(终)只能为浮点数');
            return;
        }
        // if (data['r1e'] != data['r2s']) {
        //     alert('费率1(终)必须等于费率2(始)');
        //     return;
        // }
        // if (data['r2e'] != data['r3s']) {
        //     alert('费率2(终)必须等于费率3(始)');
        //     return;
        // }
        for (var i = 0; i < 3; i++) {
            if (parseFloat(data[a[i * 2][1]]) > parseFloat(data[a[i * 2 + 1][1]])) {
                alert(a[i * 2][0] + '必须小于' + a[i * 2 + 1][0]);
                return;
            }
        }

        data['bde'] = v;
        data['isNew']=isNew;
        $.ajax({
            url:url ,
            data: data,
            type: 'POST',
            dataType: 'json',
            success: function (data) {
                if (data.success) {
                    if(isNew==1){
                        loadRateIntervalNew();
                        $("#mod-addNew").modal("toggle");
                    }else{
                        loadRateInterval();
                        $("#mod-add1").modal("toggle");
                    }

                } else {
                    alert(data.message);
                }
            },
        });

    }



    /**
     * 新增非自定义费率的提交
     */
    function addSpecialRateInterval() {
        var _bd_start = $('input[name="add2-bd-start"]').val();
        var _bd_end = $('input[name="add2-bd-end"]').val();
        var _rat_start = $('input[name="add2-rat-start"]').val();

        var data = {};
        data['companyId'] = $('#mod-cr-companyId').val();
        data['startValue'] = _bd_start;
        data['endValue'] = _bd_end;
        data['rat'] = _rat_start;
        $.ajax({
            url: "${contextPath}/sys/ssdbCompany/addSpecailRateInterval",
            data: data,
            type: 'POST',
            dataType: 'json',
            success: function (data) {
                if (data.success) {
                    loadSpecailRateInterval();
                    $("#mod-add2").modal("toggle");
                } else {
                    alert(data.message);
                }
            },
        });
    }

    /**
     * 删除非自定义费率记录
     */
    function deleteSpecailRateInterval(companyParam_id) {
        var _rat_start = $('input[name="add2-rat-start"]').val();
        var data = {};
        data['companyId'] = $('#mod-cr-companyId').val();
        data['companyParam_id'] = companyParam_id;
        $.ajax({
            url: "${contextPath}/sys/ssdbCompany/delteSpecailRateInterval",
            data: data,
            type: 'POST',
            dataType: 'json',
            success: function (data) {
                if (data.success) {
                    loadSpecailRateInterval();
                } else {
                    alert(data.message);
                }
            },
        });
    }

    //自动补全法院;
    $(document).ready(function($) {
        $.fn.typeahead.Constructor.prototype.blur = function() {
            var that = this;
            setTimeout(function () { that.hide() }, 250);
        };
        $('#mod-Addcourt-courtName').typeahead({
            source: function(query, process) {
                var parameter = {keyword : query};
                $.post('${contextPath}/sys/ssdbOrder/getCourtName', parameter, function (data) {
                    var ret = eval("(" + data + ")");
                    console.log(ret);
                    /*alert(ret);*/
                    process(ret);

                });
            }
        });
    });

    /**
     * 加载对应自定义费率
     */
    function loadSpecailRateInterval() {
        var id = $('#mod-cr-companyId').val();
        $.getJSON('${contextPath}/sys/ssdbCompany/querySsdbCompanyParamQJByCompanyId?companyId=' + id, function (result) {
            var html = '';
            $.each(result, function (i, v) {
                htmlC = '';
                htmlC += '<div class="hr-line-dashed"></div>';
                htmlC += '<div class="form-group">';
                htmlC += '	<label class="col-sm-2 control-label">标的区间' + (i + 1) + '</label>';
                htmlC += '	<div class="col-sm-10">';
                htmlC += '		<div class="row">';
                htmlC += '			<div class="col-sm-3"><input name="bd_specail_begain' + v.id + '" type="text" class="form-control" value="' + v.startValue + '"></div>';
                htmlC += '			<div class="col-sm-3"><input name="bd_specail_end' + v.id + '" type="text" class="form-control" value="' + v.endValue + '" placeholder="无上限"></div>';
                htmlC += '			<label class="col-sm-2 control-label">费率' + '</label>';
                htmlC += '			<div class="col-sm-2" ><div class="input-group"><input name="specail_rate' + v.id + '" type="text" class="form-control" value="' + v.rat + '"><span class="input-group-addon">%</span></div></div>';
                htmlC += '			<div class="col-sm-2"><button class="btn btn-white" onclick="deleteSpecailRateInterval(\'' + v.id + '\')" type="button">删除</button></div>';
                htmlC += '		</div>';
                htmlC += '	</div>';
                htmlC += '</div>';
                html += htmlC;
            });
            $("#mod-ncr-qjList").html(html);
        });
    }

    //-------------------------上传文件-----开始---------------------
    function uploadPic(attachType) {
        $("#mod-pic").modal("toggle");
        $("#mod-pic-attachType").val(attachType);
        $("#mod-pic-orderId").val($("#mod-edit-id").val());
    }

    //pic上传处理
    function picUpload() {
        applyTokenDo(uploadFile);
    }

    var appServer = 'http://b.duowenlvshi.com/oss/token?name=ssdb';
    var bucket = '${oss_bucket_ssdb}';
    var region = 'oss-cn-shenzhen';
    var applyTokenDo = function (func) {
            var url = appServer;
            $.ajax({
                type: "POST",
                url: url,
                data: "",
                dataType: "jsonp",
                success: function (e) {
                    var client = new OSS.Wrapper({
                        region: region,
                        accessKeyId: e.AccessKeyId,
                        accessKeySecret: e.AccessKeySecret,
                        stsToken: e.SecurityToken,
                        bucket: bucket
                    });
                    return func(client);
                },
                error: function (data) {
                    console.log(data);
                }
            });
        }
    ;
    var uploadFile = function (client) {
            var picFile = document.getElementById('picFileId').files[0];
            var orderId = document.getElementById('mod-pic-orderId').value;
            var fileName = UUIDjs.create().hex;
            var fileType = getFileType(picFile.name);
            console.debug("picFile" + picFile)
            console.debug("fileName" + fileName)
            console.debug("fileType" + picFile)
            console.debug("mod-pic-orderId" + orderId)
            var key = "ssdb/ssdb-company/service-cooperative-agreements/" + orderId + "/" + fileName + "." + fileType;
            return client.multipartUpload(key, picFile, {
                progress: progress
            }).then(function (res) {
                saveToDB(orderId, key, fileName, fileType);
            });
        }
    ;

    function getFileType(fileName) {
        var ldot = fileName.lastIndexOf('.')
        if (ldot >= 0)
            return fileName.substring(ldot + 1);
        else
            return "";
    }

    function saveToDB(orderId, key, fileName, fileType) {
        var attachType = $("#mod-pic-attachType").val();
        var parameters = {
            "orderId": orderId,
            "attachType": attachType,
            "path": key,
            "fileName": fileName,
            "fileType": fileType
        };
        console.debug(parameters);
        $.getJSON('${contextPath}/bill/ssdbBill/uploadFileAttach', parameters, function (result) {
            if (result.success) {
                uploadSuccess(orderId);
            } else
                alert(result.message);
        });

    };

    var progress = function (p) {//上传成功的进度条
        return function (done) {
            done();
        };
    };

    function uploadSuccess(orderId) {
        $("#mod-pic").modal("toggle");
        $('#div-' + 'service-cooperative-agreements').html('');
        var attachType = $("#mod-pic-attachType").val();
        loadPic(attachType, orderId);
    }

    function loadPic(attachType, orderId) {
        var url = '${contextPath}/bill/ssdbBill/extractFileAttach';
        var parameters = {"orderId": orderId, "attachType": attachType};
        postData(url, parameters, loadPiCallback, errorCallbackDefault);
    }

    //向后台请求数据
    function postData(url, parameters, successCallback, errorCallback) {
        $.ajax({
            type: "POST",
            url: url,
            data: parameters,
            dataType: "json",
            success: function (data) {
                successCallback(data);
            },
            error: function (data) {
                errorCallback(data);
            }
        });
    }

    function loadPiCallback(data) {
        if (data.success) {
            var url = '${oss_bucket_ssdb_url}';
            var thum = '${oss_bucket_ssdb_url_img}';
            var size = '${oss_bucket_ssdb_url_img_size}';
            var v = null;
            var sec = '';
            for (var i in data.attachs) {
                v = data.attachs[i];
                sec += '<div style="text-align:center;display:inline-block;vertical-align:top;" id="picDiv' + v.id + '">';
                sec += '<a href="' + url + v.path + '" target="_blank">';
                sec += '<img class="lazy" src="${contextPath}/static/img/loading.gif" data-original="' + thum + v.path + '" height="100" width="100" id="' + v.id + '"/>';
                sec += '</a><br/><a href="javascript:void(0)" onclick="deletePic(\'' + v.id + '\')">删除</a>';
                sec += '</div>&nbsp;';
            }
            $("#div-" + data.attachType).html(sec);
            setTimeout(function () {
                $("img.lazy").lazyload({
                    threshold: 1000
                });
            }, 200);
        } else {
            showMsg(data.message);
        }
    }

    //删除图片
    function deletePic(id) {
        $('#picDiv' + id).hide();
        var url = '${contextPath}/bill/ssdbBill/deleteFileAttach';
        var parameters = {"id": id};
        postData(url, parameters, deletePiCallback, errorCallbackDefault);
    }

    function deletePiCallback(data) {
        if (data.success) {
            showMsg('删除成功');
            loadPic('service-cooperative-agreements', $("#mod-edit-id").val());
        } else {
            $('#picDiv' + data.attachType).show();
            showMsg(data.message);
        }
    }

    function errorCallbackDefault(data) {
        console.debug("=*= eroro=*= " + data)
        ///donoting....
    }

    //显示信息
    function showMsg(msg) {
        if (msg != undefined && msg.length > 0) {
            alert(msg);
        }
    }

    //-------------------------上传文件----结束----------------------
</script>
