✨ feat(领取剪样):

This commit is contained in:
2023-02-21 20:00:55 +08:00
parent dd69400dfa
commit 2d2518f4ab
25 changed files with 1108 additions and 159 deletions
+28 -9
View File
@@ -11,11 +11,6 @@ import { formatHashTag } from '@/common/fotmat'
import colorItem from '@/pages/codeList/components/colorItem'
import { goLink } from '@/common/common'
export interface Param {
show: boolean
product_id: number
onClose?: () => void
}
export interface ColorItem {
bulk_price: number
code: string
@@ -35,18 +30,27 @@ export interface ColorItem {
count?: number
}
export interface Param {
show: boolean
product_id: number
onClose?: () => void
onSelected?: (val: ColorItem[]) => void
defaultValueIds?: number[]
}
export default memo((props: Param) => {
const { show = false, onClose, product_id } = props
const { show = false, onClose, product_id, onSelected, defaultValueIds = [] } = props
const [colorList, setColorList] = useState<ColorItem[]>([])
const { fetchData: productFetchData } = GetProductDetailApi()
const getProductDetail = async() => {
const res = await productFetchData({ id: product_id })
setColorList(res.data.product_color_list || [])
setColorList(initData(res.data.product_color_list) || [])
}
useEffect(() => {
(show && product_id) && getProductDetail()
!show && setColorList([])
}, [show, product_id])
const colorListRef = useRef<ColorItem[]>([])
@@ -54,6 +58,20 @@ export default memo((props: Param) => {
colorListRef.current = colorList
}, [colorList])
const initData = (data) => {
if (defaultValueIds.length > 0) {
return data.map((item, index) => {
if (defaultValueIds.includes(item.id)) {
return data[index] = { ...item, status: true }
}
return item
})
}
else {
return data
}
}
const onSelect = useCallback((val: ColorItem) => {
colorListRef.current.map((item, index) => {
if (item.id === val.id) {
@@ -74,8 +92,9 @@ export default memo((props: Param) => {
colorList?.map((item) => {
if (item.status) { data.push({ ...item, count: 1 }) }
})
Taro.setStorageSync('cutSample', JSON.stringify(data))
goLink('/pages/cutSampleListOrder/index')
onSelected?.(data)
// Taro.setStorageSync('cutSample', JSON.stringify(data))
// goLink('/pages/cutSampleListOrder/index')
}
return <View className={styles.main}>
<Popup show={show} showTitle={false} onClose={onClose}>