<?php
use \common\libs\MyLib;
?>
<?php $this->beginBlock('header_css'); ?>
<link href="/assets/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
<?php $this->endBlock(); ?>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>车险提成管理</h5>
            <div class="ibox-tools">
                <a class="btn btn-primary btn-xs edit-btn" data-id="0" href="javascript:void(0);" onclick="$('#listTable').bootstrapTable('refresh');">
                    <i class="fa fa-refresh"></i> 刷新
                </a>
            </div>
        </div>
        <div class="ibox-content">
            <form role="form" id="searchFrm" class="form-inline" onsubmit="return search();">
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="car_no">业务员</label>
                    <div class="input-group">
                        <input type="text" id="user_names" name="user_names" class="form-control">
                        <a class="input-group-addon" onclick="selUserDlg('user_names')">+</a>
                    </div>
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="engine_no">车牌类型</label>
                    <select name="car_no_type" class="form-control">
                        <option value="0" >所有类型</option>
                        <option value="1">京牌</option>
                        <option value="2">非京牌</option>
                    </select>
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="engine_no">保险公司</label>
                    <select name="company_id" class="form-control">
                        <option value="0">全部</option>
                        <?php
                        foreach($company_items as $item) {
                            echo '<option value="'.$item->id.'">'.$item->name.'</option>';
                        }
                        ?>
                    </select>
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="engine_no">险种类型</label>
                    <select name="insurer_type" class="form-control">
                        <option value="1">商业</option>
                        <option value="2">商业+交强</option>
                    </select>
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="engine_no">车牌号</label>
                    <input type="text" id="car_no" name="car_no" class="form-control">
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="datepicker1">出单日期</label>
                    <div class="input-group input-daterange" id="datepicker1">
                        <input type="text" class="input-sm form-control" id="begin_date" name="begin_date" value="" autocomplete="off" />
                        <span class="input-group-addon">-</span>
                        <input type="text" class="input-sm form-control" id="end_date" name="end_date" value="" autocomplete="off" />
                    </div>
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="engine_no">商业净保费</label>
                    <div class="input-group">
                        <input type="text" id="begin_totalclear" name="begin_totalclear" class="form-control">
                        <div class="input-group-addon">-</div>
                        <input type="text" id="end_totalclear" name="end_totalclear" class="form-control">
                    </div>
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="engine_no">级别</label>
                    <select name="group_id" class="form-control">
                        <option value="0">全部</option>
                        <?php
                        foreach($group_items as $item) {
                            echo '<option value="'.$item->id.'">'.$item->name.'</option>';
                        }
                        ?>
                    </select>
                </div>
                <button type="submit" class="btn btn-primary mb-8">搜索</button>
                <button type="button" class="btn btn-primary mb-8">导出</button>
                <hr>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="engine_no">基本提成比例</label>
                    <input type="text" id="yeji_rate" name="yeji_rate" class="form-control">
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="engine_no">团队长组</label>
                    <select name="dz_group" class="form-control">
                        <option value="0">请选择</option>
                        <option value="1">团队长组1</option>
                        <option value="2">团队长组2</option>
                        <option value="3">团队长组3</option>
                        <option value="4">团队长组4</option>
                        <option value="5">团队长组5</option>
                    </select>
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="engine_no">团队长提成比例</label>
                    <input type="text" id="dz_rate" name="dz_rate" class="form-control">
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="engine_no">团队长</label>
                    <div class="input-group">
                        <input type="text" id="dz_names" name="dz_names" class="form-control">
                        <a class="input-group-addon" onclick="selUserDlg('dz_names')">+</a>
                    </div>
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="engine_no">核保提成</label>
                    <input type="text" id="hebao_ticheng" name="hebao_ticheng" class="form-control">
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="engine_no">正本提成</label>
                    <input type="text" id="zhengben_ticheng" name="zhengben_ticheng" class="form-control">
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="engine_no">送单提成</label>
                    <input type="text" id="songdan_ticheng" name="songdan_ticheng" class="form-control">
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="engine_no">原新保提成比例</label>
                    <input type="text" id="first_xinbao_rate" name="first_xinbao_rate" class="form-control">
                </div>
                <button type="button" class="btn btn-primary mb-8 calc-btn">计算</button>
                <hr>
            </form>
            <div class="row">
                <div class="col-sm-12">
                    <table id="listTable">
                        <thead>
                        <tr>
                            <th data-field="state" data-checkbox="true"></th>
                            <th width="50" data-field="id">ID</th>
                            <th data-field="car_no">车牌号</th>
                            <th data-field="id_man">被保险人</th>
                            <th data-field="company_name">保险公司</th>
                            <th data-field="insurer_no">保单号</th>
                            <th data-field="print_date">出单日期</th>
                            <th data-field="total_clear">商业净保费</th>
                            <th data-field="total_rate">手续费比例</th>
                            <th data-field="yeji_rate">基本提成比例</th>
                            <th data-field="yeji_ticheng">基本提成</th>
                            <th data-field="ticheng_zong_rate">加点提成比例</th>
                            <th data-field="ticheng_money">加点提成</th>
                            <th data-field="gift1_price">自费礼品</th>
                            <th data-field="gift2_price">自费礼券</th>
                            <th data-field="yuangong_money">自费减免金额</th>
                            <th data-field="yewu_ticheng">提成</th>
                            <th data-field="op_user">业务员</th>
                            <th data-field="first_xinbao_ticheng">原新保提成</th>
                            <th data-field="op_user1">原新保业务员</th>
                            <th data-field="hebao_ticheng">核保提成</th>
                            <th data-field="op1_user">核保业务员</th>
                            <th data-field="zhengben_ticheng">正本提成</th>
                            <th data-field="op2_user">正本业务员</th>
                            <th data-field="dz_ticheng1">团队长组1提成</th>
                            <th data-field="dz_names1">团队长组1</th>
                            <th data-field="dz_ticheng2">团队长组2提成</th>
                            <th data-field="dz_names2">团队长组2</th>
                            <th data-field="dz_ticheng3">团队长组3提成</th>
                            <th data-field="dz_names3">团队长组3</th>
                            <th data-field="dz_ticheng4">团队长组4提成</th>
                            <th data-field="dz_names4">团队长组4</th>
                            <th data-field="dz_ticheng5">团队长组5提成</th>
                            <th data-field="dz_names5">团队长组5</th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<?php $this->beginBlock('footer_js'); ?>
