upload.vue 9.8 KB

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