<%@ 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-weChatOperator">客户经理</label>
                        <input type="text" id="mod-add-weChatOperator" class="form-control"/>
                    </div>

                    <div class="form-group">
                        <label for="mod-add-managerName">微信号昵称</label>
                        <input type="text" id="mod-add-managerName" class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label for="mod-add-managerWeChat">微信号</label>
                        <input type="text" id="mod-add-managerWeChat" class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label for="mod-add-managerPhone">微信号绑定手机号</label>
                        <input type="text" id="mod-add-managerPhone" class="form-control"/>
                    </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>
            </div><!-- /.modal-content -->
        </form>
    </div><!-- /.modal-dialog -->
</div>

<div id="mod-edit" class="modal fade" tabindex="-1" data-backdrop="static">
    <div class="modal-dialog">
        <form id="EditForm">
            <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>
                        <label id="mod-edit-title"></label>
                    </div>
                </div>
                <div class="modal-body" style="overflow-y: scroll;">
                    <div id="mod-edit-tip1" class="red clearfix"></div>
                    <input type="hidden" id="mod-edit-id" value="">
                    <div class="form-group">
                        <label for="mod-edit-name">公司全称</label>
                        <input type="text" id="mod-edit-name" class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label for="mod-edit-clearing-institution-name">结算机构名称</label>
                        <input type="text" id="mod-edit-clearing-institution-name" class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label for="mod-edit-loginName">登录名（简称）</label>
                        <input type="text" id="mod-edit-loginName" class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label for="mod-edit-password">密码</label>
                        <input type="password" id="mod-edit-password" class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label for="mod-edit-companyType">公司类型</label>
                        <select class="form-control" id="mod-edit-companyType">
                            <option value="1">保险公司</option>
                            <option value="0">担保公司</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="mod-edit-contact">跟单对接人姓名</label>
                        <input type="text" id="mod-edit-contact" class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label for="mod-edit-tel">跟单对接人手机</label>
                        <input type="text" id="mod-edit-tel" class="form-control"/>
                    </div>
                    <div class="form-group" style="display: none">
                        <label for="mod-edit-commision">平台返佣</label>
                        <div class="input-group">
                            <input type="text" id="mod-edit-commision" class="form-control"/>
                            <span class="input-group-addon">%</span>
                        </div>
                    </div>
                    <div class="form-group" style="display: none">
                        <label for="mod-edit-commisionLawyer">律师返佣</label>
                        <div class="input-group">
                            <input type="text" id="mod-edit-commisionLawyer" class="form-control"/>
                            <span class="input-group-addon">%</span>
                        </div>
                    </div>
                    <div class="form-group" style="display: none">
                        <label for="mod-edit-sort">合作排序(0表示不是战略合作)</label>
                        <input type="text" id="mod-edit-sort" class="form-control"/>
                    </div>
                    <div class="form-group" style="display: none">
                        <label for="mod-edit-text0">战略合作公司宣传语1(不能有|符号)</label>
                        <input type="text" id="mod-edit-text0" class="form-control"/>
                    </div>
                    <div class="form-group" style="display: none">
                        <label for="mod-edit-text1">战略合作公司宣传语2(不能有|符号)</label>
                        <input type="text" id="mod-edit-text1" class="form-control"/>
                    </div>
                    <div class="form-group" style="display: none">
                        <label for="mod-edit-text2">战略合作公司宣传语3(不能有|符号)</label>
                        <input type="text" id="mod-edit-text2" class="form-control"/>
                    </div>
                    <div class="form-group" style="display: none">
                        <label for="mod-edit-text2">每档增加返现</label>
                        <input type="text" id="mod-edit-commisionDiff" class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label for="mod-edit-text2">最低保费时返现</label>
                        <input type="text" id="mod-edit-minCommision" class="form-control"/>
                    </div>
                    <div class="form-group" style="display: none">
                        <label for="mod-edit-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-edit-pay_offLine" value="1" checked="checked"/>是
                            <input type="radio" name="mod-edit-pay_offLine" value="0"/>否
                        </div>
                    </div>
                    <div class="form-group" style="display: none">
                        <label for="mod-edit-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-edit-pay_weixin" value="1"/>是
                            <input type="radio" name="mod-edit-pay_weixin" value="0" checked="checked"/>否
                        </div>
                    </div>
                    <div class="form-group" style="display: none">
                        <label for="mod-edit-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-edit-pay_alipay" value="1"/>是
                            <input type="radio" name="mod-edit-pay_alipay" value="0" checked="checked"/>否
                        </div>
                    </div>
                    <div class="form-group" id="mod-edit-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-edit-containTax">
                                <option value="0">否</option>
                                <option value="1">是</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" style="display: none">
                        <label for="mod-edit-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-edit-advance" value="1"/>是
                            <input type="radio" name="mod-edit-advance" value="0" checked="checked"/>否
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="mod-edit-service-cost-proportion">服务费比例</label>
                        <input type="text" id="mod-edit-service-cost-proportion" class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label for="mod-edit-service-cost-remark">服务费计算规则</label>
                        <input type="text" id="mod-edit-service-cost-remark" class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label for="mod-edit-service-appoint-time">服务费约定回款时间</label>
                        <input type="text" class="form-control" placeholder="每月指定的日期。若该日期大于当月最大天数，则系统取当月最大天数"
                               id="mod-edit-service-appoint-time">
                    </div>
                    <div class="form-group">
                        <label for="mod-edit-service-cooperative-agreements">合作协议</label>
                        <div id="div-service-cooperative-agreements" class="checkbox-inline"></div>
                        <input type="button" style="margin-left: 10px"
                               onclick="uploadPic('service-cooperative-agreements');" value="上传"
                               id="mod-edit-service-cooperative-agreements">
                    </div>
                    <div class="form-group">
                        <label class="no-padding-left col-sm-2 control-label">修改记录</label>
                        <div class="col-sm-10 text-left">
                            <label class="text-left" id="mod-edit-companyInfo"></label>
                        </div>
                    </div>
                </div>
                <div class="modal-footer no-margin-top">
                    <div class="text-center">
                        <button id="mod-edit-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 id="mod-check" class="modal fade" tabindex="-1" data-backdrop="static">
    <div class="modal-dialog">
        <form id="checkForm">
            <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-edit-tip" class="red clearfix"></div>
                    <input type="hidden" id="mod-check-id" value="">
                    <div class="form-group">
                        <label for="mod-check-fail-bz">备注（认证失败）</label>
                        <input type="text" id="mod-check-fail-bz" class="form-control"/>
                    </div>
                </div>
                <div class="modal-footer no-margin-top">
                    <div class="text-center">
                        <button id="mod-check-success" type="button" class="btn btn-sm btn-primary"
                                onclick="doRenzhen(1)">
                            认证通过
                        </button>
                        <button id="mod-check-fail" type="button" class="btn btn-sm btn-yellow" onclick="doRenzhen(0)">
                            认证失败
                        </button>
                        <button class="btn btn-sm" data-dismiss="modal">
                            取消
                        </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"/>
    <button type="button" class="btn btn-purple btn-sm" id="searchd">
        <span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
        查询
    </button>

    <button type="button" class="btn btn-danger btn-sm" data-toggle='modal' onclick='add()'>
        <span class="ace-icon fa fa-edit icon-on-right bigger-110"></span>
        新增客户经理
    </button>

    <!-- <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-customRate" class="modal fade" tabindex="-1" data-backdrop="static">
    <div class="modal-dialog" style="min-width: 700px;">
        <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" style="max-height: 500px;overflow-y: scroll;">
                <form class="form-horizontal" id="modal-customRate-form">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">自定义保费</label>
                        <div class="col-sm-10 text-left">
                            <input type="hidden" name="pc" class="form-control" id="mod-cr-pcInputHid">
                            <select class="form-control" id="mod-cr-pcSel">
                                <option value="0">禁用</option>
                                <option value="1">启用</option>
                            </select>
                            <input type="hidden" name="companyId" id="mod-cr-companyId">
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-10 control-label">
                            <h5 class="text-left">最低保费设置</h5>
                        </label>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label text-left">最低保费对应的标的上限:</label>
                        <div class="col-sm-4 text-left">
                            <input type="text" name="minBd" class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">最低保费1</label>
                        <div class="col-sm-4 text-left">
                            <input type="text" name="minFee1" class="form-control"/>
                        </div>
                        <label class="col-sm-2 control-label no-padding-left">律师返现</label>
                        <div class="col-sm-4 text-left">
                            <div class="input-group">
                                <input type="text" name="minCommision1" class="form-control">
                                <span class="input-group-addon">%</span>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">最低保费2</label>
                        <div class="col-sm-4 text-left">
                            <input type="text" name="minFee2" class="form-control"/>
                        </div>
                        <label class="col-sm-2 control-label no-padding-left">律师返现</label>
                        <div class="col-sm-4 text-left">
                            <div class="input-group">
                                <input type="text" name="minCommision2" class="form-control">
                                <span class="input-group-addon">%</span>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">最低保费3</label>
                        <div class="col-sm-4 text-left">
                            <input type="text" name="minFee3" class="form-control"/>
                        </div>
                        <label class="col-sm-2 control-label no-padding-left">律师返现</label>
                        <div class="col-sm-4 text-left">
                            <div class="input-group">
                                <input type="text" name="minCommision3" class="form-control">
                                <span class="input-group-addon">%</span>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">最低保费4</label>
                        <div class="col-sm-4 text-left">
                            <input type="text" name="minFee4" class="form-control"/>
                        </div>
                        <label class="col-sm-2 control-label no-padding-left">律师返现</label>
                        <div class="col-sm-4 text-left">
                            <div class="input-group">
                                <input type="text" name="minCommision4" class="form-control">
                                <span class="input-group-addon">%</span>
                            </div>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-10 control-label">
                            <h5 class="text-left">设置标的区间对应的费率区间</h5>
                        </label>
                        <div class="col-sm-2">
                            <button class="btn btn-danger" id="mod-cr-addButton" type="button">新增区间</button>
                        </div>
                    </div>
                    <div id="mod-cr-qjList"></div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-10 control-label">
                            <h5 class="text-left">设置（非自定义费率）标的区间对应的费率区间</h5>
                        </label>
                        <div class="col-sm-2">
                            <button class="btn btn-danger" id="mod-ncr-addButton" type="button">新增区间</button>
                        </div>
                    </div>
                    <div id="mod-ncr-qjList"></div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn  btn-primary" type="button" id="modal-customRate-submit"><strong><i
                        class="fa fa-floppy-o bigger-160"></i>确定</strong></button>
                <button class="btn " data-dismiss="modal"><i class="fa fa-share bigger-160"></i> 取消</button>
            </div>
        </div>
    </div>
