| | |
| | | } |
| | | |
| | | if (col.marks) { |
| | | let mark = getMark(col.marks, record, style) |
| | | style = style ? {...style} : {} |
| | | |
| | | style = mark.style |
| | | let mark = getMark(col.marks, record, style) |
| | | |
| | | if (mark.icon) { |
| | | if (mark.position === 'front') { |
| | |
| | | if (col.editable === 'true' && !disabled) { |
| | | if (editing) { |
| | | if (!col.editType || col.editType === 'text') { |
| | | return (<td className="editing_table_cell"> |
| | | return (<td onClick={(e) => e.stopPropagation()} className="editing_table_cell"> |
| | | <Input className={err ? 'has-error' : ''} title={err} id={col.uuid + record.$$uuid} defaultValue={value} onChange={(e) => this.onChange(e.target.value)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | </td>) |
| | | } else if (col.editType === 'date') { |
| | | return (<td className="editing_table_cell"> |
| | | return (<td onClick={(e) => e.stopPropagation()} className="editing_table_cell"> |
| | | <CusDatePicker config={col} value={record[col.field] || null} open={true} onChange={this.onDateChange} blur={() => this.setState({editing: false})}/> |
| | | </td>) |
| | | } else if (col.editType === 'switch') { |
| | | let _value = record[col.field] !== undefined ? record[col.field] : '' |
| | | |
| | | return (<td className="editing_table_cell"> |
| | | return (<td onClick={(e) => e.stopPropagation()} className="editing_table_cell"> |
| | | <CusSwitch config={col} defaultValue={_value} autoFocus={true} onChange={this.onSwitchChange} onBlur={this.switchBlur}/> |
| | | </td>) |
| | | } else { |
| | | let _value = record[col.field] !== undefined ? record[col.field] : '' |
| | | |
| | | return (<td className="editing_table_cell"> |
| | | return (<td onClick={(e) => e.stopPropagation()} className="editing_table_cell"> |
| | | <Select |
| | | showSearch |
| | | defaultValue={_value} |
| | |
| | | </td>) |
| | | } |
| | | } else { |
| | | return (<td className={className + ' pointer'} style={style}> |
| | | return (<td onClick={(e) => e.stopPropagation()} className={className + ' pointer'} style={style}> |
| | | <div className="mk-mask" id={col.uuid + record.$$uuid} onClick={this.focus}></div>{content} |
| | | </td>) |
| | | } |
| | |
| | | } |
| | | |
| | | if (col.marks) { |
| | | let mark = getMark(col.marks, record, style) |
| | | style = style ? {...style} : {} |
| | | |
| | | style = mark.style |
| | | let mark = getMark(col.marks, record, style) |
| | | |
| | | if (mark.icon) { |
| | | if (mark.position === 'front') { |
| | |
| | | if (col.noValue === 'hide' && value === 0) { |
| | | val = '' |
| | | } |
| | | return (<td className="editing_table_cell"> |
| | | return (<td onClick={(e) => e.stopPropagation()} className="editing_table_cell"> |
| | | <InputNumber className={err ? 'has-error' : ''} precision={col.decimal || 0} title={err} id={col.uuid + record.$$uuid} defaultValue={val} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | </td>) |
| | | } else { |
| | | return (<td className={className + ' pointer'} style={style}> |
| | | return (<td onClick={(e) => e.stopPropagation()} className={className + ' pointer'} style={style}> |
| | | <div className="mk-mask" id={col.uuid + record.$$uuid} onClick={this.focus}></div>{content} |
| | | </td>) |
| | | } |
| | |
| | | } |
| | | |
| | | if (col.marks) { |
| | | let mark = getMark(col.marks, record, style) |
| | | style = style ? {...style} : {} |
| | | |
| | | style = mark.style |
| | | let mark = getMark(col.marks, record, style) |
| | | |
| | | if (mark.icon) { |
| | | if (mark.position === 'front') { |
| | |
| | | if (!col) return (<td {...resProps} className={className} style={style}/>) |
| | | |
| | | let disabled = false |
| | | let editable = false |
| | | if (col.ctrlField) { |
| | | disabled = col.ctrlValue.includes(record[col.ctrlField]) |
| | | } |
| | |
| | | let children = null |
| | | if (col.type === 'text') { |
| | | if (col.editable === 'true' && !disabled) { |
| | | editable = true |
| | | let _value = record[col.field] !== undefined ? record[col.field] : '' |
| | | |
| | | if (!col.editType || col.editType === 'text') { |
| | |
| | | } |
| | | |
| | | if (col.marks) { |
| | | let mark = getMark(col.marks, record, style) |
| | | style = style ? {...style} : {} |
| | | |
| | | style = mark.style |
| | | let mark = getMark(col.marks, record, style) |
| | | |
| | | if (mark.icon) { |
| | | if (mark.position === 'front') { |
| | |
| | | } |
| | | } else if (col.type === 'number') { |
| | | if (col.editable === 'true' && !disabled) { |
| | | editable = true |
| | | let _value = record[col.field] !== undefined ? record[col.field] : '' |
| | | |
| | | if (col.noValue === 'hide' && _value === 0) { |
| | |
| | | } |
| | | |
| | | if (col.marks) { |
| | | let mark = getMark(col.marks, record, style) |
| | | style = style ? {...style} : {} |
| | | |
| | | style = mark.style |
| | | let mark = getMark(col.marks, record, style) |
| | | |
| | | if (mark.icon) { |
| | | if (mark.position === 'front') { |
| | |
| | | } |
| | | |
| | | if (col.marks) { |
| | | let mark = getMark(col.marks, record, style) |
| | | style = style ? {...style} : {} |
| | | |
| | | style = mark.style |
| | | let mark = getMark(col.marks, record, style) |
| | | |
| | | if (mark.icon) { |
| | | if (mark.position === 'front') { |
| | |
| | | ) |
| | | } |
| | | |
| | | if (editable) { |
| | | return (<td onClick={(e) => e.stopPropagation()} className={'editing_all_table_cell ' + className} style={style}>{children}</td>) |
| | | } |
| | | |
| | | return (<td className={'editing_all_table_cell ' + className} style={style}>{children}</td>) |
| | | } |
| | | } |
| | |
| | | loading: PropTypes.bool, // 表格加载中 |
| | | refreshdata: PropTypes.func, // 表格中排序列、页码的变化时刷新 |
| | | chgSelectData: PropTypes.func, |
| | | allSearch: PropTypes.any, |
| | | colsCtrls: PropTypes.any |
| | | } |
| | | |
| | | state = { |
| | |
| | | pageOptions: [], |
| | | deForms: null, |
| | | visible: false, |
| | | midData: null |
| | | midData: null, |
| | | allColumns: null, |
| | | reseting: false |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | const { setting, fields, columns, BID } = this.props |
| | | const { setting, fields, columns, BID, colsCtrls } = this.props |
| | | let orderfields = {} |
| | | |
| | | let _columns = [] |
| | |
| | | let cell = null |
| | | |
| | | if (item.type === 'colspan') { |
| | | cell = { title: item.label, align: item.Align } |
| | | cell = { title: item.label, align: item.Align, $key: item.uuid } |
| | | cell.children = getColumns(item.subcols) |
| | | } else { |
| | | if (item.editable === 'true') { |
| | |
| | | |
| | | if (item.field) { |
| | | orderfields[item.uuid] = item.field |
| | | } else if (item.sortField) { |
| | | orderfields[item.uuid] = item.sortField |
| | | } |
| | | |
| | | cell = { |
| | | align: item.Align, |
| | | dataIndex: item.uuid, |
| | | title: item.editable === 'true' ? <span>{item.label}<EditOutlined className="system-color mk-edit-sign"/></span> : item.label, |
| | | sorter: !!(item.field && item.IsSort === 'true'), |
| | | sorter: (item.field || item.sortField) && item.IsSort === 'true', |
| | | width: item.Width || 120, |
| | | $type: item.type, |
| | | // $type: item.type, |
| | | $key: item.uuid, |
| | | onCell: record => ({ |
| | | record, |
| | | col: item, |
| | |
| | | pageOptions = pageOptions.sort((a, b) => a - b) |
| | | } |
| | | |
| | | let allColumns = null |
| | | if (colsCtrls) { |
| | | allColumns = [..._columns] |
| | | _columns = this.getCurColumns(_columns, this.props.allSearch) |
| | | } |
| | | |
| | | this.setState({ |
| | | forms, |
| | | signForms, |
| | | allColumns, |
| | | pageSize: setting.pageSize || 10, |
| | | pageOptions, |
| | | columns: _columns, |
| | |
| | | MKEmitter.removeListener('changeRecord', this.changeRecord) |
| | | } |
| | | |
| | | getCurColumns = (columns, allSearch) => { |
| | | const { colsCtrls } = this.props |
| | | |
| | | let values = {} |
| | | allSearch.forEach(item => { |
| | | values[item.key] = item.value |
| | | }) |
| | | let cols = null |
| | | colsCtrls.some(item => { |
| | | let originVal = item.field.map(f => values[f] || '').join('') |
| | | let contrastVal = item.contrastValue |
| | | let result = false |
| | | |
| | | if (item.match === '=') { |
| | | result = originVal === contrastVal |
| | | } else if (item.match === '!=') { |
| | | result = originVal !== contrastVal |
| | | } else { |
| | | originVal = isNaN(originVal) ? originVal : +originVal |
| | | contrastVal = isNaN(contrastVal) ? contrastVal : +contrastVal |
| | | if (item.match === '>') { |
| | | result = originVal > contrastVal |
| | | } else if (item.match === '<') { |
| | | result = originVal < contrastVal |
| | | } |
| | | } |
| | | |
| | | if (!result) return false |
| | | |
| | | cols = item.cols |
| | | |
| | | return true |
| | | }) |
| | | |
| | | if (cols) { |
| | | return columns.filter(col => cols.includes(col.$key)) |
| | | } |
| | | |
| | | return columns |
| | | } |
| | | |
| | | transferData = (menuid, data, type) => { |
| | | const { MenuID, setting } = this.props |
| | | const { edData, signForms } = this.state |
| | | |
| | | if (menuid !== MenuID) return |
| | | |
| | | if (setting.commit !== 'all' && setting.standard !== 'change') { |
| | | if (setting.commit !== 'all' && setting.commit !== 'blur' && setting.standard !== 'change') { |
| | | if (type !== 'line') { |
| | | data.forEach(item => { |
| | | let value = '' |
| | |
| | | } |
| | | |
| | | updateMutil = (data) => { |
| | | const { setting } = this.props |
| | | const { setting, colsCtrls, allSearch } = this.props |
| | | const { allColumns } = this.state |
| | | |
| | | if (colsCtrls) { |
| | | this.setState({ |
| | | columns: this.getCurColumns(allColumns, allSearch), |
| | | reseting: true, |
| | | edData: data, |
| | | visible: false, |
| | | midData: null |
| | | }, () => { |
| | | this.setState({ |
| | | reseting: false |
| | | }) |
| | | }) |
| | | |
| | | return |
| | | } |
| | | |
| | | if (setting.editType === 'multi' && data.length > 0) { |
| | | this.setState({edData: []}, () => { |
| | |
| | | return item |
| | | }) |
| | | |
| | | this.setState({columns: [], edData: []}, () => { |
| | | let _cols = this.state.allColumns |
| | | if (_cols) { |
| | | _cols = _cols.map(item => { |
| | | if (reCols[item.dataIndex]) { |
| | | item.onCell = record => ({ |
| | | record, |
| | | col: reCols[item.dataIndex] |
| | | }) |
| | | } |
| | | |
| | | return item |
| | | }) |
| | | } |
| | | |
| | | this.setState({columns: [], edData: [], allColumns: _cols}, () => { |
| | | this.setState({columns: _edColumns, edData: edData}) |
| | | }) |
| | | } |
| | |
| | | this.setState({edData: _data}, () => { |
| | | if (setting.commit === 'simple') { |
| | | this.submit() |
| | | } else if (setting.commit === 'blur') { |
| | | this.submit(record) |
| | | } |
| | | }) |
| | | } |
| | |
| | | |
| | | if (id !== tableId) return |
| | | |
| | | if (!record.$sign) { |
| | | if (setting.commit === 'blur') { |
| | | |
| | | } else if (!record.$sign) { |
| | | record.$origin = false |
| | | record.$lock = true |
| | | delete record.$forbid |
| | |
| | | if (setting.tableType && setting.hasAction && this.state.selectedRowKeys.includes(record.$$uuid)) { |
| | | this.selectdata(this.state.selectedRowKeys) |
| | | } |
| | | if (setting.commit === 'blur') { |
| | | this.submit(record) |
| | | } |
| | | }) |
| | | |
| | | } |
| | | |
| | | addRecord = (id, record) => { |
| | |
| | | return data |
| | | } |
| | | |
| | | submit = () => { |
| | | checkLineData = (item) => { |
| | | const { forms } = this.state |
| | | |
| | | let record = fromJS(item).toJS() |
| | | let err = '' |
| | | forms.forEach(col => { |
| | | if (col.editable !== 'true' || record.$deleted) { |
| | | if (col.type === 'number') { |
| | | record[col.field] = +record[col.field] |
| | | if (isNaN(record[col.field])) { |
| | | record[col.field] = 0 |
| | | } |
| | | } else { |
| | | record[col.field] = record[col.field] !== undefined ? (record[col.field] + '') : '' |
| | | } |
| | | return |
| | | } |
| | | if (col.type === 'text') { |
| | | let val = record[col.field] !== undefined ? (record[col.field] + '') : '' |
| | | if (col.required === 'true' && !val) { |
| | | err = `${col.label}不可为空` |
| | | } else if (col.datatype === 'datetime' && !val) { |
| | | val = '1949-10-01' |
| | | } |
| | | record[col.field] = val |
| | | } else if (col.type === 'number') { |
| | | let val = record[col.field] |
| | | if (col.noValue === 'hide' && !val) { |
| | | val = 0 |
| | | } else if (!val && val !== 0) { |
| | | err = `${col.label}不可为空` |
| | | return |
| | | } |
| | | val = +val |
| | | if (isNaN(val)) { |
| | | err = `${col.label}数据格式错误` |
| | | return |
| | | } |
| | | |
| | | val = +val.toFixed(col.decimal || 0) |
| | | |
| | | if (typeof(col.max) === 'number' && val > col.max) { |
| | | err = `${col.label}不可大于${col.max}` |
| | | } else if (typeof(col.min) === 'number' && val < col.min) { |
| | | err = `${col.label}不可小于${col.min}` |
| | | } |
| | | |
| | | record[col.field] = val |
| | | } |
| | | }) |
| | | |
| | | if (err) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: err, |
| | | duration: 5 |
| | | }) |
| | | |
| | | return null |
| | | } |
| | | |
| | | return [record] |
| | | } |
| | | |
| | | submit = (record) => { |
| | | const { submit, BID, setting } = this.props |
| | | const { forms } = this.state |
| | | |
| | |
| | | return |
| | | } |
| | | |
| | | let data = this.checkData() |
| | | if (setting.commit === 'blur' && !record) return |
| | | |
| | | let data = null |
| | | if (setting.commit === 'blur') { |
| | | data = this.checkLineData(record) |
| | | } else { |
| | | data = this.checkData() |
| | | } |
| | | |
| | | if (!data) return |
| | | |
| | |
| | | |
| | | render() { |
| | | const { setting, lineMarks, submit } = this.props |
| | | const { tableId, edData, columns, loading, pageOptions, selectedRowKeys, visible, midData } = this.state |
| | | const { tableId, edData, columns, loading, pageOptions, selectedRowKeys, visible, midData, reseting } = this.state |
| | | |
| | | if (reseting) return null |
| | | |
| | | const components = { |
| | | body: { |