diff --git a/src/api/addressManager.ts b/src/api/addressManager.ts new file mode 100644 index 0000000..376ba04 --- /dev/null +++ b/src/api/addressManager.ts @@ -0,0 +1,34 @@ +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: `/v1/mall/address`, + method: "post", + }) +} + +/** + * 地址详情 + * @returns + */ + export const addressDetailApi = () => { + return useRequest({ + url: `/v1/mall/address`, + method: "get", + }) +} 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..5081eb8 100644 --- a/src/common/common.ts +++ b/src/common/common.ts @@ -46,11 +46,23 @@ export const isEmptyObject = (object: any)=>{ /** * 表单检索 * @param data - * @param rules + * @param rules = { + account: [{ + message: "请输入正确的用户名", + // regex: /\d/, // 正则匹配规则 + // validator: (value:any, rule:any)=>{ // 自定义验证,返回true表示匹配到了(错误) + // return false; + // } + }], + password: [{ + message: "请输入正确的密码", + // regex: /\d/ + }] + }; * @param message * @returns */ -export const retrieval = (data: any, message: string="请填写完信息", rules?: Object)=>{ +export const retrieval = (data: any, rules?: Object, message: string="请填写完信息")=>{ return new Promise((resolve, reject)=>{ if(rules){ const keys = Reflect.ownKeys(rules); @@ -87,6 +99,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.scss b/src/components/AddressList/index.scss index 78f6d40..6089a65 100644 --- a/src/components/AddressList/index.scss +++ b/src/components/AddressList/index.scss @@ -18,7 +18,7 @@ margin: 18px auto 0; border: 1px solid #ffffff; } - .address-list:hover{ + .address-active{ border: 1px solid #68b4ff; box-shadow: 0px 0px 10px 0px rgba(0,122,255,0.27); } diff --git a/src/components/AddressList/index.tsx b/src/components/AddressList/index.tsx index 1681fbc..e60a20f 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,28 @@ 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"> + props.onSelect&&props.onSelect(item,index)} className={`address-list ${item.is_default&&'address-active'}`}> - XL纺织 - 默认 - {/* 1656488999 */} + {item.name} + { + item.is_default?默认: + {item.phone} + } - **省**市**区**街道****仓库 - 181****9790 + {/* **省**市**区**街道****仓库 */} + {item.province_name+item.city_name+item.district_name} {item.address_detail} + { + item.is_default&&{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"?