--地址管理完成
This commit is contained in:
@@ -22,6 +22,9 @@
|
||||
border: 1px solid #68b4ff;
|
||||
box-shadow: 0px 0px 10px 0px rgba(0,122,255,0.27);
|
||||
}
|
||||
.address-list:first-child{
|
||||
margin-top: 0;
|
||||
}
|
||||
.address-list:last-child{
|
||||
margin-bottom: 300px;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
import { Button, Navigator, ScrollView, Text, View } from "@tarojs/components"
|
||||
import { memo, useEffect, useState } from "react"
|
||||
import "./index.scss"
|
||||
import {addressListApi} from "@/api/addressManager"
|
||||
import {addressListApi,addressDeleteApi} from "@/api/addressManager"
|
||||
import { alert } from "@/common/common"
|
||||
import Taro, { showModal } from "@tarojs/taro"
|
||||
|
||||
interface Params{
|
||||
refresherEnabled?: boolean,//是否开启刷新
|
||||
@@ -33,8 +35,12 @@ const AddressList = memo((props:Params)=>{
|
||||
}
|
||||
useEffect(()=>{
|
||||
getData();
|
||||
// 监听刷新
|
||||
Taro.eventCenter.on("addressList:refresh", getData);
|
||||
return ()=>{
|
||||
Taro.eventCenter.off("addressList:refresh", getData);
|
||||
}
|
||||
},[])
|
||||
|
||||
// 处理刷新
|
||||
const [refreshState, setRefreshState] = useState(false);
|
||||
const handleRefresh = async ()=>{
|
||||
@@ -52,6 +58,25 @@ const AddressList = memo((props:Params)=>{
|
||||
setFocusId(item?.id);
|
||||
}
|
||||
}
|
||||
// 删除地址
|
||||
const {fetchData: deleteFetch} = addressDeleteApi()
|
||||
const handleDelete = (item:any)=>{
|
||||
showModal(({
|
||||
title: "提示",
|
||||
content: "是否删除地址?",
|
||||
async success(ev){
|
||||
if(ev.confirm){
|
||||
const result = await deleteFetch({id:item.id});
|
||||
if(result.success){
|
||||
alert.success("删除成功");
|
||||
getData();
|
||||
}else{
|
||||
alert.success(result.msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
return (
|
||||
<View className="address-scroll-view">
|
||||
@@ -62,7 +87,7 @@ const AddressList = memo((props:Params)=>{
|
||||
// data.length>0?
|
||||
// data.map((item,index)=>{
|
||||
return(
|
||||
<View onClick={()=>handleSelect(item,index)} className={`address-list ${focusId==item.id&&'address-active'}`}>
|
||||
<View onLongPress={()=>handleDelete(item)} onClick={()=>handleSelect(item,index)} className={`address-list ${focusId==item.id&&'address-active'}`}>
|
||||
<View className="address-user">
|
||||
{item.name}
|
||||
{
|
||||
@@ -75,7 +100,7 @@ const AddressList = memo((props:Params)=>{
|
||||
{/* **省**市**区**街道****仓库 */}
|
||||
{item.province_name+item.city_name+item.district_name} {item.address_detail}
|
||||
{
|
||||
item.is_default&&<Text className="address-list-phone">{item.phone}</Text>
|
||||
item.is_default&&<Text className="address-list-phone">{item.phone.replace(item.phone.substring(3,7), "****")}</Text>
|
||||
}
|
||||
</View>
|
||||
<Navigator url={`/pages/addressAdd/index?type=edit&id=${item.id}`} hoverClass="none" className="address-edit">
|
||||
|
||||
Reference in New Issue
Block a user