<nav class="breadcrumb"> 客户端界面设置 <span class="c-gray en">&gt;</span> 发现频道管理 </nav>
<style>
    .push-title{margin-top: 30px;font-size:30px;color: #000;margin-left: 25px;}

    .modal-dialog-lc{width: 320px!important;padding: 20px!important;}

    /*显示入口*/
    .show-channel{margin: 25px 0px; width: 100%;}
    .show-channel ul{overflow:hidden;width:100%;}
    .show-channel ul li{width:136px;float:left;margin: 0px 60px 40px 0px;padding: 2px;}
    .channel-icon{position: relative;width: 72px;margin: 0px auto;margin-top: 25px;border-radius: 50%;overflow: hidden;text-align:center}
    .channel-icon img{width: 100%;position: relative;cursor:pointer;}
    .channel-name{position: relative;height: 20%;text-align: center;font-size: 15px;color:#e5e5e5;margin-top: 14px;  margin-bottom: 15px;}
    .channel-name span{margin-top: -3%;position: relative;display: block;color: #333}
    .channel-del{position: relative;  height: 44px;text-align: center;font-size: 16px;width: 100%;background-color: #F3FAFD;cursor:pointer;border-top: 1px solid #e5e5e5;}
    .channel-del:hover{background-color: #E8F0F0;}
    .channel-del span{display: block;margin-top: 9px; color:#7D7D7D;}
	.ediv{padding-bottom:20px}
	.edt{padding-left:30px;}
	.edr{padding-right:20px;}
	.elp{padding-left: 0px;padding-top: 20px;padding-bottom: 20px;}
	.modal.fade.in{top: 11%;bottom:12%;}
	.mt10{margin-top: 10px;font-size: 18px;}
    /*添加按钮*/
    #channel-add-i{padding: 0;}
    .channel-add{position: relative;cursor: pointer;text-align: center;background-color: #f5f5f5;width: 109px;margin: 0px auto;border: 1px solid #e5e5e5;border-radius: 3px;padding: 3px 0px;}
    .channel-add:hover{background-color: #EAEAEA;}
    .channel-add span{color:#7D7D7D;font-size: 15px;}

    /*弹窗添加*/
     .add-text{display: block;font-size: 16px;margin-left: 42px;margin-bottom: 5px}
     .channel-input{height:30px;width:80%;border: 1px solid #dfdfdf;}
     .channel-div{text-align: center}
     .add-icon{width:80%;margin-left: 42px;} 
     .add-icon ul{overflow:hidden;width:90%;margin-left: 4.5%;padding:10px 0px 5px;;position: relative;}
     .add-icon ul li{width:19%;float:left;height: 57px;border: 2px solid #ccc;margin-left: 1%;margin-bottom: 1%;}
     .add-icon ul li:hover{border: 2px solid #6BB5C1;cursor:pointer;}
     .add-icon ul li img{width: 100%;position: relative;}   
	 .t-e {margin-left: 30px; margin-bottom: 15px; margin-top: 5px; overflow: hidden;}


     /*增加排序功能*/
     .channelmain{border: 1px solid #e5e5e5;}
     .channelsort{margin-top:10px;}
     .channelsort span{padding-left:20px;padding-right:5px}
     .channelsort input{width:40%;border-radius:5px;border:1px solid #e5e5e5;text-align:center}


    .sy_pz_type_on{-webkit-box-shadow:0 0px 1px rgba(0, 0, 0, .4);
  -moz-box-shadow:0 0px 1px rgba(0, 0, 0, .4);box-shadow:0 0px 1px rgba(0, 0, 0, .4);}
    .reward_je_p{margin-top: 4px!important;}
    .on_rk_type{color: #FFF!important;background-color: #58CAF5!important;}
     .sy_pz_type{width: 100%;margin-bottom: 20px;border: 1px solid #e5e5e5;font-size: 14px;border-radius: 4px;height: 32px;text-align: center;cursor: pointer;position: relative;}
     .sy_select{position: relative;}
     .sy_select ul{position: absolute;background-color: #FFF;-webkit-box-shadow:0 2px 4px rgba(0, 0, 0, .4);
  -moz-box-shadow:0 2px 4px rgba(0, 0, 0, .4);box-shadow:0 2px 4px rgba(0, 0, 0, .4);top: 31px;z-index: 9;display: none;}
  .sy_select ul li{width: 100%!important;margin: 0!important;text-align: center;color: #000;padding: 3px 0px;}



  .new_cel_box{width: 800px;margin: 25px 30px;}

/*楼层box、添加，排序 ,删除*/
  .lc_ul{overflow: hidden;}
  .lc_ul li{overflow: hidden;}
  .lc_ul_li{margin: 20px 0px;}
  .add_lc{cursor: pointer;text-align: center;background-color: #f5f5f5;width: 109px;margin: 0px auto;border: 1px solid #e5e5e5;border-radius: 3px;padding: 3px 0px;float: left;}
  .add_lc:hover{background-color: #EAEAEA;}
    .add_lc span{color: #7D7D7D;font-size: 15px;}

    .lc_msg{overflow: hidden;}
    .lc_msg_name{float: left;color: #FFF;background-color: #58CAF5;text-align: center;width: 132px; padding: 4px 0px;font-size: 15px;border-radius: 3px;margin-left: 2px;}
    .lc_sort{display: inline-block;margin-left: 20px;padding-top: 5px;}
    .lc_sort span{font-size: 15px;}
    .lc_sort input{width: 80px;text-align: center;font-size: 15px;border: 1px solid #e5e5e5;border-radius: 5px;vertical-align: top;}
    .del_lc{margin-left: 20px;cursor: pointer;vertical-align: text-bottom;}
/*添加楼层窗口*/
.add_lc_text{font-size: 16px;}
.add_lc_input{    font-size: 15px;text-indent: 10px;border: 1px solid #E5E5E5;border-radius: 3px;margin-left: 20px; vertical-align: top;}
</style>
    <div class="" role="main">        		
			<div style="width:100%;"><li class="edt" style="font-size: 28px; color: #7d7d7d;vertical-align: middle; padding-top: 15px; padding-bottom: 15px;">发现频道管理</div>
           
			<!--<div class="" style="border-bottom: 1px solid #e5e5e5;">
                <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  style="border-top: 1px solid #e5e5e5;">
                <p class="mt10 edt edr">发现图标入口配置</p>
                <div class="t-e">
                        <img src="<?php echo asset_url('images/explain.png');?>" alt="">
                        <span style="width: 800px;vertical-align: middle;">说明：①请在此处对发现的图标入口进行编辑；②可对图标入口进行分类，并以楼层区块的形式展示；③可选择爆炸贴并在页面显示，如HOT、NEW、热、新。</span>
                </div>
            </div>

        <div class="new_cel_box">
            <ul class="lc_ul">
                <?php foreach ($floor_channel as $floor):?>
                <li class="lc_ul_li lc_li_<?php echo $floor['id']?>">
                    <div class="lc_msg">
                        <input class="lc_msg_name" value="<?php echo $floor['name'];?>"/>
                        <img src="<?php echo asset_url('images/dellc_img.png'); ?>" alt="" title="删除该楼层" class="del_lc" data-target="#delLCModal" data-toggle="modal" fid="<?php echo $floor['id']?>">
                        <div class="lc_sort"><span>排序：</span><input type="text" class="sort_floor" name="floor_sort_num" fid="<?php echo $floor['id']?>" value="<?php echo $floor['ordernum']?>"></div>
                    </div>
                    <div class="show-channel">
                        <ul>
                        <?php
                        if (!empty($floor['channel'])) {
                            foreach ($floor['channel'] as $k => $v) {
                        ?>
                        <li>
                            <div class="sy_select">
                                <div class="sy_pz_type">
                                    <p class="reward_je_p"><?php echo !empty($v['flag']) ? $hot_flag[$v['flag']] : '请选择'; ?></p>
                                    <img src="<?php echo asset_url('images/triangle.png'); ?>" alt=""
                                         class="sel_down">
                                </div>
                                <input type="hidden" value="" name="share_integral_type">
                                <ul isn="0" channel_id="<?php echo $v['id'] ?>">
                                    <li vid="new">NEW</li>
                                    <li vid="hot">HOT</li>
                                    <li vid="xin">最新</li>
                                    <li vid="re">热门</li>
                                    <li vid="no">无</li>
                                </ul>
                            </div>

                            <div class="channelmain">
                                <div class="channel-icon"><img
                                        style="width: 72px !important;height: 72px !important;vertical-align: middle;text-align: center;"
                                        mid="<?php echo $v['id']; ?>"
                                        xdl="<?php echo $v['requiredlogin']; ?>"
                                        src="<?php echo asset_url('images/channel_img/' . $v['icon']); ?>"
                                        alt=""></div>
                                <div class="channel-name"><span><?php echo $v['title']; ?></span></div>
                                <div data-target="#delModal" data-toggle="modal" class="channel-del"><span>删除</span>
                                </div>
                            </div>
                            <div class="channelsort"><span>排序：</span><input class="sort_channel"
                                                                            channel_id="<?php echo $v['id']; ?>"
                                                                            type="text"
                                                                            name="ordernum[<?php echo $v['id'] ?>]"
                                                                            sid="<?php echo $v['id'] ?>"
                                                                            value="<?php echo $v['ordernum'] ?>">
                            </div>
                        </li>
                        <?php
                            }
                        }
                        ?>
                             <li id="channel-add-i" >
                                <div class="channel-add" fid="<?php echo $floor['id'];?>"><span>新增入口＋</span></div>
                            </li>
                        </ul>
                    <!-- <button class="edit_btn" id="save" style="margin-right: 75px;margin-top:20px;">保存修改</button> -->
                    </div>
                </li class="lc_ul_li">
                <?php endforeach;?>
                <li id="li_sort">
                    <button class="edit_btn" id="order" style="float:left;width:109px;">保存排序</button>
                </li>
                <li class="lc_ul_last">                   
                   <div class="add_lc" data-target="#add_louceng" data-toggle="modal">
                        <span>新增区块＋</span>
                    </div>                             
                </li>
            </ul>

<!--                 <button class="edit_btn" id="save" style="margin-right: 75px;margin-top:0;">保存设置</button>-->
        </div>
    </div>

     <!--添加楼层-->
    <div class="modal fade equity" id="add_louceng" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style="position: fixed; width:322px;height:170px;">
        <div class="modal-dialog-lc" style="margin-top: 5px;">
            <form id="level_form" action="" class="registerdate" >
                <div class="form-group">
                    <span class="add_lc_text">区块名称：</span>                   
                    <input type="text"  class="add_lc_input" value="" />
                </div>
               
                <div class="equity-button" style="width:100%;  padding-left: 10px;padding-top: 40px;">
                    <button type="button" class="h5a-btn btn  btn-primary equitycof add_lc_submit">确定</button>
                    <button type="button" class="h5a-btn btn  btn-default equityclose" data-dismiss="modal" style="float:right;margin-right: 10px;">取消</button>
                </div>
            </form>
        </div>  
    </div>
    

    <!--添加入口-->
    <div class="modal fade equity" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style="position: fixed; width:453px;">
        <div class="modal-dialog" style="margin:0; ">
            <form id="level_form" action="" class="registerdate">
                <input type="hidden" name="icon" value=""> 
                <!--默认添加操作-->

                <input type="hidden" name="id" value="">
                <input type="hidden" name="fid" value="">
                <div class="form-group">
                    <span class="add-text">入口名称</span>
                    <div class="channel-div">
                        <input type="text"  class="channel-input" maxlength="5" name="title" value="" style="text-indent: 10px;margin:8px 0px;"/>
                    </div>
                </div>
                <div class="form-group">
                    <span class="add-text">跳转类别</span>
                    <div class="channel-div">
                        <select name="cid" class="channel-input" style="  text-indent: 10px;margin:8px 0px;">
                            <option value="0">请选择</option>
                            <?php foreach ($goto as $key => $value) {
                            ?>
                            <option value="<?php echo $key?>" ><?php echo $value;?></option>
                            <?php
                            }?>
                        </select>
                    </div>
                </div>
                <div id="goto_value" class="form-group" style="display:none">
                    <span class="add-text"></span>
                    <div class="channel-div">
                        <input type="text" class="channel-input" name="goto_value" value="" style="  text-indent: 10px;margin:8px 0px;"/>
                    </div>
                </div>
                <div class="form-group"  style="height: 200px;overflow: scroll;overflow-x: hidden;">
                    <span class="add-text">图标</span>
                    <div class="add-icon">
                        <ul>
                            <?php
                            foreach ($iconlist as $k => $v) {
                            ?>
                            <li class="mark-choose"><img  src="<?php echo asset_url('images/channel_img').'/'.$v;?>" alt=""></li>
                            <?php
                            }
                            ?>
                        </ul>
                    </div>
                </div>
                <div class="form-group ediv">
                    <span class="dianm" style="margin-left:42px;   font-size: 16px;">是否要求登录</span>

                    <input type="hidden" name="requiredlogin" value="1">
                    <div class="biu_rdo" style="  margin-top: 10px; margin-right: 40px;">                         
                            <img src="<?php echo asset_url('images/unchoice.png');?>" alt="" class="biu_rdo_img " isc="0" sid="1"> <span>是</span>
                            <img src="<?php echo asset_url('images/unchoice.png');?>" alt="" class="biu_rdo_img left_rdo" isc="0" sid="0"> <span>否</span>
                    </div>
                </div>                               
                <div class="equity-button" style="width:100%;  padding-left: 42px;">
                    <button type="submit" class="h5a-btn btn  btn-primary equitycof" id="edit_opt">确定</button>
                    <button type="button" class="h5a-btn btn  btn-default equityclose" data-dismiss="modal" style="float:right;margin-right: 40px;">取消</button>
                </div>
            </form>
        </div>  
    </div>


    <!--确认删除弹出框-->
    <input type="hidden" name="channelId" value="">
    <div class="modal fade equity" id="delModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style="width: 360px; height: 190px; border-radius: 0px; top: 20%;">
    <div class="modal-dialog" style="  width: 100%!important;margin: 0">
        <p class="delete-title">确定要删除该入口？</p>
        <div class="equity-button">
            <button type="button" class="h5a-btn btn  btn-primary equitycof" id='optdel'>确定</button>
            <button type="button" class="h5a-btn btn  btn-default equityclose" data-dismiss="modal">取消</button>
        </div>
    </div>
</div>

<input type="hidden" name="floorId" value="">
<div class="modal fade equity" id="delLCModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style="width: 360px; height: 190px; border-radius: 0px; top: 20%;">
    <div class="modal-dialog" style="  width: 100%!important;margin: 0">
        <p class="delete-title">此楼层和其中入口将全部删除，<br>确定要删除么？</p>
        <div class="equity-button">
            <button type="button" class="h5a-btn btn  btn-primary equitycof" id="delFloor">确定</button>
            <button type="button" class="h5a-btn btn  btn-default equityclose" data-dismiss="modal">取消</button>
        </div>
    </div>
</div>

<!--    保存成功按钮-->
<div class="ok_popup">
    <img src="<?php echo asset_url('images/save_success.png')?>" alt="">
</div>

    <script>
        jQuery(document).ready(function($) {
            $('#order').on('click',  function(event) {
                event.preventDefault();
                /!* Act on the event *!/
                var formObj = {},
                    floorObj = {},
                    rege = /^\+?[0-9]+$/,
                    contr = '',
                    n = '';
                $("[name^=ordernum]").each(function(){
                    n = $.trim($(this).val());
                    if(n !== '' && !rege.test(n))
                    {
                        alert('请输入正确序号');
                        contr = 1;
                        return false;
                    }
                    formObj[($(this).attr("sid"))]=n;
                });
                if(contr==1)
                {
                    return false;
                }

                $("[name=floor_sort_num]").each(function(){
                    n = $.trim($(this).val());
                    if(n !== '' && !rege.test(n))
                    {
                        alert('请输入正确序号');
                        contr = 1;
                        return false;
                    }
                    floorObj[($(this).attr("fid"))]=n;
                });
                if(contr==1)
                {
                    return false;
                }
                if (formObj == {} && floorObj == {}) {
                    alert('请输入序号');
                    return false;
                }
                $.post(
                    "<?php echo site_url('mocuz/client/sort_new_channel')?>",
                    {channel_order: formObj, floor_order: floorObj},
                    function(data) {
                        popup_saveSuccess();
                        location.href="<?php echo site_url('mocuz/client/new_channel')?>";
                    },
                    'json'
                );
                console.log(formObj);
            });

            /*//入口排序
            $(document).on('blur', '.sort_channel', function(event) {
                event.preventDefault();
                var number = $(this).val(),
                    channel_id = $(this).attr('channel_id'),
                    rege = /^\+?[1-9][0-9]*$/;
                if(!rege.test(number))
                {
                    alert('请输入正确序号');
                    return false;
                }
                $.post(
                    "<?php echo site_url('mocuz/client/sort_new_channel')?>",
                    {id: channel_id, number: number},
                    function(data) {
                        location.href="<?php echo site_url('mocuz/client/new_channel')?>";
                    },
                    'json'
                );
            });

            //楼层排序
            $(document).on('blur', '.sort_floor', function(event) {
                event.preventDefault();
                var number = $(this).val(),
                    fid = $(this).attr('fid'),
                    rege = /^\+?[1-9][0-9]*$/;
                if(!rege.test(number))
                {
                    alert('请输入正确序号');
                    return false;
                }
                $.post(
                    "<?php echo site_url('mocuz/client/sort_floor')?>",
                    {id: fid, number: number},
                    function(data) {
                        location.href="";
                    },
                    'json'
                );
            });*/
        });
    </script>
<script type="text/javascript">
$(function(){
    // 单选按钮切换
    $('.biu_rdo img').click(function(){
        var subval = $(this).attr('sid');
        $('input[name=requiredlogin]').val(subval);
        var isc=$(this).attr('isc');
        if(isc==0){
            $(this).attr('src','<?php echo asset_url("images/choice.png");?>');
            $(this).attr('isc','1');
            $(this).siblings().attr('src','<?php echo asset_url("images/unchoice.png");?>');
            $(this).siblings().attr('isc','0');
        }
    })
})    
</script>

    
<script type="text/javascript">
    //初始化
    function init()
    {
        //将第一个图标默认为显示的图标
        var obj = $('.add-icon').find('li').eq(0);
        obj.addClass('colorOn');
        var first_icon = obj.children('img').attr('src');
        var first_icon_src = first_icon.split("images/channel_img/");
        $('input[name=icon]').val(first_icon_src[1]);
        $('input[name=id]').val("");
        $('input[name=title]').val("");
        $('#goto_value').css('display','none'); 
        $('input[name=goto_value]').val("");
        $('select[name=cid] option').each(function() {
            if($(this).val() == 0)
            {

                $(this).attr('selected',true);
            }else{

                $(this).attr('selected',false);
            }
        });     
        $('input[name=requiredlogin]').val(1);
        $('img[sid=1]').attr('src','<?php echo asset_url("images/choice.png");?>');
        $('img[sid=1]').attr('isc','1');
        $('img[sid=0]').attr('src','<?php echo asset_url("images/unchoice.png");?>');
        $('img[sid=0]').attr('isc','0');
    }

    /*添加/编辑 图标样式显示*/
    function showIcon(icon)
    {
        $(".mark-choose").each(function(){
            var icon_src = $(this).children('img').attr('src');

            var icon_src_last = icon_src.split("images/channel_img/");
            if(icon_src_last[1] == icon)
            {
                $(this).addClass('colorOn');
                $(this).siblings().removeClass('colorOn');
                return true;
            }
        });        
    }

    function popup_saveSuccess(){
        $('.ok_popup').show();
        setTimeout(function(){ $('.ok_popup').fadeOut(2000);},1000);
    }

    /*单击编辑操作*/
    $(document).on('click', '.channel-icon img', function(event) {
        event.preventDefault();
        /* Act on the event */
        init();
        var id = $(this).attr('mid');
        $.ajax({
            url: "<?php echo site_url('mocuz/client/get_new_channel')?>",
            type: 'POST',
            dataType: 'json',
            data: {id: id},
            success:function(data)
            {
                $('input[name=icon]').val(data.icon);
                $('input[name=title]').val(data.title);
                if(data.cid == 2018)
                {
                    $('#goto_value').children('span').text('帖子ID');
                }
                if(data.cid == 2021)
                {
                    $('#goto_value').children('span').text('话题帖子ID');
                }
                if(data.cid == 2022)
                {
                    $('#goto_value').children('span').text('话题ID');
                }
                if(data.cid == 1003)
                {
                    $('#goto_value').children('span').text('版块ID');
                }
                if(data.cid == 1001)
                {
                    $('#goto_value').children('span').text('地址');
                }
                if(data.cid == 1003 || data.cid == 1001 || data.cid == 2018 || data.cid == 2021 || data.cid == 2022)
                {
                    $('#goto_value').show();
                }             
                showIcon(data.icon);
                $('input[name=goto_value]').val(data.goto_value);
                $('input[name=id]').val(data.id);
                $('input[name=fid]').val(data.fid);

                $('input[name=requiredlogin]').val(data.requiredlogin);

                $('.biu_rdo img').each(function(){
                 if($(this).attr('sid') == data.requiredlogin)
                 {
                    $(this).attr('src','<?php echo asset_url("images/choice.png");?>');
                    $(this).attr('isc',1);
                 }else{
                    $(this).attr('src','<?php echo asset_url("images/unchoice.png");?>');
                    $(this).attr('isc',0);                    
                 }
                }); 


                $('select[name=cid] option').each(function() {
                                //限定必须登录的 选项
                    if(data.cid == 2019  || data.cid == 2020 || data.cid == 2011)
                    {
                        $('img[sid=0]').hide();
                        $('img[sid=0]').next('span').hide();
                    }
                    else{
                        $('img[sid=0]').show();
                        $('img[sid=0]').next('span').show();               
                    }
                     if($(this).val() == data.cid)
                     {
                        $(this).attr('selected',true);
                     }
                     else{
                        $(this).attr('selected',false);
                     }
                });

                $("#myModal").modal();
            }
        });
        
        

    });
    /*图片icon选择*/
    $(document).on('click', '.mark-choose', function(event) {
        event.preventDefault();
        /* Act on the event */
        $(this).addClass('colorOn');
        $(this).siblings().removeClass('colorOn');
        var src = $(this).children('img').attr('src');
        var icon = src.split("images/channel_img/");
        $('input[name=icon]').val(icon[1]);
    });

    $(document).ready(function() {
        $('select[name=cid]').change(function(event) {
            /* Act on the event */
            var cid = $(this).val();
            var rege = /^10.*$/;
            if(rege.test(cid))
            {
                $("#goto_value").show();
                if(cid == '1003')
                {
                    $("#goto_value").children('span').text('版块ID');
                    $("input[name=goto_value]").attr('placeholder','0');
                }
                else
                {
                    $("#goto_value").children('span').text('地址');
                    $("input[name=goto_value]").attr('placeholder','http://xxx.com');
                }
            }
            else
            {
                $("#goto_value").show();
                if(cid == '2018')
                {
                    $("#goto_value").children('span').text('帖子ID');
                    $("input[name=goto_value]").attr('placeholder','0');
                }else if(cid == '2021'){
                    $("#goto_value").children('span').text('话题帖子ID');
                    $("input[name=goto_value]").attr('placeholder','0');
                }else if(cid == '2022'){
                    $("#goto_value").children('span').text('话题ID');
                    $("input[name=goto_value]").attr('placeholder','0');
                }else{
                    $("#goto_value").hide();
                    $("#goto_value").children('span').text('地址');                    
                }                 

            }

            //限定必须登录的 选项
            if(cid == 2019  || cid == 2020 || cid == 2011)
            {
                $('img[sid=0]').hide();
                $('img[sid=0]').next('span').hide();
                $('input[name=requiredlogin]').val(1);
                $('img[sid=1]').attr('src','<?php echo asset_url("images/choice.png");?>');
                $('img[sid=1]').attr('isc','1');               
            }
            else{
                $('img[sid=0]').show();
                $('img[sid=0]').next('span').show();
                $('input[name=requiredlogin]').val(1);
                $('img[sid=1]').attr('src','<?php echo asset_url("images/choice.png");?>');
                $('img[sid=1]').attr('isc','1');   
                $('img[sid=0]').attr('src','<?php echo asset_url("images/unchoice.png");?>');
                $('img[sid=0]').attr('isc','0');               
            }
        });

        //弹窗隐藏 初始化
        $('#myModal').on('hide.bs.modal', function () {
            init();
        })

        //表单提交
        $("#edit_opt").on('click',function(event) {
            event.preventDefault();
            /* Act on the event */
            var regExp1 = /^(\w|-|[\u4e00-\u9fa5]){1,6}$/;
            var regExp2 = /^\d+$/;
            var regExp3 = /^[a-zA-z]+:\/\/[^\s]*$/;
            var param = {};
            param.title = $("input[name=title]").val();
            param.cid = $("select[name=cid]").val();
            param.icon = $("input[name=icon]").val();
            param.goto_value = $("input[name=goto_value]").val();
            if(regExp1.test(param.title) == false)
            {
                alert("请输入正确版块名");
                return false;
            }
            if(parseInt(param.cid) == 0)
            {
                alert("请选择正确跳转分类");
                return false;
            }
            /*论坛版块 只能填数*/
            if(param.cid == '1003' && ! regExp2.test(param.goto_value))
            {
                alert("请填写正确版块ID");
                return false;
            }
            /*论坛版块 只能填数*/
            if(param.cid == '2018' && ! regExp2.test(param.goto_value))
            {
                alert("请填写正确帖子ID");
                return false;
            }       
            /*外部地址填写格式*/
            if(param.cid == '1001' && ! regExp3.test(param.goto_value))
            {
                alert("请填写正确外部链接地址");
                return false;
            }

            var mode ="";
            if($('input[name=id]').val())
            {
                mode = "/"+$('input[name=id]').val();
            }
            param.requiredlogin = $('input[name=requiredlogin]').val();
            param.fid = $('input[name=fid]').val();
            $.ajax({
                url: "<?php echo site_url('mocuz/client/save_new_channel"+mode+"')?>",
                type: 'POST',
                dataType: 'json',
                data: param,
                success:function(data)
                {
                    if(data.code != 1)
                    {
                        alert(data.msg);
                        return false;
                    }
                    location.href="<?php echo site_url('mocuz/client/new_channel')?>";
                }
            })
        });
        //删除操作
        $(document).on('click', '.channel-del', function(event) {
            event.preventDefault();
            /* Act on the event */           
            $("input[name=channelId]").val($(this).prev('div').prev('div').children('img').attr('mid'));
        });
        $("#optdel").on('click', function(event) {
            event.preventDefault();
            var id = $("input[name=channelId]").val();
            $.ajax({
                url: '<?php echo site_url("mocuz/client/del_new_channel");?>',
                type: 'POST',
                dataType: 'json',
                data: {id: id},
                success:function(data){
                    if(data.code==1)
                    {
                        $("#delModal").modal('hide');
                        var obj = $('img[mid='+id+']');
                        obj.parent("div").parent("div").parent('li').remove();
                    }
                }
            })
        });
        //删除楼层
        $(document).on('click', '.del_lc', function(event) {
            event.preventDefault();
            /* Act on the event */
            $("input[name=floorId]").val($(this).attr('fid'));
        });
        $("#delFloor").on('click', function(event) {
            event.preventDefault();
            var id = $("input[name=floorId]").val();
            $.ajax({
                url: '<?php echo site_url("mocuz/client/del_floor");?>',
                type: 'POST',
                dataType: 'json',
                data: {id: id},
                success:function(data){
                    if(data.code==1)
                    {
                        $("#delLCModal").modal('hide');
                        $('.lc_li_' + id).remove();
                    }
                }
            })
        });
        //添加操作
        $(document).on('click', '.channel-add', function(event) {
            event.preventDefault();
            /* Act on the event */
            //初始化
            init();
            $('input[name=fid]').val($(this).attr('fid'));
            $("#myModal").modal();
        });



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

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

    $('.sy_select ul li').click(function(){
        var vid = $(this).attr('vid'),
            channel_id = $(this).parent().attr('channel_id');
//        $("input[name=share_integral_type]").val(vid);
        $(this).parent().hide();
        $(this).parent().siblings('.sy_pz_type').removeClass('sy_pz_type_on');
        $(this).parent().attr('isn','0');
        var text=$(this).text();
        $(this).parent().siblings('.sy_pz_type').find('p').text(text);
        $.ajax({
            url: '<?php echo site_url("mocuz/client/save_new_channel_flag");?>',
            type: 'POST',
            dataType: 'json',
            data: {id: channel_id, flag: vid},
            success:function(data){
                if(data.code==1)
                {
//                    alert('已保存')
                }
            }
        })
    })

    });         
</script>
<script type="text/javascript">
// 添加楼层
$(document).on('click', '.add_lc_submit', function(event) {
    var lc_name= $.trim($('.add_lc_input').val());
    if(lc_name==''){
        alert('请输入楼层名称!');
        $('.add_lc_input').focus();
        return FALSE;
    }
    $.ajax({
        url: '<?php echo site_url("mocuz/client/save_floor");?>',
        type: 'POST',
        dataType: 'json',
        data: {name: lc_name},
        success:function(data){
          if(data.code==1)
          {
              $("#add_louceng").modal('hide');
              var rukoubq='<li class="lc_ul_li lc_li_'+data.data.id_insert+'"><div class="lc_msg"><input class="lc_msg_name" value="'+lc_name+'" /><img src="<?php echo asset_url('images/dellc_img.png'); ?>" alt="" class="del_lc"  data-target="#delLCModal" data-toggle="modal" fid="'+data.data.id_insert+'"><div class="lc_sort"><span>排序：</span><input type="text" class="sort_floor" name="floor_sort_num" fid="'+data.data.id_insert+'" ></div></div><div class="show-channel"><ul><li id="channel-add-i" ><div class="channel-add" fid="'+data.data.id_insert+'"><span>新增入口＋</span></div></li></ul></div></li>';
              $('#li_sort').before(rukoubq);
          }
        }
    })
});

//修改楼层名称
$(document).on('blur', '.lc_msg_name', function() {
    var fname = $.trim($(this).val()),
        fid = $(this).next().attr('fid');
    if (fname === '') {
        alert('区块名称不能为空');
        return false;
    }
    $.ajax({
        url: '<?php echo site_url("mocuz/client/update_floor_name");?>',
        type: 'POST',
        dataType: 'json',
        data: {fname: fname, fid: fid},
        success:function(data){
            if(data.code==1)
            {
                popup_saveSuccess();
            }
        }
    });
})

</script>