information.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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: '#informationTable',
  10. url: '../../../getInformations',
  11. toolbar: '#toolbarDemo',
  12. title: '用户表',// 导出文件名
  13. id: 'informationTableAll',
  14. // 开启分页
  15. // page : true,
  16. page: {
  17. layout: ['count', 'prev', 'page', 'next', 'skip', 'limit']
  18. },
  19. limits: [10, 30, 50, 80, 100, 999],
  20. /*request : {
  21. 'limitName' : 'pageSize' // 分页每页条数默认字段改为pageSize
  22. },*/
  23. where: {
  24. type: '1',content: ''
  25. },
  26. cellMinWidth: 80, // 全局定义常规单元格的最小宽度,layui 2.2.1 新增
  27. cols: [[{
  28. type: 'numbers',
  29. title: '序号',
  30. width: 50,
  31. fixed: "left"
  32. }, {
  33. field: 'content',
  34. title: '内容',
  35. }, {
  36. field: 'type',
  37. align: 'center',
  38. width: 150,
  39. title: '类型'
  40. }, {
  41. field: 'createBy',
  42. align: 'center',
  43. width: 150,
  44. title: '创建人'
  45. }, {
  46. field: 'createDate',
  47. title: '创建时间',
  48. width: 220,
  49. align: 'center',
  50. templet: function (d) {
  51. return d.createDate != null ? layui.util.toDateString(d.createDate, "yyyy-MM-dd HH:mm:ss") : "";
  52. }
  53. }, {
  54. fixed: 'right',
  55. title: '操作',
  56. align: 'center',
  57. width: 150,
  58. toolbar: '#barDemo'
  59. }]],
  60. parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
  61. return {
  62. "code": 0, //解析接口状态
  63. "msg": "", //解析提示文本
  64. "count": res.data.list.total,//解析数据长度
  65. "data": res.data.list.list//解析数据列表
  66. };
  67. }
  68. });
  69. //点击查询按钮,重载表格
  70. $('#searchBtn').on('click', function () {
  71. table.reload('informationTableAll', {
  72. method: 'get',
  73. where: {
  74. content: $("#content").val()
  75. },
  76. page: {
  77. curr: 1
  78. }
  79. });
  80. return false;
  81. });
  82. // 监听头部工作栏的 新增
  83. table.on('toolbar(informationTable)', function (obj) {
  84. var checkStatus = table.checkStatus(obj.config.id);
  85. switch (obj.event) {
  86. case 'add':
  87. layer.open({
  88. type: 2,
  89. title: "添加问题",
  90. fix: false, //不固定
  91. maxmin: true,
  92. skin: 'layui-layer-molv',
  93. area: ['45%', '70%'],
  94. content: './addInformation.jsp',
  95. });
  96. break;
  97. }
  98. ;
  99. });
  100. function previewImage(textImage) {
  101. }
  102. // 监听 修改
  103. table.on('tool(informationTable)', function (obj) {
  104. var data1 = obj.data;
  105. console.log(data1)
  106. if (obj.event === 'edit') {
  107. layer.open({
  108. type: 2,
  109. title: "修改问题",
  110. area: ['45%', '70%'],
  111. skin: 'layui-layer-molv',
  112. content: './updateInformation.jsp',
  113. success: function (layero, index) {
  114. var body = layer.getChildFrame('body', index);
  115. var iframeWin = window[layero.find('iframe')[0]['name']]; // 得到iframe页的窗口对象
  116. body.find('#id').val(data1.id);
  117. body.find('#contentUpdate').val(data1.content);
  118. body.find('#type').val(data1.type);
  119. body.find('#images').val(data1.attachment);
  120. let textImage = data1.attachment;
  121. if (textImage) {
  122. let textImageList = textImage == "" ? [] : textImage.split(",");
  123. let html = "";
  124. textImageList.forEach((item, index) => {
  125. if (item != "" && (item.indexOf(".mp4") > -1 || item.indexOf(".MP4") > -1)) {
  126. html += "<video src='" + item + "' class='layui-upload-img' style='width: 50px;height: 50px;margin-right: 5px;' onclick='delImage(\"" + index + "\")'/>";
  127. } else if (item != "") {
  128. html += "<img src='" + item + "' class='layui-upload-img' style='width: 50px;height: 50px;margin-right: 5px;' onclick='delImage(\"" + index + "\")'/>";
  129. }
  130. })
  131. body.find("#preview").empty().append(html);
  132. }
  133. layui.form.render();
  134. }
  135. });
  136. } else if (obj.event === 'del') {
  137. layer.confirm('确定要删除该数据么?', {icon: 3, title: "提示"}, function (index) {
  138. $.ajax({
  139. url: "../../../deleteInformation",
  140. data: {'id': data1.id},
  141. type: "post",
  142. //dataType:"json",
  143. success: function (data) {
  144. if (data.code == 200) {
  145. layer.msg('删除成功!', {icon: 6, offset: "auto", time: 1000});//提示框
  146. } else {
  147. layer.msg('删除失败!', {icon: 5, offset: "auto", time: 1000});//提示框
  148. }
  149. setTimeout(function () {
  150. location.reload();//重新加载页面
  151. }, 1100);
  152. }
  153. });
  154. return false;
  155. });
  156. }
  157. })
  158. });