diff --git a/src/api/addressManager.ts b/src/api/addressManager.ts new file mode 100644 index 0000000..1d2f537 --- /dev/null +++ b/src/api/addressManager.ts @@ -0,0 +1,23 @@ +import { useRequest } from "@/use/useHttp" + +/** + * 获取地址列表 + * @returns + */ + export const addressListApi = () => { + return useRequest({ + url: `/v1/mall/address/list`, + method: "get", + }) +} + +/** + * 添加地址 + * @returns + */ + export const addressAddApi = () => { + return useRequest({ + url: `/lymarket/v1/mall/address`, + method: "post", + }) +} diff --git a/src/app.config.ts b/src/app.config.ts index 1f73284..c9abe95 100644 --- a/src/app.config.ts +++ b/src/app.config.ts @@ -86,6 +86,12 @@ export default { "index" ] }, + { + root: "pages/weightListAdd", + pages: [ + "index" + ] + }, { root: "pages/order", pages: [ diff --git a/src/common/common.ts b/src/common/common.ts index e2ba671..fe8f1cd 100644 --- a/src/common/common.ts +++ b/src/common/common.ts @@ -87,6 +87,31 @@ export const retrieval = (data: any, message: string="请填写完信息", rules resolve(null); }) } + /** + * toast提示 + */ + export const alert = { + success(title: string){ + Taro.showToast({ + title,icon: "success" + }) + }, + error(title: string){ + Taro.showToast({ + title,icon: "error" + }) + }, + loading(title: string){ + Taro.showToast({ + title,icon: "loading" + }) + }, + none(title: string){ + Taro.showToast({ + title,icon: "none" + }) + }, + } // 金额千位分割符 export const formatKbPrice = (number: string) => { diff --git a/src/components/AddressList/index.tsx b/src/components/AddressList/index.tsx index c3524ee..90806e1 100644 --- a/src/components/AddressList/index.tsx +++ b/src/components/AddressList/index.tsx @@ -1,7 +1,8 @@ import { Button, Navigator, ScrollView, Text, View } from "@tarojs/components" -import { memo, useState } from "react" +import { memo, useEffect, useState } from "react" import "./index.scss" +import {addressListApi} from "@/api/addressManager" interface Params{ refresherEnabled?: boolean,//是否开启刷新 @@ -11,13 +12,21 @@ interface Params{ // 地址列表 const AddressList = memo((props:Params)=>{ + const {fetchData, state} = addressListApi() + // 获取数据 + const getData = ()=>{ + fetchData(); + } + useEffect(()=>{ + getData(); + },[]) + // 处理刷新 const [refreshState, setRefreshState] = useState(false); - const handleRefresh = ()=>{ + const handleRefresh = async ()=>{ setRefreshState(true); - setTimeout(()=>{ - setRefreshState(false); - },500) + await fetchData(); + setRefreshState(false); } const data = Array.from({length:15}); @@ -25,21 +34,24 @@ const AddressList = memo((props:Params)=>{ { - data.length>0? - data.map((item,index)=>{ + state?.data?.list?.length>0? + state?.data?.list?.map((item,index)=>{ + // data.length>0? + // data.map((item,index)=>{ return( - props.onSelect&&props.onSelect(item,index)} className={`address-list ${index==0&&'address-active'}`}> + props.onSelect&&props.onSelect(item,index)} className={`address-list ${item.is_default&&'address-active'}`}> - XL纺织 + {item.name} { - index==0?默认: - 1656488999 + item.is_default?默认: + {item.phone} } - **省**市**区**街道****仓库 - 181****9790 + {/* **省**市**区**街道****仓库 */} + {item.province_name+item.city_name+item.district_name} {item.address_detail} + {item.phone} diff --git a/src/components/FromList/index.scss b/src/components/FromList/index.scss index 38257e1..e820f47 100644 --- a/src/components/FromList/index.scss +++ b/src/components/FromList/index.scss @@ -28,6 +28,11 @@ width: 100%; display: flex;align-items: center; } + .form-list-input view{ + height: 100%; + padding: 0 10px; + box-sizing: border-box; + } .form-list-input text{ width: 30px; min-width: 30px; @@ -38,6 +43,7 @@ display: flex;align-items: center; justify-content: center; flex: 1; + color: white; } .form-list-right input,.form-list-right textarea{ // flex: 0 0 auto; diff --git a/src/components/FromList/index.tsx b/src/components/FromList/index.tsx index 6635fec..8df1c6c 100644 --- a/src/components/FromList/index.tsx +++ b/src/components/FromList/index.tsx @@ -5,7 +5,7 @@ import "./index.scss" interface ListParams{ label: string, //左边label - onInput?: ()=>any, // 输入框输入 + onInput?: (ev:Object)=>void, // 输入框输入 onClick?:()=>any, //点击列表 placeholder?:string, // 提示文本 children?: any, // 插槽 @@ -28,7 +28,9 @@ const FromList = memo((props:ListParams)=>{ type=="input"? - {value&&} + {value&& + props.onInput&&props.onInput({detail: {value: ""}})} className="iconfont icon-qingkong"/> + } : type=="textarea"?