BatchImportPop.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <batch-import-dialoga
  3. v-if="type == 1"
  4. :dialogVisible.sync="dialogVisible"
  5. temUrl="/oss/images/file/20220518/1652865393160.xlsx"
  6. apiKey="importDatabankimportDataBackList"
  7. :isCheck="false"
  8. :isShowTip="false"
  9. @success="ExcelSuccess"
  10. ></batch-import-dialoga>
  11. <batch-import-dialoga
  12. v-else
  13. :dialogVisible.sync="dialogVisible"
  14. temUrl="/oss/images/file/20220324/1648102107588.docx"
  15. apiKey="bankquestionimportWordQuestionList"
  16. :isCheck="false"
  17. :isShowTip="false"
  18. :isSuccessBack="true"
  19. @success="wordSuccess"
  20. type="Word"
  21. :param="formData"
  22. ></batch-import-dialoga>
  23. </template>
  24. <script>
  25. import batchImportDialoga from "@/components/Comon/batchImportDialog.vue";
  26. export default {
  27. data() {
  28. return {
  29. dialogVisible: false,
  30. tableData: [],
  31. businObj: {},
  32. formData: {
  33. eduId: "",
  34. businessId: "",
  35. subjectId: "",
  36. projectId: "",
  37. },
  38. type: 1, //1是execl 2 word
  39. };
  40. },
  41. methods: {
  42. openBoxs(data, obj, type) {
  43. this.type = type;
  44. this.tableData = JSON.parse(JSON.stringify(data));
  45. if (type == 1) {
  46. this.businObj = JSON.parse(JSON.stringify(obj));
  47. } else {
  48. Object.keys(this.formData).map(
  49. (e) =>
  50. (this.formData[e] = e == "eduId" ? obj["educationTypeId"] : obj[e])
  51. );
  52. }
  53. this.dialogVisible = true;
  54. },
  55. wordSuccess({ list }) {
  56. if (list.length == 0) return;
  57. let numList = this.tableData;
  58. if (numList.length) {
  59. let numIndex = 0;
  60. let childrenIndex = 0;
  61. numList.forEach((items) => {
  62. if (items.sort > numIndex) {
  63. numIndex = items.sort;
  64. }
  65. if (items.index > childrenIndex) {
  66. childrenIndex = items.index;
  67. }
  68. });
  69. list.forEach((items, indexs) => {
  70. numIndex++;
  71. childrenIndex++;
  72. items.sort = numIndex;
  73. items.index = childrenIndex;
  74. items.jsonStr = JSON.stringify(items.optionsList);
  75. });
  76. } else {
  77. list.forEach((items, indexs) => {
  78. items.sort = 1 + indexs;
  79. items.index = indexs;
  80. items.jsonStr = JSON.stringify(items.optionsList);
  81. });
  82. }
  83. this.$emit("backData", list);
  84. },
  85. ExcelSuccess(data) {
  86. if (data.fullStatus == "全部成功") {
  87. this.backDataX(data.questionList);
  88. this.$message.success("全部导入成功");
  89. } else {
  90. let url =
  91. baseUrls.baseURL + "common/download?fileName=" + data.errorExcel.msg;
  92. let link = document.createElement("a");
  93. let fileName = "导入模板" + ".xlsx";
  94. document.body.appendChild(link);
  95. link.href = url;
  96. link.dowmload = fileName;
  97. link.click();
  98. link.remove();
  99. if (data.fullStatus == "部分成功") {
  100. this.backDataX(data.questionList);
  101. this.$message.warning("部分导入成功,请打开文档查看错误原因");
  102. } else {
  103. this.$message.error("导入失败,请打开文档查看错误原因");
  104. }
  105. }
  106. },
  107. backDataX(arry) {
  108. let arr = JSON.parse(JSON.stringify(arry));
  109. for (let i = 0; i < arr.length; i++) {
  110. arr[i].partScore = 0;
  111. arr[i].score = "";
  112. arr[i].status = 1;
  113. arr[i].businessList = [this.businObj];
  114. if (arr[i].type === 4) {
  115. arr[i].optionsList = JSON.parse(arr[i].jsonStr);
  116. arr[i].optionsList.forEach((item) => {
  117. if (item.type === 3 || item.type === 5) {
  118. item.optionsList = [];
  119. item.jsonStr = "";
  120. }
  121. });
  122. } else if (arr[i].type === 5) {
  123. arr[i].jsonStr = "";
  124. arr[i].optionsList = [];
  125. } else {
  126. arr[i].jsonStr = JSON.stringify(arr[i].optionsList);
  127. }
  128. }
  129. if (this.tableData.length) {
  130. let maxIndex = 0;
  131. let childrenIndex = 0;
  132. this.tableData.forEach((item) => {
  133. if (item.sort > maxIndex) {
  134. maxIndex = item.sort;
  135. }
  136. if (item.index > childrenIndex) {
  137. childrenIndex = item.index;
  138. }
  139. });
  140. arr.forEach((item, index) => {
  141. item.sort = maxIndex + 1;
  142. item.index = childrenIndex + 1;
  143. maxIndex++;
  144. childrenIndex++;
  145. });
  146. } else {
  147. arr.forEach((item, index) => {
  148. item.sort = index + 1;
  149. item.index = index;
  150. });
  151. }
  152. this.$emit("backData", arr);
  153. },
  154. },
  155. components: {
  156. batchImportDialoga,
  157. },
  158. };
  159. </script>