</div>



<%--新保费--%>
<div id="modal-customRateNew" class="modal fade" tabindex="-1" data-backdrop="static">
    <div class="modal-dialog" style="min-width: 700px;">
        <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-bodyNew" style="max-height: 500px;overflow-y: scroll;">
                <form class="form-horizontal" id="modal-customRate-formNew">
                    <div class="form-group" style="visibility:hidden;height:0;">
                        <label class="col-sm-2 control-label">自定义保费</label>
                        <div class="col-sm-10 text-left">
                            <input type="hidden" name="pc" class="form-control" id="mod-cr-pcInputHidNew">
                            <select class="form-control" id="mod-cr-pcSelNew" >
                                <option value="0">禁用</option>
                                <option value="1">启用</option>
                            </select>
                            <input type="hidden" name="companyId" id="mod-cr-companyIdNew">
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-10 control-label">
                            <h5 class="text-left">最低保费设置</h5>
                        </label>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label text-left">标的区间: 0- </label>
                        <div class="col-sm-4 text-left">
                            <input type="text" name="minBdNew" class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">最低保费</label>
                        <div class="col-sm-4 text-left">
                            <input type="text" name="minFeeNew" class="form-control"/>
                        </div>
                        <label class="col-sm-2 control-label no-padding-left">返点</label>
                        <div class="col-sm-4 text-left">
                            <div class="input-group">
                                <input type="text" name="minCommisionNew" class="form-control">
                                <span class="input-group-addon">%</span>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-10 control-label">
                            <h5 class="text-left">设置标的区间对应的费率区间</h5>
                        </label>
                        <div class="col-sm-2">
                            <button class="btn btn-danger" id="mod-cr-addButtonNew" type="button">新增区间</button>
                        </div>
                    </div>
                    <div id="mod-cr-qjListNew"></div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn  btn-primary" type="button" id="modal-customRate-submitNew"><strong><i
                        class="fa fa-floppy-o bigger-160"></i>确定</strong></button>
                <button class="btn " data-dismiss="modal"><i class="fa fa-share bigger-160"></i> 取消</button>
            </div>
        </div>
    </div>
