excelPop.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. if (file === undefined) {
  87. e.target.value = "";
  88. return;
  89. }
  90. var type = e.target.value.toLowerCase().split(".").splice(-1);
  91. if (type[0] != "xlsx" && type[0] != "xls") {
  92. self.$message.error("请上传excel文件,且上传格式需为:.xlsx、.xls");
  93. return;
  94. }
  95. let formData = new FormData();
  96. formData.append("file", file);
  97. this.$api
  98. .importDatabankimportDataBackList(formData)
  99. .then((res) => {
  100. console.log(res);
  101. if (res.data.fullStatus == "全部成功") {
  102. self.backDataX(res.data.questionList);
  103. self.$message.success("全部导入成功");
  104. } else {
  105. let url =
  106. baseUrls.baseURL +
  107. "common/download?fileName=" +
  108. res.data.errorExcel.msg;
  109. let link = document.createElement("a");
  110. let fileName = "导入模板" + ".xlsx";
  111. document.body.appendChild(link);
  112. link.href = url;
  113. link.dowmload = fileName;
  114. link.click();
  115. link.remove();
  116. if (res.data.fullStatus == "部分成功") {
  117. self.backDataX(res.data.questionList);
  118. self.$message.warning("部分导入成功,请打开文档查看错误原因");
  119. } else {
  120. self.$message.error("导入失败,请打开文档查看错误原因");
  121. }
  122. }
  123. })
  124. .finally(() => {
  125. e.target.value = "";
  126. });
  127. },
  128. backDataX(arry) {
  129. let arr = JSON.parse(JSON.stringify(arry));
  130. for (let i = 0; i < arr.length; i++) {
  131. arr[i].partScore = 0;
  132. arr[i].score = "";
  133. arr[i].status = 1;
  134. arr[i].businessList = [this.businObj];
  135. if (arr[i].type === 4) {
  136. arr[i].optionsList = JSON.parse(arr[i].jsonStr);
  137. arr[i].optionsList.forEach((item) => {
  138. if (item.type === 3 || item.type === 5) {
  139. item.optionsList = [];
  140. item.jsonStr = "";
  141. }
  142. });
  143. } else if (arr[i].type === 5) {
  144. arr[i].jsonStr = "";
  145. arr[i].optionsList = [];
  146. } else {
  147. arr[i].jsonStr = JSON.stringify(arr[i].optionsList);
  148. }
  149. }
  150. if (this.tableData.length) {
  151. let maxIndex = 0;
  152. let childrenIndex = 0;
  153. this.tableData.forEach((item) => {
  154. if (item.sort > maxIndex) {
  155. maxIndex = item.sort;
  156. }
  157. if (item.index > childrenIndex) {
  158. childrenIndex = item.index;
  159. }
  160. });
  161. arr.forEach((item, index) => {
  162. item.sort = maxIndex + 1;
  163. item.index = childrenIndex + 1;
  164. maxIndex++;
  165. childrenIndex++;
  166. });
  167. } else {
  168. arr.forEach((item, index) => {
  169. item.sort = index + 1;
  170. item.index = index;
  171. });
  172. }
  173. this.$emit("backExcelData", arr);
  174. this.dialogDRexcel = false;
  175. },
  176. },
  177. };
  178. </script>
  179. <style lang="less" scoped>
  180. /deep/.el-button {
  181. border-radius: 8px;
  182. }
  183. /deep/.el-dialog {
  184. border-radius: 8px;
  185. .el-dialog__header {
  186. padding: 0;
  187. .hearders {
  188. height: 40px;
  189. display: flex;
  190. align-items: center;
  191. justify-content: space-between;
  192. padding: 0px 18px 0px 20px;
  193. border-bottom: 1px solid #e2e2e2;
  194. .leftTitle {
  195. font-size: 14px;
  196. font-weight: bold;
  197. color: #2f4378;
  198. }
  199. .rightBoxs {
  200. display: flex;
  201. align-items: center;
  202. img {
  203. width: 14px;
  204. height: 14px;
  205. margin-left: 13px;
  206. cursor: pointer;
  207. }
  208. }
  209. }
  210. }
  211. .el-dialog__footer {
  212. padding: 0;
  213. .dialog-footer {
  214. padding: 0px 40px;
  215. height: 70px;
  216. border-top: 1px solid #e2e2e2;
  217. display: flex;
  218. align-items: center;
  219. justify-content: flex-end;
  220. }
  221. }
  222. }
  223. .swq {
  224. text-align: center;
  225. border-bottom: 1px solid #eee;
  226. }
  227. .dowmStys {
  228. color: blue;
  229. cursor: pointer;
  230. }
  231. .imgBox {
  232. width: 100%;
  233. // height: 210px;
  234. border: 1px solid #e2e2e2;
  235. border-radius: 8px;
  236. padding: 8px 8px 3px;
  237. display: flex;
  238. flex-direction: column;
  239. align-items: center;
  240. .imgLabel {
  241. flex: 1;
  242. width: 100%;
  243. border: 1px dotted #e2e2e2;
  244. color: #999;
  245. font-size: 14px;
  246. cursor: pointer;
  247. border-radius: 8px;
  248. .msPhoto {
  249. display: flex;
  250. justify-content: center;
  251. align-items: center;
  252. max-width: 100%;
  253. max-height: 270px;
  254. img {
  255. max-width: 100%;
  256. max-height: 270px;
  257. }
  258. }
  259. .imgbbx {
  260. display: flex;
  261. flex-direction: column;
  262. align-items: center;
  263. justify-content: center;
  264. width: 100%;
  265. height: 100%;
  266. i {
  267. font-weight: bold;
  268. margin: 14px 0;
  269. font-size: 24px;
  270. }
  271. }
  272. }
  273. p {
  274. margin: 5px 0px;
  275. }
  276. }
  277. </style>