<?php include_once(mvc::$cfg['PATH_TPL'].'public/headBase.php');?>
<style>
    .tdbg0 {background: #f0ad4e;}
    .tdbg1 {background: #acdae7;}
    .tdbg2 {background: #cbcecf;}
    .emptybg {background: #56a9c7dd;}
</style>
<div class="layui-fluid">
    <?php include_once(mvc::$cfg['PATH_TPL'].'daili/nadsMenu.php');?>

    <?php if (($Params['action'] != 'all') && ($Params['action'] != 'ks')):?>
    <div class="bgw" style="padding: 0;">
        <form class="layui-form" action="" method="get">
            <div class="layui-inline">
                <label class="layui-form-label">广告位置</label>
                <div class="layui-input-block" style="width:100px">
                    <select class="layui-input" name="pa_id">
                        <option value="">--所有--</option>
                        <?php foreach ($area as $item_key => $item_val): ?>
                            <option value="<?php echo $item_key; ?>" <?php if ($Params['pa_id'] == $item_key) :?>selected<?php endif ;?>><?php echo $item_val['pa_name']; ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">品牌/地区</label>
                <div class="layui-input-block">
                    <input type="text" name="tfword"  class="layui-input" value="<?php echo $Params['tfword']?>" placeholder="请输入广告品牌或者地区">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">业务员</label>
                <div class="layui-input-block" style="width:100px">
                    <select class="layui-input" name="pla_sales">
                        <option value="">--所有--</option>
                        <?php foreach ($sale as $item_key => $item_val): ?>
                            <option value="<?php echo $item_val; ?>" <?php if ($Params['pla_sales'] == $item_val) :?>selected<?php endif ;?>><?php echo $item_val; ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">收费</label>
                <div class="layui-input-block" style="width:100px">
                    <select class="layui-input" name="shoufei">
                        <option value="">--所有--</option>
                        <option value="-1" <?php if ($Params['shoufei'] == -1) :?>selected<?php endif ;?>>赠送</option>
                        <option value="1" <?php if ($Params['shoufei'] == 1) :?>selected<?php endif ;?>>收费</option>
                    </select>
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">客户名称</label>
                <div class="layui-input-block">
                    <input type="text" name="word" class="layui-input" value="<?php echo $Params['word']?>">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">投放时间</label>
                <div class="layui-input-block">
                    <input type="text" name="tftime" id="tftime" class="layui-input" value="<?php echo $Params['tftime']?>" placeholder=" ~ ">
                </div>
            </div>

            <div class="layui-inline">
                <div class="layui-input-block">
                    <input type="checkbox" name="empty" value="1" <?php if ($Params['empty'] == 1) :?>checked<?php endif ;?> title="空位">
                </div>
            </div>

            <div class="layui-inline">
                <div class="layui-input-block">
                    <input type="checkbox" name="canSale" value="1" <?php if ($Params['canSale'] == 1) :?>checked<?php endif ;?> title="可售">
                </div>
            </div>

            <div class="layui-inline">
                <input type="hidden" name="action" value="<?php echo $Params['action']; ?>">
                <button class="layui-btn act-btn" type="submit">
                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                </button>

                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </form>
    </div>
    <?php endif; ?>
    <?php if (($Params['action'] == 'all') || ($Params['action'] == 'ks')):?>
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-collapse" lay-accordion="">
                <?php foreach ($conform as $item_key => $item) : ?>
                <div class="layui-colla-item">
                    <h2 class="layui-colla-title"><?php echo $item['pa_name']; ?>&nbsp;&nbsp;&nbsp;<small><?php echo $item['size']; ?></small> &nbsp;&nbsp;最大投放<?php echo $item['pa_max']; ?>个广告</small></h2>
                    <div class="layui-colla-content" style="height:750px; overflow-y: scroll;">
                        <?php if ($item['use']) : ?>
                        <table class="layui-table YpTable">
                            <thead>
                                <tr>
                                    <th width="100px">区域</th>
                                    <?php if ($Params['action'] == 'all'): ?><th width="100px">可售卖/已在线</th><?php endif; ?>
                                    <th>价格</th>

                                    <?php if ($Params['action'] == 'all'): ?>
                                    <th width="75px">业务员</th>
                                    <th width="60px">剩余天数</th>
                                    <th width="50px">收费</th>
                                    <th width="50px">状态</th>
                                    <th width="300px">公司名称</th>
                                    <th width="75px">开始时间</th>
                                    <th width="75px">结束时间</th>
                                    <th width="50px">时长</th>
                                    <th>备注</th>
                                    <th width="75px">添加时间</th>
                                    <?php endif; ?>
                                </tr>
                            </thead>
                            <tbody>
                                <?php foreach ($item['use'] as $key => $val) : ?>
                                <?php for ($i = 0; $i < $val['row']; $i ++) :?>
                                <tr>
                                    <?php if ($i === 0): ?>
                                    <td rowspan="<?php echo $val['row']; ?>"><?php echo $val['name']; ?></td>
                                    <?php if ($Params['action'] == 'all'): ?>
                                    <td rowspan="<?php echo $val['row']; ?>">
                                        <b class="<?php if ($val['can']): ?>green<?php else: ?>red2<?php endif;?>"><?php echo $val['can']; ?></b>
                                        / <?php echo $val['has']; ?>
                                    </td>
                                    <?php endif; ?>
                                    <td rowspan="<?php echo $val['row']; ?>">
                                        <?php if (isset($price[$item['pa_id']][$key][$val['mod']])):?><?php echo $price[$item['pa_id']][$key][$val['mod']]; ?><?php else:?>暂无<?php endif; ?>
                                    </td>
                                    <?php endif; ?>

                                    <?php if (($Params['action'] == 'all') && isset($item['client'][$key][$i])) : ?>
                                    <td>
                                        <?php if ($_SESSION['_realname'] == $item['client'][$key][$i]['pla_sales']) :?>
                                        <b class="red2"><?php echo $item['client'][$key][$i]['pla_sales']; ?></b>
                                        <?php else: ?>
                                        <?php echo $item['client'][$key][$i]['pla_sales']; ?>
                                        <?php endif; ?>
                                    </td>
                                    <td>
                                        <span class="<?php if ($item['client'][$key][$i]['pat_last_day'] > 30): ?>green<?php else: ?>red2<?php endif;?>">
                                            <?php echo $item['client'][$key][$i]['pat_last_day']; ?>
                                        </span>
                                    </td>
                                    <td><?php echo $item['client'][$key][$i]['pal_shoufei'] != '-1'? '<span class="green">收费</span>': '<span class="red2">赠送</span>';?></td>
                                    <td>
                                        <?php if ($item['client'][$key][$i]['pla_status'] == 2): ?>
                                            <b class="red2">设计</b>
                                        <?php elseif ($item['client'][$key][$i]['pla_status'] == 1): ?>
                                            <?php if ($item['client'][$key][$i]['s_date'] > $today) :?><strong>预售</strong><?php else: ?><span class="green">启用</span><?php endif; ?>
                                        <?php else: ?>
                                            <span class="red2">暂停</span>
                                        <?php endif; ?>
                                    </td>
                                    <td><a target="_blank" href="https://admin.paojd.cn/nads/addPlaceAds?pla_id=<?php echo $item['client'][$key][$i]['pla_id']; ?>"><?php echo $item['client'][$key][$i]['ads_title']; ?></a></td>
                                    <td><?php echo $item['client'][$key][$i]['s_date']; ?></td>
                                    <td><?php echo $item['client'][$key][$i]['e_date']; ?></td>
                                    <td><?php echo $item['client'][$key][$i]['pat_total_day']; ?></td>
                                    <td><?php echo $item['client'][$key][$i]['pla_remark']; ?></td>
                                    <td><?php echo $item['client'][$key][$i]['ads_atime']; ?></td>
                                    <?php else:?>
                                    <?php if ($Params['action'] == 'all'): ?>
                                    <td colspan="10"></td>
                                    <?php endif; ?>
                                    <?php endif; ?>
                                </tr>
                                <?php endfor; ?>
                                <?php endforeach; ?>
                            </tbody>
                        </table>
                        <?php endif; ?>
                    </div>
                </div>
                <?php endforeach; ?>
            </div>
        </div>
    </div>
    <?php elseif ($Params['action'] == 'kf'): ?>
        <fieldset class="layui-elem-field">
            <div class="layui-field-box">
                <span class="red">广告客户</span>: <?php echo count($saller['cus']); ?>&nbsp;&nbsp;
                <span class="red">收费</span>: <?php echo count($saller['money']); ?>&nbsp;&nbsp;
                <span class="red">赠送</span>: <?php echo count($saller['free']); ?>
            </div>
        </fieldset>
    <table class="layui-table YpTable">
        <thead class="Sortable">
            <tr>
                <th class="Sort" width="300px">公司名称</th>
                <th class="Sort" width="120px">区域</th>
                <th class="Sort" width="100px">省/品牌</th>
                <th class="Sort" width="75px">业务员</th>
                <th class="Sort" sort="float" width="60px">剩余天数</th>
                <th class="Sort" width="50px">收费</th>
                <th class="Sort" width="50px">状态</th>
                <th class="Sort" width="75px">开始时间</th>
                <th class="Sort" width="75px">结束时间</th>
                <th class="Sort" sort="float" width="50px">时长</th>
                <th>备注</th>
                <th class="Sort" width="75px">添加时间</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($conform as $item_key => $item_val) : ?>
            <?php ksort($item_val['ads']); ?>
            <?php for ($i = 0; $i < $item_val['rows']; $i ++) :?>
            <?php $item = array_shift($item_val['ads']); ?>
            <tr>
                <?php if (!$i): ?>
                    <td rowspan="<?php echo $item_val['rows']; ?>">
                        <?php echo $item_key; ?> <?php if ($item_val['rows'] > 1): ?> <b class="red">+<?php echo $item_val['rows']; ?></b><?php endif; ?>
                    </td>
                <?php endif; ?>
                <td><a href="https://admin.paojd.cn/nads/addPlaceAds?pla_id=<?php echo $item['ads_id']; ?>" target="_blank"><?php echo $item['ads_name']; ?></a></td>
                <td><a href="https://admin.paojd.cn/nads/addPlaceAds?pla_id=<?php echo $item['ads_id']; ?>" target="_blank"><?php echo $item['ads_pc']; ?></a></td>
                <td><?php echo $item['ads_sale']; ?></td>
                <td><span class="<?php if ($item['ads_last'] > 30): ?>green<?php else: ?>red2<?php endif;?>"><?php echo $item['ads_last']; ?></span></td>
                <td><?php echo $item['ads_shoufei'] != '-1'? '<span class="green">收费</span>': '<span class="red2">赠送</span>';?></td>
                <td>
                    <?php if ($item['ads_status'] == 2): ?>
                        <b class="red2">设计</b>
                    <?php elseif ($item['ads_status'] == 1): ?>
                        <?php if ($item['ads_s_day'] > $today) :?><strong>预售</strong><?php else: ?><span class="green">启用</span><?php endif; ?>
                    <?php else: ?>
                        <span class="red2">暂停</span>
                    <?php endif; ?>
                </td>
                <td><?php echo $item['ads_s_day']; ?></td>
                <td><?php echo $item['ads_e_day']; ?></td>
                <td><?php echo $item['ads_total_day']; ?></td>
                <td><?php echo $item['ads_remark']; ?></td>
                <td><?php echo $item['ads_add_day']; ?></td>
            </tr>
            <?php endfor; ?>
            <?php endforeach; ?>
        </tbody>
    </table>
    <?php else: ?>
    <table class="layui-table YpTable">
        <thead class="Sortable">
            <tr>
                <th class="Sort" width="120px">区域</th>
                <th class="Sort" width="100px">省/品牌</th>
                <th class="Sort" sort="float" width="100px">价格</th>
                <th class="Sort" width="75px">业务员</th>
                <th class="Sort" sort="float" width="60px">剩余天数</th>
                <th class="Sort" width="50px">收费</th>
                <th class="Sort" width="50px">状态</th>
                <th class="Sort" width="300px">公司名称</th>
                <th class="Sort" width="75px">开始时间</th>
                <?php if ($Params['action'] != 'dsj'): ?>
                <th class="Sort" width="75px">结束时间</th>
                <th class="Sort" sort="float">时长</th>
                <?php else: ?>
                <th class="Sort" width="100px">添加时间</th>
                <th width="200px">样板</th>
                <th>设计</th>
                <?php endif; ?>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($conform as $item_key => $item) : ?>
            <tr <?php if ($item['ads_status'] == 2): ?>
                <?php if ($Params['action'] != 'dsj'): ?>class="tdbg1"<?php else:?>
                <?php if ($today > $item['ads_s_day']): ?>class="tdbg2"<?php endif; ?><?php endif; ?>
                <?php endif; ?>
                <?php if (($item['ads_status'] == 1) && ($item['ads_s_day'] > $today)): ?>class="tdbg0"<?php endif; ?>>
                <td><?php echo $item['ads_name']; ?></td>
                <td><?php echo $item['ads_pc']; ?></td>
                <td><?php echo $item['ads_price']; ?></td>

                <td><?php echo $item['ads_sale']; ?></td>
                <td><span class="<?php if ($item['ads_last'] > 30): ?>green<?php else: ?>red2<?php endif;?>"><?php echo $item['ads_last']; ?></span></td>

                <?php if ($item['ads_shoufei'] != ''): ?>
                <td><?php echo $item['ads_shoufei'] != '-1'? '<span class="green">收费</span>': '<span class="red2">赠送</span>';?></td>
                <td>
                    <?php if ($item['ads_status'] == 2): ?>
                    <b class="red2">设计</b>
                    <?php elseif ($item['ads_status'] == 1): ?>
                    <?php if ($item['ads_s_day'] > $today) :?><strong>预售</strong><?php else: ?><span class="green">启用</span><?php endif; ?>
                    <?php else: ?>
                    <span class="red2">暂停</span>
                    <?php endif; ?>
                </td>
                <?php else: ?>
                <td colspan="2" class="emptybg">空位</td>
                <?php endif; ?>

                <?php if ($Params['action'] != 'dsj'): ?>
                <td><a href="https://admin.paojd.cn/nads/addPlaceAds?pla_id=<?php echo $item['ads_id']; ?>" target="_blank"><?php echo $item['ads_title']; ?></a></td>
                <td><?php echo $item['ads_s_day']; ?></td>
                <td><?php echo $item['ads_e_day']; ?></td>
                <td><?php echo $item['ads_total_day']; ?></td>
                <?php else: ?>
                <td><a href="javascript:void(0);" <?php if (($item['ads_sale'] == $_SESSION['_realname']) || LibFc::checkDlRule('DL08', false)): ?>onclick="showDesign(<?php echo $item['ads_id']; ?>)"<?php endif; ?>><?php echo $item['ads_title']; ?></a></td>
                    <td><?php echo $item['ads_s_day']; ?></td>
                <td>
                    <b class="<?php if ($item['sucai_first_time']): ?>orange<?php else: ?>red<?php endif; ?>"><?php echo $item['ads_add_day']; ?></b>&nbsp;
                    <strong>+<?php echo $item['check_online']; ?></strong>
                </td>
                <td>
                    <a href="<?php echo $item['ads_template']; ?>" target="<?php echo $item['ads_template']; ?>">
                        <img src="<?php echo $item['ads_template']; ?>">
                    </a>&nbsp;&nbsp;&nbsp;

                    <?php if (($item['ads_sale'] == $_SESSION['_realname']) || LibFc::checkDlRule('DL08', false)): ?>
                    <a class="red" href="javascript:void(0)" onclick="template(<?php echo $item['ads_id']; ?>, <?php echo $item['ads_pa_id']; ?>)">样板</a>
                    <?php endif; ?>
                </td>
                <td>
                    <?php if ($item['ads_design']):?>
                    <strong class="red">已安排</strong>: <?php echo date('Y-m-d H:i:s', $item['ads_design']); ?>&nbsp;<strong>+<?php echo $item['check_design']; ?></strong>
                    <?php else: ?>
                    <button class="layui-btn layui-btn-xs" onclick="design(<?php echo $item['ads_id']; ?>);">通知设计</button>
                    <?php endif; ?>

                </td>
                <?php endif; ?>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
    <?php endif; ?>
</div>
<?php include_once(mvc::$cfg['PATH_TPL'].'public/footBase.php');?>
<script>
    layui.use(['table', 'laydate'], function(){
        var table = layui.table,laydate = layui.laydate;

        laydate.render({
            elem: '#betime'
            ,range: '~'
        });
        laydate.render({
            elem: '#tftime'
            ,range: '~'
        });
    });
</script>

<script>
    /**
     * 填写设计素材要求
     */
    function showDesign(ctr_id)
    {
        loadIndex = layer.load();
        layer.open({
            type: 2
            ,title:false
            ,maxmin: false
            ,scrollbar: false
            ,content:SELF_URI+ 'daili/nadsDesign?ads='+ctr_id
            ,area: ['700px', '450px']
            ,btn: ['保存', '取消']
            ,success:function (layero, index){
                layer.close(loadIndex);
            }
            ,yes: function(index, layero){
                var doc = layero.find('iframe')[0].contentDocument;
                var sucai = $(doc).find('#sucai').val();
                var yaoqiu = $(doc).find('#yaoqiu').val();

                var datas = {};
                datas['ads_id'] = ctr_id;
                datas['ads_sucai'] = sucai;
                datas['ads_require'] = yaoqiu;

                $.post(SELF_URI+ 'daili/nadsSave?isAjax=1', datas, function(res)
                {
                    if (AJAX.checkData(res))
                    {
                        layer.close(index); //再执行关闭
                        layer.msg('保存成功');
                        location.reload(true);
                    } else
                    {
                        layer.msg(res.data);
                    }
                },'json');
            }
        });
    }

    /**
     * 通知设计设计图片
     */
    function design(ads)
    {
        layer.confirm('确定通知了吗？', function(index)
        {
            var datas = {};
            datas['ads_id'] = ads;

            $.post(SELF_URI+ 'daili/nadsDesignSave?isAjax=1', datas, function(res) {
                layer.msg(AJAX.checkData(res) ? '好的.' : res.data);
            }, 'json');

            layer.close(index);
            location.reload(true);
        });
    }

    /**
     * 选择设计风格
     */
    function template(ads, tpl)
    {
        layer.open({
            type: 2,
            fixed: false,
            maxmin: true,
            area: ['900px', '684px'],
            content:SELF_URI+ 'daili/nadsTemplate?ads='+ads+'&tpl='+tpl
        });
    }
</script>
