<div class="page">
  <div class="fixed-bar">
    <div class="item-title">
      <h3>自营店铺</h3>
      <ul class="tab-base">
        <li><a href="{:url('ownshop/list')}"><span>管理</span></a></li>
        <li><a href="{:url('ownshop/add')}"><span>新增</span></a></li>
        <li><a href="javascript:void(0);" class="current"><span>经营类目</span></a></li>
      </ul>
    </div>
  </div>
  <div class="fixed-empty"></div>
  
  
  <div class="explanation" id="explanation">
      <div class="title" id="checkZoom">
          <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
          <span id="explanationZoom" title="收起提示" class="arrow"></span>
      </div>
      <ul>
          <li>删除店铺的经营类目会造成相应商品下架，请谨慎操作</li>
          <li>所有修改即时生效</li>
      </ul>
  </div>

<form id="form_bd" name="" method="post" action="{:url('ownshop/bind_class',['id'=>$Request.param.id])}">
<input type="hidden" value="ok" name="form_submit">
  <table class="ds-default-table">
    <thead class="thead">
      <tr class="space">
        <th colspan="15">店铺名称：<?php echo $store_info.store_name;?></th>
      </tr>
    </thead>
    <thead>
      <tr class="thead">
        <th></th>
        <th>分类1</th>
        <th>分类2</th>
        <th>分类3</th>
        <th>分佣比例</th>
        <th class="align-center">{$Think.lang.ds_handle}</th>
      </tr>
    </thead>
    <tbody>
      <?php if(!empty($store_bind_class_list) && is_array($store_bind_class_list)){ ?>
      <?php foreach($store_bind_class_list as $key => $value){ ?>
      <tr class="hover edit">
        <td><input class="checkitem" type="checkbox" value="<?php echo $value['bid'];?>" name="bid[]"></td>
        <td class="w25pre"><?php echo $value['class_1_name'];?></td>
        <td class="w25pre"><?php echo $value['class_2_name'];?></td>
        <td class="w25pre"><?php echo $value['class_3_name'];?></td>
        <td class="sort"><span nc_type="commis_rate" column_id="<?php echo $value['bid'];?>" title="{$Think.lang.ds_editable}" class="editable " style="vertical-align: middle; margin-right: 4px;"><?php echo $value['commis_rate'];?></span>% </td>
        <td class="w60 align-center"><a nctype="btn_del_store_bind_class" href="javascript:;" data-bid="<?php echo $value['bid'];?>">删除</a></td>
      </tr>
      <?php } ?>
      <?php }else { ?>
      <tr class="no_data">
        <td colspan="10">{$Think.lang.ds_no_record}</td>
      </tr>
      <?php } ?>
    </tbody>
    <tfoot>
    <tr class="tfoot">
    <td>
    <input id="checkallBottom" class="checkall" type="checkbox">
    </td>
    <td colspan="15">
    <label for="checkallBottom">全选</label>
    <a class="btn" onclick="if(confirm('您确定要删除该店铺等级吗？')){$('#form_bd').submit();}" href="JavaScript:void(0);">
    <span>删除</span>
    </a>
    <?php if(!empty($store_bind_class_list) && is_array($store_bind_class_list)){ ?>
    <div class="pagination"><?php echo $showpage;?></div>
    <?php } ?>
    </td>
    </tr>
    </tfoot>
  </table>
  </form>
  <table class="table tb-type2" >
    <thead class="thead">
      <tr class="space">
        <th colspan="15"><span>添加经营类目</span></th>
      </tr>
    </thead>
    <tbody>
      <tr class="noborder">
        <td class="required" colspan="2" >选择分类：</td>
      </tr>
      <tr class="noborder">
        <td colspan="2" id="gcategory" class="vatop rowform"><select id="gcategory_class1" style="width: auto;">
            <option value="0">请选择</option>
            <?php if(!empty($gc_list) && is_array($gc_list) ) {?>
            <?php foreach ($gc_list as $gc) {?>
            <option value="<?php echo $gc['gc_id'];?>" data-explain="<?php echo $gc['commis_rate']; ?>"><?php echo $gc['gc_name'];?></option>
            <?php }?>
            <?php }?>
          </select><span id="error_message" style="color:red;"></span></td>
      </tr>
      <tr>
        <td class="required" colspan="2" >分佣比例(必须为0-100的整数)：</td>
      </tr>
      <tr class="noborder">
        <td class="vatop rowform"><form id="add_form" action="<?php echo urlAdmin('ownshop', 'bind_class_add');?>" method="post">
            <input name="store_id" type="hidden" value="<?php echo $store_info.store_id;?>">
            <input id="goods_class" name="goods_class" type="hidden" value="">
            <input id="commis_rate" name="commis_rate" class="w60" type="text" value="0" />
            % <span id="error_message1" style="color:red;"></span>
          </form></td>
        <td class="vatop tips"></td>
      </tr>
    </tbody>
    <tfoot>
      <tr>
        <td colspan="2"><a id="btn_add_category" class="btn" href="JavaScript:void(0);" /><span>确认</span></a></td>
      </tr>
    </tfoot>
  </table>
</div>

<script type="text/javascript" src="{:config('url_domain_root')}static/common/js/mlselection.js" charset="utf-8"></script>
<script type="text/javascript">
$(function(){
    gcategoryInit("gcategory");

    // 提交新添加的类目
    $('#btn_add_category').on('click', function() {
        $('#error_message').hide();
        $('#error_message1').hide();
        var category_id = '';
        var validation = true;
        $('#gcategory').find('select').each(function() {
            if(parseInt($(this).val(), 10) > 0) {
                category_id += $(this).val() + ',';
            }
        });
        if (parseInt($('#gcategory').find('select').eq(0).val()) == 0) {
        	validation = false;
        }
        if(!validation) {
            $('#error_message').text('请选择分类');
            $('#error_message').show();
            return false;
        }

        var commis_rate = parseInt($('#commis_rate').val(), 10);
        if(isNaN(commis_rate) || commis_rate < 0 || commis_rate > 100) {
            $('#error_message1').text('请填写正确的分佣比例');
            $('#error_message1').show();
            return false;
        }

        $('#goods_class').val(category_id);
        $('#add_form').submit();
    });

    $('#gcategory select').live('change', function() {
        var cr = $(this).children(':selected').attr('data-explain');
        $('#commis_rate').val(parseInt(cr) || 0);
    });

    // 删除现有类目
    $('[nctype="btn_del_store_bind_class"]').on('click', function() {
        if(confirm('确认删除？删除后店铺对应分类商品将全部下架')) {
            var bid = $(this).attr('data-bid');
            $this = $(this);
            $.post('<?php echo url('ownshop/bind_class_del');?>', {bid: bid}, function(data) {
                 if(data.result) {
                     $this.parents('tr').hide();
                 } else {
                     showError(data.message);
                 }
            }, 'json');
        }
    });

    // 修改分佣比例
    $('span[nc_type="commis_rate"]').inline_edit({act: 'ownshop',op: 'bind_class_update'});
});

</script>
