import React from 'react'; import { Checkbox } from 'antd'; import { IProductItem4Cart, CheckedStatus, CartStatisticsType } from './type'; import { CheckboxChangeEvent } from 'antd/lib/checkbox'; import Counter from '@/components/Counter'; import { getLocalePrice, limitWord } from '@/shared/common/utils'; 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 (
{props.list.map(item => ( ))}
); } function SkuItem({ checkable, item, onChange }) { return (
{checkable ? (
{ const { checked } = e.target; const _item = Object.assign({}, item, { checked, }); onChange(_item); }} />
) : null}
{item.name}

{limitWord(item.name, 16)}

商品ID:{item.productItemId}

{getLocalePrice(item.price)}
{getLocalePrice(item.purchasePrice)}
{checkable ? ( { const _item = Object.assign({}, item, { quantity }); onChange(_item); }} /> ) : ( item.quantity )}
{getLocalePrice(item.totalDiscountedAmount)}
{getLocalePrice(item.purchasePrice * item.quantity)}
); }