index.vue
8.27 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
<!--
* @Date: 2024-01-15 16:25:51
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2026-01-16 16:13:44
* @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>
<IconFont name="plus" /> 添加参观者
</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, wxPayAPI } from '@/api/index'
const router = useTaroRouter();
const go = useGo();
const visitorList = ref([]);
const date = ref('');
const time = ref('');
const price = ref(0);
/**
* 生成15位身份证号中间8位替换为*号
* @param {*} inputString
*/
function replaceMiddleCharacters(inputString) {
if (!inputString || inputString.length < 15) {
return inputString; // 字符串长度不足,不进行替换
}
const start = Math.floor((inputString.length - 8) / 2); // 开始替换的索引位置
const end = start + 8; // 结束替换的索引位置
const replacement = '*'.repeat(8); // 生成包含8个*号的字符串
const replacedString = inputString.substring(0, start) + replacement + inputString.substring(end);
return replacedString;
}
const formatId = (id) => {
return replaceMiddleCharacters(id);
};
const RESERVE_STATUS = {
ENABLE: '1'
}
const checked_visitors = ref([]);
const addVisitor = (item) => {
if (item.is_reserve === RESERVE_STATUS.ENABLE) { // 今天已经预约
Taro.showToast({ title: '已预约过参观,请不要重复预约', icon: 'none' })
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;
})
const goToBooking = () => {
go('/booking');
}
const goToVisitor = () => {
go('/addVisitor');
}
// 待支付订单ID
const pending_pay_id = ref(null);
const submitBtn = async () => {
if (!checked_visitors.value.length) {
Taro.showToast({ title: '请先添加参观者', icon: 'none' })
return;
}
let pay_id = pending_pay_id.value;
if (!pay_id) { // TAG: 提交订单, 如果没有待支付订单ID, 则创建一个新的订单
Taro.showLoading({ title: '提交中...' });
const { code, data, msg } = 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)
});
Taro.hideLoading();
if (!code || code !== 1) {
return;
}
pay_id = data.pay_id;
pending_pay_id.value = pay_id;
}
// 如果金额大于零, 走微信支付, 如果等于零直接跳转成功页
if (total.value > 0) {
Taro.showLoading({ title: '支付准备中...' });
const payParams = await wxPayAPI({ pay_id }); // 参数接口
Taro.hideLoading();
if (payParams.code) {
let pay_params = payParams.data;
Taro.requestPayment({
timeStamp: pay_params.timeStamp,
nonceStr: pay_params.nonceStr,
package: pay_params.package,
signType: pay_params.signType,
paySign: pay_params.paySign,
success(res) {
go('/success', { pay_id });
},
fail(res) {
// 支付取消或失败,保留 pending_pay_id,允许用户再次点击按钮尝试支付同一订单
// 只有当 wxPayAPI 获取支付参数失败时(如下面的 else 分支),才重置 ID 以便重新创建订单
Taro.showToast({ title: '支付失败,请重试', icon: 'none' });
}
})
} else {
pending_pay_id.value = null; // 支付参数获取失败,重置订单ID
Taro.showToast({ title: payParams.msg || '获取支付信息失败', icon: 'none' });
}
} else {
// 金额等于零, 直接跳转成功页
go('/success', { pay_id });
}
}
useDidShow(async () => {
const params = router.params;
date.value = params.date || '';
time.value = params.time || '';
price.value = params.price || 0;
if (date.value && time.value) {
const { code, data } = await personListAPI({ reserve_date: date.value, begin_time: time.value.split('-')[0], end_time: time.value.split('-')[1] });
if (code) {
visitorList.value = data || [];
}
}
});
</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>