EquityConversion.vue
5.6 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
<template>
<view
class="upload-content"
:key="viewKey"
>
<view class="upload-box">
<view class="label">发票或收据</view>
<view class="upload-item">
<template v-if="imgObj.retrofitInvoice">
<image
class="img"
:src="imgObj.retrofitInvoice"
@click="previewMedia(imgObj.retrofitInvoice)"
/>
<view class="del flex">
<uni-icons
type="closeempty"
:size="10"
color="#fff"
@click="delImage('retrofitInvoice')"
></uni-icons>
</view>
</template>
<template v-else>
<view
class="upload-component"
@click="chooseImage('retrofitInvoice')"
>
<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="upload-item">
<template v-if="imgObj.retrofit">
<image
class="img"
:src="imgObj.retrofit"
@click="previewMedia(imgObj.retrofit)"
/>
<view class="del flex">
<uni-icons
type="closeempty"
:size="10"
color="#fff"
@click="delImage('retrofit')"
></uni-icons>
</view>
</template>
<template v-else>
<view
class="upload-component"
@click="chooseImage('retrofit')"
>
<uni-icons
type="plusempty"
:size="22"
color="#347BFF"
class="icon"
></uni-icons>
<view class="text">上传照片</view>
</view>
</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 = {
retrofitInvoice: imgObj.retrofitInvoice || '',
retrofit: imgObj.retrofit || ''
}
},
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) {
this.imgObj[key] = ''
this.viewKey = Date.now()
},
async chooseImage (key) {
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])
_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: toRpx(32) toRpx(32) 0;
.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>