截流自动化的商城平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lists.html 10.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. {layout name="layout1" /}
  2. <div class="wrapper">
  3. <div class="layui-card">
  4. <!-- 操作提示 -->
  5. <div class="layui-card-body">
  6. <div class="layui-collapse" style="border:1px dashed #c4c4c4">
  7. <div class="layui-colla-item">
  8. <h2 class="layui-colla-title like-layui-colla-title">操作提示</h2>
  9. <div class="layui-colla-content layui-show">
  10. <p>*可对社区话题管理,用户发布文章时需要选择对应的话题.话题下关联文章则不允许删除话题</p>
  11. </div>
  12. </div>
  13. </div>
  14. </div>
  15. <!-- 搜索区域 -->
  16. <div class="layui-card-body layui-form">
  17. <div class="layui-form-item">
  18. <div class="layui-inline">
  19. <label for="name" class="layui-form-label">话题名称:</label>
  20. <div class="layui-input-inline">
  21. <input type="text" id="name" name="name" autocomplete="off" class="layui-input">
  22. </div>
  23. </div>
  24. <div class="layui-inline">
  25. <label for="cate" class="layui-form-label">话题分类:</label>
  26. <div class="layui-input-inline">
  27. <select name="cid" id="cate">
  28. <option value="">全部</option>
  29. {volist name="cate" id="vo"}
  30. <option value="{$vo.id}">{$vo.name}</option>
  31. {/volist}
  32. </select>
  33. </div>
  34. </div>
  35. <div class="layui-inline">
  36. <a class="layui-btn layui-btn-sm layui-btn-normal" lay-submit lay-filter="search">搜索</a>
  37. <a class="layui-btn layui-btn-sm layui-btn-primary" lay-submit lay-filter="clear-search">重置</a>
  38. </div>
  39. </div>
  40. </div>
  41. <!-- 主体区域 -->
  42. <div class="layui-card-body">
  43. <button type="button" class="layui-btn layui-btn-normal layui-btn-sm layEvent" lay-event="add">新增话题</button>
  44. <table id="like-table-lists" lay-filter="like-table-lists"></table>
  45. <script type="text/html" id="table-operation">
  46. <a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="edit">编辑</a>
  47. <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a>
  48. </script>
  49. <script type="text/html" id="showTpl">
  50. <input type="checkbox" lay-filter="switch-show" data-id={{d.id}} lay-skin="switch"
  51. lay-text="显示|隐藏" {{# if(d.is_show==1){ }} checked {{# } }}/>
  52. </script>
  53. <script type="text/html" id="recommendTpl">
  54. <input type="checkbox" lay-filter="switch-recommend" data-id={{d.id}} lay-skin="switch"
  55. lay-text="是|否" {{# if(d.is_recommend==1){ }} checked {{# } }}/>
  56. </script>
  57. <script type="text/html" id="table-image">
  58. {{# if(d.image){ }}
  59. <img src="{{d.image}}" class="image-show" alt="图" style="width:80px;height:80px;">
  60. {{# } }}
  61. </script>
  62. </div>
  63. </div>
  64. </div>
  65. <script>
  66. layui.use(["table", "form"], function(){
  67. var table = layui.table;
  68. var form = layui.form;
  69. like.tableLists("#like-table-lists", "{:url()}", [
  70. {field:"name", align:"center", title:"话题名称"}
  71. ,{field:"image", align:"center", title:"话题图标", templet: "#table-image"}
  72. ,{field:"cate_name", align:"center", title:"关联分类"}
  73. ,{field:"article_num", align:"center", title:"文章数量"}
  74. ,{field:"sort", align:"center", title:"排序"}
  75. ,{field:"is_recommend", align:"center", title:"是否推荐", templet: "#recommendTpl"}
  76. ,{field:"is_show", align:"center", title:"是否显示", templet: "#showTpl"}
  77. ,{title:"操作", align:"center", fixed:"right", toolbar:"#table-operation"}
  78. ]);
  79. var active = {
  80. add: function() {
  81. layer.open({
  82. type: 2
  83. ,title: "新增话题"
  84. ,content: "{:url('community.CommunityTopic/add')}"
  85. ,area: ["90%", "90%"]
  86. ,btn: ["确定", "取消"]
  87. ,yes: function(index, layero){
  88. var iframeWindow = window["layui-layer-iframe" + index];
  89. var submit = layero.find("iframe").contents().find("#addSubmit");
  90. iframeWindow.layui.form.on("submit(addSubmit)", function(data){
  91. like.ajax({
  92. url: "{:url('community.CommunityTopic/add')}",
  93. data: data.field,
  94. type: "POST",
  95. success:function(res) {
  96. if(res.code === 1) {
  97. layui.layer.msg(res.msg, {offset: '15px', icon: 1, time: 1000});
  98. layer.close(index);
  99. table.reload("like-table-lists", {
  100. where: {},
  101. page: { cur: 1 }
  102. });
  103. }
  104. }
  105. });
  106. });
  107. submit.trigger("click");
  108. }
  109. });
  110. },
  111. edit: function(obj) {
  112. layer.open({
  113. type: 2
  114. ,title: "编辑话题"
  115. ,content: "{:url('community.CommunityTopic/edit')}?id=" + obj.data.id
  116. ,area: ["90%", "90%"]
  117. ,btn: ["确定", "取消"]
  118. ,yes: function(index, layero){
  119. var iframeWindow = window["layui-layer-iframe" + index];
  120. var submit = layero.find("iframe").contents().find("#addSubmit");
  121. iframeWindow.layui.form.on("submit(addSubmit)", function(data){
  122. data.field['id'] = obj.data.id;
  123. like.ajax({
  124. url: "{:url('community.CommunityTopic/edit')}",
  125. data: data.field,
  126. type: "POST",
  127. success:function(res) {
  128. if(res.code === 1) {
  129. layui.layer.msg(res.msg, {offset: '15px', icon: 1, time: 1000});
  130. layer.close(index);
  131. table.reload("like-table-lists", {
  132. where: {},
  133. page: { cur: 1 }
  134. });
  135. }
  136. }
  137. });
  138. });
  139. submit.trigger("click");
  140. }
  141. });
  142. },
  143. del: function(obj) {
  144. var cateName = "<span style='color: red'>"+obj.data.name+"</span>";
  145. layer.confirm("确定删除话题:"+cateName, function(index) {
  146. like.ajax({
  147. url: "{:url('community.CommunityTopic/del')}",
  148. data: {id: obj.data.id},
  149. type: "POST",
  150. success: function (res) {
  151. if (res.code === 1) {
  152. layui.layer.msg(res.msg, {offset: '15px', icon: 1, time: 1000});
  153. layer.close(index);
  154. obj.del();
  155. }
  156. }
  157. });
  158. layer.close(index);
  159. })
  160. }
  161. };
  162. like.eventClick(active);
  163. //图片放大
  164. $(document).on('click', '.image-show', function () {
  165. var src = $(this).attr('src');
  166. like.showImg(src,400);
  167. });
  168. form.on("submit(search)", function(data){
  169. table.reload("like-table-lists", {
  170. where: data.field,
  171. page: {
  172. curr: 1
  173. }
  174. });
  175. });
  176. form.on("submit(clear-search)", function(){
  177. $("#name").val("");
  178. $("#cate").val("");
  179. form.render("select");
  180. table.reload("like-table-lists", {
  181. where: {},
  182. page: {
  183. curr: 1
  184. }
  185. });
  186. });
  187. // 状态切换
  188. form.on('switch(switch-show)', function (obj) {
  189. var id = obj.elem.attributes['data-id'].nodeValue;
  190. var show = 0;
  191. if (obj.elem.checked) {
  192. show = 1;
  193. }
  194. var data = {field: 'is_show', value:show, id: id};
  195. updateField(data);
  196. });
  197. // 状态切换
  198. form.on('switch(switch-recommend)', function (obj) {
  199. var id = obj.elem.attributes['data-id'].nodeValue;
  200. var recommend = 0;
  201. if (obj.elem.checked) {
  202. recommend = 1;
  203. }
  204. var data = {field: 'is_recommend', value:recommend, id: id};
  205. updateField(data);
  206. });
  207. function updateField(data) {
  208. like.ajax({
  209. url: '{:url("community.CommunityTopic/status")}',
  210. data: data,
  211. type: "post",
  212. success: function (res) {
  213. if (res.code === 1) {
  214. layui.layer.msg(res.msg, {offset: '15px', icon: 1, time: 1000});
  215. }
  216. }
  217. });
  218. }
  219. })
  220. </script>