step2.js
4.67 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
// packageUsedCar/pages/deliveryNote/components/step2/step2.js
import { getSystemInfoSync } from '~/utils/systemInfo'
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/'
import newApi from '~/packageUsedCar/api'
import { uploadFile, getImageDisplayUrl } from "~/packageUsedCar/utils/oss/ossUpload.js";
Component({
/**
* 组件的属性列表
*/
properties: {
// 当前步骤
step: {
type: [String, Number],
value: 2
},
// 详情数据
detail: {
type: Object,
value: {}
},
},
/**
* 组件的初始数据
*/
data: {
IMG_URL,
imgList: [], // 图片列表
remark: '', // 备注
MAX_IMG_COUNT: 10, // 最大图片数量
MAX_IMAGE_SIZE: 10 * 1024 * 1024 // 图片最大10MB
},
/**
* 组件的方法列表
*/
methods: {
/**
* 删除图片
*/
delImage: function(e) {
const index = e.currentTarget.dataset.index
let imgList = this.data.imgList
imgList.splice(index, 1)
this.setData({
imgList: imgList
})
},
/**
* 选择图片并上传到 OSS(只存直链)
*/
chooseImage: function() {
let _this = this
const { imgList, MAX_IMG_COUNT, MAX_IMAGE_SIZE } = _this.data
const count = MAX_IMG_COUNT - imgList.length
let sysInfo = getSystemInfoSync()
if (count <= 0) {
wx.showToast({
title: '最多只能上传10张图片',
icon: 'none'
})
return
}
wx.chooseImage({
count: count,
mediaType: ['image'],
success(res) {
for (const file of res.tempFiles) {
if (file.size > MAX_IMAGE_SIZE) {
return wx.showToast({
title: '图片上传最大10MB',
icon: 'none'
})
}
}
_this.setData({
loadingFlag: true
})
const uploadImages = async (tempFiles) => {
wx.$util.showLoading('上传中')
try {
for (const item of tempFiles) {
const fileObj = {
tempFilePath: item.tempFilePath || item.path,
url: item.tempFilePath || item.path,
size: item.size,
};
const url = await uploadFile(fileObj);
imgList.push(url);
_this.setData({
imgList
});
}
wx.hideLoading();
} catch (error) {
wx.$util.showToast("上传失败,请重试")
} finally {
_this.setData({
loadingFlag: false
})
}
}
uploadImages(res?.tempFiles)
}
})
},
/**
* 确认提车
*/
async confirm() {
try {
const { imgList, step, remark, detail } = this.data
if (imgList.length === 0) return
// 拼接图片URL(用逗号分隔)
const confirmImages = imgList.join(',')
// 埋点
wx.$track.setTrackData(0, 'delivery_arrive_shop', {}, '', 7)
// 显示加载
wx.$util.showLoading('提交中...')
const res = await newApi.deliveryConfirmDelivery({
confirmImages,
deliveryOrderId: detail?.deliveryOrderId,
remark
})
console.log(res)
wx.hideLoading()
let { code, msg } = res.data
if (code == 0) {
this.triggerEvent('confirm', step)
this.triggerEvent('refreshlog')
} else {
throw msg
}
} catch (error) {
this.triggerEvent('openError', error)
}
},
/**
* 预览媒体(图片预览时使用展示 URL,带 OSS 处理参数)
*/
previewMedia: function(e) {
const url = e.currentTarget.dataset.url
const type = e.currentTarget.dataset.type
const rawList = this.data.imgList || []
const urls = rawList.map(u => getImageDisplayUrl(u, false))
const current = getImageDisplayUrl(url, false)
if (!urls.length) return
// 预览图片
wx.previewImage({
current: current,
urls: urls
})
},
/**
* 备注输入事件
*/
onRemarkInput: function(e) {
this.setData({
remark: e.detail.value
})
},
/**
* 重置组件数据(供外部调用)
*/
resetData: function() {
this.setData({
imgList: [],
remark: ''
})
},
/**
* 获取组件数据(供外部调用)
*/
getFormData: function() {
return {
imgList: this.data.imgList,
remark: this.data.remark
}
}
}
})