index.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. $(document).ready(() => {
  2. //init();
  3. // $('[data-toggle="tooltip"]').tooltip();
  4. // AREA_BOOK.handleSelectionChanged(0);
  5. // 锁定、解锁
  6. lockUtil.displayLock($('.lock'), lockUtil.getLocked());
  7. $('.lock').click(function () {
  8. window.location.search = `?locked=${!lockUtil.getLocked()}`;
  9. });
  10. // 搜索
  11. $('#summary-search').bind('keydown', function (event) {
  12. if (event.keyCode === 13) {
  13. // 回车搜索
  14. const searchStr = $(this).val();
  15. SUMMARY_BOOK.handleSearch(searchStr);
  16. }
  17. });
  18. // 点击导出按钮
  19. $('#export').click(() => {
  20. window.location.href = '/priceInfoClass/export';
  21. });
  22. $('#import').click(() => {
  23. $('#import-modal').modal('show');
  24. });
  25. // 导入确认
  26. $('#import-confirm').click(function () {
  27. const self = $(this);
  28. try {
  29. const formData = new FormData();
  30. const file = $("input[name='import_data']")[0];
  31. if (file.files.length <= 0) {
  32. throw '请选择文件!';
  33. }
  34. formData.append('file', file.files[0]);
  35. $.ajax({
  36. url: '/priceInfoClass/importExcel',
  37. type: 'POST',
  38. data: formData,
  39. cache: false,
  40. contentType: false,
  41. processData: false,
  42. beforeSend: function () {
  43. self.attr('disabled', 'disabled');
  44. self.text('上传中...');
  45. },
  46. success: function (response) {
  47. self.removeAttr('disabled');
  48. self.text('确定导入');
  49. if (response.err === 0) {
  50. $.bootstrapLoading.end();
  51. const message = response.msg !== undefined ? response.msg : '';
  52. if (message !== '') {
  53. alert(message);
  54. }
  55. // 成功则关闭窗体
  56. $('#import').modal("hide");
  57. window.location.reload();
  58. } else {
  59. $.bootstrapLoading.end();
  60. const message = response.msg !== undefined ? response.msg : '上传失败!';
  61. alert(message);
  62. }
  63. },
  64. error: function () {
  65. $.bootstrapLoading.end();
  66. alert("与服务器通信发生错误");
  67. self.removeAttr('disabled');
  68. self.text('确定导入');
  69. }
  70. });
  71. } catch (error) {
  72. alert(error);
  73. }
  74. });
  75. });