</div>






<div id="mod-add1" class="modal fade" tabindex="-1">
    <div class="modal-dialog" style="width: 650px;">
        <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">
                <form role="form" id="mod-add1-form" class="form-horizontal">
                    <div class="form-group">
                        <label class="col-sm-2 control-label no-padding">标的(始)</label>
                        <div class="col-sm-4">
                            <input type="text" name="add-bd-start" class="form-control">
                        </div>
                        <label class="col-sm-2 control-label no-padding">标的(终)</label>
                        <div class="col-sm-4">
                            <input type="text" name="add-bd-end" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label no-padding">费率1(始)</label>
                        <div class="col-sm-2">
                            <div class="input-group">
                                <input type="text" name="add-rat1-start" class="form-control">
                                <span class="input-group-addon">%</span>
                            </div>
                        </div>
                        <label class="col-sm-2 control-label no-padding" style="display: none;">费率1(终)</label>
                        <div class="col-sm-2" style="display: none;">
                            <div class="input-group">
                                <input type="text" name="add-rat1-end" class="form-control">
                                <span class="input-group-addon">%</span>
                            </div>
                        </div>
                        <label class="col-sm-2 control-label no-padding">律师返现</label>
                        <div class="col-sm-2">
                            <div class="input-group">
                                <input type="text" name="add-lawRat1" class="form-control">
                                <span class="input-group-addon">%</span>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label no-padding">费率2(始)</label>
                        <div class="col-sm-2">
                            <div class="input-group">
                                <input type="text" name="add-rat2-start" class="form-control">
                                <span class="input-group-addon">%</span>
                            </div>
                        </div>
                        <label class="col-sm-2 control-label no-padding" style="display: none;">费率2(终)</label>
                        <div class="col-sm-2" style="display: none;">
                            <div class="input-group">
                                <input type="text" name="add-rat2-end" class="form-control">
                                <span class="input-group-addon">%</span>
                            </div>
                        </div>
                        <label class="col-sm-2 control-label no-padding">律师返现</label>
                        <div class="col-sm-2">
                            <div class="input-group">
                                <input type="text" name="add-lawRat2" class="form-control">
                                <span class="input-group-addon">%</span>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label no-padding">费率3(始)</label>
                        <div class="col-sm-2">
                            <div class="input-group">
                                <input type="text" name="add-rat3-start" class="form-control">
                                <span class="input-group-addon">%</span>
                            </div>
                        </div>
                        <label class="col-sm-2 control-label no-padding" style="display: none;">费率3(终)</label>
                        <div class="col-sm-2" style="display: none;">
                            <div class="input-group">
                                <input type="text" name="add-rat3-end" class="form-control">
                                <span class="input-group-addon">%</span>
                            </div>
                        </div>
                        <label class="col-sm-2 control-label no-padding">律师返现</label>
                        <div class="col-sm-2">
                            <div class="input-group">
                                <input type="text" name="add-lawRat3" class="form-control">
                                <span class="input-group-addon">%</span>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label no-padding">费率4(始)</label>
                        <div class="col-sm-2">
                            <div class="input-group">
                                <input type="text" name="add-rat4-start" class="form-control">
                                <span class="input-group-addon">%</span>
                            </div>
                        </div>
                        <label class="col-sm-2 control-label no-padding" style="display: none;">费率4(终)</label>
                        <div class="col-sm-2" style="display: none;">
                            <div class="input-group">
                                <input type="text" name="add-rat4-end" class="form-control">
                                <span class="input-group-addon">%</span>
                            </div>
                        </div>
                        <label class="col-sm-2 control-label no-padding">律师返现</label>
                        <div class="col-sm-2">
                            <div class="input-group">
                                <input type="text" name="add-lawRat4" class="form-control">
                                <span class="input-group-addon">%</span>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn  btn-primary" type="button" id="mod-add1-submit"><strong><i
                        class="fa fa-floppy-o bigger-160"></i>确定</strong></button>
                <button class="btn " data-dismiss="modal"><i class="fa fa-share bigger-160"></i> 取消</button>
            </div>
        </div>
    </div>
