record.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. var page = 1;
  2. var totalPages = 0;
  3. var param1 = '';
  4. var param2 = '';
  5. var param3 = '';
  6. // 数据统计及责任人下拉 start
  7. getStaticAndSelectAjax();
  8. function getStaticAndSelectAjax(queryParam = {}) {
  9. ajaxRequest(RECORD_STATIC_AND_SELECT, "POST", queryParam, function(result) {
  10. let data = result.RESULT1;
  11. $('#xjrysl').html(result.xjrysl)
  12. $('#jrrw').html(result.jrrw)
  13. $('#csrw').html(result.csrw)
  14. $('#jrwcrw').html(result.jrwcrw)
  15. let items = '';
  16. data.forEach(function(item, key) {
  17. items += `<option value="${item.person_liable_id}">${item.name}</option>`
  18. })
  19. $('#zrr').append(items);
  20. }, function(errorMsg) {
  21. alert("请求数据失败!");
  22. })
  23. }
  24. // 数据统计end
  25. //列表渲染
  26. getListDataAjax();
  27. //获取列表 ajax请求
  28. function getListDataAjax(queryParam = {}, page = 1) {
  29. queryParam.page = page;
  30. queryParam.limit = 4; //每页显示条数
  31. queryParam.start = 0; //每页显示条数
  32. ajaxRequest(RECORD_LIST, "POST", queryParam, function(result) {
  33. let data = result.RESULT;
  34. let items = '';
  35. if (result.totalCount > 0) {
  36. data.forEach(function(item, key) {
  37. items += "<tr>" +
  38. "<td class='status' data-id=" + item.id + "></td>" +
  39. "<td>" + item.xh + "</td>" +
  40. "<td>" + item.plan_name + "</td>" +
  41. "<td>查看</td>" +
  42. "<td>" + item.ywcsj + "</td>" +
  43. "<td>" + item.zt + "</td>" +
  44. "<td>" + item.completion + "</td>" +
  45. "<td>" + item.name + "</td>" +
  46. "<td>" + item.phone + "</td>" +
  47. "</tr>"
  48. })
  49. $('#dataList').html(items);
  50. }
  51. console.log(result)
  52. console.log(result.totalCount / result.limit)
  53. totalPages = result.totalCount / result.limit;
  54. $('#totalPage').html(totalPages); //总共多少页
  55. $('#dataTotal').html(result.totalCount); //总共多少条数据
  56. $('#currentPage').val(page); //当前页面
  57. let pageFrom = (page - 1) * result.limit + 1; //开始
  58. let pageTo = result.page * result.limit; //结束
  59. // pageTo = pageTo > result.totalCount ? result.totalCount : pageTo;
  60. $('#pageFrom').html(pageFrom);
  61. $('#pageTo').html(pageTo);
  62. // 无数据时
  63. if (!data.length) {
  64. $('.pager.has-data').hide()
  65. $('.pager.no-data').show()
  66. } else {
  67. $('.pager.has-data').show()
  68. $('.pager.no-data').hide()
  69. }
  70. if (page < totalPages) {
  71. $('#nextPageButton,#lastPageButton').removeClass('disabled');
  72. } else {
  73. $('#nextPageButton,#lastPageButton').addClass('disabled');
  74. }
  75. if (page === 1) {
  76. $('#firstPageButton,#prevPageButton').addClass('disabled');
  77. } else {
  78. $('#firstPageButton,#prevPageButton').removeClass('disabled');
  79. }
  80. }, function(errorMsg) {
  81. alert("请求数据失败!");
  82. })
  83. }
  84. //分页操作
  85. $('#firstPageButton').on('click', function() {
  86. page = 1;
  87. getListDataAjax(getSearchParamObj(), 1);
  88. })
  89. $('#lastPageButton').on('click', function() {
  90. page = totalPages;
  91. getListDataAjax(getSearchParamObj(), page);
  92. })
  93. $('#prevPageButton').on('click', function() {
  94. page -= 1;
  95. getListDataAjax(getSearchParamObj(), page);
  96. })
  97. $('#nextPageButton').on('click', function() {
  98. page += 1;
  99. getListDataAjax(getSearchParamObj(), page);
  100. })
  101. //按钮搜索
  102. $('#buttonSearch').on('click', function() {
  103. page = 1;
  104. getListDataAjax(getSearchParamObj());
  105. param1 = $('#time_start').val()
  106. param2 = $('#time_end').val()
  107. param3 = $('#clzt').val()
  108. })
  109. //拼接搜索条件
  110. function getSearchParamObj() {
  111. let queryParam = {};
  112. let time_start = $('#time_start').val();
  113. let time_end = $('#time_end').val()
  114. let clzt = $('#clzt').val()
  115. queryParam.time_start = time_start;
  116. queryParam.time_end = time_end;
  117. queryParam.clzt = clzt;
  118. return queryParam;
  119. }
  120. //重置表单
  121. $('.reset').click(resetForm);
  122. //分页刷新按钮
  123. $('.pg-refresh').click(resetForm);
  124. //重置表单
  125. function resetForm() {
  126. page = 1;
  127. $("#clzt").val("");
  128. $("#time_start").val("");
  129. $("#time_end").val("");
  130. getListDataAjax(getSearchParamObj());
  131. param1 = $('#time_start').val()
  132. param2 = $('#time_end').val()
  133. param3 = $('#clzt').val()
  134. }
  135. //单位下拉
  136. getNameList()
  137. //单位下拉 ajax请求
  138. function getNameList() {
  139. ajaxRequest(DEVICE_TYPE_COMPANYLIST, "POST", {}, function(result) {
  140. let data = result.RESULT;
  141. let items = '';
  142. data.forEach(function(item, key) {
  143. items += `<option value="${item.owner_id}">${item.owner_name}</option>`
  144. })
  145. $('#getNameList').append(items);
  146. $('#getNameList2').append(items);
  147. }, function(errorMsg) {
  148. alert("请求数据失败!");
  149. })
  150. }
  151. /*新增 修改 关闭 弹框*/
  152. var layer = layui.layer;
  153. var layerCreateIndex = '';
  154. var layerUpdateIndex = ''
  155. layui.use('layer', function() {
  156. //处置弹框信息
  157. $('.handle').click(function() {
  158. if (!$('.pure-table tr').has('.checked').length) {
  159. layer.msg('请选择一条需要修改的信息!', { icon: 5 });
  160. } else {
  161. //重新渲染表单
  162. $('#handleDataForm')[0].reset()
  163. layui.use(['form'], function() {
  164. var form = layui.form;
  165. form.render('radio');
  166. });
  167. let userInfo = $('.pure-table tr').find('.checked').data('user');
  168. $('.handleDataOut input[name=company_name]').val(userInfo.company_name)
  169. $('.handleDataOut input[name=name]').val(userInfo.name)
  170. $('.handleDataOut input[name=data]').val(userInfo.data)
  171. $('.handleDataOut input[name=id').val(userInfo.id)
  172. $('.handleDataOut input[name=dwtype]').val(userInfo.dwtype)
  173. $('.handleDataOut input[name=status]').val(userInfo.status)
  174. $('.handleDataOut input[name=device_code]').val(userInfo.device_code)
  175. $('.handleDataOut textarea[name=clnr]').val(userInfo.clnr)
  176. if (userInfo.clzt == "已处理") {
  177. $('.handleDataOut textarea[name=clnr]').attr({ readonly: 'true' })
  178. $('#handleUpdate').addClass('disabled')
  179. $('.handle-range').hide()
  180. $('.handleDataOut input[name=device_code]').val(userInfo.device_code)
  181. $('.handleDataOut input[name=clwb]').val(userInfo.clwb);
  182. $("input[type=radio]").attr("disabled", "true")
  183. if (userInfo.clwb == 0) {
  184. $("#no").prop("checked", true);
  185. } else {
  186. $("#yes").prop("checked", true);
  187. }
  188. layui.use(['form'], function() {
  189. var form = layui.form;
  190. form.render('radio');
  191. });
  192. } else {
  193. $('.handleDataOut textarea[name=clnr]').removeAttr("readonly")
  194. $("input[type=radio]").removeAttr("disabled")
  195. $('#handleUpdate').removeClass('disabled')
  196. $('.handle-range').show()
  197. layui.use(['form'], function() {
  198. var form = layui.form;
  199. form.render('radio');
  200. });
  201. }
  202. layerUpdateIndex = layer.open({
  203. type: 1,
  204. title: false,
  205. closeBtn: 0,
  206. shadeClose: true,
  207. skin: 'yourclass',
  208. area: ['410px', '440px'],
  209. content: $(".handleDataOut"),
  210. success: function() {
  211. $('.clsBtn,.cancel').click(function() {
  212. layer.close(layerUpdateIndex);
  213. })
  214. }
  215. });
  216. }
  217. })
  218. })
  219. /* 处置发送请求 */
  220. $('#handleUpdate').click(function() {
  221. //获取表单的值 并转换成对象
  222. let allParam = serializeArrayToObj($("#handleDataForm").serializeArray());
  223. //验证数据是否为空
  224. let res = validParamIsEmpty(allParam, {
  225. "clnr": "请输入处理内容",
  226. });
  227. if (res.code == -1) {
  228. alert(res.msg);
  229. return;
  230. }
  231. ajaxRequest(EVENT_DANGER_MANAGE_HANDLE, "POST", allParam, function(result) {
  232. layer.close(layerUpdateIndex);
  233. layer.msg('处置成功!', { icon: 6 });
  234. getListDataAjax();
  235. }, function(errorMsg) {
  236. alert("数据修改失败!");
  237. })
  238. })
  239. // 导出 start
  240. $('.export').click(function() {
  241. getDataExport({ "time_start": param1, "time_end": param2, "clzt": param3 })
  242. })
  243. function getDataExport(queryParam = {}) {
  244. // 输出base64编码
  245. const base64 = s => window.btoa(unescape(encodeURIComponent(s)));
  246. ajaxRequest(EVENT_DANGER_MANAGE_EXPORT, "POST", queryParam, function(result) {
  247. console.log(result.RESULT)
  248. let data = result.RESULT;
  249. let newData = [];
  250. if (data) {
  251. data.forEach(function(item, index) {
  252. var time = item.time.time ? getFormatDate(item.time.time) : '';
  253. var clsj = item.clsj.time ? getFormatDate(item.clsj.time) : '';
  254. newData.push({ orderIdx: item.orderIdx, company_name: item.company_name, time: time, data: item.data, data4: item.data4, fullname: item.fullname, clzt: item.clzt, clr: item.clr, clsj: clsj })
  255. });
  256. }
  257. let str = '<tr style="text-align:center"><th>序号</th><th>单位名称</th><th>上报时间</th><th>报告数据</th><th>告警值</th><th>报告内容</th><th>处理状态</th><th>处理人</th><th>处理时间</th></tr>';
  258. // 循环遍历,每行加入tr标签,每个单元格加td标签
  259. for (let i = 0; i < newData.length; i++) {
  260. str += '<tr style="text-align:center">';
  261. for (const key in newData[i]) {
  262. // 增加\t为了不让表格显示科学计数法或者其他格式
  263. str += `<td x:str>${ newData[i][key] + '\t'}</td>`;
  264. }
  265. str += '</tr>';
  266. }
  267. // Worksheet名
  268. const worksheet = 'Sheet1'
  269. const uri = 'data:application/vnd.ms-excel;base64,';
  270. // 下载的表格模板数据
  271. const template = `<html xmlns:o="urn:schemas-microsoft-com:office:office"
  272. xmlns:x="urn:schemas-microsoft-com:office:excel"
  273. xmlns="http://www.w3.org/TR/REC-html40">
  274. <head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>
  275. <x:Name>${worksheet}</x:Name>
  276. <x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet>
  277. </x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]-->
  278. </head><body><table>${str}</table></body></html>`;
  279. // 通过创建a标签实现
  280. const link = document.createElement("a");
  281. link.href = uri + base64(template);
  282. // 对下载的文件命名
  283. link.download = "隐患管理数据表.xls";
  284. link.click();
  285. }, function(errorMsg) {
  286. alert("请求数据失败!");
  287. })
  288. }
  289. // 导出 end