<div class="col-md-10" role="main">
    <nav class="breadcrumb"></i> 分享圈<span class="c-gray en">&gt;</span>云话题</nav>
    <div class="title-box">
        <p class="t-p"  style="font-size: 28px; color: #7d7d7d;vertical-align: middle; padding-top: 15px; padding-bottom: 15px;">云话题管理-站长</p>
        <div class="t-e" style="margin-left:30px">
            <img src="assets/images/explain.png" alt="">
            <span>说明：① 云端话题在此展示，可点击下发把话题保存话题信息。下发后在后台“全部话题”中管理，类型为云话题②同名称话题不能重复下发③ 话题热度是指参与该话题的帖子数量</span>
        </div>
    </div>
    
    <div class="topic_box">
        <form method='post' action='<?php echo site_url('sharecircle/topic/cloud_topic');?>'>
            <div class="screening">
                <div class="topic_group">
                    <div class="topic_group_left">
                        <div class="gn_jf_type topic_select">
                            <p class="reward_je_p" id="type_search"><?php if(empty($type_name_search)){echo '按话题类型查询';}else{echo $type_name_search;}?></p>
                            <img src="<?php echo asset_url('images/triangle.png')?>" alt="" class="sel_down">
                        </div>
                        <ul isn="0"  class="topic_select_option">
                            <?php if (!empty($topic_type)):?>
                                <?php foreach ($topic_type as $value) :?>
                                    <li class="on_tc_type" vid="<?php echo $value['id']?>"><?php echo $value['tname']?></li>
                                <?php endforeach; endif; ?>
                        </ul>
                        <input name="type_search" type="hidden" value="<?php if(!empty($_POST['type_search'])){echo $_POST['type_search'];}elseif(!empty($val['type_search'])){echo $val['type_search'];}?>"/>
                    </div>
                    <div class="topic_group_left">
                        <input type="text" class="form-control topic_group_gjz" name="keywords_search" value="<?php if(!empty($_POST['keywords_search'])){echo $_POST['keywords_search'];}elseif(!empty($val['keywords_search'])){echo $val['keywords_search'];}?>" placeholder="按关键字查询">
                        <img src="<?php echo asset_url('images/search.png')?>" alt="" class="topic_group_gjz_img">
                    </div>
                    <input type="submit"  type="button" value="查询" class="topic_group_input"/>
                   
                </div>
                <div class="topic_group">
                    <div class="topic_group_left">
                        <input name="stime_search" type="text" class="datepicker  form-control dateinput topic_group_gjz" value="<?php if(!empty($_POST['stime_search'])){echo $_POST['stime_search'];}elseif(!empty($val['stime_search'])){echo $val['stime_search'];}?>" placeholder="选择话题时间区间"/>&nbsp;&nbsp;至&nbsp;&nbsp;
                        <input name="etime_search" type="text" class="datepicker  form-control dateinput topic_group_gjz" value="<?php if(!empty($_POST['etime_search'])){echo $_POST['etime_search'];}elseif(!empty($val['etime_search'])){echo $val['etime_search'];}?>" placeholder="选择话题时间区间"/>
                    </div>
                    <!-- <button>下发</button> -->
                    <input id="batch_xf" type="button" type="button" value="下发" class="topic_group_input"/>
                </div>
            </div>
        </form>
        <div class="m_table_box topic_table" >
            <table>
                <thead>
                <tr>
                    <th class="s-thead"></th>
                    <th class="s-thead">话题ID</th>
                    <th class="s-thead" width="400px;">话题内容</th>
                    <th class="s-thead">话题类型</th>
                    <th class="s-thead">创建时间</th>
                    <th class="s-thead">话题热度</th>
                    <th class="s-thead">话题管理</th>
                </tr>
                </thead>
                <tbody>
                <?php if (!empty($topic_list)):?>
                    <?php foreach ($topic_list as $value) :?>
                        <tr>
                            <td><img src="<?php echo asset_url('images/select_box.png')?>" alt="" class="biu_rdo_img " isc="0" tid="<?php echo $value['tid'];?>" status="<?php echo $value['status'];?>"></td>
                            <td><?php echo $value['tid'];?></td>
                            <td><?php echo $value['title'];?></td>
                            <td><?php echo $value['type_name'];?></td>
                            <td><?php echo $value['createtime'];?></td>
                            <td><?php echo $value['hot'];?></td>
                               <?php if ($value['status'] == 1){echo '<td>已下发</td>';} else {?>
                             <td><button class="topic_table_btn" tid="<?php echo $value['tid'];?>" >下发</button></td>
                            <?php }?>   
                        </tr>
                    <?php endforeach; endif; ?>
               <!--  <tr>
                    <td><img src="<?php echo asset_url('images/select_box.png')?>" alt="" class="biu_rdo_img " isc="0" vid="0"></td>
                    <td>y110</td>
                    <td>标题名标题名标题名标题名标题名标题名</td>
                    <td>情感</td>
                    <td>2016-11-11</td>
                    <td><button class="topic_table_btn" tid="1">下发</button>  </td>
                </tr> -->
                </tbody>
            </table>

        </div>
        <?php echo $pageinfo;?>
    </div>
