<?php
use \common\libs\MyLib;
?>
<?php $this->beginBlock('header_css'); ?>
<link href="/assets/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
<style>
    .btn-group .btn-white.active{
        background: #1ab394;
        color: #fff;
    }
</style>
<?php $this->endBlock(); ?>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>工作量统计</h5>
        </div>
        <div class="ibox-content">
            <form role="form" id="search" class="form-inline" onsubmit="return search();">
                <div class="form-group col-md-6" style="margin-bottom: 8px;">
                    <label for="datepicker1">提单日期</label>
                    <div class="input-group" id="datepicker1">
                        <input type="text" class="form-control" id="date_begin" name="date_begin" value="" autocomplete="off" />
                        <span class="input-group-addon">到</span>
                        <input type="text" class="form-control" id="date_end" name="date_end" value="" autocomplete="off" />
                    </div>
                </div>
                <div class="form-group col-md-6" style="margin-bottom: 8px;">
                    <label for="datepicker1">正本日期</label>
                    <div class="input-group" id="datepicker1">
                        <input type="text" class="form-control" id="date2_begin" name="date2_begin" value="" autocomplete="off" />
                        <span class="input-group-addon">到</span>
                        <input type="text" class="form-control" id="date2_end" name="date2_end" value="" autocomplete="off" />
                    </div>
                </div>
                <hr>
                <div class="form-group col-md-3" style="margin-bottom: 8px;">
                    <label for="username">工号</label>
                    <input type="text" id="username" name="username" class="form-control">
                </div>
                <div class="form-group col-md-3" style="margin-bottom: 8px;">
                    <label class="control-label">级别</label>
                    <select name="group_id" id="group_info" class="form-control">
                    </select>
                </div>
                <div class="form-group col-md-3" style="margin-bottom: 8px;">
                    <label class="control-label">保险公司</label>
                    <select name="company_id" id="company_info" class="form-control">
                    </select>
                </div>
                <hr>
                <div class="form-group col-md-12 text-center" style="margin-bottom: 8px;">
                    <a class="btn btn-primary edit-btn m-r" data-id="0" href="javascript:void(0);" onclick="print_infos('insurer')">
                        <i class="fa fa-search"></i> 搜索
                    </a>
                    <a class="btn btn-primary edit-btn m-l" data-id="0" href="javascript:void(0);" onclick="print_infos('insurer')">
                        <i class="fa fa-outdent"></i> 导出
                    </a>
                </div>
                <div class="clearfix"></div>
            </form>
        </div>
    </div>
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>工作量统计</h5>
            <div class="ibox-tools btn-group" id="date_ranges">
                <button class="btn btn-white active" data-range="today" type="button">当天</button>
                <button class="btn btn-white" data-range="week" type="button">近七天</button>
                <button class="btn btn-white" data-range="month" type="button">近一月</button>
                <button class="btn btn-white" data-range="third-month" type="button">近三月</button>
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="ibox-content">
            <div class="d-flex justify-content-between">
                <div class="ibox">
                    <div class="ibox-content">
                        <h5>提车总数</h5>
                        <h1 class="no-margins summary-info" data-name="total_car">738,200</h1>
                    </div>
                </div>
                <div class="ibox">
                    <div class="ibox-content">
                        <h5>提单总数</h5>
                        <h1 class="no-margins summary-info" data-name="total_order">738,200</h1>
                    </div>
                </div>
                <div class="ibox">
                    <div class="ibox-content">
                        <h5>商业总净保费</h5>
                        <h1 class="no-margins summary-info" data-name="total_insurer_business">738,200</h1>
                    </div>
                </div>
                <div class="ibox">
                    <div class="ibox-content">
                        <h5>交强总净保费</h5>
                        <h1 class="no-margins summary-info" data-name="total_insurer_compulsory">738,200</h1>
                    </div>
                </div>
                <div class="ibox">
                    <div class="ibox-content">
                        <h5>商业已收净保费</h5>
                        <h1 class="no-margins summary-info" data-name="total_insurer_business_received">738,200</h1>
                    </div>
                </div>
                <div class="ibox">
                    <div class="ibox-content">
                        <h5>交强已收净保费</h5>
                        <h1 class="no-margins summary-info" data-name="total_insurer_compulsory_received">738,200</h1>
                    </div>
                </div>
                <div class="ibox">
                    <div class="ibox-content">
                        <h5>总签单净保费</h5>
                        <h1 class="no-margins summary-info" data-name="total_insurer">738,200</h1>
                    </div>
                </div>
            </div>
           <div class="row">
                <div class="col-md-12">
                    <table id="listTable">
                        <thead>
                        <tr>
                            <th data-field="id">ID</th>
                            <th data-field="username">工号</th>
                            <th data-field="truename">真实姓名</th>
                            <th data-field="total_talk">通话时长</th>
                            <th data-field="total_car">提车总数</th>
                            <th data-field="total_order">提单总数</th>
                            <th data-field="total_insurer_business">商业总净保费</th>
                            <th data-field="total_insurer_compulsory">交强总净保费</th>
                            <th data-field="total_insurer_business_received">商业已收净保费</th>
                            <th data-field="total_insurer_compulsory_received">交强已收净保费</th>
                            <th data-field="total_insurer">总签单净保费</th>
                            <th data-formatter="opFormatter">操作</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>
    function opFormatter(value, row, index) {
        var opStr = [];
            opStr.push('<a href="javascript:void(0);" onclick="info(' + row.id + ')">');
            opStr.push('<i class="fa fa-plus" title="详情">&nbsp;详情</i>');
            opStr.push('</a>');
        return opStr.join(' ');
    }

    function info(id) {
        layer_show('工作量信息','/insurer/info?id=' + id + '&' + $('#search').serialize(););
    }

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

    function search() {

        $('#listTable').bootstrapTable('destroy');
        $('#listTable').bootstrapTable({
            url: "/statistics/work-search-json",
            pagination: true,
            showFooter: true,
            sidePagination: 'server',
            queryParams: function(params) {
                $('#search').find(':input:not(input[type=button],input[type=submit],button)').each(function(index,item){
                    params[$(item).attr('name')] = $(item).val();
                });
                params['range'] = $('#date_ranges.active').data('range');
                return params;
            },
            responseHandler: function (res) {
                console.log(res);
                selectInfoInit('company',res['company_info']);
                return res
            }
        });
        return false;
    }

    // 品牌选项初始化
    function selectInfoInit(selectName,options,default_val,data){
        var html = '<option value="'+ (default_val?default_val:'') +'">---请选择---</option>';
        $.each(options,function(i,item){
            var val = item['code']?item['code']:item['id'];
            var selected = data && data[selectName + '_id'] && data[selectName + '_id'] == val? 'selected': '';
            html += '<option value="'+ val +'" '+ selected +'>'+ item.name +'</option>'
        });
        $('#'+ selectName + '_info').html(html);
    }

    $(function() {
        search();
    });
</script>
<?php $this->endBlock(); ?>