index.vue
4.66 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
<template>
<view class="upload-image-box">
<view class="upload-image-box-choose">
<text class="upload-image-box-choose-txt">请选着上传图片类型:</text>
<view class="upload-image-box-choose-type">
<u-radio-group v-model="putType" @change="groupChange" placement="row">
<u-radio activeColor="#19be6b" :customStyle="{ marginBottom: '8px' }" size="28" labelSize="28"
v-for="(item, index) in chooseList" :key="index" :label="item.name" :name="item.name" @change="radioChange">
</u-radio>
</u-radio-group>
</view>
</view>
<view class="upload-image-box-bottom">
<text class="upload-image-box-bottom-txt">{{ putType }}(最多上传10张)</text>
<view class="upload-image-box-button-container">
<u-upload :fileList="fileList" @afterRead="afterRead" @delete="deletePic" name="3" multiple :maxCount="10"
:previewFullImage="true" width="200" height="150"></u-upload>
</view>
</view>
<view class="upload-image-box-submit-box">
<view class="upload-image-box-submit-box-button" @click="handleSubmit(orderId, putType)">
<view class="upload-image-box-submit-box-button-container">
<up-button color="#19be6b" type="primary" shape="square" text="确定"></up-button>
</view>
</view>
</view>
</view>
</template>
<script setup>
import { uploadFilePromise } from '@/apis/common.js';
import { uploadImageUrlByType } from '@/apis/order.js';
import { onLoad } from '@dcloudio/uni-app';
import { reactive, ref } from 'vue';
const putType = ref("装车图片")
const orderId = ref();
const fileList = ref([])
const chooseList = reactive([{ name: "装车图片" }, { name: "卸车图片" }])
// 删除图片
const deletePic = (event) => {
fileList.value.splice(event.index, 1);
};
// 新增图片
const afterRead = async (event) => {
// 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
let lists = [].concat(event.file);
let fileListLen = fileList.value.length;
lists.map((item) => {
fileList.value.push({
...item,
status: 'uploading',
message: '上传中',
});
});
for (let i = 0; i < lists.length; i++) {
let requestPath = import.meta.env.VITE_BASE_URL + import.meta.env.VITE_BASE_FILE_UPLOAD_PREFIX;
const result = await uploadFilePromise(requestPath, lists[i].url);
let item = fileList.value[fileListLen];
fileList.value.splice(fileListLen, 1, {
...item,
status: 'success',
message: '',
url: result.data.fileName,
});
fileListLen++;
}
};
// 提交图片
const handleSubmit = (id, type) => {
if (!validateImage()) {
uni.$u.toast("请等待图片上传~")
return
}
let params = {
garOrderId: id,
type: type == "装车图片" ? 1 : 2,
imageUrls: fileList.value.map(item => item.url)
}
uploadImageUrlByType(params).then(res => {
if (res.data.success) {
uni.$u.toast("图片上传完毕!");
setTimeout(() => {
uni.$u.route({
type: 'navigateBack',
url: `pages/order/other-home/detail/index`,
})
}, 300)
}
})
}
const validateImage = () => {
for (let index = 0; index < fileList.value.length; index++) {
const str = fileList.value[index].url;
if (!str.startsWith("/profile/upload")) {
return false;
}
}
return true;
}
onLoad((options) => {
orderId.value = options.orderId;
// putType.value = options.putType === "putOnImages" ? "装车图片" : "卸车图片";
})
</script>
<style lang="scss" scoped>
.upload-image-box {
height: 100%;
width: 100%;
background-color: #ffffff;
padding: 20rpx;
box-sizing: border-box;
line-height: 80rpx;
.upload-image-box-choose {
display: flex;
.upload-image-box-choose-txt {
white-space: nowrap;
}
.upload-image-box-choose-type {
display: flex;
justify-content: center;
align-items: center;
}
}
.upload-image-box-bottom {
.upload-image-box-bottom-txt {
color: $u-info;
}
.upload-image-box-button-container {
min-height: 350rpx;
min-width: 100%;
padding: 20rpx;
// background-color: $u-info-light;
border: 2rpx solid $u-border-color;
box-sizing: border-box;
border-radius: 10rpx;
}
}
.upload-image-box-submit-box {
box-sizing: border-box;
margin-top: 80rpx;
width: 100%;
.upload-image-box-submit-box-button {
box-sizing: border-box;
display: flex;
justify-content: flex-end;
align-items: center;
.upload-image-box-submit-box-button-container {
white-space: nowrap;
box-sizing: border-box;
width: 200rpx;
}
}
}
}
</style>