hookehuyr

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

- 在用户信息接口和store中添加is_signed字段记录协议签署状态
- 实现PaymentAgreementModal组件与API的交互逻辑
- 完善collectionSettings页面的用户信息获取和保存逻辑
- 添加错误处理和状态同步机制
...@@ -40,6 +40,7 @@ export const payCheckAPI = (params) => fn(fetch.post(Api.PAY_CHECK, params)); ...@@ -40,6 +40,7 @@ export const payCheckAPI = (params) => fn(fetch.post(Api.PAY_CHECK, params));
40 * @param bank 开户行 40 * @param bank 开户行
41 * @param bank_no 银行卡号 41 * @param bank_no 银行卡号
42 * @param idcard 身份证号 42 * @param idcard 身份证号
43 + * @param is_signed 是否阅读协议
43 * @returns 44 * @returns
44 */ 45 */
45 export const updateProfileAPI = (params) => fn(fetch.post(Api.UPDATE_PROFILE, params)); 46 export const updateProfileAPI = (params) => fn(fetch.post(Api.UPDATE_PROFILE, params));
......
...@@ -94,6 +94,9 @@ ...@@ -94,6 +94,9 @@
94 import { ref, computed, onMounted } from 'vue' 94 import { ref, computed, onMounted } from 'vue'
95 import { useUserStore } from '@/stores/user' 95 import { useUserStore } from '@/stores/user'
96 96
97 +// 导入接口
98 +import { updateProfileAPI, getProfileAPI } from '@/api/index'
99 +
97 /** 100 /**
98 * 用户收款说明组件 101 * 用户收款说明组件
99 * @param {Boolean} modelValue - 控制弹框显示隐藏 102 * @param {Boolean} modelValue - 控制弹框显示隐藏
...@@ -145,10 +148,26 @@ const protocolContent = ref(` ...@@ -145,10 +148,26 @@ const protocolContent = ref(`
145 /** 148 /**
146 * 检查用户是否已同意过协议 149 * 检查用户是否已同意过协议
147 */ 150 */
148 -const checkAgreementStatus = () => { 151 +const checkAgreementStatus = async () => {
149 - // TODO: 实际项目中应该从userStore.userInfo中获取相关字段 152 + try {
150 - // 这里使用mock数据 153 + // 调用API获取用户信息
151 - hasAgreed.value = userStore.userInfo?.paymentAgreementAccepted || false 154 + const result = await getProfileAPI()
155 +
156 + if (result.code && result.data) {
157 + hasAgreed.value = result.data.is_signed || false
158 + // 更新用户store中的状态
159 + if (userStore.userInfo) {
160 + userStore.userInfo.is_signed = result.data.is_signed
161 + }
162 + } else {
163 + // 如果API调用失败,使用store中的数据作为备选
164 + hasAgreed.value = userStore.userInfo?.is_signed || false
165 + }
166 + } catch (error) {
167 + console.error('获取用户协议状态失败:', error)
168 + // 如果API调用失败,使用store中的数据作为备选
169 + hasAgreed.value = userStore.userInfo?.is_signed || false
170 + }
152 } 171 }
153 172
154 /** 173 /**
...@@ -161,13 +180,28 @@ const showProtocol = () => { ...@@ -161,13 +180,28 @@ const showProtocol = () => {
161 /** 180 /**
162 * 处理同意按钮点击 181 * 处理同意按钮点击
163 */ 182 */
164 -const handleAgree = () => { 183 +const handleAgree = async () => {
165 if (!isChecked.value) return 184 if (!isChecked.value) return
166 185
167 - // TODO: 实际项目中应该调用API更新用户协议状态 186 + try {
168 - hasAgreed.value = true 187 + // 调用API更新用户协议状态
188 + const result = await updateProfileAPI({
189 + is_signed: true
190 + })
169 191
192 + if (result.code) {
193 + hasAgreed.value = true
194 + // 更新用户store中的状态
195 + if (userStore.userInfo) {
196 + userStore.userInfo.is_signed = true
197 + }
170 emit('agree') 198 emit('agree')
199 + } else {
200 + console.error('更新协议状态失败:', result.message)
201 + }
202 + } catch (error) {
203 + console.error('更新协议状态失败:', error)
204 + }
171 } 205 }
172 206
173 /** 207 /**
......
1 <!-- 1 <!--
2 * @Date: 2022-09-19 14:11:06 2 * @Date: 2022-09-19 14:11:06
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-08-05 15:29:14 4 + * @LastEditTime: 2025-08-05 18:05:59
5 * @FilePath: /jgdl/src/pages/collectionSettings/index.vue 5 * @FilePath: /jgdl/src/pages/collectionSettings/index.vue
6 * @Description: 收款设置 6 * @Description: 收款设置
7 --> 7 -->
...@@ -154,10 +154,13 @@ ...@@ -154,10 +154,13 @@
154 </template> 154 </template>
155 155
156 <script setup> 156 <script setup>
157 -import { ref } from "vue"; 157 +import { ref, onMounted } from "vue";
158 import Taro from "@tarojs/taro"; 158 import Taro from "@tarojs/taro";
159 import "./index.less"; 159 import "./index.less";
160 160
161 +// 导入接口
162 +import { updateProfileAPI, getProfileAPI } from '@/api/index'
163 +
161 /** 164 /**
162 * 收款账号信息 165 * 收款账号信息
163 */ 166 */
...@@ -202,6 +205,43 @@ const showIdentityModal = ref(false); ...@@ -202,6 +205,43 @@ const showIdentityModal = ref(false);
202 const idCardError = ref(''); 205 const idCardError = ref('');
203 206
204 /** 207 /**
208 + * 获取用户信息
209 + */
210 +const getUserInfo = async () => {
211 + try {
212 + const result = await getProfileAPI();
213 + if (result.code && result.data) {
214 + const userInfo = result.data;
215 +
216 + // 设置收款账号信息
217 + if (userInfo.bank && userInfo.bank_no) {
218 + accountInfo.value = {
219 + bankName: userInfo.bank,
220 + bankAccount: userInfo.bank_no
221 + };
222 + }
223 +
224 + // 设置身份信息
225 + if (userInfo.name && userInfo.idcard) {
226 + identityInfo.value = {
227 + userName: userInfo.name,
228 + idCard: userInfo.idcard
229 + };
230 + }
231 + }
232 + } catch (error) {
233 + console.error('获取用户信息失败:', error);
234 + }
235 +};
236 +
237 +/**
238 + * 页面加载时获取用户信息
239 + */
240 +onMounted(() => {
241 + getUserInfo();
242 +});
243 +
244 +/**
205 * 身份证号码校验 245 * 身份证号码校验
206 * @param {string} idCard - 身份证号码 246 * @param {string} idCard - 身份证号码
207 * @returns {boolean} - 是否有效 247 * @returns {boolean} - 是否有效
...@@ -269,7 +309,7 @@ const closeAccountModal = () => { ...@@ -269,7 +309,7 @@ const closeAccountModal = () => {
269 /** 309 /**
270 * 保存收款账号信息 310 * 保存收款账号信息
271 */ 311 */
272 -const saveAccountInfo = () => { 312 +const saveAccountInfo = async () => {
273 if (!tempAccountInfo.value.bankName || !tempAccountInfo.value.bankAccount) { 313 if (!tempAccountInfo.value.bankName || !tempAccountInfo.value.bankAccount) {
274 Taro.showToast({ 314 Taro.showToast({
275 title: '请填写完整信息', 315 title: '请填写完整信息',
...@@ -278,6 +318,14 @@ const saveAccountInfo = () => { ...@@ -278,6 +318,14 @@ const saveAccountInfo = () => {
278 return; 318 return;
279 } 319 }
280 320
321 + try {
322 + // 调用API保存收款账号信息
323 + const result = await updateProfileAPI({
324 + bank: tempAccountInfo.value.bankName,
325 + bank_no: tempAccountInfo.value.bankAccount
326 + });
327 +
328 + if (result.code) {
281 accountInfo.value = { ...tempAccountInfo.value }; 329 accountInfo.value = { ...tempAccountInfo.value };
282 closeAccountModal(); 330 closeAccountModal();
283 331
...@@ -285,6 +333,14 @@ const saveAccountInfo = () => { ...@@ -285,6 +333,14 @@ const saveAccountInfo = () => {
285 title: '保存成功', 333 title: '保存成功',
286 icon: 'success' 334 icon: 'success'
287 }); 335 });
336 + }
337 + } catch (error) {
338 + console.error('保存收款账号失败:', error);
339 + Taro.showToast({
340 + title: '保存失败,请重试',
341 + icon: 'none'
342 + });
343 + }
288 }; 344 };
289 345
290 /** 346 /**
...@@ -308,7 +364,7 @@ const closeIdentityModal = () => { ...@@ -308,7 +364,7 @@ const closeIdentityModal = () => {
308 /** 364 /**
309 * 保存身份信息 365 * 保存身份信息
310 */ 366 */
311 -const saveIdentityInfo = () => { 367 +const saveIdentityInfo = async () => {
312 if (!tempIdentityInfo.value.userName || !tempIdentityInfo.value.idCard) { 368 if (!tempIdentityInfo.value.userName || !tempIdentityInfo.value.idCard) {
313 Taro.showToast({ 369 Taro.showToast({
314 title: '请填写完整信息', 370 title: '请填写完整信息',
...@@ -326,6 +382,14 @@ const saveIdentityInfo = () => { ...@@ -326,6 +382,14 @@ const saveIdentityInfo = () => {
326 return; 382 return;
327 } 383 }
328 384
385 + try {
386 + // 调用API保存身份信息
387 + const result = await updateProfileAPI({
388 + name: tempIdentityInfo.value.userName,
389 + idcard: tempIdentityInfo.value.idCard
390 + });
391 +
392 + if (result.code) {
329 identityInfo.value = { ...tempIdentityInfo.value }; 393 identityInfo.value = { ...tempIdentityInfo.value };
330 closeIdentityModal(); 394 closeIdentityModal();
331 395
...@@ -333,6 +397,19 @@ const saveIdentityInfo = () => { ...@@ -333,6 +397,19 @@ const saveIdentityInfo = () => {
333 title: '保存成功', 397 title: '保存成功',
334 icon: 'success' 398 icon: 'success'
335 }); 399 });
400 + } else {
401 + Taro.showToast({
402 + title: result.message || '保存失败',
403 + icon: 'none'
404 + });
405 + }
406 + } catch (error) {
407 + console.error('保存身份信息失败:', error);
408 + Taro.showToast({
409 + title: '保存失败,请重试',
410 + icon: 'none'
411 + });
412 + }
336 }; 413 };
337 </script> 414 </script>
338 415
......
1 /* 1 /*
2 * @Date: 2025-01-08 18:00:00 2 * @Date: 2025-01-08 18:00:00
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-08-05 17:45:17 4 + * @LastEditTime: 2025-08-05 17:51:14
5 * @FilePath: /jgdl/src/stores/user.js 5 * @FilePath: /jgdl/src/stores/user.js
6 * @Description: 用户状态管理 6 * @Description: 用户状态管理
7 */ 7 */
...@@ -28,6 +28,7 @@ export const useUserStore = defineStore('user', { ...@@ -28,6 +28,7 @@ export const useUserStore = defineStore('user', {
28 bank: '', 28 bank: '',
29 bank_no: '', 29 bank_no: '',
30 idcard: '', 30 idcard: '',
31 + is_signed: false,
31 }, 32 },
32 isAuthenticated: false, 33 isAuthenticated: false,
33 isLoading: false 34 isLoading: false
...@@ -110,6 +111,7 @@ export const useUserStore = defineStore('user', { ...@@ -110,6 +111,7 @@ export const useUserStore = defineStore('user', {
110 bank: '', 111 bank: '',
111 bank_no: '', 112 bank_no: '',
112 idcard: '', 113 idcard: '',
114 + is_signed: false,
113 } 115 }
114 this.isAuthenticated = false 116 this.isAuthenticated = false
115 }, 117 },
......