<?php defined('InShopNC') or exit('Access Invalid!');?>
<style>
    input {
        width: 270px;
    }
</style>
<div class="page">
    <!-- 页面导航 -->
    <div class="fixed-bar">
        <div class="item-title">
            <h3><?php echo $output['item_title'];?></h3>
            <ul class="tab-base">
                <?php   foreach($output['menu'] as $menu) {  if($menu['menu_key'] == $output['menu_key']) { ?>
                    <li><a href="JavaScript:void(0);" class="current"><span><?php echo $menu['menu_name'];?></span></a></li>
                <?php }  else { ?>
                    <li><a href="<?php echo $menu['menu_url'];?>" ><span><?php echo $menu['menu_name'];?></span></a></li>
                <?php  } }  ?>
            </ul>
        </div>
    </div>
    <div class="fixed-empty"></div>
    <!-- 帮助 -->
    <table class="table tb-type2" id="prompt">
        <tbody>
        <tr class="space odd">
            <th colspan="12" class="nobg"> <div class="title nomargin">
                    <h5><?php echo $lang['nc_prompts'];?></h5>
                    <span class="arrow"></span> </div>
            </th>
        </tr>
        <tr>
            <td>
                <ul>
                    <li>点击添加标签，可以添加首页标签</li>
                    <li>点击删除按钮可以删除标签</li>
                </ul>
            </td>
        </tr>
        </tbody>
    </table>
    <!-- 列表 -->
    <form id="list_form" method="post">
        <table class="table tb-type2">
            <thead>
            <tr class="space">
                <th colspan="15" class="nobg"><?php echo $lang['nc_list'];?></th>
            </tr>
            <tr class="thead">
                <th class="w12">&nbsp;</th>
                <th>专题编号</th>
                <th>标签名称</th>
                <th>排序</th>
                <th class="w200 align-center"><span><?php echo $lang['nc_handle'];?></span></th>
            </tr>
            </thead>
            <tbody id="treet1">
            <?php if(!empty($output['tabs']) && is_array($output['tabs'])){ ?>
                <?php foreach($output['tabs'] as $key => $value){ ?>
                    <tr class="hover">
                        <td>&nbsp;</td>
                        <td><?php echo $value['special_id'];?></td>
                        <td><span nc_type="edit_tab_name" column_id="<?php echo $value['special_id'];?>"
                                  title="<?php echo $lang['nc_editable'];?>"
                                  class="editable tooltip w270"><?php echo $value['name'];?></span>
                        </td>
                        <td><span nc_type="edit_tab_sort" column_id="<?php echo $value['special_id'];?>"
                                  title="<?php echo $lang['nc_editable'];?>"
                                  class="editable tooltip w270"><?php echo $value['sort'];?></span>
                        </td>
                        <td class="nowrap align-center">
                            <a href="javascript:;" nctype="del_tab" data-special-id="<?php echo $value['special_id'];?>">删除</a>
                        </td>
                    </tr>
                <?php } ?>
            <?php }else { ?>
                <tr class="no_data">
                    <td colspan="16"><?php echo $lang['nc_no_record'];?></td>
                </tr>
            <?php } ?>

            <tr style="background: none repeat scroll 0% 0% rgb(255, 255, 255);">
                <td colspan="20"><a id="btn_add_home_tab" href="javascript:;" class="btn-add marginleft">添加标签</a></td>
            </tr>
            </tbody>
            <?php if(!empty($output['list']) && is_array($output['list'])){ ?>
                <tfoot>
                <tr class="tfoot">
                    <td colspan="16"><div class="pagination"> <?php echo $output['page'];?> </div></td>
                </tr>
                </tfoot>
            <?php } ?>
        </table>
    </form>
</div>

<form id="del_form" action="<?php echo urlAdmin('mb_special', 'del_tab');?>" method="post">
    <input type="hidden" id="del_special_id" name="special_id">
</form>

<div id="dialog_add_mb_home_tab" style="display:none;">
    <form id="add_form" method="post" action="<?php echo urlAdmin('mb_special', 'add_tab');?>">
        <table class="table tb-type2">
            <tbody>
                <tr class="noborder">
                    <td colspan="2" class="required"><label class="validation" for="special_id">专题编号<?php echo $lang['nc_colon'];?></label></td>
                </tr>
                <tr class="noborder">
                    <td class="vatop rowform"><input type="number" value="" name="special_id" class="txt"></td>
                    <td class="vatop tips">专题编号，必须是数字</td>
                </tr>

                <tr class="noborder">
                    <td colspan="2" class="required"><label class="validation" for="tab_name">专题描述<?php echo $lang['nc_colon'];?></label></td>
                </tr>
                <tr class="noborder">
                    <td class="vatop rowform"><input type="text" value="" name="tab_name" class="txt"></td>
                    <td class="vatop tips">专题描述，最多20个字</td>
                </tr>
                <tr class="noborder">
                    <td colspan="2" class="required"><label class="validation" for="tab_sort">标签次序<?php echo $lang['nc_colon'];?></label></td>
                </tr>
                <tr class="noborder">
                    <td class="vatop rowform"><input type="number" value="" name="tab_sort" class="txt"></td>
                    <td class="vatop tips">请保持次序准确</td>
                </tr>
            </tbody>
            <tfoot>
            <tr>
                <td colspan="2"><a id="submit" href="javascript:void(0)" class="btn"><span><?php echo $lang['nc_submit'];?></span></a></td>
            </tr>
            </tfoot>
        </table>
    </form>
</div>

<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/jquery-ui/jquery.ui.js"></script>
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/dialog/dialog.js" id="dialog_js" charset="utf-8"></script>
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/jquery.edit.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        //添加标签
        $('#btn_add_home_tab').on('click', function() {
            $('#dialog_add_mb_home_tab').nc_show_dialog({title: '添加标签'});
        });

        //提交
        $("#submit").click(function(){
            $("#add_form").submit();
        });

        $('#add_form').validate({
            errorPlacement: function(error, element){
                error.appendTo(element.parents('tr').prev().find('td:first'));
            },
            rules : {
                tab_name : {
                    required : true,
                    maxlength : 20
                }
            },
            messages : {
                tab_name : {
                    required  : "专题描述不能为空",
                    maxlength : "专题描述最多20个字"
                }
            }
        });

        //删除专题
        $('[nctype="del_tab"]').on('click', function() {
            if(confirm('确认删除?')) {
                $('#del_special_id').val($(this).attr('data-special-id'));
                $('#del_form').submit();
            }
        });

        //编辑标签名称
        $('span[nc_type="edit_tab_name"]').inline_edit({act: 'mb_special',op: 'update_tab_name'});
        //编辑标签排序
        $('span[nc_type="edit_tab_sort"]').inline_edit({act: 'mb_special',op: 'update_tab_sort'});
    });
</script>
