view.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. if (dom.options[dom.selectedIndex].text === '新疆') {
  45. if ($('#certifyInputForXJ')[0].value === null || $('#certifyInputForXJ')[0].value.trim() === '') {
  46. throw '请输入验证码。';
  47. }
  48. }
  49. const checkedDatas = $('#interface-export-modal input[type="checkbox"]:checked');
  50. if (!checkedDatas.length) {
  51. throw '请勾选导出文件。';
  52. }
  53. const parentArea = $('#export-parent-area').val();
  54. const subArea = $('#export-sub-area').val();
  55. if (!parentArea || !subArea) {
  56. throw '请选择有效地区。';
  57. }
  58. // 按照地区动态加载导出脚本
  59. const areaKey = `${parentArea}@${subArea}`;
  60. await STD_INTERFACE.loadScriptByArea(areaKey, STD_INTERFACE.ScriptType.EXPORT);
  61. if (STATE.exporting) {
  62. return;
  63. }
  64. STATE.exporting = true;
  65. if (!_exportCache || !_exportCache.length) {
  66. pr.start('导出数据接口', '正在导出文件,请稍候……');
  67. for (const checkedData of checkedDatas) {
  68. const boqType = parseInt($(checkedData).val());
  69. const requestForSummaryInfo = INTERFACE_EXPORT.requestForSummaryInfo || null;
  70. const projectID = projectObj.project.ID();
  71. const exportData = await _base.extractExportData(INTERFACE_EXPORT.entry, requestForSummaryInfo, boqType, areaKey, projectID, userID);
  72. const failList = _util.transformFailList(_cache.getItem('failList'));
  73. if (failList.length) {
  74. // 自检提示错误,打断导出
  75. setHeightByInfo(failList);
  76. throw failList.join('<br/>');
  77. }
  78. _exportCache.push(...exportData);
  79. }
  80. }
  81. if (_exportCache && _exportCache.length) {
  82. // 导出文件
  83. await _base.exportFile(_exportCache, INTERFACE_EXPORT.saveAsFile || INTERFACE_EXPORT_BASE.defaultSaveAs);
  84. }
  85. $('#interface-export-modal').modal('hide');
  86. } catch (err) {
  87. console.log(err);
  88. alert(err);
  89. } finally {
  90. _cache.setItem('failList', []);
  91. pr.end();
  92. setTimeout(() => {
  93. STATE.exporting = false;
  94. }, 300);
  95. }
  96. });
  97. //导出窗口--------
  98. $('#interface-export-modal').on('hide.bs.modal', function () {
  99. resetState();
  100. STATE.checking = false;
  101. STATE.exporting = false;
  102. $('#interface-export-modal input[type="checkbox"]:eq(0)').prop('checked', true);
  103. });
  104. $('#interface-export-modal input[type="checkbox"]').click(function () {
  105. resetState();
  106. });
  107. }
  108. return { exportListener, resetState }
  109. })();
  110. $(document).ready(() => {
  111. $('#interface-export-modal').on('show.bs.modal', () => STD_INTERFACE.initInterfaceAreas($('#export-parent-area'), $('#export-sub-area')));
  112. EXPORT_VIEW.exportListener();
  113. })
  114. function bidAreaSelectChange(dom) {
  115. if (dom.options[dom.selectedIndex].text === '广西') {
  116. $('#certifyDivForGX')[0].style.display = "";
  117. $('#certifyDivForXJ')[0].style.display = "none";
  118. $('#certifyInputForGX')[0].value = '';
  119. let gxDom1 = $('#lblTtlDiv');
  120. if (gxDom1 && gxDom1.length > 0) {
  121. gxDom1[0].style.display = "none";
  122. }
  123. let gxDom2 = $('#bidCtlDiv');
  124. if (gxDom2 && gxDom2.length > 0) {
  125. gxDom2[0].style.display = "none";
  126. }
  127. } else if (dom.options[dom.selectedIndex].text === '新疆') {
  128. //certifyDivForXJ
  129. $('#certifyDivForXJ')[0].style.display = "";
  130. $('#certifyDivForGX')[0].style.display = "none";
  131. $('#certifyInputForXJ')[0].value = '';
  132. let gxDom1 = $('#lblTtlDiv');
  133. if (gxDom1 && gxDom1.length > 0) {
  134. gxDom1[0].style.display = "none";
  135. }
  136. let gxDom2 = $('#bidCtlDiv');
  137. if (gxDom2 && gxDom2.length > 0) {
  138. gxDom2[0].style.display = "none";
  139. }
  140. } else {
  141. $('#certifyDivForXJ')[0].style.display = "none";
  142. $('#certifyDivForGX')[0].style.display = "none";
  143. let gxDom1 = $('#lblTtlDiv');
  144. if (gxDom1 && gxDom1.length > 0) {
  145. gxDom1[0].style.display = "";
  146. }
  147. let gxDom2 = $('#bidCtlDiv');
  148. if (gxDom2 && gxDom2.length > 0) {
  149. gxDom2[0].style.display = "";
  150. }
  151. }
  152. }