PaymentAgreementModal.vue 13.8 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 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
<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"
                    >
                        {{ bindStatus.is_finish ? '我已阅读' : '确认去签约' }}
                    </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 Taro from '@tarojs/taro'

// 导入接口
import { updateProfileAPI, getProfileAPI, bindJeePayAPI } 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 bindStatus = ref({
    is_finish: false,
    is_wait_audit: false,
    auth_complement_url: '',
    auth_sign_url: ''
})

// 收款说明内容
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 checkBindStatus = async () => {
    try {
        const result = await bindJeePayAPI()

        if (result.code && result.data) {
            const { auth_complement_url, auth_sign_url, is_wait_audit, is_finish } = result.data

            // 更新绑定状态
            bindStatus.value = {
                is_finish: is_finish || false,
                is_wait_audit: is_wait_audit || false,
                auth_complement_url: auth_complement_url || '',
                auth_sign_url: auth_sign_url || ''
            }
        }
    } catch (error) {
        console.error('获取绑定状态失败:', error)
    }
}

/**
 * 显示支付协议
 */
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
            }

            // 调用绑定接口
            await handleBindJeePay()
        }
    } catch (error) {
        console.error('更新协议状态失败:', error)
    }
}

/**
 * 处理确认按钮点击
 */
const handleConfirm = async () => {
    // 调用绑定接口
    await handleBindJeePay()
}

/**
 * 处理绑定计全付接口调用
 */
const handleBindJeePay = async () => {
    try {
        const result = await bindJeePayAPI()

        if (result.code && result.data) {
            const { auth_complement_url, auth_sign_url, is_wait_audit, is_finish } = result.data

            // 更新绑定状态
            bindStatus.value = {
                is_finish: is_finish || false,
                is_wait_audit: is_wait_audit || false,
                auth_complement_url: auth_complement_url || '',
                auth_sign_url: auth_sign_url || ''
            }

            // 1. 如果返回 auth_complement_url 非空时,需要跳转到补全信息网页
            if (auth_complement_url) {
                Taro.showModal({
                    title: '提示',
                    content: '需要跳转到网页完善签约信息',
                    confirmText: '去完善',
                    cancelText: '取消',
                    success: (res) => {
                        if (res.confirm) {
                            // 跳转到补全信息网页
                            Taro.navigateTo({
                                url: `/pages/webview/index?url=${encodeURIComponent(auth_complement_url)}&title=${encodeURIComponent('完善签约信息')}`
                            })
                        }
                    }
                })
                return
            }

            // 2. 如果返回 auth_sign_url 非空时,需要跳转到签约网页
            if (auth_sign_url) {
                Taro.showModal({
                    title: '提示',
                    content: '需要跳转到网页进行签约',
                    confirmText: '去签约',
                    cancelText: '取消',
                    success: (res) => {
                        if (res.confirm) {
                            // 跳转到签约网页
                            Taro.navigateTo({
                                url: `/pages/webview/index?url=${encodeURIComponent(auth_sign_url)}&title=${encodeURIComponent('签约确认')}`
                            })
                        }
                    }
                })
                return
            }

            // 3. 如果返回 is_wait_audit 为 true,则提示用户签约正在等待审核
            if (is_wait_audit) {
                Taro.showModal({
                    title: '提示',
                    content: '签约正在等待审核,请耐心等待',
                    showCancel: false,
                    confirmText: '关闭'
                })
                return
            }

            // 4. 如果返回 is_finish 为 true 则绑定成功,可以卖车
            if (is_finish) {
                emit('confirm')
                return
            }
        }
    } catch (error) {
        console.error('绑定接口调用失败:', error)
        Taro.showToast({
            title: '网络错误,请重试',
            icon: 'none'
        })
    }
}

/**
 * 处理弹框关闭
 */
const handleClose = () => {
    emit('close')
}

// 组件挂载时检查协议状态和绑定状态
onMounted(async () => {
    await checkAgreementStatus()
    await checkBindStatus()
})
</script>

<style lang="less">
.payment-agreement-modal {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 32rpx;
    padding-top: 100rpx;

    .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>