searchPro.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. layui.use([ 'element', 'table', 'laydate', 'form' ], function() {
  2. var $ = layui.jquery;
  3. var table = layui.table;
  4. var laydate = layui.laydate;
  5. var element = layui.element;
  6. var form = layui.form;
  7. // 生成表格
  8. table.render({
  9. elem : '#searchTable',
  10. url : '../../../getKeyWordsList',
  11. toolbar : '#toolbarDemo',
  12. title : '关键字表',// 导出文件名
  13. id : 'searchTableAll',
  14. // 开启分页
  15. page : {
  16. layout : [ 'count', 'prev', 'page', 'next', 'skip', 'limit' ]
  17. },
  18. /*request : {
  19. 'limitName' : 'pageSize' // 分页每页条数默认字段改为pageSize
  20. },*/
  21. where:{
  22. proTypeLabel :'',
  23. },
  24. cellMinWidth : 80, // 全局定义常规单元格的最小宽度,layui 2.2.1 新增
  25. cols : [ [ {
  26. type : 'numbers',
  27. title : '序号',
  28. width : 50,
  29. fixed : "left"
  30. },{
  31. field : 'proTypeLabel',
  32. width : 150,
  33. algin : 'center',
  34. title : '产品名称'
  35. },{
  36. field : 'likeProTypeLabel',
  37. title : '关键字',
  38. edit : 'text'
  39. },{
  40. field : 'url',
  41. title : '菜单URL',
  42. width : 250,
  43. edit : 'text'
  44. },{
  45. field : 'userStatus',
  46. title : '状态',
  47. width : 120,
  48. templet : '#statusTpl',
  49. },{
  50. field : 'createDate',
  51. title : '创建时间',
  52. width : 120,
  53. templet : function(d) {
  54. return d.createDate != null ?layui.util.toDateString(d.createDate, "yyyy-MM-dd") : "";
  55. }
  56. }, {
  57. field : 'updateDate',
  58. title : '更新时间',
  59. width : 120,
  60. templet : function(d) {
  61. return d.updateDate != null ?layui.util.toDateString(d.updateDate, "yyyy-MM-dd") : "";
  62. }
  63. } ] ],
  64. parseData : function(res) { //将原始数据解析成 table 组件所规定的数据
  65. return {
  66. "code" : 0, //解析接口状态
  67. "msg" : "", //解析提示文本
  68. "count" : res.total,//解析数据长度
  69. "data" : res.list//解析数据列表
  70. };
  71. }
  72. });
  73. //点击查询按钮,重载表格
  74. $('#searchBtn').on('click', function() {
  75. table.reload('searchTableAll', {
  76. method : 'post',
  77. where : {
  78. proTypeLabel : $("#proTypeLabel").val()
  79. },
  80. page : {
  81. curr : 1
  82. }
  83. });
  84. return false;
  85. });
  86. //监听状态按钮
  87. form.on('switch(statusDemo)', function(obj){
  88. layer.tips(this.value + ' ' + this.name + ':'+ obj.elem.checked, obj.othis);
  89. $.ajax({
  90. url : "../../../changeKeyWordsStatus",
  91. dataType : 'json',
  92. data : {
  93. 'id':obj.value
  94. },
  95. type : 'post',
  96. success : function(data) {
  97. if (data.code == 200) {
  98. layer.msg('状态修改成功!',{icon:6,offset:"auto",time:2000});//提示框
  99. }else{
  100. layer.msg('状态修改失败!',{icon:5,offset:"auto",time:2000});//提示框
  101. }
  102. setTimeout(function(){
  103. location.reload();//重新加载页面
  104. }, 2100);
  105. }
  106. })
  107. })
  108. // 监听头部工作栏的 新增
  109. table.on('toolbar(searchTable)', function(obj) {
  110. var checkStatus = table.checkStatus(obj.config.id);
  111. switch (obj.event) {
  112. case 'add':
  113. layer.open({
  114. type : 2,
  115. title : "添加产品关键字",
  116. fix: false, //不固定
  117. maxmin: true,
  118. area : [ '45%', '70%' ],
  119. content : './addSearchPro.jsp',
  120. });
  121. break;
  122. }
  123. ;
  124. });
  125. // 监听编辑关键字
  126. table.on('edit(searchTable)', function(obj){
  127. var value = obj.value, //得到修改后的值
  128. field = obj.field; //得到字段
  129. var data = obj.data,//得到所在行所有键值
  130. id = data.id;
  131. $.ajax({
  132. url:"../../../updateKeyWord",
  133. data:{
  134. id : id,
  135. value : value,
  136. field : field,
  137. },
  138. type:"post",
  139. //dataType:"json",
  140. success:function (data) {
  141. if (data.code == 200) {
  142. layer.msg('成功!',{icon:6,offset:"auto",time:1000});//提示框
  143. }else{
  144. layer.msg('失败!',{icon:5,offset:"auto",time:1000});//提示框
  145. }
  146. }
  147. });
  148. })
  149. });