inspectionForm.vue
12.2 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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
<template>
<view class="inspection-form">
<view class="form-container">
<view class="form-screenshot">
<!-- <uv-image
ref="screenshotRef"
width="100%"
src="https://cdn.uviewui.com/uview/album/1.jpg"
mode="widthFix"
></uv-image> -->
<!-- <canvas ref="screenshotRef" style="width: 100%;" canvas-id="firstCanvas" id="firstCanvas"></canvas> -->
<!-- <img
ref="screenshotRef"
:src="screenshotUrl"
crossOrigin
width="100%"
></img> -->
<InspectionPainter v-if="screenshotUrl" ref="inspectionPainterRef" :image-url="screenshotUrl" />
</view>
<uv-form labelPosition="left" :model="formModel" :rules="rules" :labelWidth="120" ref="formRef">
<uv-form-item :label="t('app.inspection.templateName')" prop="templateName" borderBottom @click="showTemplateNameSelect">
<uv-input v-model="templateName" disabled disabledColor="#ffffff" :placeholder="t('maintenance.common.input')" border="none">
</uv-input>
<template v-slot:right>
<uv-icon name="arrow-right"></uv-icon>
</template>
</uv-form-item>
<uv-form-item :label="t('VideoShopTour.questionnaire')" prop="problemList" @click="showProblemListSelect">
<template v-slot:right>
<view class="problemList-button">
<uv-icon name="plus"></uv-icon>
</view>
</template>
</uv-form-item>
<view class="problem-list-container">
<template v-if="problemInfoList.length > 0">
<uv-tags v-for="item in problemInfoList" :key="item.id" :text="item.name" class="problem-tag" size="medium"
shape="circle" plain :closable="true" bgColor="#F2F3F6" color="#6D778F" borderColor="#FFF"
closePlace="right" @close="handleCloseProblem(item)"></uv-tags>
</template>
<view v-else class="problem-empoty">{{ t('app.inspection.noMoreQuestion') }}</view>
</view>
<uv-form-item :label="t('maintenance.common.remark')" prop="remark" labelPosition="top" borderBottom>
<!-- <uv-input
v-model="formModel.remark"
placeholder="请输入备注信息"
border="none"
customStyle="background-color: #F2F3F6;height: 48px;padding: 0px 10px;margin-top: 10px;"
>
</uv-input> -->
<uv-textarea v-model="formModel.remark" :placeholder="t('maintenance.common.input')" :height="48" border="none"
placeholderStyle="font-size: 13px;" customStyle="background-color: #F2F3F6;margin-top: 10px;"></uv-textarea>
</uv-form-item>
<uv-form-item :label="t('app.inspection.needsRectificationOrNot')" prop="rectification" borderBottom>
<uv-radio-group v-model="formModel.rectification" placement="row">
<uv-radio name="1" :label="t('message.need')" style="margin-right: 20px;"></uv-radio>
<uv-radio name="0" :label="t('message.noNeedTitle')"></uv-radio>
</uv-radio-group>
</uv-form-item>
<uv-form-item v-if="formModel.rectification === '1'" :label="t('VideoShopTour.reformer')" prop="rectifiedPerson" borderBottom
@click="showRectifiedPersonSelect">
<uv-input v-model="rectifiedPerson" disabled disabledColor="#ffffff" :placeholder="t('maintenance.common.select')" border="none">
</uv-input>
<template v-slot:right>
<uv-icon name="arrow-right"></uv-icon>
</template>
</uv-form-item>
<uv-button type="primary" :text="t('button.submit')" customStyle="margin-top: 10px" @click="handleSubmit"></uv-button>
</uv-form>
<!-- 弹窗 -->
<!-- 模板列表 -->
<uv-action-sheet ref="templateSelectRef" :actions="templateOptions" :title="t('maintenance.common.select')" @select="setTemplateName">
</uv-action-sheet>
<!-- 问题列表 -->
<!-- TODO: UI需要调整 -->
<uv-action-sheet ref="problemSelectRef" class="inspection-problem-select" :actions="problemOptions" :title="t('maintenance.common.select')"
:closeOnClickAction="true" @select="setProblemList">
</uv-action-sheet>
<!-- 整改人 -->
<uv-action-sheet ref="rectifiedSelectRef" :actions="rectifiedPersonOptions" :title="t('maintenance.common.select')"
@select="setRectifiedPerson">
</uv-action-sheet>
</view>
</view>
</template>
<script setup>
import {
ref,
} from 'vue';
import {
onLoad
} from '@dcloudio/uni-app';
import {
doInspectionFormListApi,
doRectifiedPersonListApi,
doInspectionFormDetailApi,
doInspectionFormSaveApi
} from '@/api';
import {
getStageObj
} from '@/utils'
import {
getImagePath,
getFormParams,
getSops,
getImageBinary
} from './utils'
import InspectionPainter from './components/inspection-painter.vue';
import {
t
} from '@/plugins/index.js'
// 登录功能
const formModel = ref({
templateNameId: undefined, // 模版名称
problemList: [], // 问题id列表,提交时赋值
remark: '',
rectification: '1', // 是否需要整改
rectifiedPersonId: '',
})
const rules = {}
// 数据源
const templateOptions = ref([])
const rectifiedPersonOptions = ref([])
const problemOptions = ref([])
// 回显数据
const templateName = ref('')
const problemInfoList = ref([])
const rectifiedPerson = ref('')
// const ref
function hideKeyboard() {
uni.hideKeyboard()
}
// 模版
const templateSelectRef = ref(null)
function showTemplateNameSelect() {
templateSelectRef.value.open();
hideKeyboard();
}
function setTemplateName(e) {
console.log('setTemplateName', e)
templateName.value = e.name
formModel.value.templateNameId = e.value
// 联动巡检详情
problemInfoList.value = []
formModel.value.problemList = []
setProblemOptions(e.value)
}
// 问题项
const problemSelectRef = ref(null)
function showProblemListSelect() {
problemSelectRef.value.open();
hideKeyboard();
}
function setProblemList(e) {
console.log('setProblemList', e)
if (!formModel.value.problemList.includes(e.value)) {
problemInfoList.value.push(e)
formModel.value.problemList.push(e.value)
}
}
function handleCloseProblem(data) {
console.log('handleCloseProblem', data)
problemInfoList.value = problemInfoList.value.filter(item => item.value !== data.value)
formModel.value.problemList = formModel.value.problemList.filter(item => item !== data.value)
}
// 整改人
const rectifiedSelectRef = ref(null)
function showRectifiedPersonSelect() {
rectifiedSelectRef.value.open();
hideKeyboard();
}
function setRectifiedPerson(e) {
console.log('setRectifiedPerson', e)
formModel.value.rectifiedPersonId = e.loginName
rectifiedPerson.value = e.name
}
const screenshotRef = ref(null)
// const screenshotUrl = ref('https://store.keliuyun.com/images/patrol/screenshot/20250530/83115120-2850-4d9d-8ff2-5a4a001bb347.jpg')
const screenshotUrl = ref('')
const inspectionPainterRef = ref(null)
const gateId = ref()
const mallId = ref()
// 提交表单
async function handleSubmit() {
console.log('handleSubmit', inspectionPainterRef.value)
// const strBase64 = await getImageBase64(screenshotRef.value)
// const strBase64 = await getImageBase(screenshotUrl.value)
// const strBase64 = false
// const strBase64 = await inspectionPainterRef.value.getCanvasBase64H5()
const strBase64 = await inspectionPainterRef.value.getCanvasBase64()
if (strBase64) {
// 数据全法性验证
if (problemInfoList.value.length === 0) {
uni.showToast({
icon: 'error',
title: t('app.inspection.plzSelectQuestion')
})
return
}
const storeInfo = getStageObj('store')
const params = {
// true表示测试数据
...getFormParams(false, gateId.value, mallId.value),
patrolType: 1,
remark: formModel.value.remark,
handler: (formModel.value.rectification === '1' ? formModel.value.rectifiedPersonId : ''), // 是否有整改人
// pic: strBase64, // 二进制图片数据
picBase64: strBase64,
sops: JSON.stringify(getSops(problemInfoList.value)), // 问题项
}
console.log('params', params)
/* uni.showToast({icon: 'success', title: '提交成功'})
uni.redirectTo({
url: `/pages/inspection/inspectionRecord`,
}) */
doInspectionFormSaveApi(params).then(res => {
console.log('doInspectionFormSaveApi', res)
uni.showToast({
icon: 'success',
title: t('message.submitSuccess')
})
setTimeout(()=>{
uni.redirectTo({
url: `/subPackages/accountGroup/pages/inspection/inspectionRecord`,
})
},500)
})
} else {
uni.showToast({
icon: 'error',
title: t('app.inspection.getImgInfoError')// '获取图片信息失败'
})
}
}
function setProblemOptions(id) {
// 请求成功后,联动获取整改单详情
doInspectionFormDetailApi({
id
}).then(res => {
console.log('doInspectionFormDetailApi', res)
if (res.data) {
problemOptions.value = res.data.sopProjects.map(item => {
return {
name: item.name,
value: item.id,
score: item.score,
status: 0, // 提交巡检单,默认都是有问题的,故为0
}
})
}
})
}
function initPage(restaurantId) {
const storeInfo = getStageObj('store')
if (storeInfo) {
const formParams = {
// TODO: account 暂时写死
accountId: storeInfo.accountId,
// accountId: 337,
pageSize: 999,
}
const rectifiedParams = {
restaurantId, // 餐厅id
}
Promise.all([
doInspectionFormListApi(formParams),
doRectifiedPersonListApi(rectifiedParams),
]).then(([formRes, rectifiedRes]) => {
console.log('initPage', formRes, rectifiedRes)
if (formRes.data && formRes.data.list) {
templateOptions.value = formRes.data.list.map(item => {
return {
name: item.name,
value: item.id,
}
})
}
// 若有数据,默认选中第一项
if (templateOptions.value.length > 0) {
const targetItem = templateOptions.value[0]
formModel.templateNameId = targetItem.value
templateName.value = targetItem.name
setProblemOptions(targetItem.value)
}
if (rectifiedRes.data) {
rectifiedPersonOptions.value = rectifiedRes.data.map(item => {
return {
name: item.realName,
value: item.id,
loginName: item.loginName,
}
})
}
})
}
}
const painterInfo = ref(null)
onLoad((options) => {
uni.setNavigationBarTitle({
title: t('VideoShopTour.videoPatrol')
})
console.log('onLoad', options)
// const restaurantId = 9217
const restaurantId = options.restaurantId
screenshotUrl.value = `https://store.keliuyun.com/images/${options.pic}`
gateId.value = options.gateId
mallId.value = options.mallId
initPage(restaurantId)
// initPainter(screenshotUrl.value)
})
</script>
<style lang="scss" scoped>
.inspection-form {
background-color: #FFF;
padding: 10px 10px 10px 10px;
}
.form-container {
.problemList-button {
width: 60px;
height: 24px;
background-color: #F2F3F6;
/* text-align: center; */
display: flex;
justify-content: center;
align-items: center;
border-radius: 30px;
}
.problem-list-container {
display: flex;
flex-wrap: wrap;
border-bottom: 1px solid #e8e8e9;
.problem-tag {
margin-bottom: 10px;
margin-right: 10px;
}
}
.problem-empoty {
height: 40px;
line-height: 40px;
width: 100%;
text-align: center;
}
}
</style>
<style lang="scss">
::v-deep(.uv-action-sheet__item-wrap){
max-height: 300px;
overflow-y: auto;
}
.inspection-problem-select {
background-color: #FFF;
max-height: 40vh;
overflow-y: auto;
.uv-action-sheet__item-wrap {
max-height: 60vh;
overflow-y: auto;
}
}
</style>