knowledge.js 7.3 KB

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