classif.html 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>layui</title>
  6. <meta name="renderer" content="webkit">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  8. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  9. <link rel="stylesheet" href="../lib/layui-v2.5.4/css/layui.css" media="all">
  10. <link rel="stylesheet" href="../css/public.css" media="all">
  11. <style>
  12. .inoutCls {
  13. height: 22px;
  14. line-height: 22px;
  15. padding: 0 5px;
  16. font-size: 12px;
  17. background-color: #1E9FFF;
  18. max-width: 80px;
  19. border: none;
  20. color: #fff;
  21. margin-left: 10px;
  22. display: inline-block;
  23. white-space: nowrap;
  24. text-align: center;
  25. border-radius: 2px;
  26. cursor: pointer;
  27. }
  28. </style>
  29. </head>
  30. <body>
  31. <div class="layuimini-container">
  32. <div class="layuimini-main">
  33. <button type="button" class="layui-btn add">添 加</button>
  34. <div class="layui-form" style="margin-top: 20px;">
  35. <table class="layui-table">
  36. <colgroup>
  37. <col width="90">
  38. <col width="110">
  39. <col width="800">
  40. <col width="130">
  41. <col width="70">
  42. <col width="85">
  43. </colgroup>
  44. <thead>
  45. <tr>
  46. <th>id</th>
  47. <th>一级分类</th>
  48. <th class="text-center">二 / 三级分类</th>
  49. <th class="text-center">创建时间</th>
  50. <th class="text-center">状 态</th>
  51. <th>操作管理</th>
  52. </tr>
  53. </thead>
  54. <tbody>
  55. <!--一级类目循环-->
  56. <tr>
  57. <td>
  58. <div class="layui-input-inline">
  59. <input type="text" value="1" data-id="1" class="changeSort layui-input">
  60. </div>
  61. </td>
  62. <td>
  63. <div class="layui-input-inline">
  64. <input type="text" name="p0" autocomplete="off" class="layui-input" value="一级类目"
  65. onchange="editCls(this,id=1,ptype=1)">
  66. </div>
  67. </td>
  68. <td>
  69. <!--二级类目循环 start-->
  70. <div class="layui-input-block" style="margin-left: 0;">
  71. <button data-ptype="2" type="button"
  72. class="layui-btn layui-btn-primary layui-btn-sm del-child"
  73. style="border: none;"><i class="layui-icon"></i></button>
  74. <div class="layui-input-inline">
  75. <input type="text" name="p1" style="background: #ffb800;" autocomplete="off"
  76. class="inoutCls" onchange="editCls(this,id=1,ptype=2)" value="二级类目">
  77. </div>
  78. <!-- 三级类目循环 start-->
  79. <div class="layui-input-inline">
  80. --<input type="text" name="p1" autocomplete="off" class="inoutCls"
  81. onchange="editCls(this,id=1,ptype=3)" value="1。1">
  82. </div>
  83. <div class="layui-input-inline">
  84. --<input type="text" name="p1" autocomplete="off" class="inoutCls"
  85. onchange="editCls(this,id=1,ptype=3)" value="1。2">
  86. </div>
  87. <div class="layui-input-inline">
  88. --<input type="text" name="p1" autocomplete="off" class="inoutCls"
  89. onchange="editCls(this,id=1,ptype=3)" value="1。3">
  90. </div>
  91. <!-- 三级类目循环 end-->
  92. </div>
  93. <!--二级类目循环 end-->
  94. </td>
  95. <td>2019-11-20 10:40</td>
  96. <td data-id="1"><input type="checkbox" checked="" name="status" lay-skin="switch"
  97. lay-filter="switchTest"
  98. lay-text="ON|OFF">
  99. </td>
  100. <td>
  101. <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete del-child" data-ptype="1"
  102. lay-event="delete" data-id="$id">删除</a>
  103. </td>
  104. </tr>
  105. <!--一级类目循环 end-->
  106. </tbody>
  107. </table>
  108. </div>
  109. <div id="pages"></div>
  110. </div>
  111. </div>
  112. <script src="../lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
  113. <script src="../lib/layui-v2.5.4/layui.js" charset="utf-8"></script>
  114. <script src="../js/common.js?v5" charset="utf-8"></script>
  115. <!-- 注意:如果你直接复制所有代码到本地,上述js路径需要改成你本地的 -->
  116. <script>
  117. layui.use(['form', 'laypage'], function () {
  118. var form = layui.form
  119. , laypage = layui.laypage;
  120. laypage.render({ //分页
  121. elem: 'pages'
  122. , count: 100
  123. , theme: '#FFB800'
  124. });
  125. // 添加 分类
  126. $('.add').on('click', function () {
  127. layObj.dialog('dialog.html')
  128. });
  129. //监听状态 更改
  130. form.on('switch(switchTest)', function (obj) {
  131. console.log(obj.elem.checked, '改变状态')
  132. let id = obj.othis.parent().attr('data-id');
  133. let status = obj.elem.checked ? 1 : 0;
  134. $.ajax({
  135. url: '{:u("admin/change")}?id=' + id + '&status=' + status,
  136. success: (res) => {
  137. }
  138. });
  139. return false;
  140. });
  141. function editCls(that, id, type) { // 分类修改 type 是 1 顶级 2级 3级
  142. let name = $(that).val();
  143. if (!name && (type == 1 || type == 2)) {
  144. return layObj.msg('分类名称不能为空')
  145. }
  146. if (!name && type == 3) { // 演示 应该放到修改回调中 进行处理
  147. return $(that).parent().remove()
  148. }
  149. let url = '{:u("admin/edit")}?id=' + id + '&name=' + name
  150. layObj.get(url, (res) =>{
  151. if (name && res) {
  152. $(that).val(name)
  153. }
  154. })
  155. $.ajax({
  156. url: '{:u("admin/edit")}?id=' + id + '&name=' + name,
  157. success(res) {
  158. if (name && res) {
  159. $(that).val(name)
  160. }
  161. }
  162. })
  163. }
  164. // 删除二级分类
  165. $('.del-child').on('click', function () {
  166. let ptype = $(this).attr('data-ptype'); // fu
  167. let id = $(this).attr('data-id'); // fu
  168. let msg = '';
  169. if (ptype == 1) { // 等级类目
  170. msg = '一';
  171. } else if (ptype == 2) {
  172. msg = '二';
  173. }
  174. layObj.box(`是否删除${msg}级分类`, () => {
  175. let url = '{:u("admin/del")}?id=' + id
  176. layObj.get(url, (res) =>{
  177. $(this).parent().remove()
  178. })
  179. })
  180. })
  181. $('.changeSort').on('change',function () {
  182. let id = $(this).attr('data-id');
  183. let val = $(this).val();
  184. if(!val){
  185. return;
  186. }
  187. // let url = '{:u("admin/sort")}?id=' + id + '&sort='+val;
  188. let url = 'http:www.baidu.com';
  189. layObj.get(url,function (res) {
  190. console.log(res, 'sort');
  191. })
  192. })
  193. })
  194. </script>
  195. </body>
  196. </html>