fix(pre-planting): 修复购买失败时 List<dynamic> 类型转换错误和续购省市缺失

1. api_client.dart: NestJS validation error 返回 message 为数组时,
   用 join(', ') 转为字符串,避免直接传给 ApiException(String) 崩溃
2. pre_planting_purchase_page.dart: 续购时传 _position 中已保存的
   provinceCode/cityCode,满足后端 DTO 必填校验

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-02-28 06:56:49 -08:00
parent 2d7b02aa96
commit 606d3c0b22
2 changed files with 8 additions and 5 deletions

View File

@ -384,7 +384,10 @@ class ApiClient {
case DioExceptionType.badResponse:
final statusCode = error.response?.statusCode;
final data = error.response?.data;
final message = data is Map ? data['message'] ?? '请求失败' : '请求失败';
final rawMsg = data is Map ? data['message'] : null;
final message = rawMsg is List
? (rawMsg as List).join(', ')
: (rawMsg?.toString() ?? '请求失败');
switch (statusCode) {
case 400:

View File

@ -351,10 +351,10 @@ class _PrePlantingPurchasePageState
final response = await prePlantingService.createOrder(
portionCount: _quantity,
//
provinceCode: _isFirstPurchase ? _selectedProvinceCode : null,
provinceName: _isFirstPurchase ? _selectedProvinceName : null,
cityCode: _isFirstPurchase ? _selectedCityCode : null,
cityName: _isFirstPurchase ? _selectedCityName : null,
provinceCode: _isFirstPurchase ? _selectedProvinceCode : _position?.provinceCode,
provinceName: _isFirstPurchase ? _selectedProvinceName : _position?.provinceName,
cityCode: _isFirstPurchase ? _selectedCityCode : _position?.cityCode,
cityName: _isFirstPurchase ? _selectedCityName : _position?.cityName,
);
debugPrint(