index.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. {extend name="public/container"}
  2. {block name="head"}
  3. <style>
  4. .single-line {
  5. padding: 0;
  6. border: none;
  7. background: none;
  8. }
  9. </style>
  10. {/block}
  11. {block name="content"}
  12. <div class="layui-fluid">
  13. <div class="layui-card">
  14. <div class="layui-card-header">课程分类</div>
  15. <div class="layui-card-body">
  16. <div class="layui-row layui-col-space15">
  17. <div class="layui-col-md12">
  18. <form class="layui-form layui-form-pane" action="">
  19. <div class="layui-form-item">
  20. <div class="layui-inline">
  21. <label class="layui-form-label">分类名称</label>
  22. <div class="layui-input-inline">
  23. <input type="text" name="name" class="layui-input" placeholder="请输入分类名称" autocomplete="off">
  24. </div>
  25. </div>
  26. <div class="layui-inline">
  27. <div class="layui-input-inline">
  28. <div class="layui-btn-group">
  29. <button class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="search" lay-filter="search">
  30. <i class="layui-icon">&#xe615;</i>搜索
  31. </button>
  32. </div>
  33. </div>
  34. </div>
  35. </div>
  36. </form>
  37. </div>
  38. <div class="layui-col-md12">
  39. <div class="layui-btn-group">
  40. <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" data-type="add">
  41. <i class="layui-icon">&#xe608;</i>添加分类
  42. </button>
  43. <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" data-type="refresh">
  44. <i class="layui-icon">&#xe669;</i>刷新
  45. </button>
  46. </div>
  47. <table id="List" lay-filter="List"></table>
  48. <script type="text/html" id="picture">
  49. {{# if(d.grade_id){ }}
  50. <img style="cursor: pointer;" src="{{d.pic}}" width="50" height="50" lay-event='open_image'>
  51. {{# } }}
  52. </script>
  53. <script type="text/html" id="is_show">
  54. <input type='checkbox' name='id' lay-skin='switch' value="{{d.id}}" lay-filter='is_show' lay-text='显示|隐藏' {{ d.is_show == 1 ? 'checked' : '' }}>
  55. </script>
  56. <script type="text/html" id="act">
  57. <button type="button" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">
  58. <i class="iconfont icon-bianji"></i>编辑
  59. </button>
  60. <button type="button" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">
  61. <i class="iconfont icon-shanchu"></i>删除
  62. </button>
  63. </script>
  64. </div>
  65. </div>
  66. </div>
  67. </div>
  68. </div>
  69. <script src="{__ADMIN_PATH}js/layuiList.js"></script>
  70. {/block}
  71. {block name="script"}
  72. <script>
  73. //实例化form
  74. layList.form.render();
  75. //加载列表
  76. layui.use(['treeTable'], function () {
  77. var $ = layui.jquery;
  78. var treeTable = layui.treeTable;
  79. var insTb = treeTable.render({
  80. elem: '#List',
  81. tree: {
  82. iconIndex: 1,
  83. isPidData: true,
  84. idName: 'id',
  85. pidName: 'grade_id',
  86. getIcon: function (d) {
  87. return '';
  88. }
  89. },
  90. cols: [[
  91. {field: 'id', title: '编号', align: 'center', width: 60},
  92. {field: 'name', title: '分类名称'},
  93. {field: 'pic', title: '图片', templet:'#picture', align: 'center'},
  94. {field: 'special_count', title: '专题数量', align: 'center'},
  95. {field: 'sort', title: '排序', align: 'center'},
  96. {field: 'is_show', title: '状态', templet:'#is_show', align: 'center'},
  97. {field: 'right', title: '操作',align:'center',toolbar:'#act'}
  98. ]],
  99. reqData: function(data, callback) {
  100. $.get('{:Url('get_subject_list')}', function (res) {
  101. if (res.code == 200) {
  102. callback(res.data)
  103. } else {
  104. callback(res.msg)
  105. }
  106. }, 'json');
  107. }
  108. });
  109. treeTable.on('tool(List)', function (obj) {
  110. var data = obj.data;
  111. var event = obj.event;
  112. if (event === 'del') {
  113. var url=layList.U({a:'delete',q:{id:data.id}});
  114. $eb.$swal('delete',function(){
  115. $eb.axios.get(url).then(function(res){
  116. if(res.status == 200 && res.data.code == 200) {
  117. $eb.$swal('success',res.data.msg);
  118. obj.del();
  119. }else
  120. return Promise.reject(res.data.msg || '删除失败')
  121. }).catch(function(err){
  122. $eb.$swal('error',err);
  123. });
  124. })
  125. }
  126. if (event === 'edit') {
  127. layui.layer.open({
  128. type: 2,
  129. title: '编辑',
  130. area: ['800px', '500px'],
  131. content: "{:Url('create')}?id=" + data.id,
  132. end: function () {
  133. window.location.reload();
  134. }
  135. });
  136. }
  137. });
  138. //查询
  139. layList.search('search',function (where) {
  140. insTb = treeTable.render({
  141. elem: '#List',
  142. tree: {
  143. iconIndex: 1,
  144. isPidData: true,
  145. idName: 'id',
  146. pidName: 'grade_id',
  147. getIcon: function (d) {
  148. return '';
  149. }
  150. },
  151. cols: [[
  152. {field: 'id', title: '编号', align: 'center', width: 60},
  153. {field: 'name', title: '分类名称'},
  154. {field: 'pic', title: '图片', templet:'#picture', align: 'center'},
  155. {field: 'special_count', title: '专题数量', align: 'center'},
  156. {field: 'sort', title: '排序', align: 'center'},
  157. {field: 'is_show', title: '状态', templet:'#is_show', align: 'center'},
  158. {field: 'right', title: '操作',align:'center',toolbar:'#act'}
  159. ]],
  160. reqData: function(data, callback) {
  161. $.get('{:Url('get_subject_list')}', where, function (res) {
  162. if (res.code == 200) {
  163. callback(res.data)
  164. } else {
  165. callback(res.msg)
  166. }
  167. }, 'json');
  168. }
  169. });
  170. });
  171. $('.layui-btn').on('click', function (event) {
  172. var type = event.target.dataset.type;
  173. if (type === 'refresh') {
  174. insTb.refresh();
  175. } else if (type === 'add') {
  176. layui.layer.open({
  177. type: 2,
  178. title: '添加分类',
  179. content: "{:Url('create')}",
  180. area: ['60%', '70%'],
  181. end: function () {
  182. window.location.reload();
  183. }
  184. });
  185. }
  186. });
  187. });
  188. //自定义方法
  189. var action= {
  190. set_value: function (field, id, value) {
  191. layList.baseGet(layList.Url({
  192. a: 'set_value',
  193. q: {field: field, id: id, value: value}
  194. }), function (res) {
  195. layList.msg(res.msg);
  196. });
  197. },
  198. };
  199. //是否显示快捷按钮操作
  200. layList.switch('is_show',function (odj,value) {
  201. if(odj.elem.checked==true){
  202. layList.baseGet(layList.Url({a:'set_show',p:{is_show:1,id:value}}),function (res) {
  203. layList.msg(res.msg);
  204. });
  205. }else{
  206. layList.baseGet(layList.Url({a:'set_show',p:{is_show:0,id:value}}),function (res) {
  207. layList.msg(res.msg);
  208. });
  209. }
  210. });
  211. </script>
  212. {/block}