@extends('admin/layout')
@section('content')
    <body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title"></div>
                    <div class="ibox-content">
                        <form class="row" id="searchForm">

                            <div class="col-md-4">
                                <div class="input-group">
                                   <span class="input-group-btn">
                                     <button type="button" class="btn btn-md btn-info"
                                             onclick="units.audit(2)"><span
                                             class="glyphicon glyphicon-hand-up"></span> 通过</button>
                                       <button type="button" class="btn btn-md btn-warning"
                                               onclick="units.audit(3)"
                                               style="margin-left: 10px"><span
                                               class="glyphicon glyphicon-hand-down"></span> 失败</button>

                                       <button type="button" class="btn btn-md btn-primary"
                                               style="margin-left: 10px" onclick="units.edit(0)"> <span
                                               class="glyphicon glyphicon-plus"></span> 添加</button>
                                       <button type="button" class="btn btn-md btn-danger" onclick="units.delete()"
                                               style="margin-left: 10px"><span
                                               class="glyphicon glyphicon-remove"></span> 删除</button>
                                   </span>
                                </div>

                            </div>


                            <div class="col-md-6 pull-right">
                                <div class="input-group">
                                    <input type="text" placeholder="请输入名称" class="input-md form-control"
                                           name="keyword"
                                           id="keyword">
                                    <span class="input-group-btn">
                                    <button type="button" class="btn btn-md btn-primary"
                                            onclick="units.search()"> 搜索</button>
                                    <button type="reset" class="btn btn-md btn-primary" style="margin-left: 10px"
                                            name="resetBtn"> 重置</button> </span>
                                </div>
                            </div>
                        </form>
                        <hr>

                        <div class="table-responsive">

                            <table id="table" class="table table-condensed" data-mobile-responsive="true"></table>

                        </div>

                    </div>
                </div>
            </div>

        </div>
    </div>
    </body>
@endsection
@section('footer')

    <script>

        var units = {
            audit: function (status) {
                var ids = units.getIdsBySelections();
                if (ids.length === 0) {
                    layer.alert('请先选择您所要操作的对象', {icon: 0});
                    return;
                }
                var config = {
                    url: '/admin/lading-bills/audit',
                    type: 'put',
                    data: {ids: ids, auditStatus: status}
                };
                config.success = function () {
                    tips.tableRefresh('#table');
                };
                tips.ajax(config);
            },
            search: function () {
                tips.selectPage();
            },
            getIdsBySelections: function () {
                var selections = $("#table").bootstrapTable('getSelections');
                var ids = [];
                $.each(selections, function (inx, val) {
                    ids.push(val.id);
                });
                return ids;
            },
            edit: function (id) {
                var title = '添加';
                if (id > 0) {
                    title = '编辑';
                }
                layer.open({
                    type: 2,
                    content: ['/admin/lading-bills/' + id],
                    area: ['100%', '100%'],
                    title: title
                });
            },
            delete: function () {
                var ids = units.getIdsBySelections();
                if (ids.length === 0) {
                    layer.alert('请先选择您所要操作的对象', {icon: 0});
                    return;
                }
                layer.confirm('您确定要删除吗?', {icon: 3, title: '删除信息'}, function (index, layero) {
                    layer.close(index);
                    tips.ajax({
                        url: '/admin/lading-bills',
                        type: 'delete',
                        data: {ids: ids},
                        tableRefresh: '#table'
                    });
                });
            }
        };


        var config = {};
        config.url = '/admin/lading-bills';
        config.columns = [ //字段
            {checkbox: true},
            {
                title: '序号', align: 'center', formatter: function (value, item, index) {
                    return index + 1;
                }
            },
            {title: '名称', field: 'title', align: 'center'},
            {title: '金额', field: 'amount', align: 'center'},
            {title: '关联项目', field: 'relate_site', align: 'center'},
            {title: '用户姓名', field: 'username', align: 'center'},
            {
                title: '审核状态', field: 'audit', align: 'center', formatter: function (value, row) {
                    switch (value) {
                        case 1:
                            return '<button class="btn btn-xs btn-info">审核中</button>';
                        case 2:
                            return '<button class="btn btn-xs btn-success">已通过</button>';
                        case 3:
                            return '<button class="btn btn-xs btn-warning">未通过</button>';
                        default:
                            return '';
                    }
                }
            },
            {title: '创建时间', field: 'created_at', align: 'center'},

            {
                title: '操作', field: 'id', align: 'center',
                formatter: function (value, row) {
                    return (
                        '<button onclick="units.edit(' + value + ')" class="btn btn-xs"><span class="glyphicon glyphicon-edit"></span>编辑</button>&nbsp;'
                    );
                }
            }
        ];
        tips.bootstrapTable(config);


    </script>
@endsection