|
@@ -14,16 +14,16 @@ import { Form, FormField, FormItem, FormLabel, FormControl, FormMessage } from '
|
|
|
import { Input } from '@/components/ui/input'
|
|
import { Input } from '@/components/ui/input'
|
|
|
import { Switch } from '@/components/ui/switch'
|
|
import { Switch } from '@/components/ui/switch'
|
|
|
import { useAuth } from '@/utils/auth'
|
|
import { useAuth } from '@/utils/auth'
|
|
|
-// import { CitySelector } from '@/components/ui/city-selector'
|
|
|
|
|
|
|
+import { CitySelector } from '@/components/ui/city-selector'
|
|
|
|
|
|
|
|
|
|
|
|
|
const addressSchema = z.object({
|
|
const addressSchema = z.object({
|
|
|
name: z.string().min(1, '请输入收货人姓名'),
|
|
name: z.string().min(1, '请输入收货人姓名'),
|
|
|
phone: z.string().regex(/^1[3-9]\d{9}$/, '请输入正确的手机号'),
|
|
phone: z.string().regex(/^1[3-9]\d{9}$/, '请输入正确的手机号'),
|
|
|
- province: z.number().default(1),
|
|
|
|
|
- city: z.number().default(2),
|
|
|
|
|
- district: z.number().default(3),
|
|
|
|
|
- town: z.number().default(4),
|
|
|
|
|
|
|
+ province: z.number().positive('请选择省份'),
|
|
|
|
|
+ city: z.number().positive('请选择城市'),
|
|
|
|
|
+ district: z.number().positive('请选择区县'),
|
|
|
|
|
+ town: z.number().optional(),
|
|
|
address: z.string().min(1, '请输入详细地址'),
|
|
address: z.string().min(1, '请输入详细地址'),
|
|
|
isDefault: z.boolean().optional()
|
|
isDefault: z.boolean().optional()
|
|
|
})
|
|
})
|
|
@@ -61,10 +61,10 @@ export default function AddressEditPage() {
|
|
|
defaultValues: {
|
|
defaultValues: {
|
|
|
name: '',
|
|
name: '',
|
|
|
phone: '',
|
|
phone: '',
|
|
|
- province: 1,
|
|
|
|
|
- city: 2,
|
|
|
|
|
- district: 3,
|
|
|
|
|
- town: 4,
|
|
|
|
|
|
|
+ province: 0, // 设为0,让CitySelector自动选择第一个省份
|
|
|
|
|
+ city: 0, // 设为0,让CitySelector自动选择第一个城市
|
|
|
|
|
+ district: 0, // 设为0,让CitySelector自动选择第一个区县
|
|
|
|
|
+ town: 0, // 设为0,让CitySelector自动选择第一个乡镇
|
|
|
address: '',
|
|
address: '',
|
|
|
isDefault: false
|
|
isDefault: false
|
|
|
}
|
|
}
|
|
@@ -76,10 +76,10 @@ export default function AddressEditPage() {
|
|
|
form.reset({
|
|
form.reset({
|
|
|
name: address.name,
|
|
name: address.name,
|
|
|
phone: address.phone,
|
|
phone: address.phone,
|
|
|
- province: address.receiverProvince || 1,
|
|
|
|
|
- city: address.receiverCity || 2,
|
|
|
|
|
- district: address.receiverDistrict || 3,
|
|
|
|
|
- town: address.receiverTown || 4,
|
|
|
|
|
|
|
+ province: address.receiverProvince,
|
|
|
|
|
+ city: address.receiverCity,
|
|
|
|
|
+ district: address.receiverDistrict,
|
|
|
|
|
+ town: address.receiverTown || 0,
|
|
|
address: address.address,
|
|
address: address.address,
|
|
|
isDefault: address.isDefault === 1
|
|
isDefault: address.isDefault === 1
|
|
|
})
|
|
})
|
|
@@ -92,10 +92,10 @@ export default function AddressEditPage() {
|
|
|
const addressData: any = {
|
|
const addressData: any = {
|
|
|
name: data.name,
|
|
name: data.name,
|
|
|
phone: data.phone,
|
|
phone: data.phone,
|
|
|
- receiverProvince: data.province||1,
|
|
|
|
|
- receiverCity: data.city||2,
|
|
|
|
|
- receiverDistrict: data.district||3,
|
|
|
|
|
- receiverTown: data.town || 4,
|
|
|
|
|
|
|
+ receiverProvince: data.province,
|
|
|
|
|
+ receiverCity: data.city,
|
|
|
|
|
+ receiverDistrict: data.district,
|
|
|
|
|
+ receiverTown: data.town,
|
|
|
address: data.address,
|
|
address: data.address,
|
|
|
isDefault: data.isDefault ? 1 : 0
|
|
isDefault: data.isDefault ? 1 : 0
|
|
|
}
|
|
}
|
|
@@ -139,6 +139,9 @@ export default function AddressEditPage() {
|
|
|
|
|
|
|
|
|
|
|
|
|
const onSubmit = (data: AddressFormData) => {
|
|
const onSubmit = (data: AddressFormData) => {
|
|
|
|
|
+ console.debug('表单提交数据:', data)
|
|
|
|
|
+ console.debug('表单验证状态:', form.formState.isValid)
|
|
|
|
|
+ console.debug('表单错误:', form.formState.errors)
|
|
|
saveAddressMutation.mutate(data)
|
|
saveAddressMutation.mutate(data)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -182,7 +185,7 @@ export default function AddressEditPage() {
|
|
|
)}
|
|
)}
|
|
|
/>
|
|
/>
|
|
|
|
|
|
|
|
- {/* <View className="mb-4">
|
|
|
|
|
|
|
+ <View className="mb-4" style={{ display: 'none' }}>
|
|
|
<Text className="text-sm font-medium text-gray-700 mb-2">所在地区</Text>
|
|
<Text className="text-sm font-medium text-gray-700 mb-2">所在地区</Text>
|
|
|
<CitySelector
|
|
<CitySelector
|
|
|
provinceValue={form.watch('province')}
|
|
provinceValue={form.watch('province')}
|
|
@@ -195,7 +198,7 @@ export default function AddressEditPage() {
|
|
|
onTownChange={(value) => form.setValue('town', value)}
|
|
onTownChange={(value) => form.setValue('town', value)}
|
|
|
showLabels={false}
|
|
showLabels={false}
|
|
|
/>
|
|
/>
|
|
|
- </View> */}
|
|
|
|
|
|
|
+ </View>
|
|
|
|
|
|
|
|
<FormField
|
|
<FormField
|
|
|
name="address"
|
|
name="address"
|