team.js 12 KB

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