{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>类型管理</h3>
                <h5></h5>
            </div>
            {include file="public/admin_items" /}
        </div>
    </div>
    <form class="" method="post">

        <div class="ncap-form-default">
            <dl>
                <dt></dt>
                <dd>
                    <div id="gcategory" class="default_select">
                        <input type="hidden" name="class_id" value="{$type.class_id}" class="mls_id" />
                        <input type="hidden" name="class_name" value="{$type.class_name}" class="mls_name" />
                        {if $type.class_id}
                        <span>{$type.class_name}</span>
                        <input type="button" value="{$Think.lang.ds_edit}" class="edit_gcategory" />
                        {/if}
                        <select {if $type.class_id}style="display:none"{/if}>
                            <option value="0">请选择分类</option>
                            {volist name="gc_list" id="gc"}
                            <option value="{$gc.gc_id}">{$gc.gc_name}</option>
                            {/volist}
                        </select>
                    </div>
                </dd>
            </dl>
            <dl>
                <dt>{$Think.lang.type_name}</dt>
                <dd>
                    <input type="text" name="type_name" id="type_name" value="{$type.type_name}" />
                    <span class="err"></span>
                    <p class="notic"></p>
                </dd>
            </dl>
            <dl>
                <dt>{$Think.lang.type_sort}</dt>
                <dd>
                    <input type="text" name="type_sort" id="type_sort" value="{$type.type_sort}" />
                    <span class="err"></span>
                    <p class="notic"></p>
                </dd>
            </dl>
            <dl>
                <dt>选择相关品牌</dt>
                <dd>
                </dd>
            </dl>
            {if $brand_list}
            {volist name="brand_list" id="brand_gc"}
            <dl>
                <dt>{$brand_gc.name}</dt>
                <dd>
                    {volist name="brand_gc.brand" id="brand"}
                    <input type="checkbox" id="brand_{$brand.brand_id}" value="{$brand.brand_id}" name="brand_id[]"  <?php if(in_array($brand['brand_id'], $brang_related)){ echo 'checked="checked"';}?> />
                           <label for="brand_{$brand.brand_id}">{$brand.brand_name}</label>
                    {/volist}
                </dd>
            </dl>
            {/volist}
            {/if}
            <dl>
                <dt>选择相关规格</dt>
                <dd>
                </dd>
            </dl>
            {if $spec_list}
            {volist name="spec_list" id="spec_gc"}
            <dl>
                <dt>{$spec_gc.name}</dt>
                <dd>
                    {volist name="spec_gc.spec" id="spec"}
                    <input type="checkbox" id="spec_{$spec.sp_id}" value="{$spec.sp_id}" name="spec_id[]" <?php if(in_array($spec['sp_id'], $spec_related)){ echo 'checked="checked"';}?>/>
                           <label for="spec_{$spec.sp_id}">{$spec.sp_name}</label>
                    {/volist}
                </dd>
            </dl>
            {/volist}
            {/if}
        </div>


        <table class="ds-default-table">
            <thead>
                <tr>
                    <th width="100">删除</th>
                    <th width="100">排序</th>
                    <th width="200">属性名称</th>
                    <th>属性可选值</th>
                    <th width="100">显示</th>
                    <th width="100">操作</th>
                </tr>
            </thead>
            <tbody id="tr_model">
                <tr></tr>
                {if $attr_list}
                {volist name="attr_list" id="attr"}
                <tr>
            <input type="hidden" value="" name="at_value[{$attr.attr_id}][form_submit]" />
            <input type="hidden" value="{$attr.attr_id}" name="at_value[{$attr.attr_id}][attr_id]" />
            <td><input type="checkbox" name="a_del[{$attr.attr_id}]" value="{$attr.attr_id}" /></td>
            <td><input type="text" class="form-control" name="at_value[{$attr.attr_id}][sort]" value="{$attr.attr_sort}"/></td>
            <td><input type="text" class="form-control" name="at_value[{$attr.attr_id}][name]" value="{$attr.attr_name}"/></td>
            <td>{$attr.attr_value}</td>
            <td><input type="checkbox" name="at_value[{$attr.attr_id}][show]" {if $attr.attr_show} checked="checked" {/if} /></td>
            <td>
                <a href="{:url('/admin/type/attr_edit',['attr_id'=>$attr.attr_id])}">编辑</a>
            </td>
            </tr>
            {/volist}
            {/if}
            </tbody>
            <tbody>
                <tr>
                    <td>
                        <a id="add_type" class="btn-add marginleft" href="JavaScript:void(0);"> <span>添加一个属性</span> </a>
                    </td>
                </tr>
            </tbody>
        </table>
        <input class="btn" type="submit" value="提交"/>
    </form>
</div>
<!--载入-->
<script src="{$Think.config.url_domain_root}static/common/js/mlselection.js"></script>
<script>
    $(function() {
        gcategoryInit("gcategory");
        $(function() {
            gcategoryInit("gcategory");
            var i = 0;
            var tr_model = '<tr><td></td>' +
                    '<td><input type="text" class="form-control" name="at_value[key][sort]" value="0" /></td>' +
                    '<td><input type="text" class="form-control" name="at_value[key][name]" value="" /></td>' +
                    '<td><textarea rows="5" cols="80" class="form-control" name="at_value[key][value]"></textarea></td>' +
                    '<td><input type="checkbox" name="at_value[key][show]" checked="checked" /></td>' +
                    '<td><a onclick="remove_tr($(this));" href="JavaScript:void(0);">移除</a></td>' +
                    '</tr>';
            $("#add_type").click(function() {
                $('#tr_model > tr:last').after(tr_model.replace(/key/g, i));
                i++;
            });
        });
    });
    function remove_tr(o) {
        o.parents('tr:first').remove();
    }
</script>
</body>