import { ScrollView, View } from '@tarojs/components' import { useDidShow } from '@tarojs/taro' import { forwardRef, memo, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react' import classnames from 'classnames' import VirtualList from '@tarojs/components/virtual-list' import Divider from '../divider' import styles from './index.module.scss' import Search from '@/components/search' import Popup from '@/components/popup' import Goods from '@/components/goodsItem' import BottomCustomer from '@/components/BottomCustomer' import DotLoading from '@/components/dotLoading' interface prosObj { showPopup?: false | true closePopup?: () => void goodList?: any[] typeList?: any[] handCheck?: (any) => void addNums?: (any) => void reduceNums?: (any) => void // oninputEvent?: (e: string, res: object) => void, getSearchData: (any) => void handPlus: (any) => void handSure: () => void obj?: { code?: string name?: string } modeFont: Number | string clientName: string clientId: Number hasBottom?: true | false // 默认不占位底部 onBlur?: (e: string, res: object) => void } const ShoppingCart = (props: prosObj, ref) => { const { showPopup = false, closePopup, goodList = [], typeList = [], handCheck, addNums, reduceNums, // oninputEvent, getSearchData, handPlus, obj = {}, modeFont = 0, clientName = '', clientId = -1, handSure, hasBottom = true, onBlur, } = props const SearchRef = useRef() useImperativeHandle(ref, () => ({ Object: props, typeList, SearchRef, })) // 判断选择的类型 const showModefont = useMemo(() => { const modeObj = typeList.filter((item) => { return item.checked }) if (modeObj[0].id === 0) { return '条' } else { return '米' } }, [typeList]) // 已选的颜色 const selectTotal = useMemo(() => { const totalArr = goodList.filter((item) => { return item.showInput }) return totalArr.length }, [goodList]) // 选择的条数或者米数 const selectNums = useMemo(() => { const arr: any = [] goodList.forEach((item) => { if (item.showInput) { arr.push(Number(item.nums)) } }) const hate = sum(arr) return hate }, [goodList]) // onInputEven={(e, item) => oninputEvent?.(e, item)} function sum(arr) { let s = 0 for (let i = arr.length - 1; i >= 0; i--) { s += arr[i] } return s } const rows = ({ id, index, style, data }: any) => { const item = data[index] return ( <> onBlur?.(e, id)} modeFont={(modeFont as number)} handPlus={item => handPlus?.(item)} value={item || {}} clickAdd={item => addNums?.(item)} clickReduce={(item) => { reduceNums?.(item) }} goodList={goodList} > ) } const Rows = memo(rows) return ( closePopup?.()}> {obj?.code}# {obj?.name} 已选 1 种面料,{selectTotal} 个颜色,共 {selectNums} {showModefont} 布料类型 {typeList.map((item, index) => { return ( { handCheck?.(item) }} key={index} className={classnames(item.checked ? styles.activemodeFont : styles.modeFont)} > {item.name} ) })} 颜色分类({goodList?.length}) {modeFont == 0 ? '大货' : modeFont == 1 ? '剪版' : '散剪'}单位:{showModefont} {goodList.length > 0 && ( <> {Rows} )} {goodList.length === 0 && ( <> 加载中 )} {!hasBottom && } {/* */} 0 && clientName !== '')} handSure={() => { handSure() }} > ) } export default memo(forwardRef(ShoppingCart))