|
@@ -56,11 +56,11 @@
|
|
|
v-show="!display"
|
|
|
class="upload-demo"
|
|
|
ref="upload"
|
|
|
- multiple
|
|
|
- :action="uploadUrl"
|
|
|
+ :multiple="true"
|
|
|
+ action=""
|
|
|
:on-preview="handlePreview"
|
|
|
:on-remove="handleRemove"
|
|
|
- :on-success="handleSuccess"
|
|
|
+ :on-change="handleChange"
|
|
|
:file-list="fileList"
|
|
|
:auto-upload="false">
|
|
|
<el-button slot="trigger" size="small" type="primary">选取文件</el-button>
|
|
@@ -149,7 +149,7 @@
|
|
|
<script>
|
|
|
import templateChose from '../warehouse/template-chose'
|
|
|
import { getType, getCustomer, getCoDetail } from '@/api/cus'
|
|
|
- import { uploadUrl, downloadUrl } from '@/api/file'
|
|
|
+ import { uploadUrl, downloadUrl, uploadFiles } from '@/api/file'
|
|
|
export default {
|
|
|
name: 'communicate-add-or-update',
|
|
|
components: {templateChose},
|
|
@@ -170,14 +170,7 @@
|
|
|
fileList: [],
|
|
|
id: 0,
|
|
|
cusRCommProductVOS: [],
|
|
|
- dataForm: {
|
|
|
- // notes: '',
|
|
|
- // cusId: '',
|
|
|
- // coType: '',
|
|
|
- // name: '',
|
|
|
- // attachList: [],
|
|
|
- // cusRCommProductVOS: []
|
|
|
- },
|
|
|
+ dataForm: {},
|
|
|
dataRule: {
|
|
|
cusId: [{ required: true, message: '客户名称不能为空', trigger: 'blur' }],
|
|
|
coType: [{ required: true, message: '沟通类别不能为空', trigger: 'change' }],
|
|
@@ -218,24 +211,42 @@
|
|
|
await getCoDetail(this.id).then(({data}) => {
|
|
|
if (data && data.code === '200') {
|
|
|
this.dataForm = data.data
|
|
|
+ // 附件显示
|
|
|
+ this.fileList = []
|
|
|
+ data.data.attachList.forEach((item) => {
|
|
|
+ this.fileList.push({
|
|
|
+ name: item.fileName,
|
|
|
+ url: item.url,
|
|
|
+ id: item.url
|
|
|
+ })
|
|
|
+ })
|
|
|
+ console.log('this.fileList = ' + JSON.stringify(this.fileList))
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
submitUpload () {
|
|
|
- this.$refs.upload.submit()
|
|
|
+ // this.$refs.upload.submit()
|
|
|
+ if (this.fileList.length === 0) {
|
|
|
+ return this.$message.warning('请选取文件后再上传')
|
|
|
+ }
|
|
|
+ const formData = new FormData()
|
|
|
+ this.fileList.forEach((file) => {
|
|
|
+ formData.append('file', file.raw)
|
|
|
+ })
|
|
|
+ uploadFiles(formData).then(({data}) => {
|
|
|
+ if (data && data.code === '200') {
|
|
|
+ data.data.forEach((item) => {
|
|
|
+ let fileData = this.fileList.find((file) => file.name === item.originFileName)
|
|
|
+ fileData.url = item.fileUrl
|
|
|
+ })
|
|
|
+ this.$message.success('上传成功')
|
|
|
+ } else {
|
|
|
+ this.$message.error('上传失败')
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
handleRemove (file, fileList) {
|
|
|
- let _tmp = this.fileList
|
|
|
- // eslint-disable-next-line one-var
|
|
|
- let i = 0, len = _tmp.length
|
|
|
- for (; i < len; i++) {
|
|
|
- // eslint-disable-next-line no-cond-assign
|
|
|
- if (_tmp[i].name === file.name) {
|
|
|
- _tmp.splice(i, 1)
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- this.fileList = _tmp
|
|
|
+ this.fileList = fileList
|
|
|
},
|
|
|
handlePreview (file) {
|
|
|
if (file && file.url) {
|
|
@@ -245,28 +256,21 @@
|
|
|
this.previewVisible = true
|
|
|
}
|
|
|
},
|
|
|
- handleSuccess (response, file, fileList) {
|
|
|
- if (response && response.code === '200') {
|
|
|
- let lst = response.data
|
|
|
- for (let i = 0; i < lst.length; i++) {
|
|
|
- this.fileList.push({
|
|
|
- name: lst[i].originFileName,
|
|
|
- url: lst[i].fileUrl
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
+ handleChange (file, fileList) {
|
|
|
+ this.fileList = fileList
|
|
|
},
|
|
|
// 表单提交
|
|
|
dataFormSubmit () {
|
|
|
this.$refs['dataForm'].validate((valid) => {
|
|
|
if (valid) {
|
|
|
- console.log('fileList = ' + this.fileList)
|
|
|
- if (this.fileList.length > 0) {
|
|
|
- let fList = this.fileList
|
|
|
+ let fList = this.fileList
|
|
|
+ console.log('fileList = ' + fList)
|
|
|
+ if (fList.length > 0) {
|
|
|
+ this.dataForm.attachList = []
|
|
|
for (let i = 0; i < fList.length; i++) {
|
|
|
this.dataForm.attachList.push({
|
|
|
- fileName: fList[i].originFileName,
|
|
|
- url: fList[i].fileUrl
|
|
|
+ fileName: fList[i].name,
|
|
|
+ url: fList[i].url
|
|
|
})
|
|
|
}
|
|
|
}
|