From 8c3e4e9bc18c52fa783ba41685c910f34c7d177c Mon Sep 17 00:00:00 2001 From: czm <2192718639@qq.com> Date: Wed, 11 May 2022 14:28:14 +0800 Subject: [PATCH] 1 --- src/api/addressList.ts | 12 ++ src/api/order.ts | 11 ++ src/components/address/index.tsx | 145 ++++++------------ .../details/components/orderCount/index.tsx | 100 ++++++------ src/pages/details/index.tsx | 6 +- src/use/useLogin.ts | 4 +- 6 files changed, 129 insertions(+), 149 deletions(-) create mode 100644 src/api/addressList.ts create mode 100644 src/api/order.ts diff --git a/src/api/addressList.ts b/src/api/addressList.ts new file mode 100644 index 0000000..4ff2e32 --- /dev/null +++ b/src/api/addressList.ts @@ -0,0 +1,12 @@ + +import { useRequest } from "@/use/useHttp" + +/** + * 获取行政地区列表 + */ + export const GetAddressListApi = () => { + return useRequest({ + url: `/v1/mall/district/list`, + method: "get", + }) +} \ No newline at end of file diff --git a/src/api/order.ts b/src/api/order.ts new file mode 100644 index 0000000..770d977 --- /dev/null +++ b/src/api/order.ts @@ -0,0 +1,11 @@ +import { useRequest } from "@/use/useHttp" + +/** + * 下单现货销售单 + */ + export const SaleOrderApi = () => { + return useRequest({ + url: `/v1/mall/saleOrder`, + method: "post", + }) +} \ No newline at end of file diff --git a/src/components/address/index.tsx b/src/components/address/index.tsx index ba44aa5..9d4725f 100644 --- a/src/components/address/index.tsx +++ b/src/components/address/index.tsx @@ -4,6 +4,8 @@ import Drawer from "@/components/popup"; import styles from "./index.module.scss" import classnames from "classnames"; import Taro from "@tarojs/taro"; +import { GetAddressListApi } from "@/api/addressList"; + type Params = { addressOnSelect?: ({}:{name: string, id:string|number}) => void, @@ -15,90 +17,47 @@ export default memo(({ addressOnSelect, addressOnClose, show = false - }: Params) => { - const list1 = [ - { - name:'广东1', - id:1 - }, - { - name:'广东2', - id:2 - }, - { - name:'广东3', - id:3 - }, - { - name:'广东4', - id:4 - }, - { - name:'广东5', - id:5 - }, - { - name:'广东6', - id:6 - } - ] - const list2 = [ - { - name:'佛山1佛山1佛山1佛山1佛山1', - id:7 - }, - { - name:'佛山2', - id:8 - }, - { - name:'佛山3', - id:9 - }, - { - name:'佛山4', - id:10 - }, - { - name:'佛山5', - id:11 - }, - { - name:'佛山6', - id:12 - } - ] + //获取地址 + const {fetchData} = GetAddressListApi() + useEffect(() => { + getAddressList() + setList(provinceList) + }, []) - const list3 = [ - { - name:'禅城区1', - id:13 - }, - { - name:'禅城区2', - id:14 - }, - { - name:'禅城区3', - id:15 - }, - { - name:'禅城区4', - id:16 - }, - { - name:'禅城区5', - id:17 - }, - { - name:'禅城区6', - id:18 + const condition = useRef({parent_id:1}) + const getAddressList = async () => { + let res = await fetchData(condition.current) + const lists = res.data.list||[] + if(selectIndex == 0) { + setProvinceList(lists) + } else if(selectIndex == 1) { + setCityList(lists) + } else { + setAreaList(lists) } - ] + setList(lists) + } - const [list, setList] = useState(list1) + + type AddresParam = { + ad_code?: string, + id?: number, + level?: number, + level_name?: string, + name?: string, + parent_id?: number + } + //省 + const [provinceList, setProvinceList] = useState([]) + //市 + const [cityList, setCityList] = useState([]) + //区 + const [areaList, setAreaList] = useState([]) + + + const [list, setList] = useState([]) const [selectIndex, setSelectIndex] = useState(0) //0 省, 1 市,2 区 const [selectId, setSelectId] = useState(0) //选中的id const [selectArr, setSelectArr] = useState([]) //选中的省市区 @@ -132,8 +91,7 @@ export default memo(({ useEffect(() => { if(selectIndex == 0) { - setList(list1) - // getDomDes('#address_tab_0') + setList(provinceList) } else if (selectIndex == 1) { getCity() } else { @@ -142,27 +100,22 @@ export default memo(({ }, [selectIndex]) //获取市 - const getCity = () => { - - setTimeout(() => { - if(list2.length > 0) { - setSelectIndex(1) - setList(() => { return list2 }) - setCityStatus(true) - getDomDes('#address_tab_1') - } else { - setCityStatus(false) - } - },10) + const getCity = async () => { + await getAddressList() + if(cityList.length > 0) { + setSelectIndex(1) + setCityStatus(true) + getDomDes('#address_tab_1') + } else { + setCityStatus(false) + } } //获取区 const area = () => { - // setAreaStatus(false) setTimeout(() => { - if(list3.length > 0) { + if(areaList.length > 0) { setSelectIndex(2) - setList(() => { return list3 }) setAreaStatus(true) getDomDes('#address_tab_2') } else { diff --git a/src/pages/details/components/orderCount/index.tsx b/src/pages/details/components/orderCount/index.tsx index 4ac91dd..6f5233a 100644 --- a/src/pages/details/components/orderCount/index.tsx +++ b/src/pages/details/components/orderCount/index.tsx @@ -1,4 +1,4 @@ -import {Image, ScrollView, View, Text } from "@tarojs/components" +import {Image, ScrollView, View, Text, CustomWrapper } from "@tarojs/components" import Popup from "@/components/popup" import LoadingCard from "@/components/loadingCard"; import Search from "@/components/search"; @@ -27,20 +27,24 @@ type param = { export default memo(({show = false, onClose, title = '', productId = 0}: param) => { const {adminUserInfo} = useSelector(state => state.userInfo) - const selectList = [ - {id: 0, step:1, digits:0, maxNum:100000, defaultNum:1, title:'大货', unit:'件', eunit:'kg'}, - {id: 1, step:1, digits:2, maxNum:9.99, defaultNum:1, title:'剪板', unit:'米', eunit:'m'}, - {id: 2, step:1, digits:2, minNum:10, maxNum:100000, defaultNum:10, title:'散剪', unit:'米', eunit:'kg'}, - ] + const [selectList, setSelectList] = useState([ + {id: 0, step:1, digits:0, maxNum:100000, defaultNum:1, title:'大货', unit:'件', eunit:'kg', priceField:'bulk_price'}, + {id: 1, step:1, digits:2, maxNum:9.99, defaultNum:1, title:'剪板', unit:'米', eunit:'m', priceField:'length_cut_price'}, + {id: 2, step:1, digits:2, minNum:10, maxNum:100000, defaultNum:10, title:'散剪', unit:'米', eunit:'kg', priceField:'weight_cut_price'}, + ]) const [selectIndex, setSelectIndex] = useState(0) const selectProduct = (index:number) => { setSelectIndex(() => index) - //重置数据 + + } + + //重置数据 + useEffect(() => { const newList = initList(list) setList([...newList]) condition.current.code_or_name = null setSearchShow(false) - } + }, [selectIndex]) //获取面料颜色列表 const {fetchData:colorFetchData, state: colorState} = GetColorList() @@ -176,19 +180,6 @@ export default memo(({show = false, onClose, title = '', productId = 0}: param) } - //显示金额 - const priceFormat = (item) => { - let price = 0 - if(selectIndex == 0) { - price = formatMillionYuan(item.bulk_price, 100).num - } else if(selectIndex == 1) { - price = formatMillionYuan(item.length_cut_price, 100).num - } else { - price = formatMillionYuan(item.weight_cut_price, 100).num - } - return ¥{Number(price) }{' /' + selectList[selectIndex].eunit} - } - //筛选数据 const searchInput = (e) => { condition.current.code_or_name = e @@ -202,6 +193,13 @@ export default memo(({show = false, onClose, title = '', productId = 0}: param) setSearchShow(false) } + //格式化金额 + const formatPrice = useCallback((item) => { + const price = Number(formatMillionYuan(item[selectList[selectIndex].priceField], 100).num) + return ¥{price} /{selectList[selectIndex].eunit} + }, [selectIndex]) + + return ( @@ -229,35 +227,39 @@ export default memo(({show = false, onClose, title = '', productId = 0}: param) {(list.length <= 0 && colorState.loading)&&} - {(list.length > 0&& !colorState.loading)&& - - {list.map(item => { - return - - + {(list.length > 0&& !colorState.loading)&& + + + + {list.map(item => { + return + + + + + {formatHashTag(item.code, item.name)} + + {formatPrice(item)} + + + + {!item.show&& onAdd(item)}>添加 + || + getInputValue(e, item)} + defaultNum={item.count} + step={selectList[selectIndex].step} + digits={selectList[selectIndex].digits} + onClickBtn={(e) => getInputValue(e, item)} + unit={selectList[selectIndex].unit} + minNum={selectList[selectIndex].minNum} + maxNum={selectList[selectIndex].maxNum} + /> + } + - - {formatHashTag(item.code, item.name)} - {priceFormat(item)} - - - {!item.show&& onAdd(item)}>添加 - || - getInputValue(e, item)} - defaultNum={item.count} - step={selectList[selectIndex].step} - digits={selectList[selectIndex].digits} - onClickBtn={(e) => getInputValue(e, item)} - unit={selectList[selectIndex].unit} - minNum={selectList[selectIndex].minNum} - maxNum={selectList[selectIndex].maxNum} - /> - } - - - })} - + })} + } {(list.length <= 0 && !colorState.loading)&&暂无此商品} diff --git a/src/pages/details/index.tsx b/src/pages/details/index.tsx index d663095..75f1899 100644 --- a/src/pages/details/index.tsx +++ b/src/pages/details/index.tsx @@ -1,5 +1,5 @@ -import { Button, Image, RichText, ScrollView, Swiper, SwiperItem, Text, View } from '@tarojs/components' +import { Button, CustomWrapper, Image, RichText, ScrollView, Swiper, SwiperItem, Text, View } from '@tarojs/components' import Taro, { useDidShow, usePullDownRefresh, useRouter, useShareAppMessage } from '@tarojs/taro'; import classnames from "classnames"; import DesSwiper from './components/swiper'; @@ -170,7 +170,9 @@ export default (props:params) => { || placeOrder(e)}>开始下单 } - setShowOrderCount(false)} title={productName} productId={productInfo.id}/> + + setShowOrderCount(false)} title={productName} productId={productInfo.id}/> + setShowCart(false)}/> setShowPreview(false)}/> diff --git a/src/use/useLogin.ts b/src/use/useLogin.ts index c449363..45847ef 100644 --- a/src/use/useLogin.ts +++ b/src/use/useLogin.ts @@ -99,7 +99,7 @@ export default () => { const {fetchData: fetchDataUserInfo} = GetWxUserInfoApi() const getSelfUserInfo = async () => { return new Promise((reslove, reject) => { - if(userInfo.adminUserInfo.is_authorize_name) { + if(userInfo.adminUserInfo?.is_authorize_name) { reslove(true) return true } @@ -138,7 +138,7 @@ export default () => { const {fetchData: fetchDataUserPhone} = GetPhoneNumberApi() const getPhoneNumber = (code) =>{ return new Promise( async (reslove, reject) => { - if(userInfo.adminUserInfo.is_authorize_phone) { + if(userInfo.adminUserInfo?.is_authorize_phone) { reslove(true) return true }