✨ feat(领取剪样):
This commit is contained in:
@@ -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}>
|
||||
|
||||
Reference in New Issue
Block a user