fix(plan): 根据订单ID判断提交成功并统一跳转逻辑
- 修改 PlanFormContainer 成功判断:必须同时满足 code === 1 且有 order_id - 修正错误信息获取路径:res.data.msg 而非 res.data.message - 统一所有页面的 handlePlanSubmit 函数,根据实际提交结果跳转 - 移除所有 TODO 注释和模拟提交逻辑 影响文件: - src/components/plan/PlanFormContainer.vue - src/pages/index/index.vue - src/pages/product-center/index.vue - src/pages/product-detail/index.vue - src/pages/search/index.vue Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Showing
5 changed files
with
112 additions
and
74 deletions
| ... | @@ -308,7 +308,10 @@ const submit = async () => { | ... | @@ -308,7 +308,10 @@ const submit = async () => { |
| 308 | // 调用 API | 308 | // 调用 API |
| 309 | const res = await addAPI(requestData) | 309 | const res = await addAPI(requestData) |
| 310 | 310 | ||
| 311 | - if (res.code === 1) { | 311 | + // 判断成功:既要 code === 1,也要有 order_id |
| 312 | + const isSuccess = res.code === 1 && res.data?.order_id | ||
| 313 | + | ||
| 314 | + if (isSuccess) { | ||
| 312 | Taro.hideLoading() | 315 | Taro.hideLoading() |
| 313 | 316 | ||
| 314 | Taro.showToast({ | 317 | Taro.showToast({ |
| ... | @@ -320,7 +323,7 @@ const submit = async () => { | ... | @@ -320,7 +323,7 @@ const submit = async () => { |
| 320 | // 发送提交成功事件(携带 order_id) | 323 | // 发送提交成功事件(携带 order_id) |
| 321 | emit('submit', { | 324 | emit('submit', { |
| 322 | success: true, | 325 | success: true, |
| 323 | - order_id: res.data?.order_id, | 326 | + order_id: res.data.order_id, |
| 324 | product_id: props.product.id, | 327 | product_id: props.product.id, |
| 325 | form_sn: props.product.form_sn | 328 | form_sn: props.product.form_sn |
| 326 | }) | 329 | }) |
| ... | @@ -329,12 +332,20 @@ const submit = async () => { | ... | @@ -329,12 +332,20 @@ const submit = async () => { |
| 329 | } else { | 332 | } else { |
| 330 | Taro.hideLoading() | 333 | Taro.hideLoading() |
| 331 | 334 | ||
| 335 | + // 失败时,尝试从 res.data 或 res.msg 中获取错误信息 | ||
| 336 | + const errorMsg = res.data?.msg || res.msg || '提交失败,请稍后重试' | ||
| 337 | + | ||
| 332 | Taro.showToast({ | 338 | Taro.showToast({ |
| 333 | - title: res.msg || '提交失败', | 339 | + title: errorMsg, |
| 334 | icon: 'none', | 340 | icon: 'none', |
| 335 | duration: 2000 | 341 | duration: 2000 |
| 336 | }) | 342 | }) |
| 337 | 343 | ||
| 344 | + // 返回失败结果(不包含 order_id) | ||
| 345 | + emit('submit', { | ||
| 346 | + success: false | ||
| 347 | + }) | ||
| 348 | + | ||
| 338 | return false | 349 | return false |
| 339 | } | 350 | } |
| 340 | } catch (error) { | 351 | } catch (error) { | ... | ... |
| ... | @@ -220,33 +220,36 @@ const openPlanPopup = (productId) => { | ... | @@ -220,33 +220,36 @@ const openPlanPopup = (productId) => { |
| 220 | 220 | ||
| 221 | /** | 221 | /** |
| 222 | * 处理计划书提交 | 222 | * 处理计划书提交 |
| 223 | - * @description 测试环境:前端不调用后端API,直接跳转到结果页 | 223 | + * |
| 224 | - * 生产环境:需要调用 submitPlanAPI 提交表单数据 | 224 | + * @description 接收 PlanFormContainer 的提交结果事件 |
| 225 | - * @param {Object} formData - 表单数据 | 225 | + * PlanFormContainer 已经调用过 API 并处理了 toast 提示 |
| 226 | + * 这里根据成功/失败状态跳转到结果页面 | ||
| 227 | + * @param {Object} result - 提交结果 | ||
| 228 | + * @param {boolean} result.success - 是否成功 | ||
| 229 | + * @param {number} result.order_id - 订单 ID | ||
| 230 | + * @param {number} result.product_id - 产品 ID | ||
| 231 | + * @param {string} result.form_sn - 表单标识 | ||
| 226 | */ | 232 | */ |
| 227 | -const handlePlanSubmit = (formData) => { | 233 | +const handlePlanSubmit = (result) => { |
| 228 | - console.log('计划书提交:', { | 234 | + console.log('[Home Page] 计划书提交结果:', result); |
| 229 | - product_id: selectedProduct.value.id, | ||
| 230 | - product_name: selectedProduct.value.product_name, | ||
| 231 | - form_sn: selectedProduct.value.form_sn, | ||
| 232 | - form_data: formData | ||
| 233 | - }); | ||
| 234 | 235 | ||
| 235 | // 关闭弹窗 | 236 | // 关闭弹窗 |
| 236 | showPlanPopup.value = false; | 237 | showPlanPopup.value = false; |
| 237 | 238 | ||
| 238 | - // TODO: 后端接口还没有准备好,暂时不调用API | 239 | + // 构建结果页面参数 |
| 239 | - // 测试完成后需要对接 submitPlanAPI | 240 | + const params = { |
| 240 | - // const res = await submitPlanAPI({ | 241 | + success: result.success ? 'true' : 'false' |
| 241 | - // product_id: selectedProduct.value.id, | 242 | + }; |
| 242 | - // template: selectedProduct.value.form_sn, | 243 | + |
| 243 | - // form_data: formData | 244 | + // 失败时可以传递错误信息(可选) |
| 244 | - // }); | 245 | + if (!result.success) { |
| 245 | - | 246 | + params.message = '提交失败,请稍后重试'; |
| 246 | - // 模拟提交成功,跳转到结果页面 | 247 | + } |
| 247 | - go('/pages/plan-submit-result/index', { | 248 | + |
| 248 | - success: 'true' | 249 | + // 延迟跳转,确保 PlanFormContainer 的 toast 显示完毕 |
| 249 | - }); | 250 | + setTimeout(() => { |
| 251 | + go('/pages/plan-submit-result/index', params); | ||
| 252 | + }, 500); | ||
| 250 | }; | 253 | }; |
| 251 | 254 | ||
| 252 | /** | 255 | /** | ... | ... |
| ... | @@ -500,26 +500,37 @@ const openPlanPopup = (product) => { | ... | @@ -500,26 +500,37 @@ const openPlanPopup = (product) => { |
| 500 | /** | 500 | /** |
| 501 | * 处理计划书提交 | 501 | * 处理计划书提交 |
| 502 | * | 502 | * |
| 503 | - * @param {Object} formData - 表单数据 | 503 | + * @description 接收 PlanFormContainer 的提交结果事件 |
| 504 | + * PlanFormContainer 已经调用过 API 并处理了 toast 提示 | ||
| 505 | + * 这里根据成功/失败状态跳转到结果页面 | ||
| 506 | + * @param {Object} result - 提交结果 | ||
| 507 | + * @param {boolean} result.success - 是否成功 | ||
| 508 | + * @param {number} result.order_id - 订单 ID | ||
| 509 | + * @param {number} result.product_id - 产品 ID | ||
| 510 | + * @param {string} result.form_sn - 表单标识 | ||
| 504 | */ | 511 | */ |
| 505 | -const handlePlanSubmit = (formData) => { | 512 | +const handlePlanSubmit = (result) => { |
| 506 | - console.log('[Product Center] 计划书提交:', { | 513 | + console.log('[Product Center] 计划书提交结果:', result) |
| 507 | - product_id: selectedProduct.value.id, | ||
| 508 | - product_name: selectedProduct.value.product_name, | ||
| 509 | - form_sn: selectedProduct.value.form_sn, | ||
| 510 | - form_data: formData | ||
| 511 | - }) | ||
| 512 | 514 | ||
| 513 | // 关闭弹窗 | 515 | // 关闭弹窗 |
| 514 | showPlanPopup.value = false | 516 | showPlanPopup.value = false |
| 515 | 517 | ||
| 516 | - // TODO: 后端接口还没有准备好,暂时不调用API | 518 | + // 构建结果页面参数 |
| 517 | - // 测试完成后需要对接 submitPlanAPI | 519 | + const params = { |
| 520 | + success: result.success ? 'true' : 'false' | ||
| 521 | + } | ||
| 518 | 522 | ||
| 519 | - // 模拟提交成功,跳转到结果页面 | 523 | + // 失败时可以传递错误信息(可选) |
| 520 | - Taro.navigateTo({ | 524 | + if (!result.success) { |
| 521 | - url: '/pages/plan-submit-result/index?success=true' | 525 | + params.message = '提交失败,请稍后重试' |
| 522 | - }) | 526 | + } |
| 527 | + | ||
| 528 | + // 延迟跳转,确保 PlanFormContainer 的 toast 显示完毕 | ||
| 529 | + setTimeout(() => { | ||
| 530 | + Taro.navigateTo({ | ||
| 531 | + url: `/pages/plan-submit-result/index?${new URLSearchParams(params).toString()}` | ||
| 532 | + }) | ||
| 533 | + }, 500) | ||
| 523 | } | 534 | } |
| 524 | </script> | 535 | </script> |
| 525 | 536 | ... | ... |
| ... | @@ -219,33 +219,37 @@ const openPlanPopup = () => { | ... | @@ -219,33 +219,37 @@ const openPlanPopup = () => { |
| 219 | /** | 219 | /** |
| 220 | * 处理计划书提交 | 220 | * 处理计划书提交 |
| 221 | * | 221 | * |
| 222 | - * @description 测试环境:前端不调用后端API,直接跳转到结果页 | 222 | + * @description 接收 PlanFormContainer 的提交结果事件 |
| 223 | - * 生产环境:需要调用 submitPlanAPI 提交表单数据 | 223 | + * PlanFormContainer 已经调用过 API 并处理了 toast 提示 |
| 224 | - * @param {Object} formData - 表单数据 | 224 | + * 这里根据成功/失败状态跳转到结果页面 |
| 225 | + * @param {Object} result - 提交结果 | ||
| 226 | + * @param {boolean} result.success - 是否成功 | ||
| 227 | + * @param {number} result.order_id - 订单 ID(成功时) | ||
| 228 | + * @param {number} result.product_id - 产品 ID | ||
| 229 | + * @param {string} result.form_sn - 表单标识 | ||
| 225 | */ | 230 | */ |
| 226 | -const handlePlanSubmit = (formData) => { | 231 | +const handlePlanSubmit = (result) => { |
| 227 | - console.log('计划书提交:', { | 232 | + console.log('[Product Detail] 计划书提交结果:', result) |
| 228 | - product_id: productDetail.value.id, | ||
| 229 | - product_name: productDetail.value.product_name, | ||
| 230 | - form_sn: productDetail.value.form_sn, | ||
| 231 | - form_data: formData | ||
| 232 | - }) | ||
| 233 | 233 | ||
| 234 | // 关闭弹窗 | 234 | // 关闭弹窗 |
| 235 | showPlanPopup.value = false | 235 | showPlanPopup.value = false |
| 236 | 236 | ||
| 237 | - // TODO: 后端接口还没有准备好,暂时不调用API | 237 | + // 构建结果页面参数 |
| 238 | - // 测试完成后需要对接 submitPlanAPI | 238 | + const params = { |
| 239 | - // const res = await submitPlanAPI({ | 239 | + success: result.success ? 'true' : 'false' |
| 240 | - // product_id: productDetail.value.id, | 240 | + } |
| 241 | - // template: productDetail.value.form_sn, | ||
| 242 | - // form_data: formData | ||
| 243 | - // }) | ||
| 244 | 241 | ||
| 245 | - // 模拟提交成功,跳转到结果页面 | 242 | + // 失败时可以传递错误信息(可选) |
| 246 | - Taro.navigateTo({ | 243 | + if (!result.success) { |
| 247 | - url: '/pages/plan-submit-result/index?success=true' | 244 | + params.message = '提交失败,请稍后重试' |
| 248 | - }) | 245 | + } |
| 246 | + | ||
| 247 | + // 延迟跳转,确保 PlanFormContainer 的 toast 显示完毕 | ||
| 248 | + setTimeout(() => { | ||
| 249 | + Taro.navigateTo({ | ||
| 250 | + url: `/pages/plan-submit-result/index?${new URLSearchParams(params).toString()}` | ||
| 251 | + }) | ||
| 252 | + }, 500) | ||
| 249 | } | 253 | } |
| 250 | 254 | ||
| 251 | useLoad((options) => { | 255 | useLoad((options) => { | ... | ... |
| ... | @@ -460,26 +460,35 @@ const openPlanPopup = (productId) => { | ... | @@ -460,26 +460,35 @@ const openPlanPopup = (productId) => { |
| 460 | /** | 460 | /** |
| 461 | * 处理计划书提交 | 461 | * 处理计划书提交 |
| 462 | * | 462 | * |
| 463 | - * @param {Object} formData - 表单数据 | 463 | + * @description 接收 PlanFormContainer 的提交结果事件 |
| 464 | + * PlanFormContainer 已经调用过 API 并处理了 toast 提示 | ||
| 465 | + * 这里根据成功/失败状态跳转到结果页面 | ||
| 466 | + * @param {Object} result - 提交结果 | ||
| 467 | + * @param {boolean} result.success - 是否成功 | ||
| 468 | + * @param {number} result.order_id - 订单 ID | ||
| 469 | + * @param {number} result.product_id - 产品 ID | ||
| 470 | + * @param {string} result.form_sn - 表单标识 | ||
| 464 | */ | 471 | */ |
| 465 | -const handlePlanSubmit = (formData) => { | 472 | +const handlePlanSubmit = (result) => { |
| 466 | - console.log('计划书提交:', { | 473 | + console.log('[Search Page] 计划书提交结果:', result) |
| 467 | - product_id: selectedProduct.value.id, | ||
| 468 | - product_name: selectedProduct.value.product_name || selectedProduct.value.name, | ||
| 469 | - form_sn: selectedProduct.value.form_sn, | ||
| 470 | - form_data: formData | ||
| 471 | - }) | ||
| 472 | 474 | ||
| 473 | // 关闭弹窗 | 475 | // 关闭弹窗 |
| 474 | showPlanPopup.value = false | 476 | showPlanPopup.value = false |
| 475 | 477 | ||
| 476 | - // TODO: 后端接口还没有准备好,暂时不调用API | 478 | + // 构建结果页面参数 |
| 477 | - // 测试完成后需要对接 submitPlanAPI | 479 | + const params = { |
| 480 | + success: result.success ? 'true' : 'false' | ||
| 481 | + } | ||
| 482 | + | ||
| 483 | + // 失败时可以传递错误信息(可选) | ||
| 484 | + if (!result.success) { | ||
| 485 | + params.message = '提交失败,请稍后重试' | ||
| 486 | + } | ||
| 478 | 487 | ||
| 479 | - // 模拟提交成功,跳转到结果页面 | 488 | + // 延迟跳转,确保 PlanFormContainer 的 toast 显示完毕 |
| 480 | - go('/pages/plan-submit-result/index', { | 489 | + setTimeout(() => { |
| 481 | - success: 'true' | 490 | + go('/pages/plan-submit-result/index', params) |
| 482 | - }) | 491 | + }, 500) |
| 483 | } | 492 | } |
| 484 | 493 | ||
| 485 | /** | 494 | /** | ... | ... |
-
Please register or login to post a comment