index.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. {extend name="public/container"}
  2. {block name="content"}
  3. <div class="layui-fluid">
  4. <div class="layui-row layui-col-space15" id="app">
  5. <div class="layui-col-md12">
  6. <div class="layui-card">
  7. <div class="layui-card-header">搜索条件</div>
  8. <div class="layui-card-body">
  9. <form class="layui-form layui-form-pane" action="">
  10. <div class="layui-form-item">
  11. <div class="layui-inline">
  12. <label class="layui-form-label">所有分类</label>
  13. <div class="layui-input-block">
  14. <select name="is_show">
  15. <option value="">是否显示</option>
  16. <option value="1">显示</option>
  17. <option value="0">不显示</option>
  18. </select>
  19. </div>
  20. </div>
  21. <div class="layui-inline">
  22. <label class="layui-form-label">所有分类</label>
  23. <div class="layui-input-block">
  24. <select name="pid">
  25. <option value="">所有菜单</option>
  26. {volist name="cate" id="vo"}
  27. <option value="{$vo.id}">{$vo.html}{$vo.cate_name}</option>
  28. {/volist}
  29. </select>
  30. </div>
  31. </div>
  32. <div class="layui-inline">
  33. <label class="layui-form-label">产品名称</label>
  34. <div class="layui-input-block">
  35. <input type="text" name="cate_name" class="layui-input" placeholder="请输入分类名称">
  36. </div>
  37. </div>
  38. <div class="layui-inline">
  39. <div class="layui-input-inline">
  40. <button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit="search" lay-filter="search">
  41. <i class="layui-icon layui-icon-search"></i>搜索</button>
  42. </div>
  43. </div>
  44. </div>
  45. </form>
  46. </div>
  47. </div>
  48. </div>
  49. <!--产品列表-->
  50. <div class="layui-col-md12">
  51. <div class="layui-card">
  52. <div class="layui-card-header">分类列表</div>
  53. <div class="layui-card-body">
  54. <div class="alert alert-info" role="alert">
  55. 注:点击父级名称可查看子集分类,点击分页首页可返回顶级分类;分类名称和排序可进行快速编辑;
  56. <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  57. </div>
  58. <div class="layui-btn-container">
  59. <a class="layui-btn layui-btn-sm" href="{:Url('index')}">分类首页</a>
  60. <button type="button" class="layui-btn layui-btn-sm" onclick="$eb.createModalFrame(this.innerText,'{:Url('create')}')">添加分类</button>
  61. </div>
  62. <table class="layui-hide" id="List" lay-filter="List"></table>
  63. <script type="text/html" id="pic">
  64. {{# if(d.pic){ }}
  65. <img style="cursor: pointer" lay-event='open_image' src="{{d.pic}}">
  66. {{# }else{ }}
  67. 暂无图片
  68. {{# } }}
  69. </script>
  70. <script type="text/html" id="is_show">
  71. <input type='checkbox' name='id' lay-skin='switch' value="{{d.id}}" lay-filter='is_show' lay-text='显|隐' {{ d.is_show == 1 ? 'checked' : '' }}>
  72. </script>
  73. <script type="text/html" id="pid">
  74. <a href="{:Url('index')}?pid={{d.id}}">查看</a>
  75. </script>
  76. <script type="text/html" id="act">
  77. <button class="layui-btn layui-btn-xs" onclick="$eb.createModalFrame('编辑','{:Url('edit')}?id={{d.id}}')">
  78. <i class="fa fa-edit"></i> 编辑
  79. </button>
  80. <button class="layui-btn btn-danger layui-btn-xs" lay-event='delstor'>
  81. <i class="fa fa-times"></i> 删除
  82. </button>
  83. </script>
  84. </div>
  85. </div>
  86. </div>
  87. </div>
  88. </div>
  89. <script src="{__ADMIN_PATH}js/layuiList.js"></script>
  90. {/block}
  91. {block name="script"}
  92. <script>
  93. setTimeout(function () {
  94. $('.alert-info').hide();
  95. },3000);
  96. //实例化form
  97. layList.form.render();
  98. //加载列表
  99. layList.tableList('List',"{:Url('category_list',['pid'=>$pid])}",function (){
  100. return [
  101. {field: 'id', title: 'ID', sort: true,event:'id',width:'4%',align:'center'},
  102. {field: 'pid_name', title: '父级',align:'center'},
  103. {field: 'cate_name', title: '分类名称',edit:'cate_name',align:'center'},
  104. {field: 'pid', title: '查看子分类',templet:'#pid',align:'center',width:'8%'},
  105. {field: 'pic', title: '分类图标',templet:'#pic',align:'center'},
  106. {field: 'sort', title: '排序',sort: true,event:'sort',edit:'sort',width:'8%',align:'center'},
  107. {field: 'is_show', title: '状态',templet:'#is_show',width:'10%',align:'center'},
  108. {field: 'right', title: '操作',align:'center',toolbar:'#act',width:'10%',align:'center'},
  109. ];
  110. });
  111. //自定义方法
  112. var action= {
  113. set_category: function (field, id, value) {
  114. layList.baseGet(layList.Url({
  115. c: 'store.store_category',
  116. a: 'set_category',
  117. q: {field: field, id: id, value: value}
  118. }), function (res) {
  119. layList.msg(res.msg);
  120. });
  121. },
  122. }
  123. //查询
  124. layList.search('search',function(where){
  125. layList.reload(where,true);
  126. });
  127. layList.switch('is_show',function (odj,value) {
  128. if(odj.elem.checked==true){
  129. layList.baseGet(layList.Url({c:'store.store_category',a:'set_show',p:{is_show:1,id:value}}),function (res) {
  130. layList.msg(res.msg);
  131. });
  132. }else{
  133. layList.baseGet(layList.Url({c:'store.store_category',a:'set_show',p:{is_show:0,id:value}}),function (res) {
  134. layList.msg(res.msg);
  135. });
  136. }
  137. });
  138. //快速编辑
  139. layList.edit(function (obj) {
  140. var id=obj.data.id,value=obj.value;
  141. switch (obj.field) {
  142. case 'cate_name':
  143. action.set_category('cate_name',id,value);
  144. break;
  145. case 'sort':
  146. action.set_category('sort',id,value);
  147. break;
  148. }
  149. });
  150. //监听并执行排序
  151. layList.sort(['id','sort'],true);
  152. //点击事件绑定
  153. layList.tool(function (event,data,obj) {
  154. switch (event) {
  155. case 'delstor':
  156. var url=layList.U({c:'store.store_category',a:'delete',q:{id:data.id}});
  157. $eb.$swal('delete',function(){
  158. $eb.axios.get(url).then(function(res){
  159. if(res.status == 200 && res.data.code == 200) {
  160. $eb.$swal('success',res.data.msg);
  161. obj.del();
  162. }else
  163. return Promise.reject(res.data.msg || '删除失败')
  164. }).catch(function(err){
  165. $eb.$swal('error',err);
  166. });
  167. })
  168. break;
  169. case 'open_image':
  170. $eb.openImage(data.pic);
  171. break;
  172. }
  173. })
  174. </script>
  175. {/block}