1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<template>
<div class="from-table font-line-space">
<a-spin :spinning="loading" style="width: 100%;height: 100%;">
<a-row type="flex">
<a-col :span="4" class="bg-gray">
<div class="special-middle">
<div>项目编号</div>
</div>
</a-col>
<a-col :span="8">
<div class="special-middle">
<div>{{projectInfo.projNo}}</div>
</div>
</a-col>
<a-col :span="4" class="bg-gray">
<div class="special-middle">
<div>项目名称</div>
</div>
</a-col>
<a-col :span="8">
<div class="special-middle">
<div>{{projectInfo.projName}}</div>
</div>
</a-col>
</a-row>
<a-row type="flex">
<a-col :span="4" class="bg-gray">
<div class="special-middle">
<div>申报人</div>
</div>
</a-col>
<a-col :span="8">
<div class="special-middle">
<div>{{projectInfo.personName}}</div>
</div>
</a-col>
<a-col :span="4" class="bg-gray">
<div class="special-middle">
<div>申报单位</div>
</div>
</a-col>
<a-col :span="8">
<div class="special-middle">
<div>{{projectInfo.appUnitName}}</div>
</div>
</a-col>
</a-row>
<a-row type="flex">
<a-col :span="4" class="bg-gray">
<div class="special-middle">
<div>申报年度</div>
</div>
</a-col>
<a-col :span="8">
<div class="special-middle">
<div>{{projectInfo.reportYear}}</div>
</div>
</a-col>
<a-col :span="4" class="bg-gray">
<div class="special-middle">
<div>项目开始结束时间</div>
</div>
</a-col>
<a-col :span="8">
<div class="special-middle">
<div>{{moment(projectInfo.startDate).format('YYYY-MM-DD')}} 至 {{moment(projectInfo.endDate).format('YYYY-MM-DD')}}</div>
</div>
</a-col>
</a-row>
<a-row>
<a-col :span="24">
<div class="tb-title">
附件上传
</div>
</a-col>
</a-row>
<a-row type="flex" class="row_center">
<a-col :span="8" class="bg-gray">
<div class="special-middle">
<div>附件名称</div>
</div>
</a-col>
<a-col :span="10" class="bg-gray">
<div class="special-middle">
<div>附件上传</div>
</div>
</a-col>
<a-col :span="6" class="bg-gray">
<div class="special-middle">
<div>说明</div>
</div>
</a-col>
</a-row>
<a-row v-for="(item, index) in projectInfo.fileList" :key="'fileList' + index" type="flex">
<a-col :span="8" style="text-align: center; margin-top: 10px;">
<span class="required"></span>{{ item.fileExplain }}
<!-- <a-form-model-item :prop="'fileList.' + index + '.fileExplain'" :rules="{required: true, message: '*',trigger: 'blur',}">
<a-input v-model="item.fileExplain" :maxLength="100" style="width: 80%" :disabled="item.required" />
</a-form-model-item> -->
</a-col>
<a-col :span="10">
<div class="special-middle">
<div v-if="item.downloadUrl" class="file-box">
<div>
<!-- <a-icon type="file" style="margin-right: 8px" />
<span class="hover-pointer" @click="downloadfile(item)">{{item.fileName}}</span> -->
<document-view :fileUrl="item.downloadUrl" :fileName="item.fileName" :imageArray="[item.downloadUrl]"></document-view>
</div>
<a-icon type="delete" class="hover-pointer d-icon" @click="deleteTaskFile(item, index)" />
</div>
<div v-else>
<a-form-model-item :prop="'fileList.' + index + '.downloadUrl'" :rules="{required: true, message: '请上传附件',trigger: 'blur',}">
<input type="file" :ref="'fileElem' + index" class="visually-hidden" @change="handleFiles(item, index)" />
<a-button @click="fileSelect(item, index)"><a-icon type="upload" />选择文件</a-button>
</a-form-model-item>
</div>
</div>
</a-col>
<a-col :span="6">
<div class="special-middle">
<span style="margin-left: 10px; font-size: 10pt; color:red; font-weight: bold;">请上传项目任务书附件(文件类型必须为:pdf),文件大小不能超过{{fileSize}}M!</span>
</div>
</a-col>
</a-row>
</a-spin>
</div>
</template>
<script>
import moment from 'moment'
import documentView from '@/views/components/common/documentView'
const File = { fileName: "", downloadUrl: "", fileExplain: "项目任务书", downloadId: "" };
export default {
name: "taskFileEdit",
props: {
value: {
type: String,
default: () => {
return null
}
},
},
components: { documentView },
data() {
return {
projectInfo: {
projNo: '',
projName: '',
startDate: '',
endDate: '',
appPersonName: '',
appUnitName: '',
mobile: '',
address: '',
fileList: [{ ...File }],
},
fileSize: 15,
};
},
created () {
this.getProjectBasicInfoById()
},
methods: {
moment,
getProjectBasicInfoById () {
if (this.value != null) {
this.loading = true
this.$api.project.getProjectBasicInfoById({ id: this.value }).then(({ data = {} }) => {
if (data) {
this.projectInfo = data
if (this.projectInfo.fileList == null || this.projectInfo.fileList.length <= 0)
this.projectInfo.fileList = [{ ...File }]
this.loading = false
}
}).catch(() => { this.$emit('close', 'close') })
}
},
downloadfile() {
},
deleteTaskFile (item, index) {
this.$api.taskReport.deleteTaskFile({ id: item.downloadId }).then(({ data = {} }) => {
if (data) {
item.fileName = ''
item.downloadUrl = ''
item.downloadId = ''
}
}).catch(() => {
this.$message.error('删除失败')
})
},
uploadHandle (file, fileName, projId) {
let formData = new FormData()
formData.append('file', file)
formData.append('fileName', fileName)
formData.append('projId', projId)
return formData
},
handleFiles(item, index) {
let fileElem = this.$refs['fileElem' + index][0]
let files = fileElem.files
if (files.length <= 0) {
this.$message.error('未选中文件,请尝试重新选择')
return
}
if (!this.fileCheck(files[0]))
return
this.$api.taskReport.asyncUploadTaskFile(this.uploadHandle(files[0], files[0].name, this.value)).then(({ data = {} }) => {
if (data) {
item.fileName = data.fileName
item.downloadUrl = data.downloadUrl
item.downloadId = data.id
item.fileExplain = data.fileExplain
} else
this.$message.error('上传失败')
}).catch(() => {
this.$message.error('上传失败')
})
},
fileSelect (item, index) {
let fileElem = this.$refs['fileElem' + index][0]
if (fileElem) {
fileElem.click()
}
},
fileCheck (file) {
//判断是否小于1M
let isLtSize = file.size < 1024 * 1024 * this.fileSize;
if (!isLtSize) {
this.$message.error('文件大小不能超过' + this.fileSize + 'M!');
return false
}
if (file.type !== "application/pdf") {
this.$message.error('项目任务书附件必须为pdf文件类型!');
return false
}
return true
},
}
};
</script>