import {Table, Icon, Button, Spin, Row, Col,Menu, Dropdown,} from 'antd';
import { WeaTools,WeaInput,WeaTextarea,WeaSelect,WeaBrowser,WeaDatePicker,WeaTimePicker,WeaCheckbox,WeaLocaleProvider} from "ecCom"
const getLabel = WeaLocaleProvider.getLabel;
import classNames from 'classnames'
import isEqual from 'lodash/isEqual';
import './index.less'
//国际化 zxt- 20170419
const defaultLocale = {
total: getLabel(18609,"共"),
totalUnit: getLabel(18256,"条"),
};
class Main extends React.Component {
//国际化 zxt- 20170419
static contextTypes = {
antLocale: React.PropTypes.object,
}
getLocale() {
let locale = {};
if(this.context.antLocale && this.context.antLocale.Table) {
locale = this.context.antLocale.WeaTableEdit;
}
return {
...defaultLocale,
...locale,
...this.props.locale
};
}
constructor(props) {
super(props);
this.state = {
columns: [],
datas: [],
selectedRowKeys: [],
current: 1
}
this.onEdit = this.onEdit.bind(this);
}
componentDidMount() {
const { datas = [], columns = [] } = this.props;
columns.length > 0 && this.setState(datas.length > 0 ? {datas: this.addKeytoDatas(datas),columns} : {columns})
}
componentWillReceiveProps(nextProps) {
const { columns = [], datas = [], selectedRowKeys = [] } = this.props;
const _columns = nextProps.columns || [];
const _datas = nextProps.datas || [];
const _selectedRowKeys = nextProps.selectedRowKeys || [];
!isEqual(columns,_columns) && this.setState({columns: _columns});
!isEqual(datas,_datas) && this.setState({datas: this.addKeytoDatas(_datas)});
!isEqual(selectedRowKeys,_selectedRowKeys) && this.setState({selectedRowKeys: _selectedRowKeys});
}
componentDidUpdate() {
}
addKeytoDatas(datas){
let _datas = datas.map((data, i) => {
let _data = {...data};
_data.key = i
return _data
})
return _datas
}
render() {
const { datas } = this.state;
const {tableProps} = this.props;
return(
)
}
getColumns(){
const { columns } = this.state;
let _columns = [].concat(columns);
_columns = _columns.map(col => {
let _col = { ...col };
_col.render || (_col.render = ( text, record, index ) => {
return this.getColRender( _col, text, record, index );
})
return _col
});
return _columns
}
getColRender( _col, text, record, index ){
const { com } = _col;
let _com = [];
const {onCreatReq, onCreatDoc} = this.props;
com.map((c,i) => {
if(typeof c.props === 'object'){
_com.push(c);
}else{
const { key, label = '', type = 'INPUT', options = [], browserConditionParam = {}, innerStyle = {width: "100%"},
viewAttr = 2 ,showTime = false ,format = "yyyy-MM-dd",otherParams } = c;
const _type = type.toUpperCase();
let style = _type === 'BROWSER' ? {...innerStyle}:{...innerStyle, display: 'inline-block'}
_com.push(
{label && {label}}
{ _type === 'INPUT' &&
this.onEdit(record, index, key, value)} />
}
{ _type === 'TEXTAREA' &&
this.onEdit(record, index, key, value)} />
}
{ _type === 'DATEPICKER' &&
this.onEdit(record, index, key, value)} />
}
{ _type === 'TIMEPICKER' &&
this.onEdit(record, index, key, value)} />
}
{ _type === 'SELECT' &&
this.onEdit(record, index, key, value)} />
}
{ _type === 'BROWSER' &&
this.onEdit(record, index, key, ids, names, bDatas)} />
}
{ _type === 'CHECKBOX' &&
this.onEdit(record, index, key, value)}
/>
}
{
_type == "LINK_WF" &&
onCreatReq(record.wfid,record.taskId)}>{record[key]}({record.requiredWFCount})
!
}
{
_type == "LINK_DOC" &&
onCreatDoc && onCreatDoc(record.reqDocSecCategory,record.taskId)}>{record[key]}({record.requiredDocCount})
!
}
{
_type == "OPERATE" &&
{getLabel(104,"操作")}
}
)
}
});
return (
{_com}
)
}
getBrowerDatas(record, key){
let replaceDatas = [];
if(record[key + 'span'] !== undefined) {
let keys = record[key].split(',');
let values = record[key + 'span'].split(',');
if(keys.length === values.length){
keys.map((k, i) => {
if (k != '' && values[i] != '') replaceDatas.push({id: k, name: values[i]});
});
}else{
}
}
return replaceDatas
}
getPagination() {
const { pageSize = 0, paginationSize = ''} = this.props;
if( !pageSize ) return false;
const { current } = this.state;
const locale = this.getLocale();
let obj = {
size: paginationSize,
current,
pageSize,
};
return obj
}
onEdit(record, index, key, value, names, bDatas){
const { pageSize = 0 } = this.props;
const { datas, current } = this.state;
let _datas = [].concat(datas);
_datas[pageSize * (current - 1) + index][key] = value;
if(names) _datas[pageSize * (current - 1) + index][key + 'span'] = names;
this.setState({datas: _datas});
this.onChange(_datas,index);
}
onChange(datas,index){
const { columns } = this.state;
let _datas = datas.map((data, i) => {
let _data = {...data}
delete _data.key
return _data
})
typeof this.props.onChange === 'function' && this.props.onChange(_datas[index], columns);
}
getMenu(record,options,bool){
let menu = [];
if(options && bool){
options.map(item=>{
menu.push(
{item.showname}
)
})
return
}
return menu
}
onMenuClick=(record,options)=>{
typeof this.props.operate == "function" && this.props.operate(record);
}
}
export default Main;