team.js 12 KB

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