view.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /**
  2. *
  3. *
  4. * @author Zhong
  5. * @date 2019/6/5
  6. * @version
  7. */
  8. // 导出接口相关
  9. const EXPORT_VIEW = (() => {
  10. 'use strict';
  11. const _base = INTERFACE_EXPORT_BASE;
  12. const _util = _base.UTIL;
  13. const _cache = _base.CACHE;
  14. // 导出数据缓存,为了自检完后,再导出的时候不需要重新运行相关提取程序。(暂时取消了自检,但还是留着这个缓存机制)
  15. let _exportCache = [];
  16. // 操作状态
  17. const STATE = {
  18. checking: false, // 自检
  19. exporting: false, // 导出
  20. };
  21. // 回到初始状态,需要清空cache中的数据
  22. function resetState() {
  23. _exportCache = [];
  24. _cache.clear();
  25. }
  26. // 设置提示高度样式
  27. function setHeightByInfo(infos) {
  28. if (infos.length > 20) {
  29. $('#hintBox_caption').addClass('export-check');
  30. }
  31. }
  32. //事件监听
  33. function exportListener() {
  34. // 导出接口
  35. $('#interface-export-confirm').click(async function () {
  36. const pr = new SCComponent.InitProgressBar();
  37. try {
  38. let dom = $('#export-parent-area')[0];
  39. if (dom.options[dom.selectedIndex].text === '广西') {
  40. if ($('#certifyInputForGX')[0].value === null || $('#certifyInputForGX')[0].value.trim() === '') {
  41. throw '请输入验证码。';
  42. }
  43. }
  44. const checkedDatas = $('#interface-export-modal input[type="checkbox"]:checked');
  45. if (!checkedDatas.length) {
  46. throw '请勾选导出文件。';
  47. }
  48. const parentArea = $('#export-parent-area').val();
  49. const subArea = $('#export-sub-area').val();
  50. if (!parentArea || !subArea) {
  51. throw '请选择有效地区。';
  52. }
  53. // 按照地区动态加载导出脚本
  54. const areaKey = `${parentArea}@${subArea}`;
  55. await STD_INTERFACE.loadScriptByArea(areaKey, STD_INTERFACE.ScriptType.EXPORT);
  56. if (STATE.exporting) {
  57. return;
  58. }
  59. STATE.exporting = true;
  60. if (!_exportCache || !_exportCache.length) {
  61. pr.start('导出数据接口', '正在导出文件,请稍候……');
  62. for (const checkedData of checkedDatas) {
  63. const boqType = parseInt($(checkedData).val());
  64. const requestForSummaryInfo = INTERFACE_EXPORT.requestForSummaryInfo || null;
  65. const projectID = projectObj.project.ID();
  66. const exportData = await _base.extractExportData(INTERFACE_EXPORT.entry, requestForSummaryInfo, boqType, areaKey, projectID, userID);
  67. const failList = _util.transformFailList(_cache.getItem('failList'));
  68. if (failList.length) {
  69. // 自检提示错误,打断导出
  70. setHeightByInfo(failList);
  71. throw failList.join('<br/>');
  72. }
  73. _exportCache.push(...exportData);
  74. }
  75. }
  76. if (_exportCache && _exportCache.length) {
  77. // 导出文件
  78. await _base.exportFile(_exportCache, INTERFACE_EXPORT.saveAsFile || INTERFACE_EXPORT_BASE.defaultSaveAs);
  79. }
  80. $('#interface-export-modal').modal('hide');
  81. } catch (err) {
  82. console.log(err);
  83. alert(err);
  84. } finally {
  85. _cache.setItem('failList', []);
  86. pr.end();
  87. setTimeout(() => {
  88. STATE.exporting = false;
  89. }, 300);
  90. }
  91. });
  92. //导出窗口--------
  93. $('#interface-export-modal').on('hide.bs.modal', function () {
  94. resetState();
  95. STATE.checking = false;
  96. STATE.exporting = false;
  97. $('#interface-export-modal input[type="checkbox"]:eq(0)').prop('checked', true);
  98. });
  99. $('#interface-export-modal input[type="checkbox"]').click(function () {
  100. resetState();
  101. });
  102. }
  103. return { exportListener, resetState }
  104. })();
  105. $(document).ready(() => {
  106. $('#interface-export-modal').on('show.bs.modal', () => STD_INTERFACE.initInterfaceAreas($('#export-parent-area'), $('#export-sub-area')));
  107. EXPORT_VIEW.exportListener();
  108. })
  109. function bidAreaSelectChange(dom) {
  110. if (dom.options[dom.selectedIndex].text === '广西') {
  111. $('#certifyDivForGX')[0].style.display = "";
  112. $('#certifyInputForGX')[0].value = '';
  113. let gxDom1 = $('#lblTtlDiv');
  114. if (gxDom1 && gxDom1.length > 0) {
  115. gxDom1[0].style.display = "none";
  116. }
  117. let gxDom2 = $('#bidCtlDiv');
  118. if (gxDom2 && gxDom2.length > 0) {
  119. gxDom2[0].style.display = "none";
  120. }
  121. } else {
  122. //
  123. $('#certifyDivForGX')[0].style.display = "none";
  124. let gxDom1 = $('#lblTtlDiv');
  125. if (gxDom1 && gxDom1.length > 0) {
  126. gxDom1[0].style.display = "";
  127. }
  128. let gxDom2 = $('#bidCtlDiv');
  129. if (gxDom2 && gxDom2.length > 0) {
  130. gxDom2[0].style.display = "";
  131. }
  132. }
  133. }