view.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. const excludeAreas = ['山东', '广西'];
  47. const contactMap = {
  48. '山东': '王洪生18660778328',
  49. '广西': '陈叶婷15607807379',
  50. };
  51. $('#interface-import-confirm').click(async function () {
  52. try {
  53. if (STATE.importing) {
  54. return;
  55. }
  56. STATE.importing = true;
  57. const file = $('#interface-import-file')[0].files[0];
  58. if (!file) {
  59. throw '请选择导入文件。';
  60. }
  61. // 按照地区动态加载导入脚本
  62. const parentArea = $('#import-parent-area').val();
  63. const subArea = $('#import-sub-area').val();
  64. if (!parentArea || !subArea) {
  65. throw '请选择有效地区。';
  66. }
  67. if (excludeAreas.includes(parentArea) && userMobile !== '15919278500') {
  68. const message = `尊敬的用户:<br>
  69. 感谢您一直以来对纵横的信任和支持,为了更好地坚守初心,持续为您提供高质量的产品与服务,纵横公路养护云造价已升级为大司空云计价。<br>
  70. 请联系当地客服免费升级账号,使用大司空云计价继续导出导入电子招投标文件。<br>
  71. 当地服务热线:${contactMap[parentArea] || '王洪生18660778328'}<br>
  72. 全国服务热线:0756-3850888,企业QQ:800003850<br>
  73. 请点链接进入大司空云计价:<a href="https://dsk.smartcost.com.cn">https://dsk.smartcost.com.cn</a>`;
  74. window.alert(message);
  75. return;
  76. }
  77. const curAreaKey = `${parentArea}@${subArea}`;
  78. if (!(importData && areaKey && areaKey === curAreaKey)) {
  79. areaKey = curAreaKey;
  80. await STD_INTERFACE.loadScriptByArea(areaKey, STD_INTERFACE.ScriptType.IMPORT);
  81. // const onlyImportMatchBills = areaKey === '广东@中山';
  82. const onlyImportMatchBills = onlyImportMatchBillsCompilations.includes(areaKey);
  83. importData = await INTERFACE_EXPORT_BASE.extractImportData(INTERFACE_IMPORT.entry, file, areaKey, false, onlyImportMatchBills, INTERFACE_IMPORT.handleAfterImport);
  84. }
  85. const constructionName = $('#import-rename').is(':visible') ? $('#import-rename-input').val() : importData.name;
  86. // 确定建设项目的名称(不允许重复)
  87. const sameDepthProjs = getProjs(projTreeObj.tree.selected);
  88. const matchedProject = sameDepthProjs.find(node => node.data.name === constructionName);
  89. if (matchedProject || !constructionName) {
  90. $('#import-rename-input').val(constructionName);
  91. $('#import-rename').show();
  92. $('#import-rename-input').focus();
  93. return;
  94. }
  95. importData.name = constructionName;
  96. $('#interface-import-modal').modal('hide');
  97. $.bootstrapLoading.progressStart('导入文件', true);
  98. $("#progress_modal_body").text('正在导入接口文件,请稍候……');
  99. //return;
  100. // 转换成File实例
  101. const blob = new Blob([JSON.stringify(importData)], { type: 'text/plain;charset=utf-8' });
  102. const key = `${uuid.v1()}.json`;
  103. const uploadFile = new File([blob], key);
  104. // 上传文件
  105. await projTreeObj.getUploadToken();
  106. await UPLOAD_CDN.uploadSync(uploadFile, key, projTreeObj.uptoken);
  107. // 下载并处理文件
  108. await ajaxPost('/pm/import/importInterface', { key });
  109. await importProcessChecking(key, null, (projectData) => handleProjectAfterChecking(projectData));
  110. } catch (err) {
  111. console.log(err);
  112. alert(err);
  113. } finally {
  114. projTreeObj.uptoken = null;
  115. setTimeout(function () {
  116. STATE.importing = false;
  117. }, 500);
  118. }
  119. });
  120. }
  121. return {
  122. importListener,
  123. initFileAccept,
  124. };
  125. })();
  126. $(document).ready(() => {
  127. $('#interface-import-modal').on('show.bs.modal', () => {
  128. $('#import-rename-input').val('');
  129. $('#import-rename').hide();
  130. $('#interface-import-file').val('');
  131. $('#interface-import-label').text('请选择导入文件');
  132. IMPORT_VIEW.initFileAccept($('#interface-import-file'));
  133. STD_INTERFACE.initInterfaceAreas($('#import-parent-area'), $('#import-sub-area'));
  134. });
  135. IMPORT_VIEW.importListener();
  136. });