<style type="text/css">
.m_table_box table td .aa {
    width: 85px!important;
    font-size: 12px;
    background-color: #63D0F7!important;
    border: 0!important;
    padding: 5px 10px 6px 10px;
    color: #FFF;
    border-radius: 4px;
}
   
*{margin: 0;padding: 0;}
        /*body{background: #333}*/
        .newsPop{position: absolute;z-index: 1000;left:50%;top:50%;margin-left:-400px;margin-top:-265px;width: 800px;height: 470px; background: #fff;padding: 30px 40px;font-family: "微软雅黑";font-size: 16px;}
        .newsPop h3{font-size: 20px;color: #7d7d7d;margin-bottom: 15px;font-weight: bold;}
        .newsPop textarea{width: 100%;border: 1px solid #ccc;-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;font-size: 16px;color: #7d7d7d;text-align: left;line-height: 1.2;padding: 8px;height: 60px;}
        .imgBox{font-size: 0;margin: 10px 0;width: 750px;}
        .imgBox img{margin-right: 20px;width: 224px;height: 150px;vertical-align: top;}
        .imgBox .add{display:inline-block;margin-right: 20px;width: 222px;height: 148px;border: 1px solid #ccc;background:#f5f5f5 url(<?php echo asset_url('images/add.png')?>) no-repeat center;}
        .newsPop .popularity{font-weight: bold;margin: 15px 0;color: #7d7d7d;}
        .newsPop .popularity input{font-size: 14px;padding:6px;width: 120px;border: 1px solid #ccc;-wenkit-border-radius: 3px;-moz-border-radius: 3px;border-radius: 3px;font-weight: bold;color: #7d7d7d;}
        .newsPop .tipBox{font-size: 16px;color: #7d7d7d;line-height: 1.8;}
        .newsPop .tipBox .li02{text-indent: 3em;}
        .btns button{width: 120px;height: 44px;-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;font-size: 18px;color: #fff;background: #ccc;border: 0;font-weight: bold;font-family: "微软雅黑";margin-top: 20px;}
        .btns .cancel{float: left;}
        .btns .submit{background: #9de049;float: right;}
</style>
<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;">新闻列表</p>
        <div class="t-e">
                    <img src="<?php echo asset_url('images/explain.png');?>" alt="">
                    <span style="width: 800px;vertical-align: middle;">说明：该菜单用于编辑首页新闻区块内容 ① 可将原单图模式编辑成三图模式②可编辑页面浏览量和标题</span>
            </div>
    </div>
    
    <div class="topic_box" >
        <form method='post' action="<?php echo site_url('news/shownewslist')?>">
            <div class="screening">
                <div class="topic_group">
                    <div class="topic_group_left">
                        <div class="gn_jf_type topic_select">
                            <p class="reward_je_p" > <?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>   
                </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="选择话题时间区间"></input>&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="选择话题时间区间"></input>
                    </div>
                    <input type="submit" value="查询" class="topic_group_input">
                    <!-- <button>取消置顶</button> -->
                </div>
            </div>
        </form>
        <div class="m_table_box topic_table" >
            <table>
                <thead>
                <tr>
                    <th class="s-thead">帖子ID</th>
                   <!--  <th class="s-thead">列表图</th> -->
                    <th class="s-thead" width="25%">新闻标题</th>
                    <th class="s-thead" width="12%">创建时间</th>
                    <th class="s-thead" width="12%">推送时间</th>
                    <th class="s-thead">展现形式</th>
                    <th class="s-thead">人气</th>
                  
                    <th class="s-thead"width="25%">管理</th>
                </tr>
                </thead>
                <tbody>
                <?php if (!empty($data)):?>
                    <?php foreach ($data as $value) :?>
                    <tr>
                       <!--  <td><img src="<?php echo asset_url('images/select_box.png')?>" alt="" class="biu_rdo_img " isc="0" vid="0"></td> -->
                        <td><?php echo $value['id'];?></td>
                        <!-- <td> <ul class='news_listIMG'>
                            <?php foreach ($value['pic'] as $val) :?>
                                  <li><img src="<?php echo $val;?>"  width="130" height="auto"></li>
                            </ul>
                        <?php  endforeach;?>
                        </td> -->
                        <td><?php echo $value['title'];?></td>
                        <td><?php echo $value['create_time'];?></td>
                        <td><?php echo $value['ts_time'];?></td>
                        <?php if($value['type']==1):?>
                        <td><?php echo "单图";?></td>
                        <?php endif;?>
                        <?php if($value['type']==2):?>
                        <td><?php echo "三图";?></td>
                        <?php endif;?>
                        <td><?php echo $value['views'];?></td>
                        <td>
                        <div style="width:270px; margin:0 auto;">
                        <div style="float:left;">
                         <form id="form1" method="post" action="<?php echo site_url('news/update_news')?>">
                            <input type="button" name="bian" class='aa newsedit' class="topic_table_btn" data-target="#myModal" data-toggle="modal" value="编辑" ida='<?php echo  $value['id'];?>' picurl="<?php echo $value['picurl'];?>"  discuzviews="<?php echo $value['discuz_views'];?>" typea="<?php echo $value['type'];?>" title="<?php echo $value['title'];?>" createtime="<?php echo $value['c_time'];?>" tstime="<?php echo $value['t_time'];?>" top="<?php echo $value['top'];?>" views="<?php echo $value['views'];?>" fenye='<?php echo $fenyelist;?>' fid="<?php echo $value['fid'];?>">
                            <input type="hidden" name="ida" value="<?php echo $value['id'];?>">
                            <input type="hidden" name="picurl" value="<?php echo $value['picurl'];?>">
                            <input type="hidden" name="type" value="<?php echo $value['type'];?>">
                            <input type="hidden" name="title" value="<?php echo $value['title'];?>">
                            <input type="hidden" name="create_time" value="<?php echo $value['c_time'];?>">
                            <input type="hidden" name="ts_time" value="<?php echo $value['t_time'];?>">
                            <input type="hidden" name="top" value="<?php echo $value['top'];?>">
                            <input type="hidden" name="fid" value="<?php echo $value['fid'];?>">
                            <input type="hidden" name="discuz_views" value="<?php echo $value['discuz_views'];?>">
                            <input type="hidden" id="fenyechuansan" name="fenye" value='<?php echo $fenyelist;?>'>
                            <div style="float:right;"><input type="submit" name="del" class='aa newsedit' onclick="return check();" value="删除" style="margin-left: 8px;"> </div>
                            </div>
                            <div style="float:right;">
                             <input type="submit" class='aa zhi' istop='<?php echo $value['top'];?>' name="ding" class="topic_table_btn" <?php if($value['top']==1):?>
                        <?php echo "value='已置顶'";?>
                        <?php endif;?> <?php if(!$value['top']):?>
                        <?php echo "value='置顶'";?>
                        <?php endif;?> >
                        </form>
                        </div>
                        <div style="clear:both;">
                             </div>
                             </div>
                       </td> 
                    </tr>
                    <?php endforeach; endif; ?>
                <input type="hidden" id="is_top"  value='<?php echo $is_top;?>'>
                </tbody>
            </table>
        </div>
          <?php echo $page; ?>
    </div>
</div>
</from>
<div class="modal fade equity" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style=" width: 860px;height:550px;margin-left:-430px;margin-top:-275px;">
<div class="newsPop" >
        <h3>新闻标题</h3>
        <form action="<?php echo site_url('news/news_save/')?>" method="post" class="registerForm regiswidth" enctype="multipart/form-data">
        <textarea name="titleg" id="titleg"></textarea>
        <div class="imgBox">
            <img id="img1" src="">
            <input type="file" id='imgtempa' style="display: none;" name="imgtempa"> 
            <input type="hidden" id='imgtempaa'  name="imgtempaa" value=''>
          <!--   <img src="" > -->
            <img id="img2" src='' class="add">
            <input type="file" id='imgtempb' style="display: none;" name="imgtempb"> 
            <input type="hidden" id='imgtempbb'  name="imgtempbb" value=''>
             <img  id="img3" src='' class="add" style="cursor:pointer">
             <input type="file" id='imgtempc' style="display: none;" name="imgtempc" > 
            <input type="hidden" id='imgtempcc'  name="imgtempcc" value=''>
        </div>
        <div class="popularity">
            人气：<input type="text" name="viewsg" id="">
        </div>
        <div class="tipBox">
            <p class="li01">备注：①选择一张和两张图片时，页面显示单图样式；选择三张时，页面显示三图样式。</p>
            <p class="li02">②人气为该新闻的浏览量，可以修改。修改后人气数仍然会根据自然浏览量增加。</p>
        </div>
        <div class="btns">
         <input type="hidden" name="fenyeg"   value='' > 
         <input type="hidden" name="idg"   value='' > 
         <input type="hidden" name="create_timeg"   value='' > 
         <input type="hidden" name="ts_timeg"   value='' >
         <input type="hidden" name="viewsgg"   value='' > 
          <input type="hidden" name="vigg"   value='' > 
         <input type="hidden" name="topg"   value='' > 
         <input type="hidden" name="fidg"   value='' > 
        <!--  <input type="hidden" name="idg"   value='' >  -->
            <button type="button" class="cancel" data-dismiss="modal">取消</button>
            <button type="submit" class="submit" onclick="return checknum();">提交</button>
        </div>
        </form>
    </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 check(){
    if(confirm("确定要删除吗？")) {
        return true;
    }else{
        return false;
    }
}

function checknum(){    
    var temp=0;
    var chuan=0; 
   var num=$("input[name='viewsg']").val();
   var num=parseInt(num);
   var numb=$("input[name='vigg']").val();
   var numb=parseInt(numb);
    if((/^(\+|-)?\d+$/.test( num ))&&num>0){  
        temp=1; 
    }else{  
        alert("人气中请输入正整数！");  
        $("input[name='viewsg']").val(); 
        return false;  
    } 
    if(num<numb){
        alert("人气编辑值必须要比编辑之前的大！");  
        $("input[name='viewsg']").val(); 
        return false;  
    }else{
    var chuan=1;
    }
    var titleg=$("#titleg").val();
    if(!titleg){
alert("请输入标题！");
return false;
    }
    if(temp==1&&chuan==1){
        return true;
    }
}

$(function(){
    // 模拟下拉框
    $('.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');
        }
    })


   $('.zhi').click(function (){
     var istop= $(this).attr('istop');
    var top =$("#is_top").val();
    if(top=="1"&&istop!=1){
        alert("只能有一个置顶的新闻");
        return false;
    }
});


    $('.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();
       $(this).parent().prev().find('.reward_je_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');
        }
    })
    $("#img1").on('click', function() {
        $('#imgtempa').click();
        $('#imgtempa').change(function(){
       var objUrl = getObjectURL(this.files[0]) ;
       console.log("objUrl = "+objUrl) ;
      if (objUrl) {
        $('#img1').attr("src", objUrl) ;
        //$('#u'+tid).css('display','block'); 
      }
    }) ;
    });

     $("#img2").on('click', function() {
        $('#imgtempb').click();
        $('#imgtempb').change(function(){
        var objUrl = getObjectURL(this.files[0]) ;
        console.log("objUrl = "+objUrl) ;
        if (objUrl) {
            $('#img2').removeClass('add');
            $('#img2').attr("src", objUrl) ;
        //$('#u'+tid).css('display','block'); 
            }
        }) ;
    });

     $("#img3").on('click', function() {
        $('#imgtempc').click();
        $('#imgtempc').change(function(){
        var objUrl = getObjectURL(this.files[0]) ;
        console.log("objUrl = "+objUrl) ;
        if (objUrl) {
            $('#img3').removeClass('add');
            $('#img3').attr("src", objUrl) ;
        //$('#u'+tid).css('display','block'); 
            }
        }) ;
    });

//建立一個可存取到該file的url
    function getObjectURL(file) {
    var url = null ; 
    if (window.createObjectURL!=undefined) { // basic
        url = window.createObjectURL(file) ;
    } else if (window.URL!=undefined) { // mozilla(firefox)
        url = window.URL.createObjectURL(file) ;
    } else if (window.webkitURL!=undefined) { // webkit or chrome
        url = window.webkitURL.createObjectURL(file) ;
    }
    return url ;
}

        $('.newsedit').bind('click',function(){
        var id = $(this).attr('ida');
        var fid=$(this).attr('fid');
        var views=$(this).attr('views');
        var picurl=$(this).attr('picurl');
        var type=$(this).attr('typea');
        var title=$(this).attr('title');
        var create_time=$(this).attr('createtime');
        var ts_time=$(this).attr('tstime');
        var top=$(this).attr('top');
        var fenye=$(this).attr('fenye');
        var discuz_views=$(this).attr('discuzviews');
       $.post("<?php echo site_url('news/news_edit')?>", { id:id, views: views, picurl:picurl, type:type, title:title,create_time:create_time.toString(),ts_time:ts_time.toString(),top:top,fenye:fenye,discuz_views:discuz_views,fid:fid},
           function(data){
            //初始化
            if(data.code == 1){
            $("input[name='fenyeg']").val(data.fenye);
            $("input[name='idg']").val(data.ida);
             $("input[name='create_timeg']").val(data.create_time);
            $("input[name='ts_timeg']").val(data.ts_time);
             $("input[name='viewsg']").val(data.views);
             $("input[name='vigg']").val(data.views);
             $("input[name='fidg']").val(data.fid);
             $("input[name='viewsgg']").val(data.discuz_views);
            $("input[name='topg']").val(data.topa);
            $("textarea[name='titleg']").val(data.titlea);
            if(data.count==1){
                $('#img1').attr('src',data.pic[0]);
                $('#imgtempaa').attr("value", data.pic[0]);
                $('#img2').addClass('add');
                $('#img2').attr('src','');
                $('#imgtempbb').attr("value", '');
                $('#img3').addClass('add');
                $('#img3').attr('src','');
                $('#imgtempcc').attr("value", '');
            }
            if(data.count==2){
                $('#img1').attr('src',data.pic[0]);
                $('#imgtempaa').attr("value", data.pic[0]);
                $('#img2').removeClass('add');
                $('#img2').attr('src',data.pic[1]);
                $('#imgtempbb').attr("value", data.pic[1]);
                $('#img3').addClass('add');
                $('#img3').attr('src','');
                $('#imgtempcc').attr("value", '');
            }
            if(data.count==3){
                $('#img1').attr('src',data.pic[0]);
                $('#imgtempaa').attr("value", data.pic[0]);
                $('#img2').removeClass('add');
                $('#img2').attr('src',data.pic[1]);
                $('#imgtempbb').attr("value", data.pic[1]);
                $('#img3').removeClass('add');
                $('#img3').attr('src',data.pic[2]);
                $('#imgtempcc').attr("value", data.pic[2]);
            }
            $("#myModal").modal();
        }
            //$("input[name='sid']").val(sid); 
        },'json');
        
    })

})    
</script>
