<?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>B库</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>
                    <input type="text" id="car_no" name="car_no" class="form-control">
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="car_man">车主</label>
                    <input type="text" id="car_man" name="car_man" class="form-control">
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="phone">联系电话</label>
                    <input type="text" id="phone" name="phone" class="form-control">
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="datepicker1">初登日期</label>
                    <div class="input-daterange input-group" id="datepicker1">
                        <input type="text" class="input-sm form-control" id="register_begin" name="register_begin" value="" autocomplete="off" />
                        <span class="input-group-addon">-</span>
                        <input type="text" class="input-sm form-control" id="register_end" name="register_end" value="" autocomplete="off" />
                    </div>
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="">保险日期</label>
                    <div class="input-group" id="">
                        <input type="text" class="input-sm form-control" name="insurer_month_begin" value="" autocomplete="off" style="width: 50px;" />
                        <span class="input-group-addon">月</span>
                        <input type="text" class="input-sm form-control" name="insurer_day_begin" value="" autocomplete="off" style="width: 50px;" />
                        <span class="input-group-addon">日</span>
                        <span class="input-group-addon">&nbsp;&nbsp;至&nbsp;&nbsp;</span>
                        <input type="text" class="input-sm form-control" name="insurer_month_end" value="" autocomplete="off" style="width: 50px;" />
                        <span class="input-group-addon">月</span>
                        <input type="text" class="input-sm form-control" name="insurer_day_end" value="" autocomplete="off" style="width: 50px;" />
                        <span class="input-group-addon">日</span>
                    </div>
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="company">保险公司</label>
                    <input type="text" id="company" name="company" class="form-control">
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="status">状态</label>
                    <select id="status" name="status" 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="username">业务员</label>
                    <input type="text" id="username" name="username" class="form-control">
                </div>
                <button type="submit" class="btn btn-primary mb-8">搜索</button>
                <div class="form-group" style="margin-bottom: 8px;">
                    <select class="form-control" id="user_id" name="user_id">
                        <option value="0">请选择业务员</option>
                        <?php foreach($user_items as $item) {
                            echo '<option value="'.$item->id.'">'.$item->getShowName().'</option>';
                        }
                        ?>
                    </select>
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <button type="button" class="btn btn-primary btn-assign">勾选分配</button>
                    <button type="button" class="btn btn-primary btn-assign-return">勾选收回</button>
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label class="form-control-static">分配给业务员</label>
                    <input type="text" name="assign_users" id="assign_users" class="form-control">
                    <label class="form-control-static">每个业务员分配</label>
                    <input type="text" name="assign_count" id="assign_count" class="form-control">
                    <label class="form-control-static">条记录</label>
                    <button type="button" class="btn btn-primary btn-assign-all">批量分配</button>
                    <button type="button" class="btn btn-primary btn-assign-all-return">批量收回</button>
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <select class="form-control" id="invalid_id" name="invalid_id" style="width:200px;">
                        <option value="0">请选择无效理由</option>
                        <?php foreach($invalid_items as $item) {
                            echo '<option value="'.$item->id.'">'.$item->name.'</option>';
                        }
                        ?>
                    </select>
                    <button type="button" class="btn btn-primary btn-a-invalid">勾选无效数据</button>
                </div>
            </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="factory_model">车型</th>
                            <th data-field="car_man">车主</th>
                            <th data-field="phone">联系电话</th>
                            <th data-field="register_date">初登日期</th>
                            <th data-field="insurer1_date">保险日期</th>
                            <th data-field="company">保险公司</th>
                            <th data-field="engine_no">发动机号</th>
                            <th data-field="car_frame_no">车架号</th>
                            <th data-field="op_user">业务员</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: "/database/b-index-json",
                pagination: true,
                sidePagination: 'server',
                multipleSelectRow: true,
                queryParams: function(params) {
                    o['limit'] = params['limit'];
                    o['offset'] = params['offset'];
                    return o;
                }
            });
            return false;
        }

        $(function() {
            search();
            $('.input-daterange').datepicker({
                keyboardNavigation: false,
                forceParse: false,
                autoclose: true
            });

            $('.btn-assign').click(function(){
                layer.confirm('是否确认分配操作？', {
                    btn: ['确认','取消'], //按钮
                    shade: false //不显示遮罩
                }, function(){
                    var user_id = $('#user_id').val();
                    var rows = $('#listTable').bootstrapTable('getSelections');
                    var params = [];
                    rows.forEach(function(item,index,array){
                        params.push(item.id);
                    });
                    $.post('/database/b-assign',{ids:params.join(','),user_id:user_id},function(obj){
                        layer.msg(obj.msg);
                        if(obj.success) {
                            search();
                        }
                    },'json');
                }, function(){
                    //
                });
            });
            $('.btn-assign-return').click(function() {
                layer.confirm('是否确认收回操作？', {
                    btn: ['确认','取消'], //按钮
                    shade: false //不显示遮罩
                }, function(){
                    var rows = $('#listTable').bootstrapTable('getSelections');
                    var params = [];
                    rows.forEach(function(item,index,array){
                        params.push(item.id);
                    });
                    $.post('/database/b-return',{ids:params.join(',')},function(obj){
                        layer.msg(obj.msg);
                        if(obj.success) {
                            search();
                        }
                    },'json');
                }, function(){
                    //
                });
            });
            $('.btn-assign-all').click(function() {
                layer.confirm('是否确认批量分配操作？', {
                    btn: ['确认','取消'], //按钮
                    shade: false //不显示遮罩
                }, function(){
                    o.assign_users = $('#assign_users').val();
                    o.assign_count = $('#assign_count').val();
                    $.post('/database/b-all-assign',o,function(obj){
                        layer.msg(obj.msg);
                        if(obj.success) {
                            search();
                        }
                    },'json');
                }, function(){
                    //
                });
            });
            $('.btn-assign-all-return').click(function() {
                layer.confirm('是否确认批量收回操作？', {
                    btn: ['确认','取消'], //按钮
                    shade: false //不显示遮罩
                }, function(){
                    $.post('/database/b-return-all-a',o,function(obj){
                        layer.msg(obj.msg);
                        if(obj.success) {
                            search();
                        }
                    },'json');
                }, function(){
                    //
                });
            });
            $('.btn-a-invalid').click(function() {
                layer.confirm('是否确认无效？', {
                    btn: ['确认','取消'], //按钮
                    shade: false //不显示遮罩
                }, function(){
                    var invalid_id = $('#invalid_id').val();
                    var rows = $('#listTable').bootstrapTable('getSelections');
                    var params = [];
                    rows.forEach(function(item,index,array){
                        params.push(item.id);
                    });
                    $.post('/database/b-invalid',{ids:params.join(','), invalid_id:invalid_id},function(obj){
                        layer.msg(obj.msg);
                        if(obj.success) {
                            layer.msg('保存成功');
                            search();
                        }
                    },'json');
                }, function(){
                    //
                });
            });
        });
    </script>
<?php $this->endBlock(); ?>