PaymentAgreementModal.vue
9.81 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
<template>
<nut-popup
v-model:visible="visible"
position="bottom"
:catch-move="true"
:style="{ width: '100%', height: '100%' }"
>
<div class="payment-agreement-modal">
<!-- 标题 -->
<div class="modal-header">
<h2 class="title">在捡个电驴收款</h2>
</div>
<!-- 内容区域 -->
<div class="modal-content">
<!-- 收款说明 -->
<div class="info-row">
<div class="label">收款说明</div>
<div class="content">{{ paymentDescription }}</div>
</div>
<!-- 扣费说明 -->
<div class="info-row">
<div class="label">扣费说明</div>
<div class="content">{{ feeDescription }}</div>
</div>
<!-- 协议勾选区域 -->
<div v-if="!hasAgreed" class="agreement-section">
<nut-checkbox v-model="isChecked" class="agreement-checkbox">
<view class="checkbox-text">
<text>我已阅读并同意</text>
<text class="agreement-link" @tap.stop="showProtocol">
《支付协议》
</text>
</view>
</nut-checkbox>
</div>
</div>
<!-- 按钮区域 -->
<div class="modal-footer">
<div class="button-row">
<nut-button
type="default"
class="close-button"
@click="handleClose"
>
关闭
</nut-button>
<nut-button
v-if="!hasAgreed"
:disabled="!isChecked"
type="primary"
class="main-button"
color="orange"
@click="handleAgree"
>
同意
</nut-button>
<nut-button
v-else
type="primary"
class="main-button"
color="orange"
@click="handleConfirm"
>
确认
</nut-button>
</div>
</div>
</div>
<!-- 支付协议弹框 -->
<nut-popup
v-model:visible="protocolVisible"
position="right"
:closeable="true"
:close-on-click-overlay="true"
:safe-area-inset-bottom="true"
:style="{ width: '100%', height: '100%' }"
@close="protocolVisible = false"
>
<view class="protocol-container">
<!-- 标题栏 -->
<view class="protocol-header">
<text class="protocol-title">支付协议</text>
<view class="close-btn" @click="protocolVisible = false">
<text class="close-text">×</text>
</view>
</view>
<!-- 内容区域 -->
<scroll-view class="protocol-scroll" :scroll-y="true">
<view class="protocol-body">
<view class="protocol-text">{{ protocolContent }}</view>
</view>
</scroll-view>
</view>
</nut-popup>
</nut-popup>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import { useUserStore } from '@/stores/user'
// 导入接口
import { updateProfileAPI, getProfileAPI } from '@/api/index'
/**
* 用户收款说明组件
* @param {Boolean} modelValue - 控制弹框显示隐藏
* @param {Function} onAgree - 同意按钮回调
* @param {Function} onConfirm - 确认按钮回调
* @param {Function} onClose - 关闭弹框回调
*/
const props = defineProps({
modelValue: {
type: Boolean,
default: false
}
})
const emit = defineEmits(['update:modelValue', 'agree', 'confirm', 'close'])
const userStore = useUserStore()
// 弹框显示状态
const visible = computed({
get: () => props.modelValue,
set: (value) => emit('update:modelValue', value)
})
// 支付协议弹框显示状态
const protocolVisible = ref(false)
// 勾选状态
const isChecked = ref(false)
// 是否已同意过协议(mock数据)
const hasAgreed = ref(false)
// 收款说明内容
const paymentDescription = ref('交易金额会在交易完成后的3个工作日内,入账至你登记的收款账户。')
// 扣费说明内容
const feeDescription = ref('在每笔交易过程中,平台将抽取最终成交金额的1%作为平台服务费。')
// 支付协议内容
const protocolContent = ref(`
1. 用户在使用捡个电驴收款服务时,需遵守相关法律法规。
2. 平台有权对异常交易进行风险控制。
3. 用户应确保收款信息的真实性和准确性。
4. 平台将按照约定收取相应的服务费用。
5. 如有争议,双方应友好协商解决。
`)
/**
* 检查用户是否已同意过协议
*/
const checkAgreementStatus = async () => {
try {
// 调用API获取用户信息
const result = await getProfileAPI()
if (result.code && result.data) {
hasAgreed.value = result.data.is_signed || false
// 更新用户store中的状态
if (userStore.userInfo) {
userStore.userInfo.is_signed = result.data.is_signed
}
} else {
// 如果API调用失败,使用store中的数据作为备选
hasAgreed.value = userStore.userInfo?.is_signed || false
}
} catch (error) {
console.error('获取用户协议状态失败:', error)
// 如果API调用失败,使用store中的数据作为备选
hasAgreed.value = userStore.userInfo?.is_signed || false
}
}
/**
* 显示支付协议
*/
const showProtocol = () => {
protocolVisible.value = true
}
/**
* 处理同意按钮点击
*/
const handleAgree = async () => {
if (!isChecked.value) return
try {
// 调用API更新用户协议状态
const result = await updateProfileAPI({
is_signed: true
})
if (result.code) {
hasAgreed.value = true
// 更新用户store中的状态
if (userStore.userInfo) {
userStore.userInfo.is_signed = true
}
emit('agree')
} else {
console.error('更新协议状态失败:', result.message)
}
} catch (error) {
console.error('更新协议状态失败:', error)
}
}
/**
* 处理确认按钮点击
*/
const handleConfirm = () => {
emit('confirm')
}
/**
* 处理弹框关闭
*/
const handleClose = () => {
emit('close')
}
// 组件挂载时检查协议状态
onMounted(async () => {
checkAgreementStatus()
})
</script>
<style lang="less">
.payment-agreement-modal {
display: flex;
flex-direction: column;
height: 100%;
padding: 32rpx;
padding-top: 80rpx;
.modal-header {
text-align: center;
margin-bottom: 40rpx;
.title {
font-size: 36rpx;
font-weight: 600;
color: #333;
margin: 0;
}
}
.modal-content {
flex: 1;
display: flex;
flex-direction: column;
.info-row {
display: flex;
margin-bottom: 32rpx;
.label {
width: 160rpx;
font-size: 28rpx;
font-weight: 500;
color: #333;
flex-shrink: 0;
}
.content {
flex: 1;
font-size: 28rpx;
color: #666;
line-height: 1.6;
}
}
.agreement-section {
margin-top: 40rpx;
text-align: center;
.agreement-checkbox {
font-size: 28rpx;
.checkbox-text {
white-space: nowrap;
display: inline-block;
}
.agreement-link {
color: #ffa500;
text-decoration: underline;
cursor: pointer;
}
}
}
}
.modal-footer {
padding-top: 32rpx;
border-top: 1rpx solid #eee;
.button-row {
display: flex;
gap: 24rpx;
align-items: center;
.close-button {
flex: 1;
border: 1rpx solid #ddd;
color: #666;
}
.main-button {
flex: 1;
}
}
}
}
/* 支付协议弹框样式 */
.protocol-container {
width: 100%;
height: 100vh;
background: white;
display: flex;
flex-direction: column;
}
.protocol-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 32rpx 40rpx;
border-bottom: 1rpx solid #eee;
background: white;
position: sticky;
top: 0;
z-index: 10;
}
.protocol-title {
font-size: 36rpx;
font-weight: bold;
color: #333;
}
.close-btn {
width: 60rpx;
height: 60rpx;
display: flex;
align-items: center;
justify-content: center;
background: #f5f5f5;
border-radius: 50%;
cursor: pointer;
}
.close-text {
font-size: 40rpx;
color: #666;
line-height: 1;
}
.protocol-scroll {
flex: 1;
height: 0;
}
.protocol-body {
padding: 40rpx;
}
.protocol-text {
font-size: 28rpx;
line-height: 1.8;
color: #666;
white-space: pre-line;
word-wrap: break-word;
}
</style>