import React, { Component } from 'react'; import { ConfigItemProp, ColumnProp, ConfigItemColorProp } from '../../../component/chart.d'; import styles from "./configItemColor.module.css"; // import {} from "./configItemColor.d"; import { Button, Divider } from 'antd'; import ConfigItemColorAdd from './configItemColor.add'; import { ConfigItemInterface } from './configItem.d'; interface Prop extends ConfigItemInterface{ } interface State { } const title:ColumnProp[] = [ { name : "颜色", key : "startColor" }, { name : "渐变色", key : "endColor" }, { name : "位置", key : 'width' }, { name : "操作", key : "action" } ]; export default class ConfigItemColor extends Component { add : ConfigItemColorAdd|null = null ; renderItem = (data:ConfigItemColorProp)=>{ return (
{data.position}
this.onEdit(data)}>编辑 this.onDel(data)}>删除
) } onDel = (data:ConfigItemColorProp)=>{ let val : ConfigItemColorProp[] = this.props.data.value ; val = val.filter(item=>item.id!=data.id); this.changeValue(val) } onEdit = (data?:ConfigItemColorProp)=>{ this.add && this.add.show(data) } onChangeColor = (newData:ConfigItemColorProp , oldData?:ConfigItemColorProp)=>{ console.log(newData); let res : ConfigItemColorProp[] = [...this.props.data.value]; if(oldData){ res = res.map(item=>{ if(item.id == oldData.id){ item = {...newData}; } return item; }) }else{ res.push({ ...newData, id:new Date().getTime().toString() }); } // const tmp : ConfigItemProp = { // ...this.props.data, // value : res // } this.changeValue(res); this.add?.hide() } changeValue = (newValue:ConfigItemColorProp[])=>{ const {data} = this.props; this.props.onChange && this.props.onChange({ ...data, value:newValue }) } render(){ let value : ConfigItemColorProp[] = this.props.data.value; value = value || []; return (
{ title.map(item=>{ return (
{item['name']}
) }) }
{ value.map(item=>{ return this.renderItem(item) }) } this.add=ref} />
) } }