{include file="public/header" /}
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>{$Think.lang.goods_class_index_class}</h3>
            </div>
        </div>
    </div>

<form id="goods_class_form" name="goodsClassForm" enctype="multipart/form-data" method="post">
    <input type="hidden" name="form_submit" value="ok" />
    <input type="hidden" name="gc_id" value="{$class_info.gc_id}" />
    <div class="ncap-form-default">
      <dl class="row">
        <dt class="tit">
          <label class="cn_name" for="cn_name">分类别名</label>
        </dt>
        <dd class="opt">
          <input type="text" maxlength="20"  value="{present name='cn_alias'}{$nav_info.cn_alias}{/present}" name="cn_alias" id="cn_alias" class="input-txt">
          <span class="err"></span>
          <p class="notic">可选项。设置别名后，别名将会替代原分类名称展示在分类导航菜单列表中。</p>
        </dd>
      </dl>
      <dl class="row">
        <dt class="tit">
          <label><em>*</em>推荐分类</label>
        </dt>
        <dd class="opt">
          <div> 分类下的三级分类 <a class="ncap-btn" nctype="class_hide" href="javascript:void(0);">隐藏未选项</a></div>
          <div id="class_div" class="scrollbar-box">
            <div class="ncap-type-spec-list">
              <?php if (!empty($third_class)) {?>
              <?php foreach ($third_class as $key => $val) {?>
              <dl>
                <dt id="class_dt_<?php echo $key;?>"><?php echo $val['name'];?></dt>
                <?php if (!empty($val['class'])) {?>
                <dd>
                  <?php foreach ($val['class'] as $k => $v) {?>
                  <label for="class_<?php echo $k;?>">
                    <input type="checkbox" name="class_id[]" value="<?php echo $k;?>" <?php if(!empty($nav_info['cn_classids']) && in_array($k, $nav_info['cn_classids'])){ echo 'checked="checked"';}?>>
                    <?php echo $v;?> </label>
                  <?php }?>
                </dd>
                <?php }?>
              </dl>
              <?php }?>
              <?php }?>
            </div>
          </div>
          <p class="notic">推荐分类将在展开后的二、三级导航列表上方突出显示，建议根据分类名称长度控制选择数量不超过8个以确保展示效果。</p>
        </dd>
      </dl>
      <dl class="row">
        <dt class="tit">
          <label><em>*</em>推荐品牌</label>
        </dt>
        <dd class="opt">
          <div id="brandcategory">快捷定位
            <select class="class-select">
              <option value="0">{$Think.lang.ds_please_choose}</option>
              <?php if(!empty($gc_list)){ ?>
              <?php foreach($gc_list as $k => $v){ ?>
              <?php if ($v['gc_parent_id'] == 0) {?>
              <option value="<?php echo $v['gc_id'];?>"><?php echo $v['gc_name'];?></option>
              <?php } ?>
              <?php } ?>
              <?php } ?>
            </select>
            分类下对应的品牌 <a class="ncap-btn" nctype="brand_hide" href="javascript:void(0);">隐藏未选项</a></div>
          <div id="brand_div" class="scrollbar-box">
            <div class="ncap-type-spec-list">
              <?php if(is_array($brand_list) && !empty($brand_list)) {?>
              <?php foreach ($brand_list as $k=>$val){?>
              <dl>
                <dt id="brand_dt_<?php echo $k;?>"><?php echo $val['name'];?></dt>
                <?php if($val['brand']) {?>
                <dd>
                  <?php foreach ($val['brand'] as $bval){?>
                  <label for="brand_<?php echo $bval['brand_id'];?>">
                    <input type="checkbox" name="brand_id[]" value="{defined name='cn_brandids'}<?php echo $bval['brand_id']?>" <?php if(in_array($bval['brand_id'], $nav_info.cn_brandids)){ echo 'checked="checked"';}?> id="brand_<?php echo $bval['brand_id'];?>{/defined}" />
                    <?php echo $bval['brand_name']?></label>
                  <?php }?>
                </dd>
                <?php }?>
              </dl>
              <?php }?>
              <?php }else{?>
              <div><?php echo lang('type_add_brand_null_one');?><a href="JavaScript:void(0);" onclick="window.parent.openItem('shop|brand')"><?php echo lang('nc_brand_manage');?></a><?php echo lang('type_add_brand_null_two')?></div>
              <?php }?>
            </div>
          </div>
          <p class="notic">推荐品牌将在展开后的二、三级导航列表右侧突出显示，建议选择数量为8个具有图片的品牌，超过将被隐藏。</p>
        </dd>
      </dl>
      <dl class="row">
        <dt class="tit">
          <label for="pic">广告1图</label>
        </dt>
        <dd class="opt">
          <div class="input-file-show-shop"><span class="show"><a class="nyroModal" rel="gal" href="{defined name='cn_adv1'}<?php echo $nav_info.cn_adv1;?>{/defined}"> <i class="fa fa-picture-o"></i> </a></span><span class="type-file-box-shop">
            <input class="type-file-file" id="adv1" name="adv1" type="file" size="30" nc_type="change_pic" hidefocus="true" title="点击前方预览图可查看大图，点击按钮选择文件并提交表单后上传生效">
            <input type="text" name="textfield" id="textfield2" class="type-file-text" />
            <input type="button" name="button" id="button1" value="" class="type-file-button" />
            </span></div>
          <label title="分类导航广告图1-跳转链接" for="cn_adv1_link" class="ml5"><i class="fa fa-link"></i>
            <input type="text" value="{defined name='cn_adv1_link'}<?php echo $nav_info.cn_adv1_link;?>{/defined}" name="cn_adv1_link" id="cn_adv1_link" class="input-txt ml5">
          </label>
          <p class="notic">广告图片将展示在推荐品牌下方，请使用宽度190像素，高度150像素的jpg/gif/png格式图片作为分类导航广告上传，<br/>
            如需跳转请在后方添加以http://开头的链接地址。</p>
        </dd>
      </dl>
      <dl class="row">
        <dt class="tit">
          <label for="pic">广告2图</label>
        </dt>
        <dd class="opt">
          <div class="input-file-show-shop"><span class="show"><a class="nyroModal" rel="gal" href="{defined name='cn_adv2'}<?php echo $nav_info.cn_adv2;?>{/defined}"> <i class="fa fa-picture-o"></i> </a></span><span class="type-file-box-shop">
            <input class="type-file-file" id="adv2" name="adv2" type="file" size="30" nc_type="change_pic" hidefocus="true" title="点击前方预览图可查看大图，点击按钮选择文件并提交表单后上传生效">
            <input type="text" name="textfield" id="textfield3" class="type-file-text" />
            <input type="button" name="button" id="button1" value="" class="type-file-button" />
            </span></div>
          <label for="cn_adv2_link" title="分类导航广告图2-跳转链接" class="ml5"><i class="fa fa-link"></i>
            <input type="text" value="{defined name='cn_adv2'}<?php echo $nav_info.cn_adv2_link;?>{/defined}" name="cn_adv2_link" id="cn_adv2_link" class="input-txt ml5">
          </label>
          <p class="notic">广告图片将展示在推荐品牌下方，请使用宽度190像素，高度150像素的jpg/gif/png格式图片作为分类导航广告上传，<br/>
            如需跳转请在后方添加以http://开头的链接地址。</p>
        </dd>
      </dl>
      <div class="bot"><a href="JavaScript:void(0);" class="btn btn-big btn-green" id="submitBtn">{$Think.lang.ds_submit;}</a></div>
    </div>
  </form>
