workflowUpload.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <template>
  2. <div v-loading="loading">
  3. <el-upload
  4. class="upload-demo"
  5. :drag="fileInfo.type !== 'btn'"
  6. multiple
  7. :limit="fileInfo.limit"
  8. ref="upload"
  9. action="string"
  10. :on-remove="handleRemove"
  11. :before-remove="beforeRemove"
  12. :on-exceed="handleExceed"
  13. :on-preview="clickDownload"
  14. :file-list="attList"
  15. :auto-upload="true"
  16. :show-file-list="fileInfo.type !== 'btn'"
  17. :before-upload="deforeUp"
  18. :http-request="signUpload"
  19. >
  20. <div v-if="fileInfo.type !== 'btn'">
  21. <i class="el-icon-upload"></i>
  22. <div class="el-upload__text">点击上传</div>
  23. </div>
  24. <div v-if="fileInfo.type === 'btn'">
  25. <el-button
  26. :size="fileInfo.size ? fileInfo.size : 'medium'"
  27. :type="fileInfo.btntype"
  28. >{{ fileInfo.typename }}</el-button
  29. >
  30. </div>
  31. </el-upload>
  32. </div>
  33. </template>
  34. <script>
  35. export default {
  36. props: ["fileInfo", "fileList", "type"],
  37. data() {
  38. return {
  39. fileLists: [],
  40. attList: [],
  41. loading: false,
  42. num: 0,
  43. s: false,
  44. };
  45. },
  46. methods: {
  47. clickDownload(file) {
  48. this.$emit("clickDownload", file);
  49. },
  50. signUpload() {},
  51. //删除
  52. handleRemove(file) {
  53. console.log(file);
  54. console.log(this.attList);
  55. for (let i = 0; i < this.attList.length; i++) {
  56. if (this.attList[i].name === file.name) {
  57. this.attList.splice(i, 1);
  58. console.log(55555);
  59. this.$emit("delloadBack", this.attList);
  60. }
  61. }
  62. },
  63. beforeRemove(file) {
  64. console.log(file);
  65. },
  66. //数量限制
  67. handleExceed(files, fileList) {
  68. this.$message.warning(
  69. `当前限制选择 ${this.fileInfo.limit} 个文件,本次选择了 ${
  70. files.length
  71. } 个文件,共选择了 ${files.length + fileList.length} 个文件`
  72. );
  73. },
  74. deforeUp(file) {
  75. const isLt2M = file.size / 1024 / 1024 < 100;
  76. if (!isLt2M) {
  77. this.$message.error("上传文件大小不能超过 20MB!");
  78. return false;
  79. }
  80. if (this.fileInfo.type == "img") {
  81. const isImg = file.type.split("/")[0] == "image";
  82. if (!isImg) {
  83. this.$message.error("请上传图片格式文件!");
  84. return false;
  85. }
  86. }
  87. if (this.fileInfo.typexz == "ppt") {
  88. const isImg = file.name.split(".")[1] == "pptx";
  89. console.log(file.name.split(".")[1] == "pptx");
  90. if (!isImg) {
  91. this.$message.error("请上传ppt格式文件!");
  92. return false;
  93. }
  94. }
  95. if (this.fileInfo.typexz == "csv") {
  96. const isImg = file.name.split(".")[1] == "csv";
  97. if (!isImg) {
  98. this.$message.error("请上传csv格式文件!");
  99. return false;
  100. }
  101. }
  102. if (this.fileInfo.typexz == "xlsx") {
  103. const isImg = file.name.split(".")[1] == "xlsx";
  104. if (!isImg) {
  105. this.$message.error("请上传xlsx格式文件!");
  106. return false;
  107. }
  108. }
  109. this.loading = true;
  110. let query = new FormData();
  111. query.append("file", file);
  112. if (this.fileInfo.typename == "新增素材") {
  113. query.append("advType", this.fileInfo.advType);
  114. query.append("advTypeName", this.fileInfo.advTypeName);
  115. }
  116. if (
  117. this.fileInfo.url == "/market/cIllegalCallTask/importTempByProv" ||
  118. this.fileInfo.url ==
  119. "/market/cChannelInfo/cIllegalCallTask/importTempByProv"
  120. ) {
  121. query.append("taskId", this.fileInfo.taskId);
  122. query.append("tempId", this.fileInfo.tempId);
  123. }
  124. //违规外呼
  125. if (this.fileInfo.uploadType == "outCall") {
  126. query.append("uploadType", "outCall");
  127. query.append("relId", this.fileInfo.relId);
  128. }
  129. if (this.fileInfo.uploadType == "train") {
  130. query.append("uploadType", "train");
  131. query.append("relId", this.fileInfo.relId);
  132. }
  133. //运营类项目考核及结算
  134. if (this.fileInfo.url == "/market/cmkAttachInfo/upload") {
  135. query.append("uploadType", this.fileInfo.uploadType);
  136. }
  137. if (this.fileInfo.url == "/market/cStoreOutWo/importData") {
  138. query.append("woNo", this.fileInfo.woNo);
  139. }
  140. if (this.fileInfo.url == "/market/cStoreScheTrainEva/importDataEva") {
  141. query.append("evaId", this.fileInfo.evaId);
  142. }
  143. this.num++;
  144. let _this = this;
  145. this.$http({
  146. url: this.fileInfo.url,
  147. method: "post",
  148. headers: {
  149. "Content-Type": "application/json",
  150. },
  151. data: query,
  152. })
  153. .then((res) => {
  154. if (this.fileInfo.type === "btn") {
  155. this.$refs["upload"].clearFiles();
  156. this.$emit("uploadBack", res);
  157. if (res.data.result == 0) {
  158. this.$emit("onSuccess", file);
  159. _this.$message({
  160. message: res.data.desc,
  161. type: "success",
  162. });
  163. } else if (res.data.result == 1) {
  164. _this.$message({
  165. message: res.data.desc,
  166. type: "error",
  167. });
  168. } else if (res.data.result == 2) {
  169. _this.$message({
  170. message: res.data.desc,
  171. type: "warning",
  172. });
  173. } else if (res.data.result == 3) {
  174. _this.$message({
  175. message: res.data.desc,
  176. type: "info",
  177. });
  178. } else {
  179. _this.$message({
  180. message: res.data.desc,
  181. type: "success",
  182. });
  183. }
  184. this.num--;
  185. if (this.num == 0) {
  186. this.loading = false;
  187. }
  188. return;
  189. }
  190. if (this.fileInfo.type === "voice") {
  191. this.attList = res.data;
  192. } else {
  193. this.attList.push({
  194. id: res.data.body.id,
  195. name: res.data.body.fileName,
  196. fileCode: res.data.body.fileCode,
  197. opName: res.data.body.opName,
  198. opNo: res.data.body.opNo,
  199. opTime: res.data.body.opTime,
  200. attchFileId: res.data.body.attchFileId,
  201. type: res.data.body.type,
  202. });
  203. }
  204. this.$emit("uploadBack", this.attList);
  205. this.num--;
  206. if (this.num == 0) {
  207. this.loading = false;
  208. }
  209. return true;
  210. })
  211. .catch((res) => {
  212. this.$message({
  213. message: file.name + "上传失败",
  214. type: "error",
  215. });
  216. this.num--;
  217. if (this.num == 0) {
  218. this.loading = false;
  219. }
  220. for (let i = 0; i < this.$refs["upload"].uploadFiles.length; i++) {
  221. if (file.name == this.$refs["upload"].uploadFiles[i].name) {
  222. this.$refs["upload"].uploadFiles.splice(i, 1);
  223. }
  224. }
  225. return false;
  226. });
  227. },
  228. },
  229. mounted() {
  230. console.log(this.$refs["upload"].name);
  231. this.$refs["upload"].uploadFiles = [];
  232. console.log(this.$refs["upload"]);
  233. console.log(this.attList);
  234. // this.$refs.upload.clearFiles();
  235. },
  236. created() {
  237. this.attList = [];
  238. if (this.fileInfo.fileList != undefined) {
  239. console.log(this.fileInfo.fileList);
  240. for (let i = 0; i < this.fileInfo.fileList.length; i++) {
  241. this.attList.push({
  242. id: this.fileInfo.fileList[i].id,
  243. name: this.fileInfo.fileList[i].fileName,
  244. fileCode: this.fileInfo.fileList[i].fileCode,
  245. opName: this.fileInfo.fileList[i].opName,
  246. opNo: this.fileInfo.fileList[i].opNo,
  247. opTime: this.fileInfo.fileList[i].opTime,
  248. attchFileId: this.fileInfo.fileList[i].attchFileId,
  249. type: this.fileInfo.fileList[i].type,
  250. });
  251. }
  252. }
  253. // let list = {
  254. // attchFileId: "",
  255. // fileCode: "202209271105276441",
  256. // name: "1231233333333333.xlsx",
  257. // id: "202209271105276441",
  258. // opName: "范岩",
  259. // opNo: "fanyan",
  260. // opTime: "2022-09-27 11:05:27",
  261. // type: undefined,
  262. // };
  263. // this.fileList.push(list)
  264. },
  265. watch: {
  266. fileList: {
  267. handler(newVal, oldVal) {
  268. this.attList = [];
  269. if (this.fileList != undefined) {
  270. for (let i = 0; i < this.fileList.length; i++) {
  271. this.attList.push({
  272. id: this.fileList[i].id,
  273. name: this.fileList[i].name,
  274. fileCode: this.fileList[i].fileCode,
  275. opName: this.fileList[i].opName,
  276. opNo: this.fileList[i].opNo,
  277. opTime: this.fileList[i].opTime,
  278. attchFileId: this.fileList[i].attchFileId,
  279. type: this.fileList[i].type,
  280. });
  281. }
  282. }
  283. },
  284. },
  285. },
  286. };
  287. </script>
  288. <style scoped lang="scss">
  289. </style>