index.vue
9.12 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
<!--
* @Date: 2024-01-15 16:25:51
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2026-01-24 12:44:25
* @FilePath: /xyxBooking-weapp/src/pages/submit/index.vue
* @Description: 预约人员信息
-->
<template>
<view class="submit-page">
<view @tap="goToBooking" class="visit-time">
<view>参访时间</view>
<view class="flex items-center">
<text style="font-size: 30rpx">{{ date }} {{ time }}</text>
<IconFont name="rect-right" class="ml-1" />
</view>
</view>
<view @tap="goToVisitor" class="add-visitors">
<view class="flex items-center justify-center">
<IconFont name="plus" class="mr-1" /> 添加参观者
</view>
</view>
<view v-if="visitorList.length" class="visitors-list">
<view
v-for="(item, index) in visitorList"
:key="index"
@tap="addVisitor(item)"
class="visitor-item"
>
<view style="margin-right: 32rpx">
<image
v-if="!checked_visitors.includes(item.id)"
:src="icon_check1"
style="width: 38rpx; height: 38rpx"
/>
<image v-else :src="icon_check2" style="width: 38rpx; height: 38rpx" />
</view>
<view>
<view style="color: #a67939">{{ item.name }}</view>
<view>证件号:{{ formatId(item.id_number) }}</view>
<view
v-if="item.is_reserve === RESERVE_STATUS.ENABLE"
style="color: #9c9a9a; font-size: 26rpx"
>*已预约过{{ date }}参观,请不要重复预约</view
>
</view>
</view>
</view>
<view v-else class="no-visitors-list">
<image
src="https://cdn.ipadbiz.cn/xys/booking/%E6%9A%82%E6%97%A0@2x.png"
style="width: 320rpx; height: 320rpx"
/>
<view class="no-visitors-list-title">您还没有添加过参观者</view>
</view>
<view style="height: 160rpx"></view>
<view class="submit-wrapper">
<view class="control-wrapper">
<view class="left">
<view style="margin-left: 32rpx; display: flex; align-items: center">
订单金额 <view style="color: #ff1919; display: inline-block"
>¥<view style="font-size: 48rpx; display: inline-block"> {{ total }}</view>
</view>
</view>
</view>
<view @tap="submitBtn" class="right">提交订单</view>
</view>
<view style="font-size: 27rpx; margin-left: 32rpx; color: #ff1919; margin-bottom: 32rpx"
>提交后请在10分钟内完成支付</view
>
</view>
</view>
</template>
<script setup>
import { ref, computed } from 'vue'
import Taro, { useDidShow, useRouter as useTaroRouter } from '@tarojs/taro'
import { IconFont } from '@nutui/icons-vue-taro'
import { useGo } from '@/hooks/useGo'
import icon_check1 from '@/assets/images/多选01@2x.png'
import icon_check2 from '@/assets/images/多选02@2x.png'
import { personListAPI, addReserveAPI } from '@/api/index'
import { wechat_pay } from '@/utils/wechatPay'
import { mask_id_number } from '@/utils/tools'
import { showError, showLoading, hideLoading } from '@/utils/toast'
const router = useTaroRouter()
const go = useGo()
const visitorList = ref([])
const date = ref('')
const time = ref('')
const price = ref(0)
const period_type = ref('')
const formatId = id => mask_id_number(id)
/**
* @description 当天预约标记
* - ENABLE 表示该参观者今天已预约,不允许重复预约
* @readonly
*/
const RESERVE_STATUS = {
ENABLE: '1'
}
const checked_visitors = ref([])
const is_submitting = ref(false) // 是否正在提交订单
/**
* @description 选择/取消选择参观者
* - 已预约过当天参观的参观者不允许选择
* @param {Object} item 参观者数据
* @returns {void} 无返回值
*/
const addVisitor = item => {
if (item.is_reserve === RESERVE_STATUS.ENABLE) {
// 今天已经预约
showError('已预约过参观,请不要重复预约')
return
}
if (checked_visitors.value.includes(item.id)) {
checked_visitors.value = checked_visitors.value.filter(v => v !== item.id)
} else {
checked_visitors.value.push(item.id)
}
}
const total = computed(() => {
return price.value * checked_visitors.value.length
})
/**
* @description 返回重新选择参访时间页
* @returns {void} 无返回值
*/
const goToBooking = () => {
go('/booking')
}
/**
* @description 跳转新增参观者页
* @returns {void} 无返回值
*/
const goToVisitor = () => {
go('/addVisitor')
}
// 待支付订单ID
const pending_pay_id = ref(null)
// 待支付订单是否需要支付
const pending_need_pay = ref(null)
/**
* @description 刷新参观者列表(并同步“当天已预约”标记)
* @param {Object} options 选项
* @param {boolean} options.reset_checked 是否清空已勾选参观者
* @returns {Promise<void>} 无返回值
*/
const refreshVisitorList = async options => {
if (!date.value || !time.value) {
return
}
const res = await personListAPI({
reserve_date: date.value,
begin_time: time.value.split('-')[0],
end_time: time.value.split('-')[1],
period_type: period_type.value
})
if (res && res.code) {
visitorList.value = res.data || []
if (options?.reset_checked) {
checked_visitors.value = []
}
}
}
/**
* @description 提交订单
* - 先创建预约单拿 pay_id(支持"待支付订单"复用)
* - need_pay=1 时拉起微信支付
* @returns {Promise<void>} 无返回值
*/
const submitBtn = async () => {
if (is_submitting.value) {
return
}
if (!checked_visitors.value.length) {
showError('请先添加参观者')
return
}
is_submitting.value = true
try {
let pay_id = pending_pay_id.value
let need_pay = pending_need_pay.value
if (!pay_id) {
// TAG: 提交订单, 如果没有待支付订单ID, 则创建一个新的订单
showLoading('提交中...')
let reserve_res = null
try {
reserve_res = await addReserveAPI({
reserve_date: date.value,
begin_time: time.value.split('-')[0],
end_time: time.value.split('-')[1],
person_id_list: JSON.stringify(checked_visitors.value),
period_type: period_type.value
})
} finally {
hideLoading()
}
if (!reserve_res || reserve_res.code !== 1) {
return
}
pay_id = reserve_res.data.pay_id
pending_pay_id.value = pay_id
need_pay = reserve_res.data?.need_pay
pending_need_pay.value = need_pay
await refreshVisitorList({ reset_checked: true })
}
// 以接口返回的 need_pay 为准:1=需要支付,0=不需要支付
if (Number(need_pay) === 1 || need_pay === true) {
const pay_res = await wechat_pay({ pay_id })
if (pay_res && pay_res.code === 1) {
pending_pay_id.value = null
pending_need_pay.value = null
go('/success', { pay_id })
return
}
// 支付失败/取消后,刷新参观者列表
refreshVisitorList({ reset_checked: true }).catch(() => {})
// wechat_pay 内部已经处理了弹窗和返回上一页,这里不需要额外处理
} else {
pending_pay_id.value = null
pending_need_pay.value = null
go('/success', { pay_id })
}
} finally {
is_submitting.value = false
}
}
useDidShow(async () => {
const params = router.params
date.value = params.date || ''
time.value = params.time || ''
price.value = params.price || 0
period_type.value = params.period_type || ''
await refreshVisitorList()
})
</script>
<style lang="less">
.submit-page {
margin: 32rpx;
position: relative;
.visit-time {
background-color: #fff;
display: flex;
align-items: center;
justify-content: space-between;
padding: 24rpx;
border-radius: 16rpx;
}
.add-visitors {
border: 2rpx dashed #a67939;
color: #a67939;
border-radius: 10rpx;
text-align: center;
padding: 21rpx 0;
margin: 32rpx 0;
font-size: 37rpx;
}
.visitors-list {
.visitor-item {
background-color: #fff;
border-radius: 16rpx;
padding: 32rpx;
margin-bottom: 32rpx;
display: flex;
align-items: center;
}
}
.no-visitors-list {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
img {
margin-top: 32rpx;
margin-bottom: 32rpx;
width: 320rpx;
}
.no-visitors-list-title {
color: #a67939;
font-size: 34rpx;
}
}
.submit-wrapper {
position: fixed;
bottom: 0;
left: 0;
width: 750rpx;
display: flex;
background-color: #fff;
// padding: 32rpx;
justify-content: space-between;
flex-direction: column;
box-shadow: 0 -10rpx 8rpx 0 rgba(0, 0, 0, 0.12);
.control-wrapper {
display: flex;
justify-content: space-between;
align-items: center;
}
.left {
display: flex;
justify-content: center;
align-items: center;
flex-wrap: nowrap;
}
.right {
background-color: #a67939;
color: #fff;
margin: 32rpx;
padding: 26rpx 96rpx;
border-radius: 5px;
font-size: 35rpx;
margin-bottom: 0;
}
}
}
</style>