hookehuyr

feat(用户协议): 实现支付协议签署功能并完善用户信息管理

- 在用户信息接口和store中添加is_signed字段记录协议签署状态
- 实现PaymentAgreementModal组件与API的交互逻辑
- 完善collectionSettings页面的用户信息获取和保存逻辑
- 添加错误处理和状态同步机制
......@@ -40,6 +40,7 @@ export const payCheckAPI = (params) => fn(fetch.post(Api.PAY_CHECK, params));
* @param bank 开户行
* @param bank_no 银行卡号
* @param idcard 身份证号
* @param is_signed 是否阅读协议
* @returns
*/
export const updateProfileAPI = (params) => fn(fetch.post(Api.UPDATE_PROFILE, params));
......
......@@ -94,6 +94,9 @@
import { ref, computed, onMounted } from 'vue'
import { useUserStore } from '@/stores/user'
// 导入接口
import { updateProfileAPI, getProfileAPI } from '@/api/index'
/**
* 用户收款说明组件
* @param {Boolean} modelValue - 控制弹框显示隐藏
......@@ -145,10 +148,26 @@ const protocolContent = ref(`
/**
* 检查用户是否已同意过协议
*/
const checkAgreementStatus = () => {
// TODO: 实际项目中应该从userStore.userInfo中获取相关字段
// 这里使用mock数据
hasAgreed.value = userStore.userInfo?.paymentAgreementAccepted || false
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
}
}
/**
......@@ -161,13 +180,28 @@ const showProtocol = () => {
/**
* 处理同意按钮点击
*/
const handleAgree = () => {
const handleAgree = async () => {
if (!isChecked.value) return
// TODO: 实际项目中应该调用API更新用户协议状态
hasAgreed.value = true
emit('agree')
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)
}
}
/**
......
<!--
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-08-05 15:29:14
* @LastEditTime: 2025-08-05 18:05:59
* @FilePath: /jgdl/src/pages/collectionSettings/index.vue
* @Description: 收款设置
-->
......@@ -154,10 +154,13 @@
</template>
<script setup>
import { ref } from "vue";
import { ref, onMounted } from "vue";
import Taro from "@tarojs/taro";
import "./index.less";
// 导入接口
import { updateProfileAPI, getProfileAPI } from '@/api/index'
/**
* 收款账号信息
*/
......@@ -202,6 +205,43 @@ const showIdentityModal = ref(false);
const idCardError = ref('');
/**
* 获取用户信息
*/
const getUserInfo = async () => {
try {
const result = await getProfileAPI();
if (result.code && result.data) {
const userInfo = result.data;
// 设置收款账号信息
if (userInfo.bank && userInfo.bank_no) {
accountInfo.value = {
bankName: userInfo.bank,
bankAccount: userInfo.bank_no
};
}
// 设置身份信息
if (userInfo.name && userInfo.idcard) {
identityInfo.value = {
userName: userInfo.name,
idCard: userInfo.idcard
};
}
}
} catch (error) {
console.error('获取用户信息失败:', error);
}
};
/**
* 页面加载时获取用户信息
*/
onMounted(() => {
getUserInfo();
});
/**
* 身份证号码校验
* @param {string} idCard - 身份证号码
* @returns {boolean} - 是否有效
......@@ -269,7 +309,7 @@ const closeAccountModal = () => {
/**
* 保存收款账号信息
*/
const saveAccountInfo = () => {
const saveAccountInfo = async () => {
if (!tempAccountInfo.value.bankName || !tempAccountInfo.value.bankAccount) {
Taro.showToast({
title: '请填写完整信息',
......@@ -278,13 +318,29 @@ const saveAccountInfo = () => {
return;
}
accountInfo.value = { ...tempAccountInfo.value };
closeAccountModal();
try {
// 调用API保存收款账号信息
const result = await updateProfileAPI({
bank: tempAccountInfo.value.bankName,
bank_no: tempAccountInfo.value.bankAccount
});
Taro.showToast({
title: '保存成功',
icon: 'success'
});
if (result.code) {
accountInfo.value = { ...tempAccountInfo.value };
closeAccountModal();
Taro.showToast({
title: '保存成功',
icon: 'success'
});
}
} catch (error) {
console.error('保存收款账号失败:', error);
Taro.showToast({
title: '保存失败,请重试',
icon: 'none'
});
}
};
/**
......@@ -308,7 +364,7 @@ const closeIdentityModal = () => {
/**
* 保存身份信息
*/
const saveIdentityInfo = () => {
const saveIdentityInfo = async () => {
if (!tempIdentityInfo.value.userName || !tempIdentityInfo.value.idCard) {
Taro.showToast({
title: '请填写完整信息',
......@@ -326,13 +382,34 @@ const saveIdentityInfo = () => {
return;
}
identityInfo.value = { ...tempIdentityInfo.value };
closeIdentityModal();
try {
// 调用API保存身份信息
const result = await updateProfileAPI({
name: tempIdentityInfo.value.userName,
idcard: tempIdentityInfo.value.idCard
});
Taro.showToast({
title: '保存成功',
icon: 'success'
});
if (result.code) {
identityInfo.value = { ...tempIdentityInfo.value };
closeIdentityModal();
Taro.showToast({
title: '保存成功',
icon: 'success'
});
} else {
Taro.showToast({
title: result.message || '保存失败',
icon: 'none'
});
}
} catch (error) {
console.error('保存身份信息失败:', error);
Taro.showToast({
title: '保存失败,请重试',
icon: 'none'
});
}
};
</script>
......
/*
* @Date: 2025-01-08 18:00:00
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-08-05 17:45:17
* @LastEditTime: 2025-08-05 17:51:14
* @FilePath: /jgdl/src/stores/user.js
* @Description: 用户状态管理
*/
......@@ -28,6 +28,7 @@ export const useUserStore = defineStore('user', {
bank: '',
bank_no: '',
idcard: '',
is_signed: false,
},
isAuthenticated: false,
isLoading: false
......@@ -110,6 +111,7 @@ export const useUserStore = defineStore('user', {
bank: '',
bank_no: '',
idcard: '',
is_signed: false,
}
this.isAuthenticated = false
},
......