</div>

<%--新费率新增--%>
<div id="mod-addNew" class="modal fade" tabindex="-1">
    <div class="modal-dialog" style="width: 650px;">
        <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">
                <form role="form" id="mod-add1-formNew" class="form-horizontal">
                    <div class="form-group">
                        <label class="col-sm-2 control-label no-padding">标的(始)</label>
                        <div class="col-sm-4">
                            <input type="text" name="add-bd-startNew" class="form-control">
                        </div>
                        <label class="col-sm-2 control-label no-padding">标的(终)</label>
                        <div class="col-sm-4">
                            <input type="text" name="add-bd-endNew" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label no-padding">费率</label>
                        <div class="col-sm-2">
                            <div class="input-group">
                                <input type="text" name="add-rat1-startNew" class="form-control">
                                <span class="input-group-addon">%</span>
                            </div>
                        </div>
                        <label class="col-sm-2 control-label no-padding">返点</label>
                        <div class="col-sm-2">
                            <div class="input-group">
                                <input type="text" name="add-lawRat1New" class="form-control">
                                <span class="input-group-addon">%</span>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn  btn-primary" type="button" id="mod-add1-submitNew"><strong><i
                        class="fa fa-floppy-o bigger-160"></i>确定</strong></button>
                <button class="btn " data-dismiss="modal"><i class="fa fa-share bigger-160"></i> 取消</button>
            </div>
        </div>
    </div>
