优化细节

This commit is contained in:
2025-07-24 19:37:45 +08:00
parent 3e315bf9ee
commit 3693b2d5ed
54 changed files with 1143 additions and 595 deletions

View File

@@ -4,17 +4,54 @@ import {Dongdong, ArrowRight, CheckNormal, Checked} from '@nutui/icons-react-tar
import Taro from '@tarojs/taro'
import {View} from '@tarojs/components'
import {ShopUserAddress} from "@/api/shop/shopUserAddress/model";
import {listShopUserAddress} from "@/api/shop/shopUserAddress";
import {listShopUserAddress, removeShopUserAddress, updateShopUserAddress} from "@/api/shop/shopUserAddress";
const Address = () => {
const [list, setList] = useState<ShopUserAddress[]>([{},{},{},{}])
const [list, setList] = useState<ShopUserAddress[]>([])
const [address, setAddress] = useState<ShopUserAddress>()
const reload = () => {
listShopUserAddress({userId: Taro.getStorageSync('UserId')}).then(res => {
// setList(res)
}).catch(error => {
console.error("Failed to fetch goods detail:", error);
listShopUserAddress({
userId: Taro.getStorageSync('UserId')
})
.then(data => {
setList(data || [])
// 默认地址
setAddress(data.find(item => item.isDefault))
})
.catch(() => {
Taro.showToast({
title: '获取地址失败',
icon: 'error'
});
})
}
const onDefault = async (item) => {
if(address){
await updateShopUserAddress({
...address,
isDefault: false
})
}
await updateShopUserAddress({
id: item.id,
isDefault: true
})
Taro.showToast({
title: '设置成功',
icon: 'success'
});
reload();
}
const onDel = async (id?: number) => {
await removeShopUserAddress(id)
Taro.showToast({
title: '删除成功',
icon: 'success'
});
reload();
}
useEffect(() => {
@@ -35,26 +72,14 @@ const Address = () => {
/>
<Space>
<Button onClick={() => Taro.navigateTo({url: '/user/address/add'})}></Button>
<Button type="success" fill="dashed"></Button>
<Button type="success" fill="dashed"
onClick={() => Taro.navigateTo({url: '/user/address/wxAddress'})}></Button>
</Space>
</div>
</ConfigProvider>
)
}
if (list.length == 0) {
return (
<CellGroup>
<Cell className={''}>
<Space>
<Button></Button>
<Button></Button>
</Space>
</Cell>
</CellGroup>
)
}
return (
<>
<CellGroup>
@@ -70,46 +95,31 @@ const Address = () => {
</div>
</Cell>
</CellGroup>
{list.map((item,index) => (
// <CellGroup key={item.id}>
// <Cell title={item.name}
// extra={
// <Button
// type="primary"
// size="small"
// >
// 修改
// </Button>
// }
// >
// <div className={'text-sm'}>{item.fullAddress}</div>
//
// </Cell>
// </CellGroup>
{list.map((item, _) => (
<Cell.Group>
<Cell className={'flex flex-col gap-1'}>
<View>
<View className={'font-medium text-sm'}> 13800010001</View>
<View className={'font-medium text-sm'}>{item.name} {item.phone}</View>
</View>
<View className={'text-xs'}>
广西13
{item.province} {item.city} {item.region} {item.address}
</View>
</Cell>
<Cell
align="center"
title={
<View className={'flex items-center gap-1'}>
{index == 0 ? <Checked className={'text-green-600'} size={16}/> : <CheckNormal size={16} />}
<View className={'flex items-center gap-1'} onClick={() => onDefault(item)}>
{item.isDefault ? <Checked className={'text-green-600'} size={16}/> : <CheckNormal size={16}/>}
<View className={'text-gray-400'}></View>
</View>
}
extra={
<>
<View className={'text-gray-400'}>
<View className={'text-gray-400'} onClick={() => onDel(item.id)}>
</View>
<Divider direction={'vertical'}/>
<View className={'text-gray-400'}>
<View className={'text-gray-400'} onClick={() => Taro.navigateTo({url: '/user/address/add?id=' + item.id})}>
</View>
</>