This commit is contained in:
li tong bao
2022-05-11 14:39:57 +08:00
39 changed files with 2491 additions and 340 deletions
+49 -96
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) {
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 {
+9 -5
View File
@@ -1,6 +1,6 @@
.checkbox_main{
width: 60px;
height: 60px;
width: 50px;
height: 50px;
display: flex;
justify-content: center;
align-items: center;
@@ -13,14 +13,18 @@
text-align: center;
line-height: 40px;
}
.no_checkbox_item{
border:0;
background-color: #DDDDDD;
}
.checkbox_item_select{
background-color: $color_main;
border: 0;
color: #fff;
width: 44px;
height: 44px;
width: 40px;
height: 40px;
text-align: center;
line-height: 44px;
line-height: 40px;
.miconfont{
font-size: 26px;
}
+8 -6
View File
@@ -4,13 +4,15 @@ import { useEffect, useState } from "react";
import styles from "./index.module.scss"
type params = {
onSelect?: () => void,
onClose?: () => void,
status?: false|true
onSelect?: () => void, //选择触发
onClose?: () => void, //取消触发
status?: false|true //是否选中
disabled?: false|true //是否禁用
}
export default ({onSelect, onClose, status = false}: params) => {
export default ({onSelect, onClose, status = false, disabled = false}: params) => {
const [selected, SetSelected] = useState(false)
const onSelectEven = () => {
if(disabled) return false
let res = !selected
if(res) {
onSelect?.()
@@ -25,8 +27,8 @@ export default ({onSelect, onClose, status = false}: params) => {
return (
<>
<View className={styles.checkbox_main} onClick={() => onSelectEven()}>
<View className={classnames(styles.checkbox_item, selected&&styles.checkbox_item_select)}>
{selected&&<View className={classnames('iconfont', 'icon-tick_gou', styles.miconfont)}></View>}
<View className={classnames(styles.checkbox_item, disabled&&styles.no_checkbox_item, selected&&styles.checkbox_item_select)}>
{selected&&<View className={classnames('iconfont', 'icon-tick', styles.miconfont)}></View>}
</View>
</View>
</>
@@ -9,4 +9,8 @@
display: flex;
justify-content: center;
align-items: center;
.icon_a_btn{
font-size: 30px;
margin-top: 3px;
}
}
+5 -3
View File
@@ -1,4 +1,4 @@
import { View } from "@tarojs/components"
import { View, Text } from "@tarojs/components"
import { memo } from "react"
import style from "./index.module.scss"
@@ -11,8 +11,10 @@ export default memo(({onClose, styleObj = {}}:Params) => {
return (
<View
style={styleObj}
className={`iconfont icon-cuo ${style.icon_a_cuowuwrong_self}`}
className={style.icon_a_cuowuwrong_self}
onClick={onClose}
></View>
>
<Text className={`iconfont icon-qingkong ${style.icon_a_btn}`}></Text>
</View>
)
})
+28 -10
View File
@@ -1,18 +1,19 @@
import { View } from "@tarojs/components";
import style from "./index.module.scss"
import classnames from "classnames";
import { memo, ReactNode, useMemo } from "react";
import { memo, ReactNode, useEffect, useMemo, useRef } from "react";
import CloseBtnIcon from "@/components/closeBtn"
export interface Params {
title?: string,
show?: false|true,
showTitle?: false|true,
onClose?:() => void,
children?: ReactNode,
IconButton?: ReactNode,
showIconButton?: false|true,
position?: 'bottom'|'top'|'right'
title?: string, //标题
show?: false|true, //显示显示弹窗
showTitle?: false|true, //是否显示标题
onClose?:() => void, //关闭事件
children?: ReactNode, //插槽内容
// IconButton?: ReactNode, //
showIconButton?: false|true, //是否显示关闭按钮
position?: 'bottom'|'top'|'right', //弹出位置
animationEnd?: () => void //弹出动画结束
}
export default memo((
{
@@ -22,9 +23,26 @@ export default memo((
onClose,
showIconButton = false,
children,
position = 'bottom'
position = 'bottom',
animationEnd
}:Params) => {
const animationTime = useRef<any>(null)
useEffect(() => {
if(show) {
animationTime.current = setTimeout(() => {
animationEnd?.()
}, 260)
} else {
clearTimeout(animationTime.current)
}
}, [show])
useEffect(() => {
return () => {
clearTimeout(animationTime.current)
}
}, [])
return (
<>
+8 -4
View File
@@ -3,7 +3,7 @@ import styles from "./index.module.scss"
import CloseBtn from "@/components/closeBtn"
import classnames from "classnames";
import { debounce } from "@/common/util";
import { memo, useEffect, useRef, useState } from "react";
import { forwardRef, memo, useEffect, useImperativeHandle, useRef, useState } from "react";
type Params = {
clickOnSearch?: (val: string) => void
@@ -19,7 +19,7 @@ type Params = {
debounceTime?: number //防抖时间,不设默认为零
}
export default memo(({
export default forwardRef(({
clickOnSearch,
changeOnSearch,
disabled = false,
@@ -29,8 +29,8 @@ export default memo(({
btnStyle = {},
placeIcon = 'inner',
btnTitle = '搜索',
debounceTime = 0
}:Params) => {
debounceTime = 0,
}:Params, ref) => {
const [inputCon , setInputCon] = useState('')
const debounceTimeRef = useRef(0)
@@ -43,6 +43,10 @@ export default memo(({
changeData(value)
}
useImperativeHandle(ref, () => ({
clearInput
}))
const clearInput = () => {
setInputCon('')
changeOnSearch?.('')
+9 -3
View File
@@ -41,7 +41,7 @@
}
.con{
padding:30px;
padding-bottom: 0;
padding-bottom: 100px;
box-sizing: border-box;
flex:1;
height: 0;
@@ -54,12 +54,11 @@
display: flex;
justify-content: space-between;
&:nth-child(n+2) {
margin-top: 30px;
margin-top: 37px;
}
.checkbox{
display: flex;
align-items: center;
}
.img{
width: 126px;
@@ -77,9 +76,12 @@
flex-direction: column;
justify-content: space-between;
margin-left: 20px;
padding-right: 10px;
box-sizing: border-box;
.title{
font-size: $font_size;
color: $color_font_one;
@include common_ellipsis;
}
.subtitle{
color: $color_font_two;
@@ -97,10 +99,14 @@
}
}
}
.no_product_item_select{
opacity: 0.3;
}
.count{
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: flex-end;
.price{
font-size: $font_size;
font-weight: 700;
+119 -31
View File
@@ -5,22 +5,47 @@ import MCheckbox from "@/components/checkbox";
import LoadingCard from "@/components/loadingCard";
import InfiniteScroll from "@/components/infiniteScroll";
import styles from "./index.module.scss"
import { useEffect, useState } from "react";
import { useCallback, useEffect, useRef, useState } from "react";
import Taro from "@tarojs/taro";
import { goLink } from "@/common/common";
import {GetShoppingCartApi} from "@/api/shopCart"
import {GetShoppingCartApi, DelShoppingCartApi} from "@/api/shopCart"
import { formatHashTag, formatImgUrl, formatMillionYuan } from "@/common/fotmat";
type param = {
show?: true|false,
onClose?: () => void
}
export default ({show = false, onClose}: param) => {
const selectList = ['不限', '剪板', '散剪', '大货']
const [selectIndex, setSelectIndex] = useState(0)
const selectList = [
{value:-1, title:'不限', unit:'', eunit:''},
{value:0, title:'大货', unit:'件', eunit:'kg'},
{value:1,title:'剪板', unit:'米', eunit:'m'},
{value:2,title:'散剪', unit:'米', eunit:'kg'},
]
const [selectIndex, setSelectIndex] = useState(-1)
const selectProduct = (index:number) => {
setSelectIndex(index)
}
useEffect(() => {
resetList()
setSelectStatus(true)
}, [selectIndex])
//重置勾选数据
const resetList = () => {
list?.map(item => {
if(selectIndex == item.sale_mode || selectIndex == -1) {
item.select = true
} else {
item.select = false
}
})
setList([...list])
}
//获取数据
const [list, setList] = useState<any[]>([])
const [loading, setLoading] = useState(false)
@@ -28,14 +53,29 @@ export default ({show = false, onClose}: param) => {
const getShoppingCart = async () => {
setLoading(true)
const {data} = await fetchData()
setList(data)
let color_list = data.color_list||[]
initList(color_list)
setList(color_list)
setLoading(false)
}
//初始化全部数据
const initList = (color_list) => {
if(selectIndex == -1) {
color_list?.map(item => {
item.select = true
})
}
}
//显示是展示数据
useEffect(() => {
if(!show) return
getShoppingCart()
if(!show) {
setList([])
setSelectIndex(-1)
} else {
getShoppingCart()
}
}, [show])
useEffect(() => {
@@ -49,11 +89,12 @@ export default ({show = false, onClose}: param) => {
setShowPopup(show)
}, [show])
//全选反选
const [selectStatus, setSelectStatus] = useState(false)
const selectAll = () => {
list.map(item => {
item.select = !selectStatus
if(selectIndex == item.sale_mode || selectIndex == -1)
item.select = !selectStatus
})
setSelectStatus(!selectStatus)
setList([...list])
@@ -62,12 +103,29 @@ export default ({show = false, onClose}: param) => {
//checkbox选中回调
const selectCallBack = (item) => {
item.select = true
checkSelect()
setList([...list])
}
//checkbox选中判断是否全部选中,全部选中后是全选,否则反选
const checkSelect = () => {
let list_count = 0
let select_count = 0
list?.map(item => {
if(selectIndex == -1 || selectIndex == item.sale_mode) {
list_count ++
if(item.select) select_count++
}
})
console.log('list_count::',list_count)
console.log('select_count::',select_count)
setSelectStatus(select_count == list_count)
}
//checkbox关闭回调
const colseCallBack = (item) => {
item.select = false
checkSelect()
setList([...list])
}
@@ -77,16 +135,28 @@ export default ({show = false, onClose}: param) => {
setShowPopup(false)
}
//删除购物车内容
const {fetchData:delShopFetchData} = DelShoppingCartApi()
const delSelect = () => {
Taro.showModal({
content: '删除所选商品?',
success: function (res) {
success: async function (res) {
if (res.confirm) {
Taro.showToast({
title: '成功',
icon: 'success',
duration: 2000
})
getSelectId()
const res = await delShopFetchData({id:selectIds.current})
if(res.success) {
getShoppingCart()
Taro.showToast({
title: '成功',
icon: 'success',
})
} else {
Taro.showToast({
title: res.msg,
icon: 'none',
})
}
} else if (res.cancel) {
console.log('用户点击取消')
}
@@ -94,11 +164,30 @@ export default ({show = false, onClose}: param) => {
})
}
//获取面料选中的id
const selectIds = useRef<number[]>([])
const getSelectId = () => {
list?.map(item => {
if(selectIndex == -1 || selectIndex == item.sale_mode) {
item.select&&selectIds.current.push(item.id)
}
})
}
//格式化金额
const formatPirce = useCallback((price) => {
const {num} = formatMillionYuan(price, 100)
return Number(num)
}, [])
//格式化数量
const formatCount = useCallback((item) => {
return item.sale_mode == 0? item.roll + '件': item.length + 'm'
}, [])
return (
<View className={styles.shop_cart_main}>
<Popup showTitle={false} show={showPopup} onClose={() => closePopup()}>
<Popup showTitle={false} show={showPopup} onClose={() => closePopup()} >
<View className={styles.popup_con}>
<View className={styles.header}>
<View onClick={selectAll}>{!selectStatus?'全选':'反选'}</View>
@@ -108,37 +197,36 @@ export default ({show = false, onClose}: param) => {
</View>
</View>
<View className={styles.search}>
{selectList.map((item, index) => {
return <View key={index} onClick={() => selectProduct(index)} className={classnames(styles.search_item, (selectIndex==index)&&styles.search_item_select)}>{item}</View>
{selectList.map((item) => {
return <View key={item.value} onClick={() => selectProduct(item.value)} className={classnames(styles.search_item, (selectIndex==item.value)&&styles.search_item_select)}>{item.title}</View>
})}
</View>
<View className={styles.con}>
{loading&&<LoadingCard/>}
{!loading&&list.length > 0&&<InfiniteScroll refresherTriggered={true} refresherEnabled={true} selfonScrollToLower={() => {console.log('触底了')}} paddingBottom={100}>
{!loading&&list?.length > 0&&<InfiniteScroll refresherTriggered={true} refresherEnabled={true} moreStatus={false} >
<View className={styles.product_list}>
{list.map((item, index) => {
return <View key={index} className={styles.product_item}>
{list?.map((item, index) => {
return <View key={index} className={classnames(styles.product_item, (selectIndex!=-1&&selectIndex!= item.sale_mode)&&styles.no_product_item_select)}>
<View className={styles.checkbox}>
<MCheckbox status={item.select} onSelect={() => selectCallBack(item)} onClose={() => colseCallBack(item)}/>
<MCheckbox disabled={selectIndex!=-1&&selectIndex!=item.sale_mode} status={item.select} onSelect={() => selectCallBack(item)} onClose={() => colseCallBack(item)}/>
</View>
<View className={styles.img}>
<Image src="https://bpic.588ku.com//back_origin_min_pic/22/01/11/aa3da17bab9a6556564028e4f1d77874.jpg!/fw/750/quality/99/unsharp/true/compress/true"/>
<Image mode="aspectFill" src={formatImgUrl(item.texture_url)}/>
</View>
<View className={styles.des}>
<View className={styles.title}>{item.title}</View>
<View className={styles.subtitle}>07703# 21S单面平纹(食毛)</View>
<View className={styles.tag}>剪板</View>
<View className={styles.title}>{formatHashTag(item.product_code, item.product_name)}</View>
<View className={styles.subtitle}>{item.product_color_code +' ' + item.product_color_name}</View>
<View className={styles.tag}>{item.sale_mode_name}</View>
</View>
<View className={styles.count}>
<View className={styles.price}><text>¥</text>40.5<text>/kg</text></View>
<View className={styles.long}>×12m</View>
<View className={styles.price}><text>¥</text>{formatPirce(item.sale_price)}<text>/kg</text></View>
<View className={styles.long}>×{formatCount(item)}</View>
</View>
</View>
})}
</View>
</InfiniteScroll>}
{!loading&&list.length == 0 &&<View className={styles.empty}>
{!loading&&list?.length == 0 &&<View className={styles.empty}>
<View className={styles.title}>暂未选择商品</View>
<View className={styles.btn}>去选购</View>
</View>}