knowledge.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. layui.use([ 'laypage', 'layer', 'table', 'element','form','treetable'], function(){
  2. var laypage = layui.laypage //分页
  3. ,$ = layui.jquery
  4. ,layer = layui.layer //弹层
  5. ,table = layui.table //表格
  6. ,form = layui.form
  7. ,treetable = layui.treetable;
  8. if($('#menulist').attr('lay-filter') == 'menulist'){
  9. var renderTable = function (wheres = {}) {
  10. treetable.render({
  11. treeColIndex: 1,
  12. treeSpid:0,
  13. treeIdName: 'id',
  14. treePidName: 'pid',
  15. treeDefaultClose: true,
  16. treeLinkage: false,
  17. elem: '#menulist',
  18. url: '/dictionarynews/labelform',
  19. page: false,
  20. where:wheres,
  21. id:'tablerReload',
  22. cols: [[
  23. {type:'numbers'}
  24. // {field: 'id', title: 'ID', width:80, sort: true,align:'center'}
  25. ,{field: 'name', title: '栏目名称',align:'center'},
  26. {field: 'sort', title: '排序',width:80, edit: 'text',align:'center',sort: true,templet:"#sortBox"},
  27. // ,{field: 'sort', title: '排序',align:'center',sort: true},
  28. {field: 'is_show', title: '审核',width:100, align:'center', templet:"#Toexamine",templet:function(d){
  29. if(d.is_show == 2){
  30. return '<input type="checkbox" value="'+d.id+'" name="'+d.is_show+'" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  31. } else {
  32. return '<input type="checkbox" checked value="'+d.id+'" name="'+d.is_show+'" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  33. }
  34. }}
  35. ,{field: 'create_at', title: '添加时间', width:200,align:'center'}
  36. ,{fixed: 'right',title:'操作', width: 165, align:'center', toolbar: '#operate'}
  37. ]],
  38. done: function () {
  39. layer.closeAll('loading');
  40. }
  41. });
  42. };
  43. renderTable();
  44. }
  45. //列表操作
  46. table.on('tool(menulist)', function(obj){
  47. var layEvent = obj.event,
  48. data = obj.data;
  49. if(layEvent === 'edit'){
  50. layer.open({
  51. type: 2,
  52. title: '编辑',
  53. closeBtn: 1, //不显示关闭按钮
  54. shade: [0],
  55. area: ['600px', '500px'],
  56. anim: 2,
  57. content: '/dictionarynews/editlabel?id='+data.id, //iframe的url,no代表不显示滚动条
  58. end:function () {
  59. renderTable();
  60. }
  61. });
  62. } else if(layEvent === 'del') {
  63. layer.confirm('您确定要删除吗?',{btn:['确认','取消']},function(){
  64. $.post('/dictionarynews/editlabelform',{data:{id:data.id,del:2}},function (data) {
  65. if(data.data != null){
  66. layer.msg(ReturnInfo(data.data),{icon:5});
  67. return false;
  68. }
  69. layer.msg(data.msg);
  70. renderTable();
  71. })
  72. })
  73. }
  74. });
  75. var $ = layui.$, active = {
  76. addDatas: function(){ //获取选中数据
  77. layer.open({
  78. type: 2,
  79. title: '新增栏目',
  80. closeBtn: 1, //不显示关闭按钮
  81. shade: [0],
  82. area: ['600px', '500px'],
  83. anim: 2,
  84. content: '/dictionarynews/labelcreate',
  85. end: function(){
  86. renderTable();
  87. }
  88. });
  89. },
  90. reload:function () {
  91. var form = pfgs_serialize($('form'));
  92. var city = '';
  93. if(form.province != ''){
  94. city = form.province;
  95. }
  96. if(form.city != ''){
  97. city = form.city;
  98. }
  99. renderTable({id:city});
  100. }
  101. };
  102. $('.demoTable .layui-btn').on('click', function(){
  103. var type = $(this).data('type');
  104. active[type] ? active[type].call(this) : '';
  105. });
  106. //修改排序
  107. table.on('edit(menulist)', function(obj){
  108. var data = obj.data;
  109. $.post('/dictionarynews/editlabelform',{data:{id:data.id,sort:data.sort}},function (data) {
  110. if(data.data != null){
  111. layer.msg(ReturnInfo(data.data),{icon:5});
  112. return false;
  113. }
  114. layer.msg(data.msg);
  115. renderTable();
  116. })
  117. })
  118. //显示或隐藏
  119. form.on('switch(switchTest)', function(data){
  120. var state = '';
  121. if(data.elem.name == 1){
  122. state = 2;
  123. }else if(data.elem.name == 2){
  124. state = 1;
  125. }
  126. layer.confirm('确定要修改此操作吗?',{btn: ['确定', '取消']},function () {
  127. $.post('/dictionarynews/editlabelform',{data:{id:data.value,is_show:state}},function (data) {
  128. if(data.data != null){
  129. layer.msg(ReturnInfo(data.data),{icon:5});
  130. return false;
  131. }
  132. layer.msg(data.msg);
  133. renderTable();
  134. })
  135. },function (aa) {
  136. renderTable();
  137. })
  138. });
  139. //修改
  140. form.on('submit(editlabel)', function(data){
  141. $.post('/dictionarynews/editlabelform',{'data':data.field},function (data) {
  142. layer.msg(data.msg);
  143. })
  144. return false;
  145. });
  146. //添加
  147. form.on('submit(addlabel)', function(data){
  148. $.post('/dictionarynews/labelcreateform',{'data':data.field},function (data) {
  149. if(data.data != null){
  150. layer.msg(ReturnInfo(data.data),{icon:5});
  151. return ;
  152. }
  153. layer.msg(data.msg);
  154. })
  155. return false;
  156. });
  157. //加载省数据
  158. function loadProvince() {
  159. $.ajax({
  160. url : '/dictionarynews/pidlist',
  161. type : 'post',
  162. async: false,//使用同步的方式,true为异步方式
  163. data : {'pid':0},//这里使用json对象
  164. success : function(data){
  165. var areaData = data.data;
  166. var proHtml = '';
  167. for (var i = 0; i < areaData.length; i++) {
  168. proHtml += '<option value="' + areaData[i].id +'">' + areaData[i].name + '</option>';
  169. }
  170. //初始化省数据
  171. $('select[name=province]').append(proHtml);
  172. form.render();
  173. },
  174. fail:function(){
  175. }
  176. });
  177. }
  178. loadProvince();
  179. form.on('select(province)',function (data) {
  180. $.post('/dictionarynews/pidlist',{'pid':data.value},function (data) {
  181. $('select[name=city]').html('');
  182. var proHtml = '<option value="">请选择子栏目</option>';
  183. if(data.code == 200){
  184. var areaData = data.data;
  185. for (var i = 0; i < areaData.length; i++) {
  186. proHtml += '<option value="' + areaData[i].id +'">' + areaData[i].name + '</option>';
  187. }
  188. //初始化省数据
  189. $('select[name=city]').append(proHtml);
  190. }
  191. form.render();
  192. })
  193. })
  194. });