team.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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. console.log(data)
  137. data.forEach(function(item, key) {
  138. items += `<option value="${item.owner_id}">${item.owner_name}</option>`
  139. })
  140. $('#getNameList').append(items);
  141. // $('#getNameList2').append(items);
  142. }, function(errorMsg) {
  143. alert("请求数据失败!");
  144. })
  145. }
  146. /*新增 修改 关闭 弹框*/
  147. var layer = layui.layer;
  148. var layerCreateIndex = '';
  149. var layerUpdateIndex = ''
  150. layui.use('layer', function() {
  151. //新增弹框
  152. // $('.add').click(function() {
  153. // layerCreateIndex = layer.open({
  154. // type: 1,
  155. // title: false,
  156. // closeBtn: 0,
  157. // shadeClose: true,
  158. // skin: 'yourclass',
  159. // area: ['450px', '500px'],
  160. // content: $(".addDeviceTypeOut"),
  161. // success: function() {
  162. // $('.clsBtn,.cancel').click(function() {
  163. // layer.close(layerCreateIndex);
  164. // })
  165. // }
  166. // })
  167. // }),
  168. //修改弹框信息
  169. $('.edit').click(function() {
  170. if (!$('.pure-table tr').has('.checked').length) {
  171. layer.msg('请选择一条需要修改的信息!', { icon: 5 });
  172. } else {
  173. let userInfo = $('.pure-table tr').find('.checked').data('user');
  174. $('.editDeviceTypeOut input[name=type_name]').val(userInfo.type_name)
  175. $('.editDeviceTypeOut input[name=type_value]').val(userInfo.type_value)
  176. $('.editDeviceTypeOut select[name=transmission_model]').val(userInfo.transmission_model)
  177. $('.editDeviceTypeOut input[name=business').val(userInfo.business)
  178. $('.editDeviceTypeOut select[name=company_code]').val(userInfo.company_code)
  179. $('.editDeviceTypeOut input[name=id').val(userInfo.id)
  180. layerUpdateIndex = layer.open({
  181. type: 1,
  182. title: false,
  183. closeBtn: 0,
  184. shadeClose: true,
  185. skin: 'yourclass',
  186. area: ['410px', '400px'],
  187. content: $(".editDeviceTypeOut"),
  188. success: function() {
  189. $('.clsBtn,.cancel').click(function() {
  190. layer.close(layerUpdateIndex);
  191. })
  192. }
  193. });
  194. }
  195. })
  196. //删除信息
  197. $('.delete').click(function() {
  198. if (!$('.pure-table tr').has('.checked').length) {
  199. //layer.msg('请选择一条需要修改的信息');
  200. layer.msg('请选择一条需要删除的信息!', { icon: 5 });
  201. } else {
  202. let dataId = $('.pure-table tr').find('.checked').data('id');
  203. ajaxRequest(DEVICE_TYPE_DELETE, "POST", { "ID_LIST": [{ "id": dataId }] }, function(result) {
  204. $(".pure-table tbody tr.selected").remove()
  205. let data = result
  206. layer.close(layer.layerCreateIndex);
  207. layer.msg('删除成功!', { icon: 6 });
  208. getListDataAjax()
  209. }, function(errorMsg) {
  210. alert("用户删除失败!");
  211. }, 2)
  212. }
  213. })
  214. })
  215. /* 新增发送请求 */
  216. $('#addMenu').click(function() {
  217. //获取表单的值 并转换成对象
  218. let allParam = serializeArrayToObj($("#addMenuForm").serializeArray());
  219. //验证数据是否为空
  220. let res = validParamIsEmpty(allParam, {
  221. "type_name": "请输入类型名称",
  222. "type_value": "请输入类型参数",
  223. "transmission_model": "请选择传输类型",
  224. "business": "请输入厂家名称",
  225. "company_code": "请选择所属单位",
  226. });
  227. if (res.code == -1) {
  228. alert(res.msg);
  229. return;
  230. }
  231. //验证通过 请求ajax
  232. ajaxRequest(DEVICE_TYPE_ADD, "POST", allParam, function(result) {
  233. layer.close(layerCreateIndex);
  234. layer.msg('添加成功!', { icon: 6 });
  235. getListDataAjax();
  236. $('#addMenuForm')[0].reset();
  237. }, function(errorMsg) {
  238. alert("异常错误!");
  239. })
  240. })
  241. /* 修改发送请求 */
  242. $('#dataUpdate').click(function() {
  243. //获取表单的值 并转换成对象
  244. let allParam = serializeArrayToObj($("#updateMenuForm").serializeArray());
  245. //验证数据是否为空
  246. let res = validParamIsEmpty(allParam, {
  247. "type_name": "请输入类型名称",
  248. "type_value": "请输入类型参数",
  249. "transmission_model": "请选择传输方式",
  250. "business": "请输入厂家名称",
  251. });
  252. if (res.code == -1) {
  253. alert(res.msg);
  254. return;
  255. }
  256. ajaxRequest(DEVICE_TYPE_UPDATE, "POST", allParam, function(result) {
  257. layer.close(layerUpdateIndex);
  258. layer.msg('修改成功!', { icon: 6 });
  259. getListDataAjax();
  260. }, function(errorMsg) {
  261. alert("数据修改失败!");
  262. })
  263. })
  264. // 导出 start
  265. $('.export').click(function() {
  266. getDataExport({ "team_name": param1, "add_people": param2 })
  267. })
  268. function getDataExport(queryParam = {}) {
  269. // 输出base64编码
  270. const base64 = s => window.btoa(unescape(encodeURIComponent(s)));
  271. ajaxRequest(RECORD_EXPORT, "POST", queryParam, function(result) {
  272. console.log('result.RESULT')
  273. console.log(result.RESULT)
  274. let data = result.RESULT;
  275. let newData = [];
  276. if (data) {
  277. data.forEach(function(item, index) {
  278. 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 })
  279. });
  280. }
  281. let str = '<tr style="text-align:center"><th>序号</th><th>任务名称</th><th>应完成时间</th><th>当前状态</th><th>完成情况%</th><th>相关责任人</th><th>联系电话</th></tr>';
  282. // 循环遍历,每行加入tr标签,每个单元格加td标签
  283. for (let i = 0; i < newData.length; i++) {
  284. str += '<tr style="text-align:center">';
  285. for (const key in newData[i]) {
  286. // 增加\t为了不让表格显示科学计数法或者其他格式
  287. str += `<td x:str>${ newData[i][key] + '\t'}</td>`;
  288. }
  289. str += '</tr>';
  290. }
  291. // Worksheet名
  292. const worksheet = 'Sheet1'
  293. const uri = 'data:application/vnd.ms-excel;base64,';
  294. // 下载的表格模板数据
  295. const template = `<html xmlns:o="urn:schemas-microsoft-com:office:office"
  296. xmlns:x="urn:schemas-microsoft-com:office:excel"
  297. xmlns="http://www.w3.org/TR/REC-html40">
  298. <head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>
  299. <x:Name>${worksheet}</x:Name>
  300. <x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet>
  301. </x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]-->
  302. </head><body><table>${str}</table></body></html>`;
  303. // 通过创建a标签实现
  304. const link = document.createElement("a");
  305. link.href = uri + base64(template);
  306. // 对下载的文件命名
  307. link.download = "维保记录数据表.xls";
  308. link.click();
  309. }, function(errorMsg) {
  310. alert("请求数据失败!");
  311. }, 3)
  312. }
  313. // 导出 end