import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Table, Typography, Icon, Switch, Modal, Input, InputNumber, Tooltip, Button, notification, message } from 'antd'
|
import moment from 'moment'
|
|
import Api from '@/api'
|
import asyncComponent from '@/utils/asyncComponent'
|
import Utils, { getEditTableSql } from '@/utils/utils.js'
|
import MKEmitter from '@/utils/events.js'
|
import zhCN from '@/locales/zh-CN/main.js'
|
import enUS from '@/locales/en-US/main.js'
|
import '@/assets/css/table.scss'
|
import './index.scss'
|
|
const { Paragraph } = Typography
|
const { confirm } = Modal
|
const CardCellComponent = asyncComponent(() => import('@/tabviews/custom/components/card/cardcellList'))
|
|
class BodyRow extends React.Component {
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.props.data), fromJS(nextProps.data))
|
}
|
|
render() {
|
let { lineMarks, data, ...resProps } = this.props
|
let style = {}
|
let className = ''
|
|
lineMarks && lineMarks.some(mark => {
|
let originVal = data[mark.field[0]] + ''
|
let contrastVal = ''
|
let result = false
|
|
if (mark.field[1] === 'static') {
|
contrastVal = mark.contrastValue + ''
|
} else {
|
contrastVal = data[mark.field[2]] + ''
|
}
|
|
if (mark.match === '=') {
|
result = originVal === contrastVal
|
} else if (mark.match === '!=') {
|
result = originVal !== contrastVal
|
} else if (mark.match === 'like') {
|
result = originVal.indexOf(contrastVal) > -1
|
} else if (mark.match === '>') {
|
try {
|
originVal = parseFloat(originVal)
|
contrastVal = parseFloat(contrastVal)
|
} catch (e) {
|
originVal = NaN
|
}
|
|
if (!isNaN(originVal) && !isNaN(contrastVal) && originVal > contrastVal) {
|
result = true
|
}
|
} else if (mark.match === '<') {
|
try {
|
originVal = parseFloat(originVal)
|
contrastVal = parseFloat(contrastVal)
|
} catch (e) {
|
originVal = NaN
|
}
|
|
if (!isNaN(originVal) && !isNaN(contrastVal) && originVal < contrastVal) {
|
result = true
|
}
|
}
|
|
if (result) {
|
if (mark.signType[0] === 'font') {
|
style.color = mark.color
|
} else if (mark.signType[0] === 'background') {
|
style.background = mark.color
|
if (mark.fontColor) {
|
style.color = mark.fontColor
|
}
|
className = 'background'
|
} else if (mark.signType[0] === 'underline') {
|
style.textDecoration = 'underline'
|
style.color = mark.color
|
} else if (mark.signType[0] === 'line-through') {
|
style.textDecoration = 'line-through'
|
style.color = mark.color
|
}
|
}
|
|
return result
|
})
|
|
return <tr {...resProps} className={className} style={style}/>
|
}
|
}
|
|
class BodyCell extends React.Component {
|
state = {
|
editing: false,
|
err: null
|
}
|
|
getMark = (record, marks, style, content) => {
|
marks.some(mark => {
|
let originVal = record[mark.field[0]] + ''
|
let contrastVal = ''
|
let result = false
|
|
if (mark.field[1] === 'static') {
|
contrastVal = mark.contrastValue + ''
|
} else {
|
contrastVal = record[mark.field[2]] + ''
|
}
|
|
if (mark.match === '=') {
|
result = originVal === contrastVal
|
} else if (mark.match === '!=') {
|
result = originVal !== contrastVal
|
} else if (mark.match === 'like') {
|
result = originVal.indexOf(contrastVal) > -1
|
} else if (mark.match === '>') {
|
try {
|
originVal = parseFloat(originVal)
|
contrastVal = parseFloat(contrastVal)
|
} catch (e) {
|
originVal = NaN
|
}
|
|
if (!isNaN(originVal) && !isNaN(contrastVal) && originVal > contrastVal) {
|
result = true
|
}
|
} else if (mark.match === '<') {
|
try {
|
originVal = parseFloat(originVal)
|
contrastVal = parseFloat(contrastVal)
|
} catch (e) {
|
originVal = NaN
|
}
|
|
if (!isNaN(originVal) && !isNaN(contrastVal) && originVal < contrastVal) {
|
result = true
|
}
|
}
|
|
if (result) {
|
if (mark.signType[0] === 'font') {
|
style.color = mark.color
|
} else if (mark.signType[0] === 'background') {
|
style.background = mark.color
|
if (mark.fontColor) {
|
style.color = mark.fontColor
|
}
|
} else if (mark.signType[0] === 'underline') {
|
style.textDecoration = 'underline'
|
style.color = mark.color
|
} else if (mark.signType[0] === 'line-through') {
|
style.textDecoration = 'line-through'
|
style.color = mark.color
|
} else if (mark.signType[0] === 'icon') {
|
let icon = (<Icon style={{color: mark.color}} type={mark.signType[3]} />)
|
if (mark.signType[1] === 'front') {
|
content = <span>{icon} {content}</span>
|
} else {
|
content = <span>{content} {icon}</span>
|
}
|
}
|
}
|
return result
|
})
|
|
return content
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.props.record), fromJS(nextProps.record)) ||
|
nextState.editing !== this.state.editing ||
|
nextState.err !== this.state.err
|
}
|
|
componentDidMount () {
|
MKEmitter.addListener('tdFocus', this.tdFocus)
|
}
|
|
/**
|
* @description 组件销毁,清除state更新,清除快捷键设置
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
MKEmitter.removeListener('tdFocus', this.tdFocus)
|
}
|
|
tdFocus = (id) => {
|
const { col, record } = this.props
|
|
if (id !== col.uuid + record.$Index) return
|
this.focus()
|
}
|
|
enterPress = () => {
|
const { col, record } = this.props
|
const { value } = this.state
|
|
this.setState({editing: false})
|
if (col.enter === '$next') {
|
MKEmitter.emit('nextLine', col, record.$Index)
|
} else {
|
MKEmitter.emit('tdFocus', col.enter + record.$Index)
|
}
|
|
if (value !== record[col.field]) {
|
MKEmitter.emit('changeRecord', col.tableId, {...record, [col.field]: value})
|
}
|
}
|
|
focus = () => {
|
const { col, record } = this.props
|
|
let err = null
|
let val = record[col.field] !== undefined ? record[col.field] : ''
|
|
if (col.type === 'number') {
|
val = +val
|
if (isNaN(val)) {
|
val = 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
|
}
|
} else if (col.required === 'true' && !val) {
|
err = '请填写' + col.label
|
}
|
|
this.setState({editing: true, value: val, err}, () => {
|
let node = document.getElementById(col.uuid + record.$Index)
|
node && node.select()
|
})
|
}
|
|
onBlur = () => {
|
const { col, record } = this.props
|
const { value } = this.state
|
|
this.setState({editing: false})
|
|
if (value !== record[col.field]) {
|
MKEmitter.emit('changeRecord', col.tableId, {...record, [col.field]: value})
|
}
|
}
|
|
onChange = (val) => {
|
const { col } = this.props
|
|
let err = null
|
|
if (col.type === 'number') {
|
val = +val
|
if (isNaN(val)) {
|
val = 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
|
}
|
} else if (col.required === 'true' && !val) {
|
err = '请填写' + col.label
|
}
|
this.setState({value: val, err})
|
}
|
|
render() {
|
let { col, config, record, style, className } = this.props
|
const { editing, value, err } = this.state
|
|
let children = null
|
if (col.type === 'text') {
|
let content = ''
|
if (record[col.field] !== undefined) {
|
content = `${record[col.field]}`
|
}
|
|
if (content !== '') {
|
if (col.textFormat === 'YYYY-MM-DD' && /^[1-9]\d{3}(-|\/)(0[1-9]|1[0-2])(-|\/)(0[1-9]|[1-2][0-9]|3[0-1])/.test(content)) {
|
content = `${content.substr(0, 4)}-${content.substr(5, 2)}-${content.substr(8, 2)}`
|
} else if (col.textFormat === 'YYYY-MM-DD HH:mm:ss' && /^[1-9]\d{3}(-|\/)(0[1-9]|1[0-2])(-|\/)(0[1-9]|[1-2][0-9]|3[0-1]).([0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]/.test(content)) {
|
content = `${content.substr(0, 4)}-${content.substr(5, 2)}-${content.substr(8, 2)} ${content.substr(11, 2)}:${content.substr(14, 2)}:${content.substr(17, 2)}`
|
}
|
|
content = (col.prefix || '') + content + (col.postfix || '')
|
}
|
|
if (col.marks) {
|
style = style || {}
|
content = this.getMark(record, col.marks, style, content)
|
}
|
|
if (col.editable === 'true') {
|
if (editing) {
|
return (<td className="editing_table_cell">
|
<Input id={col.uuid + record.$Index} defaultValue={value} onChange={(e) => this.onChange(e.target.value)} onPressEnter={this.enterPress} onBlur={this.onBlur}/>
|
{err ? <Tooltip title={err}><Icon type="exclamation-circle" /></Tooltip> : null}
|
</td>)
|
} else {
|
return (<td className={className + ' pointer'} style={style}><div className="mk-mask" onClick={this.focus}></div>{content}</td>)
|
}
|
} else {
|
children = content
|
}
|
} else if (col.type === 'number') {
|
let content = ''
|
try {
|
content = parseFloat(record[col.field])
|
if (isNaN(content)) {
|
content = ''
|
}
|
} catch (e) {
|
content = ''
|
}
|
|
if (content !== '') {
|
let decimal = col.decimal || 0
|
if (col.format === 'percent') {
|
content = content * 100
|
decimal = decimal > 2 ? decimal - 2 : 0
|
}
|
|
content = content.toFixed(decimal)
|
|
if (col.format === 'thdSeparator') {
|
content = content.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,')
|
}
|
|
content = col.prefix + content + col.postfix
|
}
|
|
if (col.marks) {
|
style = style || {}
|
content = this.getMark(record, col.marks, style, content)
|
}
|
|
if (col.editable === 'true') {
|
if (editing) {
|
return (<td className="editing_table_cell">
|
<InputNumber id={col.uuid + record.$Index} defaultValue={value} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/>
|
{err ? <Tooltip title={err}><Icon type="exclamation-circle" /></Tooltip> : null}
|
</td>)
|
} else {
|
return (<td className={className + ' pointer'} style={style}><div className="mk-mask" onClick={this.focus}></div>{content}</td>)
|
}
|
} else {
|
children = content
|
}
|
} else if (col.type === 'textarea') {
|
let content = ''
|
if (record[col.field] !== undefined) {
|
content = `${record[col.field]}`
|
}
|
|
if (content) {
|
content = col.prefix + content + col.postfix
|
}
|
|
children = (
|
<div>
|
{content ? <Paragraph copyable ellipsis={{ rows: 3, expandable: true }}>{content}</Paragraph> : null }
|
</div>
|
)
|
} else if (col.type === 'custom') {
|
style.padding = '0px'
|
if (col.style) {
|
style = {...style, ...col.style}
|
}
|
|
children = (
|
<CardCellComponent data={record} cards={config} elements={col.elements}/>
|
)
|
} else if (col.type === 'action') {
|
style.padding = '0px 5px'
|
children = (
|
<CardCellComponent data={record} cards={config} elements={col.elements}/>
|
)
|
} else if (col.type === 'operation') {
|
style.padding = '0px 5px'
|
children = (
|
<Button type="link" style={{color: 'rgb(255, 77, 79)', backgroundColor: 'transparent'}} onClick={() => MKEmitter.emit('delRecord', col.tableId, {...record})}>删除</Button>
|
)
|
}
|
|
return (<td className={className} style={style}>{children}</td>)
|
}
|
}
|
|
class NormalTable extends Component {
|
static propTpyes = {
|
statFValue: PropTypes.any, // 合计字段数据
|
MenuID: PropTypes.string, // 菜单Id
|
setting: PropTypes.object, // 表格全局设置:tableType(表格是否可选、单选、多选)、columnfixed(列固定)、actionfixed(按钮固定)
|
columns: PropTypes.array, // 表格列
|
lineMarks: PropTypes.any, // 行标记
|
fields: PropTypes.array, // 组件字段集
|
BID: PropTypes.any, // 主表ID
|
data: PropTypes.any, // 表格数据
|
total: PropTypes.any, // 总数
|
loading: PropTypes.bool, // 表格加载中
|
refreshdata: PropTypes.func, // 表格中排序列、页码的变化时刷新
|
}
|
|
state = {
|
dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
|
data: [],
|
edData: [],
|
edColumns: [],
|
tableId: '', // 表格ID
|
pageIndex: 1, // 初始页面索引
|
pageSize: 10, // 每页数据条数
|
columns: null, // 显示列
|
fields: [],
|
pickup: false, // 收起未选择项
|
orderfields: {}, // 排序id与field转换
|
loading: false,
|
editable: 'false'
|
}
|
|
UNSAFE_componentWillMount () {
|
const { setting, fields, columns, data } = this.props
|
let orderfields = {}
|
let initEditLine = null
|
let edColumns = []
|
let tableId = (() => {
|
let uuid = []
|
let _options = 'abcdefghigklmnopqrstuv'
|
for (let i = 0; i < 19; i++) {
|
uuid.push(_options.substr(Math.floor(Math.random() * 0x20), 1))
|
}
|
return uuid.join('')
|
}) ()
|
|
let _columns = []
|
columns.forEach(item => {
|
if (item.Hide === 'true') return
|
if (item.type === 'index') {
|
item.field = '$Index'
|
item.type = 'text'
|
}
|
|
item.tableId = tableId
|
|
if (!initEditLine && item.editable === 'true') {
|
initEditLine = item
|
}
|
|
if (item.marks && item.marks.length === 0) {
|
item.marks = ''
|
}
|
|
if (item.field) {
|
orderfields[item.uuid] = item.field
|
}
|
|
let _item = {
|
align: item.Align,
|
dataIndex: item.uuid,
|
title: item.label,
|
sorter: item.field && item.IsSort === 'true',
|
width: item.Width || 120,
|
onCell: record => ({
|
record,
|
col: item,
|
config: item.type === 'custom' || item.type === 'action' ? {setting, columns: fields} : null,
|
})
|
}
|
|
if (item.type !== 'action') {
|
let _copy = fromJS(_item).toJS()
|
_copy.sorter = false
|
|
if (item.editable === 'true') {
|
_copy.title = <span>{item.label}<Icon className="system-color" style={{position: 'absolute', bottom: 0, right: 0}} type="edit" /></span>
|
}
|
edColumns.push(_copy)
|
}
|
_columns.push(_item)
|
})
|
|
if (setting.delable !== 'false') {
|
edColumns.push({
|
align: 'center',
|
dataIndex: 'mkoperation',
|
title: '操作',
|
sorter: false,
|
width: 100,
|
onCell: record => ({
|
record,
|
col: {type: 'operation', tableId: tableId},
|
})
|
})
|
}
|
|
if (setting.borderColor) { // 边框颜色
|
let style = `#${tableId} table, #${tableId} tr, #${tableId} th, #${tableId} td {border-color: ${setting.borderColor}}`
|
let ele = document.createElement('style')
|
ele.innerHTML = style
|
document.getElementsByTagName('head')[0].appendChild(ele)
|
}
|
|
this.setState({
|
data,
|
columns: _columns,
|
edColumns,
|
tableId,
|
orderfields,
|
initEditLine,
|
editable: setting.editable
|
})
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
componentDidMount () {
|
const { fields, columns } = this.props
|
const { data, editable } = this.state
|
|
let _fields = []
|
|
let fieldType = {}
|
fields.forEach(item => {
|
fieldType[item.field] = item.datatype
|
})
|
|
columns.forEach(col => {
|
if (!col.field || col.type === 'index') return
|
|
_fields.push({...col, datatype: fieldType[col.field] || 'Nvarchar(50)'})
|
})
|
|
this.setState({
|
fields: _fields,
|
})
|
|
if (editable === 'true' && data && data.length > 0) {
|
setTimeout(() => {
|
this.pickupChange()
|
}, 200)
|
}
|
|
MKEmitter.addListener('nextLine', this.nextLine)
|
MKEmitter.addListener('delRecord', this.delRecord)
|
MKEmitter.addListener('resetTable', this.resetTable)
|
MKEmitter.addListener('changeRecord', this.changeRecord)
|
}
|
|
/**
|
* @description 组件销毁,清除state更新
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
MKEmitter.removeListener('nextLine', this.nextLine)
|
MKEmitter.removeListener('delRecord', this.delRecord)
|
MKEmitter.removeListener('resetTable', this.resetTable)
|
MKEmitter.removeListener('changeRecord', this.changeRecord)
|
}
|
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
if (!is(fromJS(this.props.data), fromJS(nextProps.data))) {
|
this.setState({data: nextProps.data || []})
|
if (this.state.editable === 'true') {
|
setTimeout(() => {
|
this.pickupChange()
|
}, 200)
|
}
|
}
|
}
|
|
nextLine = (col, index) => {
|
const { setting } = this.props
|
const { edData, initEditLine, tableId } = this.state
|
|
if (col.tableId !== tableId) return
|
|
index = +index
|
|
if (index < edData.length && initEditLine) {
|
MKEmitter.emit('tdFocus', initEditLine.uuid + (index + 1))
|
} else if (col.footEnter === 'add' && setting.addable === 'true') {
|
setTimeout(() => {
|
this.plusLine(initEditLine)
|
}, 10)
|
} else if (col.footEnter === 'sub') {
|
setTimeout(() => {
|
this.checkData()
|
}, 10)
|
}
|
}
|
|
plusLine = (initEditLine) => {
|
const { edData, fields } = this.state
|
|
let item = {...edData[edData.length - 1]}
|
|
item.key = item.key + 1
|
item.$$uuid = '$new'
|
item.$Index = item.key + 1 + ''
|
|
fields.forEach(col => {
|
item[col.field] = item[col.field] !== undefined ? item[col.field] : ''
|
|
if (col.initval !== '$copy') {
|
item[col.field] = col.initval
|
}
|
if (col.type === 'number') {
|
item[col.field] = +item[col.field]
|
if (isNaN(item[col.field])) {
|
item[col.field] = 0
|
}
|
}
|
})
|
|
this.setState({edData: [...edData, item]}, () => {
|
MKEmitter.emit('tdFocus', initEditLine.uuid + item.$Index)
|
})
|
}
|
|
delRecord = (id, record) => {
|
const { tableId, edData } = this.state
|
|
if (id !== tableId) return
|
|
let _data = []
|
|
if (record.$$uuid === '$new') {
|
_data = edData.filter(item => item.$Index !== record.$Index)
|
_data = _data.map((item, index) => {
|
item.key = index
|
item.$Index = 1 + index + ''
|
return item
|
})
|
} else {
|
_data = edData.map(item => {
|
if (item.$Index === record.$Index) {
|
record.$deleted = true
|
return record
|
} else {
|
return item
|
}
|
})
|
}
|
|
this.setState({edData: _data})
|
}
|
|
changeRecord = (id, record) => {
|
const { tableId } = this.state
|
|
if (id !== tableId) return
|
|
let _data = this.state.edData.map(item => {
|
if (item.$Index === record.$Index) {
|
return record
|
} else {
|
return item
|
}
|
})
|
|
this.setState({edData: _data})
|
}
|
|
addLine = () => {
|
const { BID } = this.props
|
const { edData, fields } = this.state
|
|
let item = {}
|
if (edData.length > 0) {
|
item = {...edData[edData.length - 1]}
|
item.key = item.key + 1
|
item.$$uuid = '$new'
|
item.$Index = item.key + 1 + ''
|
} else {
|
item.key = 0
|
item.$$uuid = '$new'
|
item.$Index = item.key + 1 + ''
|
item.$$BID = BID || ''
|
}
|
|
fields.forEach(col => {
|
item[col.field] = item[col.field] !== undefined ? item[col.field] : ''
|
|
if (col.initval !== '$copy') {
|
item[col.field] = col.initval
|
}
|
if (col.type === 'number') {
|
item[col.field] = +item[col.field]
|
if (isNaN(item[col.field])) {
|
item[col.field] = 0
|
}
|
}
|
})
|
|
this.setState({edData: [...edData, item]})
|
}
|
|
checkData = () => {
|
const { edData, fields } = this.state
|
|
if (edData.length === 0) {
|
notification.warning({
|
top: 92,
|
message: '提交数据不可为空!',
|
duration: 5
|
})
|
return
|
}
|
let err = ''
|
let data = fromJS(edData).toJS().map(item => {
|
let line = []
|
fields.forEach(col => {
|
if (col.editable !== 'true' || item.$deleted) {
|
if (col.type === 'number') {
|
item[col.field] = +item[col.field]
|
if (isNaN(item[col.field])) {
|
item[col.field] = 0
|
}
|
} else {
|
item[col.field] = item[col.field] !== undefined ? (item[col.field] + '') : ''
|
}
|
return
|
}
|
if (col.type === 'text') {
|
let val = item[col.field] !== undefined ? (item[col.field] + '') : ''
|
if (col.required === 'true' && !val) {
|
line.push(`${col.label}不可为空`)
|
}
|
item[col.field] = val
|
} else if (col.type === 'number') {
|
let val = item[col.field]
|
if (!val && val !== 0) {
|
line.push(`${col.label}不可为空`)
|
return
|
}
|
val = +val
|
if (isNaN(val)) {
|
line.push(`${col.label}数据格式错误`)
|
return
|
}
|
|
val = +val.toFixed(col.decimal || 0)
|
|
if (typeof(col.max) === 'number' && val > col.max) {
|
line.push(`${col.label}不可大于${col.max}`)
|
} else if (typeof(col.min) === 'number' && val < col.min) {
|
line.push(`${col.label}不可小于${col.min}`)
|
}
|
|
item[col.field] = val
|
}
|
})
|
|
if (line.length > 0) {
|
err += `第${item.$Index}行:` + line.join(',') + ';'
|
}
|
|
return item
|
})
|
|
if (err) {
|
notification.warning({
|
top: 92,
|
message: err,
|
duration: 5
|
})
|
} else {
|
this.submit(data)
|
}
|
}
|
|
submit = (data) => {
|
const { submit, BID } = this.props
|
const { fields } = this.state
|
|
let result = getEditTableSql(submit, data, fields)
|
|
let param = {
|
excel_in: result.lines,
|
BID: BID || ''
|
}
|
|
this.setState({
|
loading: true
|
})
|
|
if (submit.intertype === 'system') { // 系统存储过程
|
param.func = 'sPC_TableData_InUpDe'
|
|
if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
|
result.sql = result.sql.replace(/\$@/ig, '/*')
|
result.sql = result.sql.replace(/@\$/ig, '*/')
|
result.bottom = result.bottom.replace(/\$@/ig, '/*')
|
result.bottom = result.bottom.replace(/@\$/ig, '*/')
|
} else {
|
result.sql = result.sql.replace(/@\$|\$@/ig, '')
|
result.bottom = result.bottom.replace(/@\$|\$@/ig, '')
|
}
|
|
param.excel_in_type = 'true'
|
param.LText1 = Utils.formatOptions(result.insert)
|
param.LText2 = Utils.formatOptions(result.bottom)
|
param.LText = Utils.formatOptions(result.sql)
|
param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
|
param.secretkey = Utils.encrypt(param.LText, param.timestamp)
|
|
param.menuname = submit.logLabel
|
|
if (window.GLOB.probation) {
|
param.s_debug_type = 'Y'
|
}
|
|
Api.genericInterface(param).then((res) => {
|
if (res.status) {
|
this.execSuccess(res)
|
} else {
|
this.execError(res)
|
}
|
}, () => {
|
this.execError({})
|
})
|
} else if (submit.intertype === 'inner' && submit.innerFunc) { // 自定义存储过程
|
param.func = submit.innerFunc
|
|
Api.genericInterface(param).then((res) => {
|
if (res.status) {
|
this.execSuccess(res)
|
} else {
|
this.execError(res)
|
}
|
}, () => {
|
this.execError({})
|
})
|
}
|
}
|
|
execSuccess = (res) => {
|
const { submit } = this.props
|
|
if (res && res.ErrCode === 'S') { // 执行成功
|
notification.success({
|
top: 92,
|
message: res.ErrMesg || this.state.dict['main.action.confirm.success'],
|
duration: submit.stime ? submit.stime : 2
|
})
|
} else if (res && res.ErrCode === 'Y') { // 执行成功
|
Modal.success({
|
title: res.ErrMesg || this.state.dict['main.action.confirm.success']
|
})
|
} else if (res && res.ErrCode === '-1') { // 完成后不提示
|
|
}
|
|
this.setState({
|
loading: false
|
})
|
|
if (submit.closetab === 'true') {
|
MKEmitter.emit('popclose')
|
}
|
if (submit.execSuccess !== 'never') {
|
this.repick()
|
MKEmitter.emit('refreshByButtonResult', submit.$menuId, submit.execSuccess, submit)
|
}
|
}
|
|
execError = (res) => {
|
const { submit } = this.props
|
|
if (res.ErrCode === 'E') {
|
Modal.error({
|
title: res.message || res.ErrMesg,
|
})
|
} else if (res.ErrCode === 'N') {
|
notification.error({
|
top: 92,
|
message: res.message || res.ErrMesg,
|
duration: submit.ntime ? submit.ntime : 10
|
})
|
} else if (res.ErrCode === 'F') {
|
notification.error({
|
className: 'notification-custom-error',
|
top: 92,
|
message: res.message || res.ErrMesg,
|
duration: submit.ftime ? submit.ftime : 10
|
})
|
} else if (res.ErrCode === 'NM') {
|
message.error(res.message || res.ErrMesg)
|
}
|
|
this.setState({
|
loading: false
|
})
|
|
if (submit.execError !== 'never') {
|
this.repick()
|
MKEmitter.emit('refreshByButtonResult', submit.$menuId, submit.execError, submit)
|
}
|
}
|
|
repick = () => {
|
const { data } = this.state
|
|
this.setState({
|
data: [],
|
edData: [],
|
pickup: false,
|
}, () => {
|
this.setState({
|
data: data,
|
})
|
})
|
}
|
|
changeTable = (pagination, filters, sorter) => {
|
const { orderfields } = this.state
|
|
this.setState({
|
pageIndex: pagination.current,
|
pageSize: pagination.pageSize
|
})
|
|
sorter.field = orderfields[sorter.field] || ''
|
|
this.props.refreshdata(pagination, filters, sorter)
|
}
|
|
resetTable = (id, repage) => {
|
const { MenuID } = this.props
|
|
if (id !== MenuID) return
|
|
if (repage !== 'false') {
|
this.setState({
|
pageIndex: 1
|
})
|
}
|
}
|
|
pickupChange = () => {
|
const { submit } = this.props
|
const { data } = this.state
|
|
let pickup = !this.state.pickup
|
|
if (!submit.sheet) {
|
notification.warning({
|
top: 92,
|
message: '提交按钮尚未设置,不可编辑!',
|
duration: 5
|
})
|
return
|
}
|
|
if (!pickup && !is(fromJS(data), fromJS(this.state.edData))) {
|
const _this = this
|
confirm({
|
title: '数据已修改,确定放弃保存吗?',
|
onOk() {
|
_this.setState({
|
data: [],
|
edData: [],
|
pickup
|
}, () => {
|
_this.setState({
|
data: data,
|
edData: pickup ? fromJS(data).toJS() : []
|
})
|
})
|
},
|
onCancel() {}
|
})
|
} else {
|
this.setState({
|
data: [],
|
edData: [],
|
pickup,
|
loading: false,
|
editable: 'false'
|
}, () => {
|
this.setState({
|
data: data,
|
edData: pickup ? fromJS(data).toJS() : []
|
})
|
})
|
}
|
}
|
|
render() {
|
const { setting, statFValue, lineMarks, submit } = this.props
|
const { pickup, tableId, data, edData, columns, edColumns, loading } = this.state
|
|
const components = {
|
body: {
|
row: BodyRow,
|
cell: BodyCell
|
}
|
}
|
|
// 数据收起时,过滤已选数据
|
let _data = data
|
let _columns = columns
|
|
if (pickup) {
|
_data = edData
|
_data = _data.filter(item => !item.$deleted)
|
_columns = edColumns
|
}
|
|
let _pagination = false
|
if (!pickup && setting.laypage !== 'false' && setting.laypage !== false) {
|
_pagination = {
|
current: this.state.pageIndex,
|
pageSize: this.state.pageSize,
|
pageSizeOptions: ['10', '25', '50', '100', '500', '1000'],
|
showSizeChanger: true,
|
total: this.props.total || 0,
|
showTotal: (total, range) => `${range[0]}-${range[1]} ${this.state.dict['main.pagination.of']} ${total} ${this.state.dict['main.pagination.items']}`
|
}
|
}
|
|
let _footer = ''
|
|
if (!pickup && statFValue && statFValue.length > 0) {
|
_footer = statFValue.map(f => `${f.label}(合计):${f.value}`).join(';')
|
}
|
|
let height = setting.height || false
|
|
return (
|
<div className={`edit-custom-table ${pickup ? 'editable' : ''} ${setting.tableHeader || ''} ${height ? 'fixed-height' : ''} ${setting.mode || ''}`} id={tableId}>
|
<Switch title="编辑" className="main-pickup" checkedChildren="开" unCheckedChildren="关" checked={pickup} onChange={this.pickupChange} />
|
{pickup ? <Button style={submit.style} onClick={() => setTimeout(() => {this.checkData()}, 10)} loading={loading} className="submit-table" type="link">提交</Button> : null}
|
<Table
|
components={components}
|
style={setting.style}
|
size={setting.size || 'middle'}
|
bordered={setting.bordered !== 'false'}
|
columns={_columns}
|
dataSource={_data}
|
loading={this.props.loading}
|
scroll={{ x: '100%', y: height }}
|
onRow={(record, index) => {
|
return {
|
lineMarks,
|
data: record
|
}
|
}}
|
onChange={this.changeTable}
|
pagination={_pagination}
|
/>
|
{_footer ? <div className={'normal-table-footer ' + (_pagination ? 'pagination' : '')}>{_footer}</div> : null}
|
{pickup && setting.addable === 'true' ? <Button onClick={this.addLine} style={{display: 'block', width: '100%', color: '#26C281', border: '1px solid #dddddd', borderRadius: 0}} icon="plus" type="link"></Button> : null}
|
</div>
|
)
|
}
|
}
|
|
export default NormalTable
|