</div>



<div id="mod-add2" class="modal fade" tabindex="-1">
    <div class="modal-dialog" style="width: 650px;">
        <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">
                <form role="form" id="mod-add2-form" class="form-horizontal">
                    <div class="form-group">
                        <label class="col-sm-2 control-label no-padding">标的(始)</label>
                        <div class="col-sm-4">
                            <input type="text" name="add2-bd-start" class="form-control">
                        </div>
                        <label class="col-sm-2 control-label no-padding">标的(终)</label>
                        <div class="col-sm-4">
                            <input type="text" name="add2-bd-end" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label no-padding">费率</label>
                        <div class="col-sm-2">
                            <div class="input-group">
                                <input type="text" name="add2-rat-start" class="form-control">
                                <span class="input-group-addon">%</span>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn  btn-primary" type="button" id="mod-add2-submit"><strong><i
                        class="fa fa-floppy-o bigger-160"></i>确定</strong></button>
                <button class="btn " data-dismiss="modal"><i class="fa fa-share bigger-160"></i> 取消</button>
            </div>
        </div>
    </div>
</div>

<div id="modal-service" class="modal fade" tabindex="-1" data-backdrop="static">
    <div class="modal-dialog" style="min-width: 700px;">
        <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" style="max-height: 500px;overflow-y: scroll;">
                <form class="form-horizontal" id="modal-service-form">
                    <div class="form-group">
                        <label class="col-sm-10 control-label">
                            <h5 class="text-left">诉保服务</h5>
                        </label>
                        <div class="col-sm-2">
                            <button class="btn btn-primary" id="mod-sb-addButton" type="button">新增服务</button>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div id="mod-service-sbList"></div>
                    <div class="form-group">
                        <label class="col-sm-10 control-label">
                            <h5 class="text-left">配送服务</h5>
                        </label>
                        <div class="col-sm-2">
                            <button class="btn btn-primary" id="mod-ps-addButton" type="button">新增服务</button>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div id="mod-service-psList"></div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn  btn-primary" type="button" id="modal-service-submit"><strong>
                    <i class="fa fa-floppy-o bigger-160"></i>保存</strong></button>
                <button class="btn " data-dismiss="modal"><i class="fa fa-share bigger-160"></i> 取消</button>
            </div>
        </div>
    </div>
</div>

<div id="modal-addServices" class="modal fade" tabindex="-1" data-backdrop="static">
    <div class="modal-dialog" style="min-width: 700px;">
        <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" style="max-height: 500px;overflow-y: scroll;">
                <form class="form-horizontal" id="modal-service-form-fw">
                    <input type="hidden" name="companyId" id="mod-addServices-companyId">
                    <div class="form-group">
                        <label class="col-sm-10 control-label">
                            <h5 class="text-left">诉保服务</h5>
                        </label>
                    </div>
                    <div id="mod-addServices-sbList"></div>
                    <div class="form-group">
                        <label class="col-sm-10 control-label">
                            <h5 class="text-left">配送服务</h5>
                        </label>
                    </div>
                    <div id="mod-addServices-psList"></div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-primary" type="button" id="modal-addServices-submit"><strong>
                    <i class="fa fa-floppy-o bigger-160"></i>保存</strong></button>
                <button class="btn " data-dismiss="modal"><i class="fa fa-share bigger-160"></i> 取消</button>
            </div>
        </div>
    </div>
