import React from "react"; import { Checkbox } from "antd"; import { IProductItem4Cart } from "@/models/cart"; import { CheckboxChangeEvent } from "antd/lib/checkbox"; import Counter from "@/components/Counter"; import { CheckedStatus, CartStatisticsType } from "@/shared/common/constants"; type P = { cartStatisticsType?: CartStatisticsType; checkable?: boolean; //是否开启选择框 list: IProductItem4Cart[]; onChange?( item: IProductItem4Cart[], status: CheckedStatus, totalQuantity: number, totalAmount ); }; export default function SkuList(props: P) { //处理选中 或 数量变化的状态 const onChange = (_item: IProductItem4Cart) => { const { list } = props; let checkedCount = 0, totalQuantity = 0, totalAmount = 0; const temp = []; list.forEach(i => { if (i.productItemId === _item.productItemId) { temp.push(_item); if ( CartStatisticsType.SELECTED === props.cartStatisticsType && _item.checked ) { _item.checked && ++checkedCount; totalQuantity += _item.quantity; totalAmount += _item.quantity * _item.purchasePrice; } else { _item.checked && ++checkedCount; totalQuantity += _item.quantity; totalAmount += _item.quantity * _item.purchasePrice; } } else { temp.push(i); i.checked && ++checkedCount; totalQuantity += i.quantity; totalAmount += i.quantity * i.purchasePrice; } }); const status = checkedCount === 0 ? CheckedStatus.NON : checkedCount === list.length ? CheckedStatus.All : CheckedStatus.INDETERMINATE; props.onChange && props.onChange(temp, status, totalQuantity, totalAmount); }; if (!props.list || !props.list.length) { return null; } return (
{item.name}
{item.productItemId}