<?php /*a:1:{s:69:"/www/wwwroot/666.u7u.top/application/ohbbs/view/assortment/index.html";i:1551420528;}*/ ?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/public/static/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/public/static/css/admin.css" media="all">
</head>
<body>
  
<div class="layui-fluid">
  <div class="layui-row layui-col-space10">
    <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-body tpwz-table-full">
            <div class="tpwz-pad-t10 tpwz-pad-l10 tpwz-bom-10 reloadForm">
              <a href="<?php echo url('add'); ?>" class="layui-btn addkey">添加分类</a>
              <div class="layui-btn layui-btn-primary" data-type="getCheckData">删除分类</div>
            </div>
          	<table id="res" lay-filter="res"></table>
  	        <script type="text/html" id="barDemo">
                <a href="<?php echo url('edit'); ?>?id={{d.id}}" class="layui-btn layui-btn-xs" style="color: #fff;">编辑</a>
  	            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" style="color: #fff;">删除</a>
  	        </script>
            <script type="text/html" id="checkboxTpl">
              <input type="checkbox" name="status" value="{{d.id}}" title="显示" lay-filter="lockDemo" {{ d.status == 1 ? 'checked' : '' }}>
            </script>
          </div>
        </div>
      </div>
    </div>
  </div>
<script src="/public/static/skin/js/jquery.min.js"></script>
<script src="/public/static/layui/layui.js"></script>
<script>
layui.config({
  base: '/public/static/modules/'
}).extend({
  wz: 'wz'
});
layui.use(['wz','table','form'], function () {
    var table = layui.table;
    var form = layui.form;
    var wz = layui.wz;
    table.render({
        elem: '#res'
        , url: '<?php echo url("api/assortment/getAssortment"); ?>'
        , id: 'resReload'
        , page: true
        , limit: 10
        , cols: [[
        	  {type:'checkbox',fixed: 'left'}
            , {field: 'sort', title: '分类排序', edit: 'text', width: 100, sort: true}
            , {field: 'name', title: '分类名称', edit: 'text'}
            , {field: 'title', title: '所属菜单'}
            , {field:'lock', title:'是否显示', width:120, templet: '#checkboxTpl', unresize: true}
            , {field: 'create_time', title: '提交时间', width: 230}
            , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 120}
        ]]
    });
    table.on('tool(res)',function(obj){
        var data = obj.data;
        var layEvent =obj.event;
        var tr = obj.tr;
        if (layEvent === 'del'){
            layer.confirm('真的删除吗？',{icon: 2,skin: 'layui-layer-admin-modal'},function(index){
                obj.del();
                layer.close(index);
                $.ajax({
                    type: "post",
                    url: "<?php echo url('del'); ?>?id="+data.id,
                    async: true
                });
            });
        }
    });
    form.on('checkbox(lockDemo)', function(obj){
      if (obj.elem.checked == true) {
        var value = 1;
      }else{
        var value = 0;
      }
      $.post("<?php echo url('getedit'); ?>", {'id':this.value,'status': value}, function (data) {
          if (data.code == 1) {
              layer.msg(data.msg, {time: 2000}, function () {
                  location.href = data.url;
              });
          } else {
              layer.msg(data.msg, {time: 2000});
          }
      });
    });
  	table.on('edit(res)', function(obj){
  		var value = obj.value //得到修改后的值
  		,data = obj.data //得到所在行所有键值
  		,field = obj.field; //得到字段
  		$.post("<?php echo url('getedit'); ?>", data, function (data) {
  		    if (data.code == 1) {
  		        layer.msg(data.msg, {time: 2000}, function () {
  		            location.href = data.url;
  		        });
  		    } else {
  		        layer.msg(data.msg, {time: 2000});
  		    }
  		});
  	});
	  var $ = layui.$, reloadActive = {
	    getCheckData: function(){ //获取选中数据
	      	var checkStatus = table.checkStatus('resReload');
      		if(checkStatus.data.length==0){
      		layer.msg('请先选择要删除的数据行！', {icon: 2});
      			return ;
      		}
      		var ids = "";
      		for(var i=0;i<checkStatus.data.length;i++){
      			ids += checkStatus.data[i].id+",";
      		}
      		layer.msg('删除中...', {icon: 2});
      		$.post("<?php echo url('alldel'); ?>", {'ids':ids}, function (data) {
      		    if (data.code == 1) {
      		        layer.msg(data.msg, {time: 2000}, function () {
      		            location.href = data.url;
      		        });
      		    } else {
      		        layer.msg(data.msg, {time: 2000});
      		    }
      		});
	    }
	  };
    $('.reloadForm .layui-btn').on('click',function(){
        var type = $(this).data('type');
        reloadActive[type] ? reloadActive[type].call(this): '';
    });
});
</script>
</body>
</html>

