@extends('admin/layout')
@section('header')
    <link href="{{asset('css/plugins/switchery/switchery.css')}}" rel="stylesheet">
    <style>
        .btn-danger, .btn-primary, .btn-info {
            background: #2a94e0 !important;
            border-color: #2a94e0 !important;
        }

        .table-striped > tbody > tr:nth-of-type(odd) {
            background: #f8f8f8 !important;
        }

        .table-striped > tbody > tr .btn {
            background: none !important;
        }

        .table-striped > tbody > tr td {
            font-size: 14px !important;
        }

        .table-striped > tbody > tr:hover {
            background: #ffebd8 !important;
        }

        .table-striped > tbody > tr:hover .btn {
            background: #2a94e0 !important;
            color: #fff !important;
        }

        .table-striped > tbody > tr:hover .btn .glyphicon {
            color: #fff !important;
        }
    </style>
@endsection

@section('content')
    @php   $authUser=auth()->user() @endphp
    <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-content">
                        <form id="searchForm">
                            <div class="input-group">

                                <select name="siteUserId" id="siteUserId" title="" class="form-control"
                                        style="width: 150px;float: right" onchange="tips.selectPage();">
                                    <option value="">请选择人员</option>
                                    @foreach($userList as $item)
                                        <option value="{{$item->id}}">{{$item->nickname}}</option>
                                    @endforeach
                                </select>

                                <select name="status" id="status" title="" class="form-control"
                                        style="width: 150px;float: right" onchange="tips.selectPage();">
                                    <option value="">请选择项目状态</option>
                                    @foreach(\App\Http\Models\Site::STATUS_MAP as $key=>$item)
                                        @if(!in_array($key,[5,6]))
                                            <option value="{{$key}}">{{$item}}</option>
                                        @endif
                                    @endforeach
                                </select>

                                <input type="text" placeholder="请输入域名或项目名称" class="input-md form-control"
                                       name="keyword"
                                       id="keyword" style="width: 300px;float: right">
                                <span class="input-group-btn">

                                    <button type="button" class="btn btn-md btn-primary"
                                            onclick="units.search()"> 搜索</button>
                                    <button type="button" class="btn btn-md btn-primary" style="margin-left: 10px"
                                            name="btnReset"> 重置</button>
                                    </span>
                            </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 src="{{asset('js/plugins/switchery/switchery.js')}}"></script>

    <script>

        var jsSwitch = document.querySelector(".js-switch");
        new Switchery(jsSwitch, {color: "#1AB394", size: 'small'});

        var units = {
            search: function () {
                tips.selectPage();
            },
            getIdsBySelections: function () {
                var selections = $("#table").bootstrapTable('getSelections');
                var ids = [];
                $.each(selections, function (inx, val) {
                    ids.push(val.id);
                });
                return ids;
            },
            openDetail: function (id, title) {
                tips.page('/admin/sites/' + id + '/overview', title);
            },
        };

        var config = {};
        config.url = '/admin/bid/site-list/' + "{{$type}}";
        config.pageSize = 50;
        config.showColumns = true;
        config.columns = [ //字段
            {checkbox: true},
            {
                title: '序号', align: 'center', formatter: function (value, item, index) {
                    return index + 1;
                },
                width: '10px'
            },
            {title: '项目状态', field: 'statusTitle', align: 'center', sortable: true, width: '30px'},
            {title: '项目名称', field: 'cn_title', align: 'center', width: '240px'},
            {title: '域名', field: 'domain', align: 'center', width: '160px'},
            {title: '竞价人员', field: 'bidder_title', align: 'center', width: '160px'},
            {title: '设计', field: 'designer', align: 'center'},
            {title: '前端', field: 'web_front', align: 'center'},
            {title: '赠送费用', field: 'bid_give_fee', align: 'center'},
            {title: '总费用', field: 'total_fee', align: 'center'},
            {title: '账户上线日期', field: 'bid_account_online_time', align: 'center', width: '180px', sortable: true},
            {title: '暂停日期', field: 'bid_account_pause_time', align: 'center', width: '180px'},
            {title: '客户评分', field: 'bid_score', align: 'center', width: '80px', sortable: true},
            {title: '投放时长', field: 'sustain_days', align: 'center', width: '80px', sortable: true},
            {
                title: '操作', field: 'id', align: 'center',
                formatter: function (value, row) {

                    var str = '<button onclick="units.openDetail(' + value + ',\'' + row.cn_title + '\')" class="btn btn-xs"><span class="glyphicon glyphicon-menu-hamburger"></span>详情</button><br>';

                    if (row.is_google_bid) {
                        if (row.bid_status) {
                            if (!row.bid_account_pause_time) {
                                str += '<span class="glyphicon glyphicon-fire" style="color:red">PPC</span>'
                            } else {
                                str += '<span class="glyphicon glyphicon-fire" style="color:red"><del>PPC</del></span>'
                            }

                        } else {
                            str += '<span class="glyphicon glyphicon-fire" style="color:#C0C0C0">PPC</span>'
                        }
                    }

                    return str;
                }
            }
        ];
        tips.bootstrapTable(config);

        $(document).on('click', '#allotStaff', function () {
            var ids = units.getIdsBySelections();
            if (ids.length === 0) {
                layer.alert('请先选择您所要操作的对象', {icon: 0});
                return;
            }
            var siteIds = '?';
            $.each(ids, function (inx, val) {
                siteIds += 'siteIds[]=' + val + '&';
            });

            layer.open({
                type: 2,
                content: ['/admin/site/allot' + siteIds],
                area: ['50%', '50%'],
                title: '修改'
            });

        });

        $(document).on('click', '#batchDelete', 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/sites',
                    type: 'delete',
                    data: {ids: ids},
                    tableRefresh: '#table'
                });
            });
        });

    </script>
@endsection