<script src="/assets/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="/assets/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="/assets/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script>
    var o = {};

    function selUserDlg(name) {
        title = '选择用户';
        layer_show(title, '/finance/sel-user-dlg?name='+name);
    }

    function refreshList() {
        $('#listTable').bootstrapTable('refresh');
    }

    function search() {
        o = {};
        var params = $("#searchFrm").serializeArray();
        $.each(params, function(index) {
            o[this['name']] = this['value'];
        });
        $('#listTable').bootstrapTable('destroy');
        $('#listTable').bootstrapTable({
            url: "/finance/ticheng-jisuan-json",
            pagination: true,
            sidePagination: 'server',
            multipleSelectRow: true,
            queryParams: function(params) {
                o['offset'] = params['offset'];
                o['limit'] = params['limit'];
                return o;
            },
            responseHandler: function (res) {
                var totals = res.rows.pop();
                var html = '<tfoot><tr><td colspan="33" class="">';
                $.each(totals,function (i,d) {
                    html += '<div class="layui-show-md-inline-block m-r-lg m-l-lg">' +
                        '<span>'+ d[0] +'：</span>' +
                        '<span class="font-bold">'+ d[1] +'</span>' +
                        '</div>'
                });
                html += '</td></tr></tfoot>';
                $('#listTable').find('tfoot').remove();
                $('#listTable').append(html);
                return res;
            }
        });
        return false;
    }

    $(function() {
        search();
        $('.input-daterange').datepicker({
            keyboardNavigation: false,
            forceParse: false,
            autoclose: true
        });
        $('.calc-btn').click(function(){
            var index = parent.layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            var params = $("#searchFrm").serialize();
            $.post('/finance/ticheng-jisuan-save', params, function(obj) {
                parent.layer.close(index);
                parent.layer.msg(obj.msg);
                if(obj.success) {
                    refreshList();
                }
            }, 'json');
        });
    });
</script>
<?php $this->endBlock(); ?>
