export_view.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Zhong
  6. * @date 2019/6/5
  7. * @version
  8. */
  9. //导出接口相关
  10. const ExportView = (() => {
  11. let _base = XML_EXPORT_BASE,
  12. _cache = _base.CACHE,
  13. _util = _base.UTIL;
  14. // 导出数据缓存
  15. let _exportCache = [];
  16. //设置工程编号表格数据设置
  17. const sheetSetting = {
  18. header: [
  19. {headerName: '名称', headerWidth: 200, dataCode: 'name', dataType: 'String'},
  20. {headerName: '工程编号', headerWidth: 200, dataCode: 'code', dataType: 'String'},
  21. ],
  22. view: {
  23. lockColumns: ['name'],
  24. lockRows: [0]
  25. }
  26. };
  27. //操作状态
  28. const STATE = {
  29. checking: false, //自检
  30. exporting: false, //导出
  31. confirming: false //导出确认
  32. };
  33. let spread = null;
  34. let sheetData = [];
  35. //初始化设置工程编号表格
  36. function initSpread(datas) {
  37. if (spread) {
  38. return;
  39. }
  40. spread = SheetDataHelper.createNewSpread($("#exportSpread")[0], 1);
  41. sheetCommonObj.spreadDefaultStyle(spread);
  42. let sheet = spread.getSheet(0);
  43. sheetCommonObj.initSheet(sheet, sheetSetting, 30);
  44. sheetCommonObj.showTreeData(sheet, sheetSetting, datas);
  45. }
  46. //获取设置的工程编号
  47. function getCodeFromSheet(sheet, isTwoLevel) {
  48. let codeCol = 1;
  49. let rst = [];
  50. //排除建设项目行
  51. for (let row = 1; row < sheet.getRowCount(); row++) {
  52. const rowData = (sheetData||[])[row];
  53. if (rowData && (!isTwoLevel || rowData.projType === 'Tender')) {
  54. rst.push(sheet.getText(row, codeCol) || '');
  55. }
  56. }
  57. return rst;
  58. }
  59. // 回到初始状态,需要清空cache中的数据
  60. function resetState() {
  61. _exportCache = [];
  62. _cache.clear();
  63. }
  64. // 设置提示高度样式
  65. function setHeightByInfo(infos) {
  66. if (infos.length * 20 > 400) {
  67. $('#hintBox_caption').addClass('export-check');
  68. }
  69. }
  70. // 显示工程编码设置窗口
  71. function showSetCodeModal(isPring) {
  72. if (isPring) {
  73. setTimeout(() => {
  74. $('#exportCode').modal('show');
  75. }, 300);
  76. } else {
  77. $('#exportCode').modal('show');
  78. }
  79. }
  80. // 确定导出
  81. async function handleExportConfirm(codes) {
  82. if (!spread || !_exportCache || !_exportCache.length) {
  83. return false;
  84. }
  85. if (STATE.confirming) {
  86. return;
  87. }
  88. STATE.confirming = true;
  89. let pr = new SCComponent.InitProgressBar();
  90. try {
  91. pr.start('导出数据接口', '正在导出文件,请稍候……');
  92. // 导出文件
  93. await _base.exportFile(codes, _exportCache, XMLStandard.resetContentCode, XMLStandard.saveAsFile);
  94. } catch (err) {
  95. console.log(err);
  96. alert(err);
  97. }
  98. pr.end();
  99. $('#exportCode').modal('hide');
  100. $('#export').modal('hide');
  101. setTimeout(() => {
  102. STATE.confirming = false;
  103. }, 300);
  104. }
  105. //事件监听
  106. function exportListener() {
  107. //导出接口-项目自检
  108. $('#export-check').click(async function () {
  109. let failList = _cache.getItem('failList');
  110. let checkedDatas = $('#export input[type="checkbox"]:checked');
  111. if (!checkedDatas.length) {
  112. return;
  113. }
  114. if (STATE.checking) {
  115. return;
  116. }
  117. STATE.checking = true;
  118. let pr = new SCComponent.InitProgressBar();
  119. try {
  120. if (!_exportCache || !_exportCache.length) {
  121. pr.start('导出数据接口', '正在自检,请稍候……');
  122. for (let checkedData of checkedDatas) {
  123. let fileKind = parseInt($(checkedData).val());
  124. let exportData = await _base.extractExportData(XMLStandard.entry, _base.CONFIG.GRANULARITY.PROJECT,
  125. XMLStandard.summaryObj, fileKind, projectObj.project.ID(), userID);
  126. _exportCache.push(...exportData);
  127. }
  128. }
  129. // 基本信息、工程特征必填项自检,这里的必填项不由xsd文件规定,而是后台根据业务需要配置
  130. const requiredFails = _util.propertyCheck();
  131. if (requiredFails.length) {
  132. setHeightByInfo(requiredFails);
  133. throw requiredFails.join('<br/>');
  134. }
  135. failList = _util.deWeightHints(failList);
  136. if (failList.length) {
  137. //设置提示弹窗
  138. setHeightByInfo(failList);
  139. throw failList.join('<br/>');
  140. }
  141. // 弱自检
  142. const infos = _util.softCheck();
  143. if (infos.length) {
  144. setHeightByInfo(infos);
  145. throw infos.join('<br/>');
  146. }
  147. throw '自检完成,未检测到错误数据。'
  148. } catch (err) {
  149. console.log(err);
  150. alert(err);
  151. }
  152. pr.end();
  153. setTimeout(() => {
  154. STATE.checking = false;
  155. }, 300);
  156. });
  157. //导出接口,如果没有错误,弹出工程编号设置窗口
  158. $('#export-confirm').click(async function () {
  159. let failList = _cache.getItem('failList');
  160. let checkedDatas = $('#export input[type="checkbox"]:checked');
  161. if (!checkedDatas.length) {
  162. return;
  163. }
  164. if (STATE.exporting) {
  165. return;
  166. }
  167. STATE.exporting = true;
  168. let pr = new SCComponent.InitProgressBar();
  169. try {
  170. let isPring = false; //是否调用了进度条(控制工程窗口什么时候显示,优化交互)
  171. if (!_exportCache || !_exportCache.length) {
  172. isPring = true;
  173. pr.start('导出数据接口', '正在导出文件,请稍候……');
  174. for (let checkedData of checkedDatas) {
  175. let fileKind = parseInt($(checkedData).val());
  176. let exportData = await _base.extractExportData(XMLStandard.entry, _base.CONFIG.GRANULARITY.PROJECT,
  177. XMLStandard.summaryObj, fileKind, projectObj.project.ID(), userID);
  178. _exportCache.push(...exportData);
  179. }
  180. pr.end();
  181. }
  182. // 基本信息、工程特征必填项自检,这里的必填项不由xsd文件规定,而是后台根据业务需要配置
  183. const requiredFails = _util.propertyCheck();
  184. if (requiredFails.length) {
  185. setHeightByInfo(requiredFails);
  186. throw requiredFails.join('<br/>');
  187. }
  188. failList = _util.deWeightHints(failList);
  189. if (failList.length) {
  190. //错误-设置提示弹窗
  191. setHeightByInfo(failList);
  192. throw failList.join('<br/>');
  193. }
  194. // 如果没有自检过,需要进行弱自检,并且弹出的窗口包含“继续、取消”按钮
  195. const infos = _util.softCheck();
  196. if (infos.length) {
  197. const doYes = () => {
  198. showSetCodeModal(isPring);
  199. };
  200. hintBox.infoBox('系统提示', infos.join('<br/>'), hintBox.btnType.yesNo, doYes, null, ['继续', '取消']);
  201. setTimeout(() => {
  202. STATE.exporting = false;
  203. }, 300);
  204. return;
  205. }
  206. //弹出工程编号设置窗口
  207. showSetCodeModal(isPring);
  208. } catch (err) {
  209. console.log(err);
  210. pr.end();
  211. alert(err);
  212. }
  213. setTimeout(() => {
  214. STATE.exporting = false;
  215. }, 300);
  216. });
  217. //工程编号设置窗口-----
  218. //设置工程编号
  219. $('#exportCode').on('shown.bs.modal', function () {
  220. let projectData = null;
  221. if(typeof SEIObject !== 'undefined' && SEIObject.exporting == true){//如果是重庆指标接口调用的
  222. if(SEIObject.fileCache && SEIObject.fileCache.length == 2){
  223. projectData = SEIObject.fileCache[0].projectData;
  224. }else{
  225. alert('数据错误!');
  226. $(this).modal('hide');
  227. return false;
  228. }
  229. $("#export_index_checkbox").show();
  230. }else {
  231. if (!_exportCache || !_exportCache.length) {
  232. alert('数据错误!');
  233. $(this).modal('hide');
  234. return false;
  235. }
  236. projectData = _cache.getItem('projectData');
  237. $("#export_index_checkbox").hide();
  238. }
  239. const shtData = XML_EXPORT_BASE.UTIL.getCodeSheetData(projectData);
  240. initSpread(shtData);
  241. sheetData = shtData;
  242. });
  243. //设置完工程编号后,导出数据。如果选中多个文件,导出压缩包
  244. $('#exportCode-confirm').click(async function () {
  245. // 工程编号
  246. const projectData = _cache.getItem('projectData');
  247. const isTwoLevel = projectData ? !!projectData.isTwoLevel : false;
  248. let codes = getCodeFromSheet(spread.getSheet(0), isTwoLevel);
  249. if (codes.includes('')) {
  250. alert('单项、单位工程工程编号不可为空。');
  251. STATE.confirming = false;
  252. return false;
  253. }
  254. if ([...new Set(codes)].length !== codes.length) {
  255. alert('单项、单位工程工程编号必须唯一。');
  256. STATE.confirming = false;
  257. return false;
  258. }
  259. typeof SEIObject !== 'undefined' && SEIObject.exporting ? await exportUtil.exprotZBFX(codes) : await handleExportConfirm(codes);
  260. });
  261. //导出窗口--------
  262. $('#export').on('hide.bs.modal', function() {
  263. resetState();
  264. STATE.checking = false;
  265. STATE.exporting = false;
  266. STATE.confirming = false;
  267. //恢复设置提示弹窗 因为是共用的alert
  268. //$('#hintBox_caption').removeClass('export-check'); 已经统一在info_box关闭时删除了
  269. $('#export input[type="checkbox"]:eq(0)').prop('checked', true);
  270. if (spread) {
  271. spread.destroy();
  272. spread = null;
  273. }
  274. });
  275. $('#export input[type="checkbox"]').click(function () {
  276. resetState();
  277. });
  278. }
  279. return {exportListener}
  280. })();