</div>
<script type="text/javascript" src="<?php echo asset_url('js/bootstrap-datepicker.js') ?>"></script>
<script type="text/javascript" src="<?php echo asset_url('js/validate.js') ?>"></script>
<script type="text/javascript" src="<?php echo asset_url('js/bootstrapValidator.min.js') ?>"></script>
<script type="text/javascript" src="<?php echo asset_url('js/common.js') ?>"></script>
<script type="text/javascript">
$(function(){
    //下发
    $('.topic_table_btn').on('click', function() {
        var _this = $(this);
        var tid = $(this).attr('tid');
        var title=$(this).parent().prev().prev().prev().prev().text();
        $.ajax({
            url: "<?php echo site_url('sharecircle/topic/xf_topic')?>",
            type: 'POST',
            dataType: 'json',
            data: {tid: tid,titles:title},
            success:function(data)
            {
                //console.log(data);
                if(data.code==1){
                alert("成功插入"+data.data+"条数据");
               location.href="<?php echo site_url('sharecircle/topic/cloud_topic')?>";
                }
                if(data.code==0){
                alert("要下发的话题和本地创建的话题有重复，不能下发");
                return false;
                }
            }
        })
    });
//批量下发

     $('#batch_xf').click(function(e){
        var ids = '';
        var titles='';
        var status=true;
         if(confirm("确定要下发吗？")) {
            $('.biu_rdo_img').each(function() {
                if($(this).attr('status')==1&&$(this).attr('isc') == 1){
                    alert('已经下发的话题不能再下发');
                    status=false;
                    return false;
                }
                if ($(this).attr('isc') == 1) {
                    if (ids === '') {
                        ids += $(this).attr('tid');
                    } else {
                        ids += ',' + $(this).attr('tid');
                    }
                    if (titles === '') {
                        titles += $(this).parent().next().next().text();
                    } else {
                        titles += '||,' + $(this).parent().next().next().text();
                    }
                }
            });
             if (ids === ''&&status) {
                alert('请选择要下发的话题');
                status=false;
                return false;
                }
                if(status==true){
                $.ajax({
                    url: "<?php echo site_url('sharecircle/topic/xf_topic')?>",
                    type: 'POST',
                    dataType: 'json',
                    data: {tid: ids,titles:titles},
                    success:function(data)
                    {
                        //console.log(data);
                if(data.code==1){
                    alert("成功插入"+data.data+"条数据");
                    location.href="<?php echo site_url('sharecircle/topic/cloud_topic')?>";
                }
                if(data.code==0){
                alert("要下发的话题和本地创建的话题有重复，不能下发");
                return false;
                }
                    }
                })
            }
        }
    });
        
    //批量下发

    // // 模拟下拉框
    // $('.gn_jf_type').click(function(e){
    //     e.stopPropagation();
    //     var isn=$('.topic_select_option').attr('isn');
    //     if(isn==0){
    //         $('.topic_select_option').show();
    //         $('.topic_select_option').attr('isn','1');
    //         $('.gn_jf_type').not($(this)).siblings('ul').hide();
    //         $('.gn_jf_type').not($(this)).siblings('ul').attr('isn','0');
    //     }else{
    //         $('.topic_select_option').hide();
    //         $('.topic_select_option').attr('isn','0');
    //     }
    // })
       // 模拟下拉框
    $('.gn_jf_type').click(function(e){
        e.stopPropagation();
        var ul=$(this).next('.topic_select_option');
        var isn=ul.attr('isn');
        if(isn==0){
            ul.show();
            ul.attr('isn','1');
            $('.gn_jf_type').not($(this)).siblings('ul').hide();
            $('.gn_jf_type').not($(this)).siblings('ul').attr('isn','0');
        }else{
            ul.hide();
            ul.attr('isn','0');
        }
    })

    $('.topic_select_option li').mouseover(function(){
        $(this).addClass('on_rk_type');
        $(this).siblings().removeClass('on_rk_type');
    })

    $('.topic_select_option li').click(function(){
        var vid = $(this).attr('vid');
        $(this).parent().next().val(vid);
        $('.topic_select_option').hide();
        $('.topic_select_option').attr('isn','0');
        var text=$(this).text();
        $('.gn_jf_type p').text(text);
    })

     // 单选按钮切换
    $('.biu_rdo_img').click(function(){
        var isc=$(this).attr('isc');
        if(isc==0){
            $(this).attr('src','<?php echo asset_url('images/selected_box.png')?>');
            $(this).attr('isc','1');
        }else{
            $(this).attr('src','<?php echo asset_url('images/select_box.png')?>');
            $(this).attr('isc','0');
        }
    })
})    
</script>
