EquityUpload.vue
8.99 KB
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<template>
<view
class="upload-content"
:key="viewKey"
>
<view class="upload-box">
<view class="label">购车发票</view>
<view class="upload-item">
<template v-if="imgObj.invoice">
<image
class="img"
:src="imgObj.invoice"
@click="previewMedia(imgObj.invoice)"
/>
<view class="del flex">
<uni-icons
type="closeempty"
:size="10"
color="#fff"
@click="delImage('invoice')"
></uni-icons>
</view>
</template>
<template v-else>
<view
class="upload-component"
@click="chooseImage('invoice')"
>
<uni-icons
type="plusempty"
:size="22"
color="#347BFF"
class="icon"
></uni-icons>
<view class="text">上传照片</view>
</view>
</template>
</view>
</view>
<view class="upload-box">
<view class="label">行驶证或车辆合格证</view>
<view class="value flex">
<view class="upload-item">
<template v-if="imgObj.driveFront">
<image
class="img"
:src="imgObj.driveFront"
@click="previewMedia(imgObj.driveFront)"
/>
<view class="del flex">
<uni-icons
type="closeempty"
:size="10"
color="#fff"
@click="delImage('driveFront')"
></uni-icons>
</view>
</template>
<template v-else>
<view
class="upload-component"
@click="chooseImage('driveFront')"
>
<uni-icons
type="plusempty"
:size="22"
color="#347BFF"
class="icon"
></uni-icons>
<view class="text">行驶证主页/车辆合格证</view>
</view>
</template>
</view>
<view class="upload-item">
<template v-if="imgObj.driveBack">
<image
class="img"
:src="imgObj.driveBack"
@click="previewMedia(imgObj.driveBack)"
/>
<view class="del flex">
<uni-icons
type="closeempty"
:size="10"
color="#fff"
@click="delImage('driveBack')"
></uni-icons>
</view>
</template>
<template v-else>
<view
class="upload-component"
@click="chooseImage('driveBack')"
>
<uni-icons
type="plusempty"
:size="22"
color="#347BFF"
class="icon"
></uni-icons>
<view class="text">行驶证副页/车辆合格证</view>
</view>
</template>
</view>
</view>
</view>
<view class="upload-box">
<view class="label">合同购买时里程数</view>
<view class="upload-item">
<template v-if="imgObj.contract">
<image
class="img"
:src="imgObj.contract"
@click="previewMedia(imgObj.contract)"
/>
<view class="del flex">
<uni-icons
type="closeempty"
:size="10"
color="#fff"
@click="delImage('contract')"
></uni-icons>
</view>
</template>
<template v-else>
<view
class="upload-component"
@click="chooseImage('contract')"
>
<uni-icons
type="plusempty"
:size="22"
color="#347BFF"
class="icon"
></uni-icons>
<view class="text">上传照片</view>
</view>
</template>
</view>
</view>
<view class="upload-box">
<view class="label">其他</view>
<view class="value flex">
<template v-if="imgObj.other.length < 9">
<view
class="upload-item"
@click="chooseImage('other',true)"
>
<uni-icons
type="plusempty"
:size="22"
color="#347BFF"
class="icon"
></uni-icons>
<view>上传照片最多9张</view>
</view>
</template>
<template v-if="imgObj.other.length">
<template v-for="(i,index) in imgObj.other">
<view
class="upload-item"
:key="index"
>
<image
class="img"
:src="i"
@click="previewMedia(imgObj.other,index)"
/>
<view class="del flex">
<uni-icons
type="closeempty"
:size="10"
color="#fff"
@click="delImage('other',index , true)"
></uni-icons>
</view>
</view>
</template>
</template>
</view>
</view>
</view>
</template>
<script type='text/ecmascript-6'>
import { uploadFile } from '@/utils/ossUpload.js'
import permision from '@/js_sdk/wa-permission/permission.js'
export default {
name: 'EquityUpload',
props: {
externalData: null,
},
watch: {
externalData: {
handler (val) {
let { imgObj } = val
if(Object.keys(this.imgObj).length) return
this.imgObj = {
invoice: imgObj.invoice || '',
driveFront: imgObj.driveFront || '',
driveBack: imgObj.driveBack || '',
contract: imgObj.contract || '',
other: imgObj.other || []
}
},
deep: true,
immediate: true
}
},
data () {
return {
viewKey: Date.now(),
imgObj: { }
}
},
mounted () {
},
methods: {
previewMedia (urls, index = 0) {
uni.previewImage({
current: index,
urls: Array.isArray(urls) ? urls : [urls],
})
},
delImage (key, index, isArray) {
if (isArray) this.imgObj[key].splice(index, 1)
else this.imgObj[key] = ''
this.viewKey = Date.now()
},
async chooseImage (key, isArray) {
let _this = this
try {
// #ifdef APP-PLUS
const photoLibrary = await permision.requestAndroidPermission('android.permission.READ_EXTERNAL_STORAGE')
const camera = await permision.requestAndroidPermission('android.permission.CAMERA')
const isOnline = await uni.$isNetWork()
if (photoLibrary != 1) throw '您的设备不支持相册功能或未授权访问,请前往设置中开启相册权限'
if (camera != 1) throw '您的设备不支持摄像头功能或未授权访问,请前往设置中开启摄像头权限'
if (!isOnline) throw '当前无网络连接,请连接网络后重试'
// #endif
uni.chooseImage({
count: 1,
async success (res) {
uni.showLoading({ title: '上传中...', mask: true })
const url = await uploadFile(res.tempFiles[0], res.tempFilePaths[0])
if (isArray) _this.imgObj[key].push(url)
else _this.imgObj[key] = url
_this.viewKey = Date.now()
uni.hideLoading()
},
fail (err) {
uni.hideLoading()
if (err.errMsg.indexOf('cancel') === -1) {
return uni.showToast({
title: '图片上传失败',
icon: 'none'
})
}
},
})
} catch (error) {
uni.hideLoading()
return uni.showToast({
title: error,
icon: 'none'
})
}
},
}
}
</script>
<style scoped lang='scss'>
.upload-content {
padding: 0 toRpx(32);
.upload-box {
display: flex;
margin-bottom: toRpx(32);
.label {
width: toRpx(168);
flex-shrink: 0;
margin-right: toRpx(32);
}
.value {
gap: toRpx(16);
flex-wrap: wrap;
}
.upload-item {
width: toRpx(192);
height: toRpx(192);
border-radius: toRpx(12);
background: #f5f8ff;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
color: #999999;
font-size: toRpx(20);
position: relative;
.del {
position: absolute;
width: toRpx(32);
height: toRpx(32);
background: #00000080;
border-radius: 100%;
top: toRpx(8);
right: toRpx(4);
justify-content: center;
}
.upload-component {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.icon {
font-weight: 700;
margin-bottom: toRpx(22);
}
.img {
width: 100%;
height: 100%;
}
.text {
width: 80%;
text-align: center;
}
}
}
}
</style>