meetingDeclarationUpload.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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'],
  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. for(var i=0;i<this.attList.length;i++)
  82. {
  83. if(this.attList[i].fileName == file.name){
  84. this.$message.error('文件名重复,请修改文件名后,再上传!');
  85. this.attList.push(this.attList[i])
  86. return false
  87. }
  88. }
  89. this.loading = true;
  90. let query = new FormData();
  91. query.append("file", file);
  92. if(this.fileInfo.typename == '新增素材'){
  93. query.append("advType", this.fileInfo.advType);
  94. query.append("advTypeName", this.fileInfo.advTypeName);
  95. }
  96. if(this.fileInfo.url == '/market/cIllegalCallTask/importTempByProv'||this.fileInfo.url == '/market/cChannelInfo/cIllegalCallTask/importTempByProv'){
  97. query.append("taskId", this.fileInfo.taskId);
  98. query.append("tempId", this.fileInfo.tempId);
  99. }
  100. //违规外呼
  101. if(this.fileInfo.uploadType == 'outCall'){
  102. query.append("uploadType", 'outCall');
  103. query.append("relId", this.fileInfo.relId);
  104. }
  105. if(this.fileInfo.uploadType == 'train'){
  106. query.append("uploadType", 'train');
  107. query.append("relId", this.fileInfo.relId);
  108. }
  109. //运营类项目考核及结算
  110. if(this.fileInfo.url == '/market/cmkAttachInfo/upload'){
  111. query.append("uploadType", this.fileInfo.uploadType);
  112. }
  113. if(this.fileInfo.url == '/market/cStoreOutWo/importData'){
  114. query.append("woNo", this.fileInfo.woNo);
  115. }
  116. if(this.fileInfo.url == '/market/cStoreScheTrainEva/importDataEva'){
  117. query.append("evaId", this.fileInfo.evaId);
  118. }
  119. this.num++;
  120. let _this = this;
  121. this.$http({
  122. url: this.fileInfo.url,
  123. method: "post",
  124. headers: {
  125. "Content-Type": "application/json",
  126. },
  127. data: query,
  128. }).then((res) => {
  129. if (this.fileInfo.type === 'btn') {
  130. this.$refs['upload'].clearFiles();
  131. this.$emit('uploadBack',res)
  132. _this.$message({
  133. message: res.data.desc,
  134. type: 'success'
  135. });
  136. this.num--;
  137. if (this.num == 0) {
  138. this.loading = false;
  139. }
  140. return
  141. }
  142. if (this.fileInfo.type === 'voice') {
  143. this.attList = res.data;
  144. } else {
  145. this.attList.push({
  146. id: res.data.body.id,
  147. fileName: res.data.body.fileName,
  148. fileCode: res.data.body.fileCode,
  149. opName: res.data.body.opName,
  150. opNo: res.data.body.opNo,
  151. opTime: res.data.body.opTime,
  152. attchFileId: res.data.body.attchFileId,
  153. type: res.data.body.type,
  154. });
  155. }
  156. this.$emit('uploadBack', this.attList);
  157. this.num--;
  158. if (this.num == 0) {
  159. this.loading = false;
  160. }
  161. return true
  162. }).catch((res) => {
  163. this.$message({
  164. message: file.name+'上传失败',
  165. type: 'error'
  166. });
  167. this.num--;
  168. if (this.num == 0) {
  169. this.loading = false;
  170. }
  171. for (let i = 0; i < this.$refs['upload'].uploadFiles.length; i++) {
  172. if(file.name == this.$refs['upload'].uploadFiles[i].name){
  173. this.$refs['upload'].uploadFiles.splice(i,1)
  174. }
  175. }
  176. return false
  177. })
  178. },
  179. },
  180. mounted() {
  181. },
  182. created() {
  183. this.attList = [];
  184. for (let i = 0; i < this.fileList.length; i++) {
  185. this.attList.push({
  186. id: this.fileList[i].id,
  187. fileName: this.fileList[i].fileName,
  188. fileCode: this.fileList[i].fileCode,
  189. opName: this.fileList[i].opName,
  190. opNo: this.fileList[i].opNo,
  191. opTime: this.fileList[i].opTime,
  192. attchFileId: this.fileList[i].attchFileId,
  193. type: this.fileList[i].type,
  194. })
  195. }
  196. },
  197. watch: {
  198. fileList() {
  199. this.attList = [];
  200. for (let i = 0; i < this.fileList.length; i++) {
  201. this.attList.push({
  202. id: this.fileList[i].id,
  203. fileName: this.fileList[i].fileName,
  204. fileCode: this.fileList[i].fileCode,
  205. opName: this.fileList[i].opName,
  206. opNo: this.fileList[i].opNo,
  207. opTime: this.fileList[i].opTime,
  208. attchFileId: this.fileList[i].attchFileId,
  209. type: this.fileList[i].type,
  210. })
  211. }
  212. }
  213. }
  214. }
  215. </script>
  216. <style scoped lang="scss">
  217. </style>