| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- /**
- *
- *
- * @author Zhong
- * @date 2019/6/5
- * @version
- */
- // 导出接口相关
- const EXPORT_VIEW = (() => {
- 'use strict';
- const _base = INTERFACE_EXPORT_BASE;
- const _util = _base.UTIL;
- const _cache = _base.CACHE;
- // 导出数据缓存,为了自检完后,再导出的时候不需要重新运行相关提取程序。(暂时取消了自检,但还是留着这个缓存机制)
- let _exportCache = [];
- // 操作状态
- const STATE = {
- checking: false, // 自检
- exporting: false, // 导出
- };
- // 回到初始状态,需要清空cache中的数据
- function resetState() {
- _exportCache = [];
- _cache.clear();
- }
- // 设置提示高度样式
- function setHeightByInfo(infos) {
- if (infos.length > 20) {
- $('#hintBox_caption').addClass('export-check');
- }
- }
- //事件监听
- function exportListener() {
- // 导出接口
- $('#interface-export-confirm').click(async function () {
- const pr = new SCComponent.InitProgressBar();
- try {
- let dom = $('#export-parent-area')[0];
- if (dom.options[dom.selectedIndex].text === '广西') {
- if ($('#certifyInputForGX')[0].value === null || $('#certifyInputForGX')[0].value.trim() === '') {
- throw '请输入验证码。';
- }
- }
- const checkedDatas = $('#interface-export-modal input[type="checkbox"]:checked');
- if (!checkedDatas.length) {
- throw '请勾选导出文件。';
- }
- const parentArea = $('#export-parent-area').val();
- const subArea = $('#export-sub-area').val();
- if (!parentArea || !subArea) {
- throw '请选择有效地区。';
- }
- // 按照地区动态加载导出脚本
- const areaKey = `${parentArea}@${subArea}`;
- await STD_INTERFACE.loadScriptByArea(areaKey, STD_INTERFACE.ScriptType.EXPORT);
- if (STATE.exporting) {
- return;
- }
- STATE.exporting = true;
- if (!_exportCache || !_exportCache.length) {
- pr.start('导出数据接口', '正在导出文件,请稍候……');
- for (const checkedData of checkedDatas) {
- const boqType = parseInt($(checkedData).val());
- const requestForSummaryInfo = INTERFACE_EXPORT.requestForSummaryInfo || null;
- const projectID = projectObj.project.ID();
- const exportData = await _base.extractExportData(INTERFACE_EXPORT.entry, requestForSummaryInfo, boqType, areaKey, projectID, userID);
- const failList = _util.transformFailList(_cache.getItem('failList'));
- if (failList.length) {
- // 自检提示错误,打断导出
- setHeightByInfo(failList);
- throw failList.join('<br/>');
- }
- _exportCache.push(...exportData);
- }
- }
- if (_exportCache && _exportCache.length) {
- // 导出文件
- await _base.exportFile(_exportCache, INTERFACE_EXPORT.saveAsFile || INTERFACE_EXPORT_BASE.defaultSaveAs);
- }
- $('#interface-export-modal').modal('hide');
- } catch (err) {
- console.log(err);
- alert(err);
- } finally {
- _cache.setItem('failList', []);
- pr.end();
- setTimeout(() => {
- STATE.exporting = false;
- }, 300);
- }
- });
- //导出窗口--------
- $('#interface-export-modal').on('hide.bs.modal', function () {
- resetState();
- STATE.checking = false;
- STATE.exporting = false;
- $('#interface-export-modal input[type="checkbox"]:eq(0)').prop('checked', true);
- });
- $('#interface-export-modal input[type="checkbox"]').click(function () {
- resetState();
- });
- }
- return { exportListener, resetState }
- })();
- $(document).ready(() => {
- $('#interface-export-modal').on('show.bs.modal', () => STD_INTERFACE.initInterfaceAreas($('#export-parent-area'), $('#export-sub-area')));
- EXPORT_VIEW.exportListener();
- })
- function bidAreaSelectChange(dom) {
- if (dom.options[dom.selectedIndex].text === '广西') {
- $('#certifyDivForGX')[0].style.display = "";
- $('#certifyInputForGX')[0].value = '';
- } else {
- //
- $('#certifyDivForGX')[0].style.display = "none";
- }
- }
|