import * as React from 'react' import { Modal, Form } from 'antd' import cx from 'classnames' import { FormComponentProps } from 'antd/lib/form' import { ModalProps } from 'antd/lib/modal' import './index.scss' import { limitWord, optimizePic } from '@/shared/common/utils' import { ChannelProduct, Character } from '@xmly/cbp-spec/lib/portal/service/oss/ChannelStrategyService' import { PriceModalType } from '../PriceModal/type' import { Price } from './helper' type P = ModalProps & FormComponentProps & { type: PriceModalType visible: boolean dataSource: Array columns: any currentRole?: Character onConfirm(): any extral?: any } type S = { dataSource: Array } // 设置特殊价、价盘价弹窗 class PriceSetMoal extends React.Component { readonly state: S = { dataSource: [], } UNSAFE_componentWillReceiveProps(nextProps: P) { this.setState({ dataSource: nextProps.dataSource, }) } // 改变选中状态 changeCheckStatus = (e, rowData: any) => { const { dataSource } = this.state const checked = e.target.checked let curDatasource = [] // 一级 if (rowData.productId) { rowData.checked = checked rowData.indeterminate = false rowData.items = rowData.items.map(item => { return { ...item, checked, } }) curDatasource = Price.getChangedDataSource(rowData.id, dataSource, rowData) } else { let checkCount = 0 const spu = Price.getSpuBasedOnSkuId(dataSource, rowData.id) const skuList = spu.items let isCheckedAll = false rowData.checked = checked skuList.forEach(item => { if (item.checked) checkCount++ }) isCheckedAll = skuList.length === checkCount spu.checked = isCheckedAll spu.indeterminate = !isCheckedAll && checkCount > 0 curDatasource = Price.getChangedDataSource(spu.id, dataSource, spu) } this.setState({ dataSource: curDatasource, }) } renderTableHead = () => { const { columns } = this.props return ( columns && columns.map((item, index) => { return (
{item.title}
) }) ) } renderTableBody = () => { const { dataSource } = this.state const { columns, type } = this.props const lastColumn = columns[columns.length - 1] const lastKey = lastColumn.dataIndex return ( dataSource && dataSource.map((spu, spuIndex: number) => { const skuList = spu.items return (
{/*
{columns.map((column: any, index) => { const key = column.dataIndex; if (index === 0) { return (
this.changeCheckStatus(e, spu)} > {spu.productName}
); } else { const renderLimit = type === PriceModalType.SPECIAL ? index < columns.length - 1 : index <= columns.length - 1; return renderLimit ? (
{column.render ? column.render(spu[key], spu, index) : spu[key]}
) : null; } })}
*/} {skuList.map((sku: any, index: number) => { return (
{columns.map((column, index) => { const key = column.dataIndex if (index === 0) { return (
{/* this.changeCheckStatus(e, sku)} > */}
{sku.itemName ? limitWord(sku.itemName, 18) : '无'}
商品ID:{sku.itemId}
) } else { const renderLimit = type === PriceModalType.SPECIAL ? index < columns.length - 1 : index <= columns.length - 1 return renderLimit ? (
{column.render ? column.render(sku[key], sku, index) : sku[key]}
) : null } })}
) })} {type === PriceModalType.SPECIAL && (
{lastColumn.render ? lastColumn.render(spu[lastKey], spu, spuIndex) : spu[lastKey]}
)}
{/*
*/}
) }) ) } render() { const { visible, title, onCancel, onConfirm, width = 800, currentRole, type } = this.props return (
{/*
渠道: 广州那啥公司
*/}
角色: {currentRole && currentRole.name}
{this.renderTableHead()}
{this.renderTableBody()} {this.props.extral}
) } } export default Form.create

()(PriceSetMoal)