</div>

<div id="mod-pic" class="modal fade" tabindex="-1">
    <div class="modal-dialog" style="max-width: 500px;">
        <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">
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS  -->
                        <form id="picform">
                            <input id="picFileId" type="file" name="file" multiple/>
                            <input type="hidden" name="attachType" id="mod-pic-attachType"/>
                            <input type="hidden" name="orderId" id="mod-pic-orderId"/>
                            <div class="hr hr-12 dotted"></div>
                            <div class="text-center">
                                <button type="button" class="btn btn-sm btn-primary" onclick="picUpload();">上传
                                </button>
                                <button type="reset" class="btn btn-sm">清除</button>
                            </div>
                        </form>
                    </div><!-- /.col -->
                </div><!-- /.row -->

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

<div id="mod-service-sb" class="modal fade" tabindex="-1">
    <div class="modal-dialog" style="max-width: 500px;">
        <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">
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS  -->
                        <form id="picform-sb">
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding">标的(始)</label>
                                <div class="col-sm-4">
                                    <input type="text" name="add-bd-start" class="form-control">
                                </div>
                            </div>
                            <div class="hr hr-12 dotted"></div>
                            <div class="text-center">
                                <button type="button" class="btn btn-sm btn-primary" id="mod-pic-submit-sb">上传</button>
                                <button type="reset" class="btn btn-sm">清除</button>
                            </div>
                        </form>
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</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 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>';
    });

    function deleteUser(id){
        if(confirm("确定要删除该用户吗")){
            $.ajax({
                dataType: "json",
                url: "${contextPath}/sbdx/user/deleteUserById",
                type: "post",
                data: {
                    'userId': id
                },
                complete: function (ret) {
                    var ret = eval("(" + ret.responseText + ")");
                    if (ret.success) {
                        alert("操作成功");
                        myGrid.trigger("reloadGrid");
                    } else {
                        alert(ret.message);
                    }
                }
            });
        }
    }

    function showdetail(id) {
        $("#modal-table-body").html("");
        var html ='';
        //  myGrid.trigger("reloadGrid");刷新
        // html_sb += '<div class="form-group col-sm-6">';
        //  html_sb += '   <label><input type="checkbox" name="mod-addServices-check" value="' + result[i].id + '"">' + result[i].labelContent + '</label>'
        //  html_ps += '</div>';
        //  $("#modal-addServices").modal("toggle");
        $.ajax({
            dataType: "json",
            url: "${contextPath}/sbdx/user/getSbdxUserById",
            type: "post",
            data: {
                'userId': id
            },
            complete: function (ret) {
                var ret = eval("(" + ret.responseText + ")");
                var user = ret.sbdxUser;
                var activations = ret.activationVOList;
                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="form-group col-sm-6">';
                html +=  '客户经理：<label><input type="text" id="username" readonly name="mod-update-username" value="' + user.username + '""></label>';
                html +='</div>';
                html += '<div class="form-group col-sm-6">';
                html +=  '微信昵称：<label><input type="text" id="weChatOperator" name="mod-update-weChatOperator" value="' + user.weChatOperator + '""></label>';
                html +='</div>';
                html += '<div class="form-group col-sm-6">';
                html +=  '微信号：<label><input type="text" id="weChatNum" name="mod-update-weChatNum" value="' + user.weChatNum + '""></label>';
                html +='</div>';
                html += '<div class="form-group col-sm-6">';
                html +=  '微信绑定手机号：<label><input type="text" id="userPhone" name="mod-update-userPhone" value="' + user.userPhone + '""></label>';
                html +='</div>';
                html += '<div class="form-group col-sm-6">';
                html +=  '<button class="btn btn-white" onclick="updateUser(\'' + id + '\')" type="button">保存</button>';
                html +='</div>';
                if(activations.length > 0){
                    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="form-group col-sm-12" >';
                    html += '<table class="tab" border="1" style="height: 150px;width: 700px;">' +
                        '<tr style="background-color: #ccc"><th>日期</th><th>新增微信数</th><th>新增激活数</th><th>总微信好友数</th><th>总激活数</th><th>激活率</th></tr>';
                    for(var i = 0;i<activations.length;i++){
                        html += '<tr><td>'+activations[i].date+'</td><td>'+activations[i].addWeChatCount+'</td><td>'+activations[i].addActivationCount+'</td><td>'+activations[i].weChatCount+'</td><td>'+activations[i].activationCount+'</td><td>'+parseFloat(activations[i].activationRate).toFixed(2)+'%</td></tr>';
                    }
                    html +='</table></div>';
                }
                $("#modal-table-body").html(html);
                $("#modal-table-body").height("500px");
                $("#modal-table").modal("toggle");
                $(".tab td").css("text-align","center");
                $(".tab th").css("text-align","center");
                // myGrid.trigger("reloadGrid");
            }
        });
    }
    function updateUser(id){
        //微信昵称
        var weChatOperator = $("#weChatOperator").val();
        //微信号
        var weChatNum = $("#weChatNum").val();
        //微信绑定手机号
        var userPhone = $("#userPhone").val();
        if(!weChatOperator){
            alert("微信昵称不能为空");
            return;
        }
        if(!weChatNum){
            alert("微信号不能为空");
            return;
        }
        if(!userPhone){
            alert("手机号不能为空");
            return;
        }
        $.ajax({
            dataType: "json",
            url: "${contextPath}/sbdx/user/updateSbdxUser",
            type: "post",
            data: {
                userId: id,
                weChatOperator: weChatOperator,
                weChatNum: weChatNum,
                userPhone:userPhone
            },
            complete: function (ret) {
                var ret = eval("(" + ret.responseText + ")");
                if (ret.success) {
                    alert("操作成功");
                    $("#modal-table").modal("toggle");
                    myGrid.trigger("reloadGrid");
                } else {
                    alert(ret.message);
                }
            }
        });

    }

    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 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);
    }

    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-add-submit").on("click", function (e) {
            //手机号
            var managerPhone = $("#mod-add-managerPhone").val();
            //微信号
            var weChat = $("#mod-add-managerWeChat").val();
            //微信号昵称
            var managerName = $("#mod-add-managerName").val();
            //客户经理
            var weChatOperator = $("#mod-add-weChatOperator").val();
            if(!weChatOperator){
                alert("请输入客户经理");
                return;
            }
            if(!managerName){
                alert("请输入微信号昵称");
                return;
            }
            if(!weChat){
                alert("请输入微信号");
                return;
            }
            if(!managerPhone){
                alert("请输入手机号");
                return;
            }

            $.ajax({
                dataType: "json",
                url: "${contextPath}/sbdx/user/saveSbdxUser",
                type: "post",
                data: {
                    managerPhone: managerPhone,
                    managerWeChat: weChat,
                    managerName: managerName,
                    weChatOperator: weChatOperator
                },
                complete: function (ret) {
                    var ret = eval("(" + ret.responseText + ")");
                    if (ret.success) {
                        alert("添加成功")
                        $("#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}/sbdx/user/getUser",
                datatype: "json",
                height: '99%',
                colModel: [
                    {
                        name: 'userName',
                        label: '客户经理',
                        width: 100,
                    },{
                        name: 'weChatNum',
                        label: '微信号',
                        width: 200,
                    },{
                        name: 'weChatOperator',
                        label: '微信号昵称',
                        width: 100,
                    },
                    {
                        name: 'userPhone',
                        label: '微信号绑定手机',
                        width: 80,
                    },{
                        name: 'weChatCount',
                        label: '微信好友数',
                        width: 80
                    },{
                        name: 'activationCount',
                        label: '激活数',
                        width: 80
                    },{
                        name: 'activationRate',
                        label: '激活率',
                        width: 80,
                        formatter: activationRate
                    },{
                        name: 'id',
                        index: '',
                        label: '操作',
                        width: 150,
                        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>";
                template += " |<button data-toggle='modal' onclick='deleteUser(\"" + cellvalue + "\")' class='btn btn-minier btn-yellow'><i class='ace-icon fa fa-hdd-o '></i>删除</button>";
                return template;
            }

            function activationRate(cellvalue, options, cell){
                var rate = parseFloat(cellvalue).toFixed(2);
                return rate+"%";
            }



            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()));
                myGrid.setGridParam({
                    postData: {'keyword': keyword},
                    url: '${contextPath}/sbdx/user/getUser',
                    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);
                }
            },
        });
    }

    /**
     * 加载对应自定义费率
     */
    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>
