<?php 
  include '../core/core.php';
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>代刷网SEO后台管理</title>
  <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/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../public/static/layuiadmin/style/admin.css" media="all">
  <script src="../public/static/jquery-3.5.1.min.js"></script>
</head>
<body>
<div class="layui-form layui-form-pane">
  <?php 
    if($act=='edit' && $id){
      $classInfo = $DB->getRow("SELECT * FROM `pre_class` WHERE `id`='".$id."'");
      if(!$classInfo){
        admin_error();
      }
      $path = $classInfo['path'];
      $title = $classInfo['title'];
      $word = $classInfo['word'];
    }
  ?>
        <div id="isShow" style="display:">
          <div class="layui-form-item">
            <label class="layui-form-label">分类目录</label>
            <div class="layui-input-inline">
              <input type="text" name="path" required="" value="<?php echo $path;?>" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">分类名称</label>
            <div class="layui-input-inline">
              <input type="text" name="title" required="" value="<?php echo $title;?>" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">关键词（每个用,隔开）</label>
            <div class="layui-input-block">
              <textarea placeholder="多个用,隔开比如：我爱你,你爱我,我也爱你" name="word" class="layui-textarea"><?php echo $word;?></textarea>
            </div>
          </div>
          <div class="layui-form-item" style="text-align: center;">
            <?php 
                if($act=='add'){
                  echo ' <button class="layui-btn" lay-submit="" lay-filter="classAdd">立即添加</button>';
                }elseif($act=='edit' && $id){
                  echo ' <button class="layui-btn" lay-submit="" lay-filter="classEdit">立即修改</button>';
                }
             ?>
          </div>
        </div>
</div>


<script src="../public/static/layuiadmin/layui/layui.all.js"></script>
  <script>
  layui.config({
      base: '../public/static/layuiadmin/' //静态资源所在路径
    }).extend({
      index: 'lib/index' //主入口模块
    }).use(['index','form','table'], function(){
      var $ = layui.$
      ,table = layui.table
      ,layedit = layui.layedit
      ,laydate = layui.laydate
      ,form = layui.form
      ,admin = layui.admin
      ,element = layui.element
      ,layer = layui.layer;
      element.render();

      form.on('submit(classAdd)', function(data){
        path = data.field.path;
        title = data.field.title;
        word = data.field.word;
        var load = layer.load({time:false});
        $.ajax({
              url: "./ajax.php?act=classAdd",
              data: {path,title,word},
              type: "GET",
              dataType: "json",
              success: function(data){
                  layer.close(load);
                  if(data.code==1){
                    layer.msg(data.msg,{icon:6});
                  }else{
                    layer.msg(data.msg,{icon:5});
                  }
              },
              error: function(data){
                  layer.close(load);
                  layer.msg("未知错误");
              }
          });
      });

      form.on('submit(classAdd)', function(data){
        path = data.field.path;
        title = data.field.title;
        word = data.field.word;
        var load = layer.load({time:false});
        $.ajax({
              url: "./ajax.php?act=classAdd",
              data: {path,title,word},
              type: "POST",
              dataType: "json",
              success: function(data){
                  layer.close(load);
                  if(data.code==1){
                      layer.msg(data.msg,{icon:6});
                    }else{
                      layer.msg(data.msg,{icon:5});
                    }
              },
              error: function(data){
                  layer.close(load);
                  layer.msg("未知错误");
              }
          });
      });

      form.on('submit(classEdit)', function(data){
        id = $_GET['id'];
        path = data.field.path;
        title = data.field.title;
        word = data.field.word;
        var load = layer.load({time:false});
        $.ajax({
              url: "./ajax.php?act=classEdit",
              data: {id,path,title,word},
              type: "POST",
              dataType: "json",
              success: function(data){
                  layer.close(load);
                  if(data.code==1){
                      layer.msg(data.msg,{icon:6});
                    }else{
                      layer.msg(data.msg,{icon:5});
                    }
              },
              error: function(data){
                  layer.close(load);
                  layer.msg("未知错误");
              }
          });
      });
});

  </script>
<?php 
  include 'foot.php';
?>