<?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="name">保险类型</label>
                    <select name="insurer_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="name">车牌类型</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="name">保险公司</label>
                    <select name="company_id" class="form-control">
                        <option value="0">所有公司</option>
                        <?php
                        foreach($company_items as $item) {
                            echo '<option value="'.$item->id.'"';
                            echo '>'.$item->name.'</option>';
                        }
                        ?>
                    </select>
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="name">出单日期</label>
                    <div class="input-daterange input-group">
                        <input type="text" id="begin_date" name="begin_date" class="form-control date" value="<?=date('Y-m-d')?>" autocomplete="off">
                        <div class="input-group-addon">-</div>
                        <input type="text" id="end_date" name="end_date" class="form-control date" value="<?=date('Y-m-d')?>" autocomplete="off">
                    </div>
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="name">商业净保费</label>
                    <div class="input-group">
                        <input type="text" id="begin_totalclear" name="begin_totalclear" class="form-control">
                        <div class="input-group-addon">元</div>
                        <div class="input-group-addon">-</div>
                        <input type="text" id="end_totalclear" name="end_totalclear" class="form-control">
                        <div class="input-group-addon">元</div>
                    </div>
                </div>
                <button type="submit" class="btn btn-primary mb-8">搜索</button>
                <br>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="name">设置补点比例</label>
                    <div class="input-group">
                        <input type="text" id="budian_rate" name="budian_rate" class="form-control">
                        <div class="input-group-addon">%</div>
                    </div>
                </div>
                <button type="button" class="btn btn-primary mb-8 btn-save">保存</button>
            </form>
            <div class="row">
                <div class="col-sm-12">
                    <table id="listTable">
                        <thead>
                        <tr>
                            <th 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="insurer_type">保险类型</th>
                            <th data-field="budian_rate">补点比例</th>
                            <th data-field="budian_money">补点金额</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 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/budian-list-json",
            pagination: true,
            sidePagination: 'server',
            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="18" class="text-left">';
                $.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
        });
        $(".btn-save").click(function(){
            layer.confirm('是否保存当前条件下的所有记录补点比例？', {
                btn: ['保存','取消'], //按钮
                shade: false //不显示遮罩
            }, function(){
                var last_url = '/finance/budian-save';
                var params = $("#searchFrm").serialize();

                $.get(last_url,params,function(obj){
                    layer.msg(obj.msg);
                    if(obj.success){
                        refreshList();
                    }
                },'json');
            }, function(){
                //
            });
        });
    });
</script>
<?php $this->endBlock(); ?>
