You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
3.6 KiB

  1. <script>
  2. import {uploadFileList} from '@/api/base/baseFunction.js';
  3. export default {
  4. name: "uploadFileList",
  5. props: {
  6. uploadDialog: {
  7. type: Boolean,
  8. default: false,
  9. },
  10. title: {
  11. type: String,
  12. default: '上传文件',
  13. },
  14. label: {
  15. type: String,
  16. default: '',
  17. },
  18. no: {
  19. type: [String,Number],
  20. default: ''
  21. },
  22. path: {
  23. type: String,
  24. request: true,
  25. },
  26. uploadStatus: {
  27. type: Boolean,
  28. default: false,
  29. },
  30. fileList: {
  31. type: Array,
  32. default:() => [],
  33. },
  34. folder: {
  35. type: String,
  36. default: ''
  37. },
  38. orderRef3: {
  39. type: [String,Number],
  40. default: ''
  41. },
  42. orderRef4: {
  43. type: [String,Number],
  44. default: ''
  45. },
  46. },
  47. data () {
  48. return {
  49. //fileRemark: '',
  50. }
  51. },
  52. methods: {
  53. closeFileUpdate () {
  54. this.$emit('update:uploadDialog',false)
  55. if (this.uploadStatus) {
  56. return
  57. }
  58. //this.fileRemark = ''
  59. this.$refs.uploadFile.clearFiles()
  60. this.$emit("update:fileList",[])
  61. },
  62. onRemove (file,fileList) {
  63. this.$emit("update:fileList",fileList)
  64. },
  65. onChange (file,fileList) {
  66. this.$emit("update:fileList",fileList)
  67. },
  68. upload () {
  69. if (this.fileList.length === 0) {
  70. this.$message.warning("未选择需要上传的文件")
  71. return;
  72. }
  73. if (this.uploadStatus) {
  74. this.$emit('update:uploadDialog',false)
  75. this.$message.success("操作成功")
  76. return
  77. }
  78. let data = new FormData()
  79. for (let i = 0; i < this.fileList.length; i++) {
  80. data.append("file",this.fileList[i].raw)
  81. }
  82. data.append("orderRef1", this.$store.state.user.site)
  83. data.append("orderRef2", this.no)
  84. data.append("orderRef3", this.orderRef3)
  85. data.append("orderRef4", this.orderRef4)
  86. data.append("createBy", this.$store.state.user.name)
  87. //data.append("fileRemark", this.fileRemark)
  88. data.append("folder", this.folder)
  89. uploadFileList(this.path, data).then(({data})=>{
  90. if (data && data.code === 0) {
  91. this.$emit('update:uploadDialog',false)
  92. this.$message.success(data.msg)
  93. } else {
  94. this.$message.warning(data.msg)
  95. }
  96. }).catch((error) => {
  97. this.$message.error(error)
  98. })
  99. }
  100. }
  101. }
  102. </script>
  103. <template>
  104. <div>
  105. <el-dialog :title="title" v-drag @close="closeFileUpdate" :visible="uploadDialog" width="400px" append-to-body>
  106. <el-form label-position="top" label-width="80px">
  107. <el-form-item :label="label" >
  108. <el-input v-model="no" readonly style="width: 120px"></el-input>
  109. </el-form-item>
  110. <el-form-item label=" ">
  111. <el-upload drag :file-list="fileList"
  112. ref="uploadFile"
  113. :on-remove="onRemove" :on-change="onChange"
  114. multiple :auto-upload="false"
  115. style="text-align: left;">
  116. <i class="el-icon-upload"></i>
  117. <div class="el-upload__text">将文件拖到此处<em>点击上传</em></div>
  118. </el-upload>
  119. </el-form-item>
  120. <!-- <el-form-item label="备注:">-->
  121. <!-- <el-input type="textarea" placeholder="请输入内容" v-model="fileRemark"></el-input>-->
  122. <!-- </el-form-item>-->
  123. </el-form>
  124. <span slot="footer" class="dialog-footer">
  125. <el-button type="primary" v-if="!uploadStatus" @click="upload">保存</el-button>
  126. <el-button type="primary" @click="$emit('update:uploadDialog',false)">关闭</el-button>
  127. </span>
  128. </el-dialog>
  129. </div>
  130. </template>
  131. <style scoped>
  132. /deep/ .el-form-item--medium .el-form-item__content{
  133. height: auto;
  134. }
  135. </style>