<?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" class="form-inline" onsubmit="return search();">
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="code">礼品编号</label>
                    <input type="text" id="code" name="code" class="form-control">
                </div>
                <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="frame_no">车架号</label>
                    <input type="text" id="frame_no" name="frame_no" class="form-control">
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="engine_no">发动机号</label>
                    <input type="text" id="engine_no" name="engine_no" class="form-control">
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="status">状态</label>
                    <select name="status" id="status" class="form-control">
                        <option value="0" >全部</option>
                        <option value="1">未使用</option>
                        <option value="2">使用中</option>
                        <option value="3">使用完</option>
                    </select>
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="type_id">分类</label>
                    <select name="type_id" id="type_id" class="form-control">
                        <option value="0">---请选择---</option>
                        <?php
                        foreach($type_items as $item) {
                            echo '<option value="'.$item->id.'"';
                            echo '>'.$item->name.'</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>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="insurer1_no">商业保单号</label>
                    <input type="text" id="insurer1_no" name="insurer1_no" 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="s_start_date" name="s_start_date" autocomplete="off" value="" />
                        <span class="input-group-addon">到</span>
                        <input type="text" class="input-sm form-control" id="s_end_date" name="s_end_date" autocomplete="off" value="" />
                    </div>
                </div>
                <div class="form-group" style="margin-bottom: 8px;">
                    <label for="datepicker2">正本日期</label>
                    <div class="input-daterange input-group" id="datepicker2">
                        <input type="text" class="input-sm form-control" id="p_start_date" name="p_start_date" autocomplete="off" value="" />
                        <span class="input-group-addon">到</span>
                        <input type="text" class="input-sm form-control" id="p_end_date" name="p_end_date" autocomplete="off" value="" />
                    </div>
                </div>
                <button type="submit" class="btn btn-primary mb-8">搜索</button>
            </form>
            <div class="row">
                <div class="col-sm-12">
                    <table id="listTable">
                        <thead>
                        <tr>
                            <th width="50" data-field="id">ID</th>
                            <th data-field="code">礼品编号</th>
                            <th data-field="name">礼品</th>
                            <th data-field="car_no">车牌号</th>
                            <th data-field="car_frame_no">车架号</th>
                            <th data-field="submit_user">提单人</th>
                            <th data-field="use_date">出库日期</th>
                            <th data-field="status">状态</th>
                            <th data-field="username">操作员</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="edit(' + row.id + ')">');
        if(row.use_num > row.finish_num) {
            opStr.push('<i class="fa fa-edit" title="出库"></i>');
        } else {
            opStr.push('<i class="fa fa-file-o" title="详情"></i>');
        }
        opStr.push('</a>');

        return opStr.join(' ');
    }
    function edit(id) {
        title = '礼品核销';
        layer_show(title, '/gift/gift-use-edit?id='+id);
    }
    function refreshList() {
        $('#listTable').bootstrapTable('refresh');
    }

    function search() {
        $('#listTable').bootstrapTable('destroy');
        $('#listTable').bootstrapTable({
            url: "/gift/gift-use-json",
            pagination: true,
            sidePagination: 'server',
            queryParams: function(params) {
                params.code = $('#code').val();
                params.car_no = $('#car_no').val();
                params.frame_no = $('#frame_no').val();
                params.engine_no = $('#engine_no').val();
                params.status = $('#status').val();
                params.type_id = $('#type_id').val();
                params.username = $('#username').val();
                params.insurer1_no = $('#insurer1_no').val();
                params.s_start_date = $('#s_start_date').val();
                params.s_end_date = $('#s_end_date').val();
                params.p_start_date = $('#p_start_date').val();
                params.p_end_date = $('#p_end_date').val();
                return params;
            }
        });
        return false;
    }

    $(function() {
        $('.input-daterange').datepicker({
            keyboardNavigation: false,
            forceParse: false,
            autoclose: true
        });
        search();
    });
</script>
<?php $this->endBlock(); ?>
