excelPop.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <template>
  2. <div>
  3. <el-dialog
  4. :visible.sync="dialogDRexcel"
  5. :append-to-body="true"
  6. width="780px"
  7. :show-close="false"
  8. :close-on-click-modal="false"
  9. >
  10. <div slot="title" class="hearders">
  11. <div class="leftTitle">批量导入</div>
  12. <div class="rightBoxs">
  13. <img
  14. src="@/assets/images/Close@2x.png"
  15. alt=""
  16. @click="dialogDRexcel = false"
  17. />
  18. </div>
  19. </div>
  20. <div class="swq">
  21. <img
  22. style="width: 182px; height: 168px"
  23. src="@/assets/images/dr.png"
  24. alt=""
  25. />
  26. </div>
  27. <div style="padding-left: 100px">
  28. <p>第一步:下载excel导入模板</p>
  29. <p style="padding-left: 50px">
  30. <i class="el-icon-upload"></i
  31. ><span class="dowmStys" @click="getDowm">下载模板</span>
  32. </p>
  33. <p>第二步:点击“上传Excel”</p>
  34. <label
  35. for="mobles2"
  36. class="el-button el-button--primary el-button--mini"
  37. >上传Excel</label
  38. ><input
  39. style="display: none"
  40. type="file"
  41. id="mobles2"
  42. ref="input2"
  43. @change="importMobleadd"
  44. />
  45. </div>
  46. <span slot="footer" class="dialog-footer">
  47. <el-button @click="dialogDRexcel = false">取 消</el-button>
  48. </span>
  49. </el-dialog>
  50. </div>
  51. </template>
  52. <script>
  53. import * as baseUrls from "@/utils/request.js";
  54. export default {
  55. data() {
  56. return {
  57. dialogDRexcel: false,
  58. tableData: [],
  59. businObj: {},
  60. };
  61. },
  62. methods: {
  63. openBoxs(arr, obj) {
  64. if (arr.length) {
  65. this.tableData = JSON.parse(JSON.stringify(arr));
  66. }
  67. this.businObj = JSON.parse(JSON.stringify(obj));
  68. this.dialogDRexcel = true;
  69. },
  70. getDowm() {
  71. let url =
  72. baseUrls.BASE_IMG_URL +
  73. "/oss/images/file/20220518/1652865393160.xlsx" +
  74. `?time=${this.$methodsTools.getNewTime()}`;
  75. let link = document.createElement("a");
  76. let fileName = "导入模板" + ".xlsx";
  77. document.body.appendChild(link);
  78. link.href = url;
  79. link.dowmload = fileName;
  80. link.click();
  81. link.remove();
  82. },
  83. importMobleadd(e) {
  84. var self = this;
  85. var file = e.target.files[0];
  86. let formData = new FormData();
  87. formData.append("file", file);
  88. this.$api
  89. .importDatabankimportDataBackList(formData)
  90. .then((res) => {
  91. console.log(res);
  92. if (res.data.fullStatus == "全部成功") {
  93. self.backDataX(res.data.questionList);
  94. self.$message.success("全部导入成功");
  95. } else {
  96. let url =
  97. baseUrls.baseURL +
  98. "common/download?fileName=" +
  99. res.data.errorExcel.msg;
  100. let link = document.createElement("a");
  101. let fileName = "导入模板" + ".xlsx";
  102. document.body.appendChild(link);
  103. link.href = url;
  104. link.dowmload = fileName;
  105. link.click();
  106. link.remove();
  107. if (res.data.fullStatus == "部分成功") {
  108. self.backDataX(res.data.questionList);
  109. self.$message.warning("部分导入成功,请打开文档查看错误原因");
  110. } else {
  111. self.$message.error("导入失败,请打开文档查看错误原因");
  112. }
  113. }
  114. })
  115. .finally(() => {
  116. e.target.value = "";
  117. });
  118. },
  119. backDataX(arry) {
  120. let arr = JSON.parse(JSON.stringify(arry));
  121. for (let i = 0; i < arr.length; i++) {
  122. arr[i].partScore = 0;
  123. arr[i].score = "";
  124. arr[i].status = 1;
  125. arr[i].businessList = [this.businObj];
  126. if (arr[i].type === 4) {
  127. arr[i].optionsList = JSON.parse(arr[i].jsonStr);
  128. arr[i].optionsList.forEach((item) => {
  129. if (item.type === 3 || item.type === 5) {
  130. item.optionsList = [];
  131. item.jsonStr = "";
  132. }
  133. });
  134. } else if (arr[i].type === 5) {
  135. arr[i].jsonStr = "";
  136. arr[i].optionsList = [];
  137. } else {
  138. arr[i].jsonStr = JSON.stringify(arr[i].optionsList);
  139. }
  140. }
  141. if (this.tableData.length) {
  142. let maxIndex = 0;
  143. let childrenIndex = 0;
  144. this.tableData.forEach((item) => {
  145. if (item.sort > maxIndex) {
  146. maxIndex = item.sort;
  147. }
  148. if (item.index > childrenIndex) {
  149. childrenIndex = item.index;
  150. }
  151. });
  152. arr.forEach((item, index) => {
  153. item.sort = maxIndex + 1;
  154. item.index = childrenIndex + 1;
  155. maxIndex++;
  156. childrenIndex++;
  157. });
  158. } else {
  159. arr.forEach((item, index) => {
  160. item.sort = index + 1;
  161. item.index = index;
  162. });
  163. }
  164. this.$emit("backExcelData", arr);
  165. this.dialogDRexcel = false;
  166. },
  167. },
  168. };
  169. </script>
  170. <style lang="less" scoped>
  171. /deep/.el-button {
  172. border-radius: 8px;
  173. }
  174. /deep/.el-dialog {
  175. border-radius: 8px;
  176. .el-dialog__header {
  177. padding: 0;
  178. .hearders {
  179. height: 40px;
  180. display: flex;
  181. align-items: center;
  182. justify-content: space-between;
  183. padding: 0px 18px 0px 20px;
  184. border-bottom: 1px solid #e2e2e2;
  185. .leftTitle {
  186. font-size: 14px;
  187. font-weight: bold;
  188. color: #2f4378;
  189. }
  190. .rightBoxs {
  191. display: flex;
  192. align-items: center;
  193. img {
  194. width: 14px;
  195. height: 14px;
  196. margin-left: 13px;
  197. cursor: pointer;
  198. }
  199. }
  200. }
  201. }
  202. .el-dialog__footer {
  203. padding: 0;
  204. .dialog-footer {
  205. padding: 0px 40px;
  206. height: 70px;
  207. border-top: 1px solid #e2e2e2;
  208. display: flex;
  209. align-items: center;
  210. justify-content: flex-end;
  211. }
  212. }
  213. }
  214. .swq {
  215. text-align: center;
  216. border-bottom: 1px solid #eee;
  217. }
  218. .dowmStys {
  219. color: blue;
  220. cursor: pointer;
  221. }
  222. .imgBox {
  223. width: 100%;
  224. // height: 210px;
  225. border: 1px solid #e2e2e2;
  226. border-radius: 8px;
  227. padding: 8px 8px 3px;
  228. display: flex;
  229. flex-direction: column;
  230. align-items: center;
  231. .imgLabel {
  232. flex: 1;
  233. width: 100%;
  234. border: 1px dotted #e2e2e2;
  235. color: #999;
  236. font-size: 14px;
  237. cursor: pointer;
  238. border-radius: 8px;
  239. .msPhoto {
  240. display: flex;
  241. justify-content: center;
  242. align-items: center;
  243. max-width: 100%;
  244. max-height: 270px;
  245. img {
  246. max-width: 100%;
  247. max-height: 270px;
  248. }
  249. }
  250. .imgbbx {
  251. display: flex;
  252. flex-direction: column;
  253. align-items: center;
  254. justify-content: center;
  255. width: 100%;
  256. height: 100%;
  257. i {
  258. font-weight: bold;
  259. margin: 14px 0;
  260. font-size: 24px;
  261. }
  262. }
  263. }
  264. p {
  265. margin: 5px 0px;
  266. }
  267. }
  268. </style>