view.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * @Descripttion: 导入接口视图相关
  3. * @Author: vian
  4. * @Date: 2020-09-08 09:36:52
  5. */
  6. const IMPORT_VIEW = (() => {
  7. const {
  8. EXPORT_KIND: { BID_INVITATION }
  9. } = window.commonConstants;
  10. /**
  11. * 根据接口配置文件,设置可被接受的导入文件类型,只导入招标文件
  12. * @param {Object} $file - 文件选择Jquery dom
  13. * @return {Void}
  14. */
  15. function initFileAccept($file) {
  16. const set = new Set();
  17. Object
  18. .values(INTERFACE_CONFIG)
  19. .forEach(config => {
  20. Object
  21. .entries(config.fileSuffix)
  22. .forEach(([type, suffix]) => {
  23. if (+type === BID_INVITATION) {
  24. set.add(suffix);
  25. }
  26. });
  27. });
  28. const accept = [...set].join(',');
  29. $file.prop('accept', accept);
  30. }
  31. // 导入相关事件监听器
  32. let importData = null;
  33. let areaKey = '';
  34. const onlyImportMatchBillsCompilations = ['广东@中山', '浙江@杭州', '广西@广西'];
  35. function importListener() {
  36. // 文件选择变更
  37. $('#interface-import-file').change(function () {
  38. importData = null;
  39. areaKey = '';
  40. $('#import-rename-input').val('');
  41. $('#import-rename').hide();
  42. const file = $(this)[0].files[0];
  43. $('#interface-import-label').text(file && file.name || '请选择导入文件');
  44. });
  45. // 导入确认事件
  46. $('#interface-import-confirm').click(async function () {
  47. try {
  48. if (STATE.importing) {
  49. return;
  50. }
  51. STATE.importing = true;
  52. const file = $('#interface-import-file')[0].files[0];
  53. if (!file) {
  54. throw '请选择导入文件。';
  55. }
  56. // 按照地区动态加载导入脚本
  57. const parentArea = $('#import-parent-area').val();
  58. const subArea = $('#import-sub-area').val();
  59. if (!parentArea || !subArea) {
  60. throw '请选择有效地区。';
  61. }
  62. if (parentArea === '山东') {
  63. const message = `尊敬的用户:<br>
  64. 感谢您一直以来对纵横的信任和支持,为了更好地坚守初心,持续为您提供高质量的产品与服务,纵横公路养护云造价已升级为大司空云计价。<br>
  65. 请联系当地客服免费升级账号,使用大司空云计价继续导出导入电子招投标文件。<br>
  66. 当地服务热线:王洪生18660778328<br>
  67. 全国服务热线:0756-3850888,企业QQ:800003850<br>
  68. 请点链接进入大司空云计价:<a href="https://dsk.smartcost.com.cn">https://dsk.smartcost.com.cn</a>`;
  69. window.alert(message);
  70. return;
  71. }
  72. const curAreaKey = `${parentArea}@${subArea}`;
  73. if (!(importData && areaKey && areaKey === curAreaKey)) {
  74. areaKey = curAreaKey;
  75. await STD_INTERFACE.loadScriptByArea(areaKey, STD_INTERFACE.ScriptType.IMPORT);
  76. // const onlyImportMatchBills = areaKey === '广东@中山';
  77. const onlyImportMatchBills = onlyImportMatchBillsCompilations.includes(areaKey);
  78. importData = await INTERFACE_EXPORT_BASE.extractImportData(INTERFACE_IMPORT.entry, file, areaKey, false, onlyImportMatchBills, INTERFACE_IMPORT.handleAfterImport);
  79. }
  80. const constructionName = $('#import-rename').is(':visible') ? $('#import-rename-input').val() : importData.name;
  81. // 确定建设项目的名称(不允许重复)
  82. const sameDepthProjs = getProjs(projTreeObj.tree.selected);
  83. const matchedProject = sameDepthProjs.find(node => node.data.name === constructionName);
  84. if (matchedProject || !constructionName) {
  85. $('#import-rename-input').val(constructionName);
  86. $('#import-rename').show();
  87. $('#import-rename-input').focus();
  88. return;
  89. }
  90. importData.name = constructionName;
  91. $('#interface-import-modal').modal('hide');
  92. $.bootstrapLoading.progressStart('导入文件', true);
  93. $("#progress_modal_body").text('正在导入接口文件,请稍候……');
  94. //return;
  95. // 转换成File实例
  96. const blob = new Blob([JSON.stringify(importData)], { type: 'text/plain;charset=utf-8' });
  97. const key = `${uuid.v1()}.json`;
  98. const uploadFile = new File([blob], key);
  99. // 上传文件
  100. await projTreeObj.getUploadToken();
  101. await UPLOAD_CDN.uploadSync(uploadFile, key, projTreeObj.uptoken);
  102. // 下载并处理文件
  103. await ajaxPost('/pm/import/importInterface', { key });
  104. await importProcessChecking(key, null, (projectData) => handleProjectAfterChecking(projectData));
  105. } catch (err) {
  106. console.log(err);
  107. alert(err);
  108. } finally {
  109. projTreeObj.uptoken = null;
  110. setTimeout(function () {
  111. STATE.importing = false;
  112. }, 500);
  113. }
  114. });
  115. }
  116. return {
  117. importListener,
  118. initFileAccept,
  119. };
  120. })();
  121. $(document).ready(() => {
  122. $('#interface-import-modal').on('show.bs.modal', () => {
  123. $('#import-rename-input').val('');
  124. $('#import-rename').hide();
  125. $('#interface-import-file').val('');
  126. $('#interface-import-label').text('请选择导入文件');
  127. IMPORT_VIEW.initFileAccept($('#interface-import-file'));
  128. STD_INTERFACE.initInterfaceAreas($('#import-parent-area'), $('#import-sub-area'));
  129. });
  130. IMPORT_VIEW.importListener();
  131. });