</div>
<script src="{:config('url_domain_root')}static/plugins/perfect-scrollbar.min.js"></script>
<script src="{:config('url_domain_root')}static/plugins/js/jquery.nyroModal/custom.min.js"></script>
<script src="{:config('url_domain_root')}static/common/js/mlselection.js"></script>
<script>
$(function(){
    $('#submitBtn').on('click',function () {
        $('#goods_class_form').submit();
    });
//自动加载滚动条
    $('#class_div').perfectScrollbar();
    $('#brand_div').perfectScrollbar();

// 点击查看图片
    $('.nyroModal').nyroModal();
    //按钮先执行验证再提交表单
    $("#submitBtn").click(function(){

        if($("#goods_class_form").valid()){
            $("#goods_class_form").submit();
        }
    });

    $("#pic").change(function(){
        $("#textfield1").val($(this).val());
    });
    $("#adv1").change(function(){
        $("#textfield2").val($(this).val());
    });
    $("#adv2").change(function(){
        $("#textfield3").val($(this).val());
    });

    // 类型搜索
    $("#brandcategory > select").on('change',function(){
        brand_scroll($(this));
    });

    // 品牌隐藏未选项
    $('a[nctype="brand_hide"]').on('click',function(){
        checked_hide('brand');
    });
    // 品牌全部显示
    $('a[nctype="brand_show"]').on('click',function(){
        checked_show('brand');
    });
    // 子级分类隐藏未选项
    $('a[nctype="class_hide"]').on('click',function(){
        checked_hide('class');
    });
    // 子级分类全部显示
    $('a[nctype="class_show"]').on('click',function(){
        checked_show('class');
    });
});
var brandScroll = 0;
function brand_scroll(o){
    var id = o.val();
    if(!$('#brand_dt_'+id).is('dt')){
        return false;
    }
    $('#brand_div').scrollTop(-brandScroll);
    var sp_top = $('#brand_dt_'+id).offset().top;
    var div_top = $('#brand_div').offset().top;
    $('#brand_div').scrollTop(sp_top-div_top);
    brandScroll = sp_top-div_top;
}


//隐藏未选项
function checked_show(str) {
    $('#'+str+'_div').find('dt').show().end().find('label').show();
    $('#'+str+'_div').find('dl').show();
    $('a[nctype="'+str+'_show"]').attr('nctype',str+'_hide').html('隐藏未选项');
    $('#'+str+'_div').perfectScrollbar('destroy').perfectScrollbar();
}

//显示全部选项
function checked_hide(str) {
    $('#'+str+'_div').find('dt').hide();
    $('#'+str+'_div').find('input[type="checkbox"]').parents('label').hide();
    $('#'+str+'_div').find('input[type="checkbox"]:checked').parents('label').show();
    $('#'+str+'_div').find('dl').each(function(){
        if ($(this).find('input[type="checkbox"]:checked').length == 0 ) $(this).hide();
    });
    $('a[nctype="'+str+'_hide"]').attr('nctype',str+'_show').html('显示未选项');
    $('#'+str+'_div').perfectScrollbar('destroy').perfectScrollbar();
}
gcategoryInit('brandcategory');
</script>