This commit is contained in:
czm 2022-05-11 14:28:14 +08:00
parent d0f069937b
commit 8c3e4e9bc1
6 changed files with 129 additions and 149 deletions

12
src/api/addressList.ts Normal file
View File

@ -0,0 +1,12 @@
import { useRequest } from "@/use/useHttp"
/**
*
*/
export const GetAddressListApi = () => {
return useRequest({
url: `/v1/mall/district/list`,
method: "get",
})
}

11
src/api/order.ts Normal file
View File

@ -0,0 +1,11 @@
import { useRequest } from "@/use/useHttp"
/**
*
*/
export const SaleOrderApi = () => {
return useRequest({
url: `/v1/mall/saleOrder`,
method: "post",
})
}

View File

@ -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<AddresParam[]>([])
//市
const [cityList, setCityList] = useState<AddresParam[]>([])
//区
const [areaList, setAreaList] = useState<AddresParam[]>([])
const [list, setList] = useState<AddresParam[]>([])
const [selectIndex, setSelectIndex] = useState(0) //0 省, 1 市2 区
const [selectId, setSelectId] = useState(0) //选中的id
const [selectArr, setSelectArr] = useState<any>([]) //选中的省市区
@ -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) {
const getCity = async () => {
await getAddressList()
if(cityList.length > 0) {
setSelectIndex(1)
setList(() => { return list2 })
setCityStatus(true)
getDomDes('#address_tab_1')
} else {
setCityStatus(false)
}
},10)
}
//获取区
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 {

View File

@ -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 <View className={styles.priceText}><Text>¥</Text>{Number(price) }<Text>{' /' + selectList[selectIndex].eunit}</Text></View>
}
//筛选数据
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 <View className={styles.priceText}><Text>¥</Text>{price}<Text> /{selectList[selectIndex].eunit}</Text></View>
}, [selectIndex])
return (
<View className={styles.shop_cart_main}>
@ -229,16 +227,20 @@ export default memo(({show = false, onClose, title = '', productId = 0}: param)
<View className={styles.product_color_con}>
{(list.length <= 0 && colorState.loading)&&<LoadingCard/>}
{(list.length > 0&& !colorState.loading)&&<InfiniteScroll moreStatus={false}>
{(list.length > 0&& !colorState.loading)&&
<InfiniteScroll moreStatus={false}>
<View className={styles.color_con}>
{list.map(item => {
return <View className={styles.item}>
return <View className={styles.item} key={item.id}>
<View className={styles.item_color}>
<Image src={item.texture_url}/>
</View>
<View className={styles.item_con}>
<View className={styles.title}>{formatHashTag(item.code, item.name)}</View>
<View className={styles.num}>{priceFormat(item)}</View>
<View className={styles.num}>
{formatPrice(item)}
</View>
</View>
<View className={styles.btn_con}>
{!item.show&&<View className={styles.btn} onClick={() => onAdd(item)}></View>

View File

@ -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) => {
|| <View className={styles.buy_btn} onClick={(e) => placeOrder(e)}></View>
}
</View>
<CustomWrapper>
<OrderCount show={showOrderCount} onClose={() => setShowOrderCount(false)} title={productName} productId={productInfo.id}/>
</CustomWrapper>
<ShopCart show={showCart} onClose={() => setShowCart(false)}/>
<Preview value={colorInfo} show={showPreview} onClose={() => setShowPreview(false)}/>
<View className='common_safe_area_y'></View>

View File

@ -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
}