view.js 6.4 KB

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