{extend name="public:base" /}
{block name="css"}
<style type="text/css">
.layui-table-body, .layui-table-box, .layui-table-cell{
overflow: visible;
}
 
/* 设置下拉框的高度与表格单元相同 */
 td .layui-table-cell .layui-form-select {
	margin-top: -10px;
	margin-left: -15px;
	margin-right: -15px;
}

</style>
{/block}
{block name="body"}
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-header layuiadmin-card-header-auto">
	  {if condition="checkRuleButton('forum/addtags')"}
        <button class="layui-btn layuiadmin-btn-tags" data-type="add">添加</button>
		{/if}
      </div>
      <div class="layui-card-body">    
        <table id="LAY-app-content-tags" lay-filter="LAY-app-content-tags"></table>
		<script type="text/html" id="inputSel">
			<select name="detpl"  lay-filter="detpl" id="{{d.id}}" >
			{volist name="template" id="vo"}
				<option value="{$vo}" {{# if (d.detpl == "{$vo}"){ }} selected {{# } }}>{$vo}</option>
			{/volist}
			</select>
		</script>
		<script type="text/html" id="buttonHot">
		{if condition="checkRuleButton('Forum/tagshot')"}<input type="checkbox" name="is_hot" lay-skin="primary" lay-filter="menu-show" {{# if(d.is_hot ==1){ }}checked value="0"{{#  } else { }}value="1"{{#  } }} id="{{d.id}}" >
		{else /}<input type="checkbox" title="禁用" disabled> {/if}
        </script>
        <script type="text/html" id="layuiadmin-app-cont-tagsbar">
		{if condition="checkRuleButton('forum/tagsform')"}
          <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></a>
		{else /}<a class="layui-btn layui-btn-disabled layui-btn-normal layui-btn-xs"><i class="layui-icon layui-icon-edit"></i></a>{/if}
        {if condition="checkRuleButton('forum/tagsdelete')"} 
		  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i></a>
		{else /}<a class="layui-btn layui-btn-disabled layui-btn-danger layui-btn-xs"><i class="layui-icon layui-icon-delete"></i></a>{/if}
        </script>
      </div>
    </div>
  </div>

{/block}

{block name="js"}
  <script>
  var forumList = "{:url('Forum/list')}",
      forumListdel = "{:url('Forum/listdel')}",
      forumListform = "{:url('Forum/listform')}",
      forumReplys = "{:url('Forum/replys')}",
      forumRedel = "{:url('Forum/redel')}",
      forumReplysform = "{:url('Forum/replysform')}",
      forumTags = "{:url('Forum/tags')}",
      forumTagsDelete = "{:url('Forum/tagsdelete')}",
      forumTagsForm = "{:url('Forum/tagsform')}";
  layui.config({
    base: '/static/admin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'forum', 'table','form'], function(){

    var table = layui.table,
	form = layui.form;
    var $ = layui.$, active = {
      add: function(){
        layer.open({
          type: 2
          ,title: '添加分类'
          ,content: 'tagsform.html'
          ,area: ['400px', '450px']
          ,btn: ['确定', '取消']
          ,yes: function(index, layero){
            var othis = layero.find('iframe').contents().find("#layuiadmin-app-form-tags")
            ,sort = othis.find('input[name="sort"]').val()
            ,tags = othis.find('input[name="tags"]').val()
            ,ename = othis.find('input[name="ename"]').val()
			,detpl = othis.find('select[name="detpl"]').val()
			,icon = othis.find('input[name="icon"]').val()
            ,desc = othis.find('input[name="desc"]').val();
            
            if(!tags.replace(/\s/g, '')) return;
			
        $.ajax({
				type:"post",
				url:"{:url('Forum/tagsform')}",
				data:{"sort":sort,"catename":tags,"ename":ename,"detpl":detpl,"icon":icon,"desc":desc},
				daType:"json",
				success:function (data){
					if (data.code == 0) {
						layer.msg(data.msg,{icon:6,time:2000});
					} else {
						layer.open({title:'添加失败',content:data.msg,icon:5,anim:6});
					}
				}
			});
            table.reload('LAY-app-content-tags');
            layer.close(index);
          }
        }); 
      }
    }
	
	//详情页模板选择控制
	form.on('select(detpl)', function(data){
	var detpl = data.value;
	$.post("{:url('Forum/tplSet')}",{"id":data.elem.id,"detpl":detpl});
	//执行重载
      table.reload('LAY-app-content-tags', {
        where: detpl
      });
	});


//分类热点控制
	form.on('checkbox(menu-show)', function(data){
	var data = data.elem;
	data.value = data.checked ? 1 : 0;
	$.ajax({
			type:'post',
			url:"{:url('Forum/tagshot')}",
			data:{"id":data.id,"is_hot":data.value,},
			dataType:'json',
			success:function(data){
				if(data.code == 0){
					layer.msg(data.msg,{icon:6,time:2000});
				} else {
					layer.open({title:'修改失败',content:data.msg,icon:5,adim:6});
				}
			}
		});
	return false;
	});

	
    $('.layui-btn.layuiadmin-btn-tags').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  });
  </script>
{/block}
