优化细节
This commit is contained in:
@@ -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>
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user