upload.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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.$message({
  126. message: res.data.desc,
  127. type: 'success'
  128. });
  129. }else if(res.data.result==1){
  130. _this.$message({
  131. message: res.data.desc,
  132. type: 'error'
  133. });
  134. }else if(res.data.result==2){
  135. _this.$message({
  136. message: res.data.desc,
  137. type: 'warning'
  138. });
  139. }else if(res.data.result==3){
  140. _this.$message({
  141. message: res.data.desc,
  142. type: 'info'
  143. });
  144. }else{
  145. _this.$message({
  146. message: res.data.desc,
  147. type: 'success'
  148. });
  149. }
  150. this.num--;
  151. if (this.num == 0) {
  152. this.loading = false;
  153. }
  154. return
  155. }
  156. if (this.fileInfo.type === 'voice') {
  157. this.attList = res.data;
  158. } else {
  159. this.attList.push({
  160. id: res.data.body.id,
  161. fileName: res.data.body.fileName,
  162. fileCode: res.data.body.fileCode,
  163. opName: res.data.body.opName,
  164. opNo: res.data.body.opNo,
  165. opTime: res.data.body.opTime,
  166. attchFileId: res.data.body.attchFileId,
  167. type: res.data.body.type,
  168. });
  169. }
  170. this.$emit('uploadBack', this.attList);
  171. this.num--;
  172. if (this.num == 0) {
  173. this.loading = false;
  174. }
  175. return true
  176. }).catch((res) => {
  177. this.$message({
  178. message: file.name+'上传失败',
  179. type: 'error'
  180. });
  181. this.num--;
  182. if (this.num == 0) {
  183. this.loading = false;
  184. }
  185. for (let i = 0; i < this.$refs['upload'].uploadFiles.length; i++) {
  186. if(file.name == this.$refs['upload'].uploadFiles[i].name){
  187. this.$refs['upload'].uploadFiles.splice(i,1)
  188. }
  189. }
  190. return false
  191. })
  192. },
  193. },
  194. mounted() {
  195. },
  196. created() {
  197. this.attList = [];
  198. for (let i = 0; i < this.fileList.length; i++) {
  199. this.attList.push({
  200. id: this.fileList[i].id,
  201. fileName: this.fileList[i].fileName,
  202. fileCode: this.fileList[i].fileCode,
  203. opName: this.fileList[i].opName,
  204. opNo: this.fileList[i].opNo,
  205. opTime: this.fileList[i].opTime,
  206. attchFileId: this.fileList[i].attchFileId,
  207. type: this.fileList[i].type,
  208. })
  209. }
  210. },
  211. watch: {
  212. fileList() {
  213. this.attList = [];
  214. for (let i = 0; i < this.fileList.length; i++) {
  215. this.attList.push({
  216. id: this.fileList[i].id,
  217. fileName: this.fileList[i].fileName,
  218. fileCode: this.fileList[i].fileCode,
  219. opName: this.fileList[i].opName,
  220. opNo: this.fileList[i].opNo,
  221. opTime: this.fileList[i].opTime,
  222. attchFileId: this.fileList[i].attchFileId,
  223. type: this.fileList[i].type,
  224. })
  225. }
  226. }
  227. }
  228. }
  229. </script>
  230. <style scoped lang="scss">
  231. </style>