team.js 13 KB

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