index.vue
8.29 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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<template>
<view class="scan-detail-container">
<view class="scan-detail-box">
<view class="scan-time">
<view class="scan-label">
分发时间:
</view>
<view class="scan-time">
{{ details.garCreateTime }}
</view>
</view>
<view class="scan-time">
<view class="scan-label">
司机姓名:
</view>
<view class="scan-time">
{{ details.garOrderHandlerName }}
</view>
</view>
<view class="scan-time">
<view class="scan-label">
司机电话:
</view>
<view class="scan-time" style="color: #000000">
{{ details.garOrderHandlerTel }}
</view>
</view>
<view class="scan-time">
<view class="scan-label">
所属公司:
</view>
<view class="scan-time">
{{ details.garOrderCompanyName }}
</view>
</view>
</view>
<view class="scan-submit-info">
<view class="scan-submit-title-box">
<up-badge :isDot="true" type="success"></up-badge><text>提交信息</text>
</view>
<view class="scan-car-num">
<view class="scan-car-num-label">
车牌号
</view>
<view class="scan-car-num-content">
{{ details.garHandlerCarCode }}
</view>
</view>
<view class="scan-car-num">
<view class="scan-car-num-label">
车辆载重
</view>
<view class="scan-car-num-content">
<up-input :disabled="!isDeletable" placeholder="请输入数字,单位吨" border="surround"
v-model="details.garCarryingWeight" @change="handlerInputChange"></up-input>
</view>
</view>
<view class="scan-upload-fill-image-box">
<view class="scan-upload-fill-image-label">
<view>
全景照片
</view>
<view v-if="isDeletable">
{{ fileList.length }}/{{ maxCount }}
</view>
</view>
<view class="scan-upload-fill-image-btn" v-if="maxCount">
<u-upload width="200" height="150" :deletable="isDeletable" :fileList="fileList"
@afterRead="afterRead" @delete="deletePic" name="3" multiple :maxCount="maxCount"
:previewFullImage="true"></u-upload>
</view>
</view>
</view>
<view class="scan-submit-button-box" v-if="isNew">
<view class="scan-submit-button-btn">
<u-button type="primary" @tap="handlerSubmit" text="确认"></u-button>
</view>
</view>
</view>
</template>
<script setup>
import {
uploadFilePromise
} from '@/apis/common.js';
import {
askTransport,
scanDetail
} from '@/apis/order.js';
import {
onLoad
} from '@dcloudio/uni-app';
import {
computed,
ref,
onMounted
} from 'vue';
const details = ref({});
const fileList = ref([]);
const isDeletable = ref(false);
const maxCount = computed(() => isDeletable.value ? 3 : fileList.value.length);
// 删除图片
const deletePic = (event) => {
fileList.value.splice(event.index, 1);
};
const location = ref({});
const takeLocalCallBack = (lngLat) => {
const ll = lngLat.split(",");
console.log(ll);
location.value = {
longitude: ll[0],
latitude: ll[1]
};
}
// 生命周期处理
onMounted(() => {
// 挂载全局回调
window.takeLocationCallBack = takeLocalCallBack
})
const takeLocation = () => {
console.log("获取定位信息");
// 获取定位信息
window.JsInterface.takeLocation();
}
const isNew = ref(false)
// 新增图片
const afterRead = async (event) => {
// 获取定位信息
takeLocation();
// 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
let lists = [].concat(event.file);
let fileListLen = fileList.value.length;
lists.map((item) => {
fileList.value.push({
...item,
status: 'uploading',
message: '上传中',
});
});
// 将blob转为file对象的方法
function blobToFile(blob, fileName) {
return new File([blob], fileName, {
type: 'image/png'
})
}
for (let i = 0; i < lists.length; i++) {
// 获取blob对象
fetch(lists[i].url)
.then(response => response.blob())
.then(blob => {
// 将blob转换为file
let fileN = blobToFile(blob, lists[i].name)
// 上传file对象
let requestPath = import.meta.env.VITE_BASE_URL + import.meta.env
.VITE_BASE_FILE_UPLOAD_PREFIX;
uploadFilePromise(requestPath, fileN).then(result => {
let item = fileList.value[fileListLen];
fileList.value.splice(fileListLen, 1, {
...item,
status: 'success',
message: '',
url: result.data.fileName,
});
fileListLen++;
});
})
}
};
const handlerInputChange = (val) => {
console.log(val);
}
const handlerSubmit = async () => {
// 校验参数
let params = {
...details.value,
fillImageList: fileList.value.map((item) => item.url),
garOrderHandlerCompanyName: details.value.garOrderCompanyName,
garOrderHandlerCompanyId: details.value.garOrderCompanyId,
// 添加定位信息
latitude: location.value.latitude,
longitude: location.value.longitude
}
if (validateParams(params)) {
await askTransport(params).then((res) => {
console.log(res);
if (res.data.code == 200) {
uni.$u.toast("当前趟次记录完毕!")
}
}).catch((err) => {
uni.$u.toast("当前趟次记录失败")
})
// 返回上级
uni.navigateBack({
delta: 1
});
}
}
const validateParams = (params) => {
if (!params.garOrderHandlerName) {
uni.$u.toast("请输入处理人姓名");
return false;
}
if (!params.garOrderHandlerTel) {
uni.$u.toast("请输入处理人电话");
return false;
}
if (!params.garOrderCompanyName) {
uni.$u.toast("请输入处理人单位");
return false;
}
if (!params.garCarryingWeight) {
uni.$u.toast("请输入车辆载重");
return false;
}
if (!validateImage(params.fillImageList)) {
return false;
}
if (typeof(location.value.latitude) === 'undefined') {
console.log('定位获取失败', );
uni.$u.toast("需要位置权限才能提交");
return;
}
return true;
}
const validateImage = (fillImageList) => {
if (fillImageList instanceof Array && fillImageList.length > 0) {
for (let index = 0; index < fillImageList.length; index++) {
const str = fillImageList[index];
if (!str.includes("/profile/upload")) {
uni.$u.toast("请等待图片上传~");
return false;
}
}
return true;
}
uni.$u.toast("请上传图片~");
return false;
}
onLoad((options) => {
if (options.data) {
details.value = JSON.parse(decodeURIComponent(options.data));
isDeletable.value = true;
isNew.value = true;
}
if (options.garAskId) {
// TODO query
scanDetail(options.garAskId).then((res) => {
console.log(res);
details.value = res.data.data;
details.value.garOrderCompanyName = details.value.garOrderHandlerCompanyName;
fileList.value = details.value.fillImageList.map((item) => {
return {
url: import.meta.env.VITE_BASE_URL + item
}
})
})
}
})
</script>
<style lang="scss" scoped>
$l-h-8: 80rpx;
.scan-detail-container {
width: 100%;
height: 100%;
box-sizing: border-box;
padding: 20rpx;
.scan-detail-box {
background-color: white;
margin-bottom: 40rpx;
color: $u-main-color;
.scan-time {
display: flex;
width: 100%;
// 底部阴影 向内发散
border-bottom: 1rpx solid #f5f5f5;
line-height: 100rpx;
align-items: center;
.scan-label {
width: 30%;
display: flex;
align-items: center;
justify-content: center;
}
.scan-time {
width: 60%;
}
.scan-icon {
width: 10%;
display: flex;
}
}
}
.scan-submit-info {
width: 100%;
background-color: white;
box-sizing: border-box;
padding: 20rpx;
color: $u-content-color;
.scan-submit-title-box {
display: flex;
align-items: center;
text {
margin-left: 15rpx;
}
}
.scan-car-num {
display: flex;
line-height: $l-h-8;
align-items: center;
.scan-car-num-label {
width: 20%;
// 文字不换行
white-space: nowrap;
}
.scan-car-num-content {
width: auto;
display: flex;
justify-content: center;
align-items: center;
}
}
.scan-upload-fill-image-box {
line-height: $l-h-8;
width: 100%;
.scan-upload-fill-image-label {
display: flex;
justify-content: space-between;
}
.scan-upload-fill-image-btn {}
}
}
.scan-submit-button-box {
margin-top: 40rpx;
background-color: white;
padding: 20rpx;
}
}
</style>