point.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. var page = 1;
  2. var totalPages = 0;
  3. var param1 = '';
  4. var param2 = '';
  5. //列表渲染
  6. getListDataAjax();
  7. //获取列表ajax请求
  8. function getListDataAjax(queryParam = {}, page = 1) {
  9. queryParam.page = page;
  10. queryParam.limit = 20; //每页显示条数
  11. queryParam.start = (queryParam.page - 1) * queryParam.limit;
  12. ajaxRequest(POINT_LIST, "POST", queryParam, function(result) {
  13. let data = result.RESULT;
  14. let items = '';
  15. if (result.totalCount > 0) {
  16. data.forEach(function(item, key) {
  17. items += "<tr>" +
  18. "<td class='status' data-user='" + JSON.stringify(item) + "' data-id='" + item.id + "'></td>" +
  19. "<td>" + item.xh + "</td>" +
  20. "<td>" + item.spot_name + "</td>" +
  21. "<td>" + item.company_name + "</td>" +
  22. "<td>" + item.spot_address + "</td>" +
  23. "<td>" + item.type_name + "</td>" +
  24. "<td>" + item.latest_change_time + "</td>" +
  25. "<td ><a class='pointLabel view-detail' data-id=" + item.id + ">查看</a></td>" +
  26. "<td ><a class='pointDetail' data-id=" + item.id + "><img src='../../images/tupianbtn.png'></a></td>"
  27. "</tr>"
  28. })
  29. $('#dataList').html(items);
  30. } else {
  31. $('#dataList').html('');
  32. }
  33. totalPages = result.totalCount / result.limit;
  34. totalPages = Math.ceil(totalPages);
  35. $('#totalPage').html(totalPages); //总共多少页
  36. $('#dataTotal').html(result.totalCount); //总共多少条数据
  37. $('#currentPage').val(page); //当前页面
  38. let pageFrom = (page - 1) * result.limit + 1; //开始
  39. let pageTo = result.page * result.limit; //结束
  40. pageTo = pageTo > result.totalCount ? result.totalCount : pageTo;
  41. $('#pageFrom').html(pageFrom);
  42. $('#pageTo').html(pageTo);
  43. // 无数据时
  44. if (!result.totalCount) {
  45. $('.pager.has-data').hide()
  46. $('.pager.no-data').show()
  47. } else {
  48. $('.pager.has-data').show()
  49. $('.pager.no-data').hide()
  50. }
  51. if (page < totalPages) {
  52. $('#nextPageButton,#lastPageButton').removeClass('disabled');
  53. } else {
  54. $('#nextPageButton,#lastPageButton').addClass('disabled');
  55. }
  56. if (page === 1) {
  57. $('#firstPageButton,#prevPageButton').addClass('disabled');
  58. } else {
  59. $('#firstPageButton,#prevPageButton').removeClass('disabled');
  60. }
  61. }, function(errorMsg) {
  62. alert("请求数据失败!");
  63. }, 3)
  64. }
  65. //单位下拉
  66. getNameList()
  67. //单位下拉 ajax请求
  68. function getNameList() {
  69. ajaxRequest(DEVICE_TYPE_COMPANYLIST, "POST", {}, function(result) {
  70. let data = result.RESULT;
  71. let items = '';
  72. data.forEach(function(item, key) {
  73. items += `<option value="${item.owner_id}">${item.owner_name}</option>`
  74. })
  75. $('#getNameList').append(items);
  76. $('#getNameList2').append(items);
  77. }, function(errorMsg) {
  78. alert("请求数据失败!");
  79. })
  80. }
  81. //按钮搜索
  82. $('#buttonSearch').on('click', function() {
  83. page = 1;
  84. getListDataAjax(getSearchParamObj());
  85. param1 = $('#spot_name').val()
  86. param2 = $('#spot_address').val()
  87. })
  88. //拼接搜索条件
  89. function getSearchParamObj() {
  90. let queryParam = {};
  91. let spot_name = $('#spot_name').val();
  92. let spot_address = $('#spot_address').val();
  93. queryParam.spot_name = spot_name;
  94. queryParam.spot_address = spot_address;
  95. return queryParam;
  96. }
  97. //重置表单
  98. $('.reset').click(resetForm);
  99. //分页刷新按钮
  100. $('.pg-refresh').click(resetForm);
  101. //重置表单
  102. function resetForm() {
  103. page = 1;
  104. $("#spot_name").val("");
  105. $("#spot_address").val("");
  106. getListDataAjax(getSearchParamObj());
  107. param1 = $('#spot_name').val()
  108. param5 = $('#spot_address').val()
  109. }
  110. //分页操作
  111. $('#firstPageButton').on('click', function() {
  112. page = 1;
  113. getListDataAjax(getSearchParamObj(), 1);
  114. })
  115. $('#lastPageButton').on('click', function() {
  116. page = totalPages;
  117. getListDataAjax({}, page);
  118. })
  119. $('#prevPageButton').on('click', function() {
  120. page -= 1;
  121. getListDataAjax(getSearchParamObj(), page);
  122. })
  123. $('#nextPageButton').on('click', function() {
  124. page += 1;
  125. getListDataAjax(getSearchParamObj(), page);
  126. })
  127. layui.use('layer', function() {
  128. // 新增弹框
  129. $(document).on('click', '.add', function() {
  130. layerCreateIndex = layer.open({
  131. type: 1,
  132. title: false,
  133. closeBtn: 0,
  134. shadeClose: true,
  135. skin: 'yourclass',
  136. area: ['450px', '400px'],
  137. content: $(".addDataOut"),
  138. success: function() {
  139. // getTeamInnerList();
  140. $('.clsBtn,.cancel').click(function() {
  141. innerPage = 1;
  142. layer.close(layerCreateIndex);
  143. })
  144. }
  145. })
  146. })
  147. //修改弹框信息
  148. $('.edit').click(function() {
  149. let dataId = $('.pure-table #dataList tr').find('.checked').data('id');
  150. if (!$('.pure-table tr').has('.checked').length) {
  151. layer.msg('请选择一条需要修改的信息!', { icon: 5 });
  152. } else {
  153. let userInfo = $('.pure-table tr').find('.checked').data('user');
  154. $('.editDataOut input[name=spot_name]').val(userInfo.spot_name)
  155. $('.editDataOut select[name=company_code]').val(userInfo.company_code)
  156. $('.editDataOut input[name=spot_address]').val(userInfo.spot_address)
  157. $('.editDataOut input[name=equipment_code]').val(userInfo.spot_label_analysis)
  158. $("input[name='spot_type']").each(function() {
  159. if ($(this).val() != userInfo.spot_type) {
  160. $(this).removeAttr("checked");
  161. } else {
  162. $(this).prop("checked", "checked");
  163. }
  164. });
  165. layui.use(['form'], function() {
  166. var form = layui.form;
  167. form.render('radio');
  168. })
  169. if (userInfo.picture_route) {
  170. $('#pictureRouteShow').attr('src', userInfo.picture_route)
  171. $('#pictureRouteShow').css('display', 'block')
  172. }
  173. layerUpdateIndex = layer.open({
  174. type: 1,
  175. title: false,
  176. closeBtn: 0,
  177. shadeClose: true,
  178. skin: 'yourclass',
  179. area: ['450px', '400px'],
  180. content: $(".editDataOut"),
  181. success: function() {
  182. $('.clsBtn,.cancel').click(function() {
  183. innerPage = 1;
  184. layer.close(layerUpdateIndex);
  185. })
  186. }
  187. });
  188. }
  189. })
  190. //删除信息
  191. $('.delete').click(function() {
  192. if (!$('.pure-table tr').has('.checked').length) {
  193. //layer.msg('请选择一条需要修改的信息');
  194. layer.msg('请选择一条需要删除的信息!', { icon: 5 });
  195. } else {
  196. let dataId = $('.pure-table #dataList tr').find('.checked').data('id');
  197. ajaxRequest(POINT_DELETE, "POST", { "ID_LIST": [{ "id": dataId }] }, function(result) {
  198. $(".pure-table tbody tr.selected").remove()
  199. layer.close(layer.layerCreateIndex);
  200. layer.msg('删除成功!', { icon: 6 });
  201. getListDataAjax()
  202. }, function(errorMsg) {
  203. alert("用户删除失败!");
  204. }, 2)
  205. }
  206. })
  207. })
  208. /* 新增发送请求 */
  209. $('#addData').click(function() {
  210. //获取表单的值 并转换成对象
  211. let allParam = serializeArrayToObj($("#addDataForm").serializeArray());
  212. //验证数据是否为空
  213. let res = validParamIsEmpty(allParam, {
  214. "spot_name": "请输入点位名称",
  215. "company_code": "请选择所属单位/项目",
  216. "spot_address": "请输入点位地址",
  217. "equipment_code": "请输入设备编号",
  218. "spot_type": "请选择设备类型",
  219. });
  220. if (res.code == -1) {
  221. alert(res.msg);
  222. return;
  223. }
  224. //验证文件
  225. // 判断文件是否为空
  226. var file = $("input[name='picture_route']").val(); //用户文件内容(文件)
  227. if (file == "") {
  228. alert("请选择上传的目标文件! ")
  229. return false;
  230. }
  231. //判断文件类型
  232. var fileExtension = file.substring(file.lastIndexOf(".") + 1).toLowerCase();
  233. let allowExtension = ['jpg', 'jpeg', 'png', 'gif'];
  234. if (allowExtension.indexOf(fileExtension.toLowerCase()) < 0) {
  235. alert("请选择图片文件!");
  236. return false;
  237. }
  238. //上传文件
  239. uploadImg('pictureRouteAdd', function(data) {
  240. data = JSON.parse(data); //aa json字符串转对象
  241. if (data.flag) {
  242. //将返回的路径 拼接到提交的数据对象里
  243. allParam['picture_route'] = data.data;
  244. //验证通过 请求ajax
  245. ajaxRequest(POINT_ADD, "POST", allParam, function(result) {
  246. layer.close(layerCreateIndex);
  247. layer.msg('添加成功!', { icon: 6 });
  248. getListDataAjax();
  249. $('#addDataForm')[0].reset();
  250. }, function(errorMsg) {
  251. alert("异常错误!");
  252. }, 3)
  253. } else {
  254. //这里应该弹出删除失败的 后台返回的原因
  255. alert('上传图片失败');
  256. return;
  257. }
  258. });
  259. })
  260. /* 修改发送请求 */
  261. $('#updateData').click(function() {
  262. //获取表单的值 并转换成对象
  263. let allParam = serializeArrayToObj($("#editDataForm").serializeArray());
  264. //验证数据是否为空
  265. let res = validParamIsEmpty(allParam, {
  266. "spot_name": "请输入点位名称",
  267. "company_code": "请选择所属单位/项目",
  268. "spot_address": "请输入点位地址",
  269. "equipment_code": "请输入设备编号",
  270. "spot_type": "请选择设备类型",
  271. });
  272. if (res.code == -1) {
  273. alert(res.msg);
  274. return;
  275. }
  276. //验证文件
  277. // 判断文件是否为空
  278. if ($("input[name='picture_route']").val()) {
  279. var file = $("input[name='picture_route']").val(); //用户文件内容(文件)
  280. //判断文件类型
  281. var fileExtension = file.substring(file.lastIndexOf(".") + 1).toLowerCase();
  282. let allowExtension = ['jpg', 'jpeg', 'png', 'gif'];
  283. if (allowExtension.indexOf(fileExtension.toLowerCase()) < 0) {
  284. alert("请选择图片文件!");
  285. return false;
  286. }
  287. }
  288. let dataId = $('.pure-table tr').find('.checked').data('id');
  289. allParam.id = dataId;
  290. ajaxRequest(POINT_EDIT, "POST", allParam, function(result) {
  291. layer.close(layerUpdateIndex);
  292. layer.msg('修改成功!', { icon: 6 });
  293. getListDataAjax();
  294. }, function(errorMsg) {
  295. alert("数据修改失败!");
  296. }, 2)
  297. })
  298. // 导出 start
  299. $('.export').click(function() {
  300. getDataExport({ "spot_name": param1, "spot_address": param2 })
  301. })
  302. function getDataExport(queryParam = {}) {
  303. // 输出base64编码
  304. const base64 = s => window.btoa(unescape(encodeURIComponent(s)));
  305. ajaxRequest(POINT_EXPORT, "POST", queryParam, function(result) {
  306. let data = result.RESULT;
  307. let newData = [];
  308. if (data) {
  309. data.forEach(function(item, index) {
  310. newData.push({ xh: item.xh, spot_name: item.spot_name, company_name: item.company_name, spot_address: item.spot_address, type_name: item.type_name, latest_change_time: item.latest_change_time })
  311. });
  312. }
  313. let str = '<tr style="text-align:center"><th>序号</th><th>点位名称</th><th>所属单位/项目</th><th>点位地址</th><th>设备类型</th><th>最新更改时间</th></tr>';
  314. // 循环遍历,每行加入tr标签,每个单元格加td标签
  315. for (let i = 0; i < newData.length; i++) {
  316. str += '<tr style="text-align:center">';
  317. for (const key in newData[i]) {
  318. // 增加\t为了不让表格显示科学计数法或者其他格式
  319. str += `<td x:str>${ newData[i][key] + '\t'}</td>`;
  320. }
  321. str += '</tr>';
  322. }
  323. // Worksheet名
  324. const worksheet = 'Sheet1'
  325. const uri = 'data:application/vnd.ms-excel;base64,';
  326. // 下载的表格模板数据
  327. const template = `<html xmlns:o="urn:schemas-microsoft-com:office:office"
  328. xmlns:x="urn:schemas-microsoft-com:office:excel"
  329. xmlns="http://www.w3.org/TR/REC-html40">
  330. <head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>
  331. <x:Name>${worksheet}</x:Name>
  332. <x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet>
  333. </x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]-->
  334. </head><body><table>${str}</table></body></html>`;
  335. // 通过创建a标签实现
  336. const link = document.createElement("a");
  337. link.href = uri + base64(template);
  338. // 对下载的文件命名
  339. link.download = "维保点位数据表.xls";
  340. link.click();
  341. }, function(errorMsg) {
  342. alert("请求数据失败!");
  343. }, 3)
  344. }
  345. // 导出 end
  346. //点位标签弹框
  347. $(document).on('click', 'a.pointLabel', function() {
  348. let dwId = $(this).data('id');
  349. layerDepartmentIndex = layer.open({
  350. type: 1,
  351. title: false,
  352. closeBtn: 0,
  353. shadeClose: true,
  354. skin: 'yourclass',
  355. area: [
  356. '450px', '430px'
  357. ],
  358. content: $(".pointLabelOut"),
  359. success: function() {
  360. ajaxRequest(POINT_LIST, "POST", { "id": dwId }, function(result) {
  361. var data = result.RESULT[0];
  362. $('#pointDetailUrl').attr('src', BASEURL + data.spot_label_route);
  363. $('#spotName').html(data.spot_name);
  364. $('#spotAddress').html(data.spot_address);
  365. $('#spotLabelAnalysis').html(data.spot_label_analysis);
  366. $('#data1').html(data.data1);
  367. }, function(errorMsg) {
  368. alert("请求数据失败!");
  369. }, 3);
  370. $('.pointLabelDownload').click(function() {
  371. cutDiv()
  372. })
  373. $('.clsBtn2,.cancel2').click(function() {
  374. innerPage = 1;
  375. layer.close(layerDepartmentIndex);
  376. })
  377. }
  378. })
  379. })
  380. //点位详情点击
  381. $(document).on('click', 'a.pointDetail', function() {
  382. let id = $(this).data('id'); //单位ID
  383. layerReportIndex = layer.open({
  384. type: 1,
  385. title: false,
  386. closeBtn: 0,
  387. shadeClose: true,
  388. skin: 'yourclass',
  389. area: [
  390. '400px', '400px'
  391. ],
  392. content: $(".pointDetailOut"),
  393. success: function() {
  394. ajaxRequest(POINT_LIST, "POST", { "id": id }, function(result) {
  395. var data = result.RESULT[0];
  396. $('#weibaoReportUrl').attr('src', data.picture_route);
  397. }, function(errorMsg) {
  398. alert("请求数据失败!");
  399. }, 3);
  400. $('.clsBtn3,.cancel3').click(function() {
  401. layer.close(layerReportIndex);
  402. })
  403. }
  404. })
  405. })
  406. // 点位标签下载 start
  407. var saveFile = function(data, filename) {
  408. var save_link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
  409. save_link.href = data;
  410. save_link.download = filename;
  411. var event = document.createEvent('MouseEvents');
  412. event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  413. save_link.dispatchEvent(event);
  414. }
  415. var downPng = function(canvas) {
  416. console.log(canvas);
  417. var img_data1 = Canvas2Image.saveAsPNG(canvas, true).getAttribute('src');
  418. saveFile(img_data1, 'download.png');
  419. }
  420. var cutDiv = function() {
  421. var content = document.getElementById("imgOut");
  422. html2canvas(content, {
  423. onrendered: function(canvas) {
  424. downPng(canvas);
  425. }
  426. });
  427. }
  428. // 点位标签下载 end