From cc1a76df575c18f0d0ee96e8658461efdce3a918 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 17 一月 2023 18:01:01 +0800 Subject: [PATCH] 2023-01-17 --- src/tabviews/custom/components/table/edit-table/normalTable/index.jsx | 473 ++++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 356 insertions(+), 117 deletions(-) diff --git a/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx b/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx index 6ef85b0..bcf4ee3 100644 --- a/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx +++ b/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx @@ -6,7 +6,6 @@ import moment from 'moment' import Api from '@/api' -import options from '@/store/options.js' import asyncComponent from '@/utils/asyncComponent' import Utils, { getEditTableSql, getMark } from '@/utils/utils.js' import MkIcon from '@/components/mk-icon' @@ -14,7 +13,7 @@ import zhCN from '@/locales/zh-CN/main.js' import enUS from '@/locales/en-US/main.js' import CusSwitch from './cusSwitch' -import '@/assets/css/table.scss' +import Encrypts from '@/components/encrypts' import './index.scss' const { Paragraph } = Typography @@ -138,7 +137,9 @@ setTimeout(() => { if (col.enter === '$next') { MKEmitter.emit('nextLine', col, record.$$uuid) - } else { + } else if (col.enter === '$sub') { + MKEmitter.emit('subLine', col, record) + } else if (col.enter !== '$noAct') { MKEmitter.emit('tdFocus', col.enter + record.$$uuid) } }, 50) @@ -213,7 +214,7 @@ this.setState({value: val, err}) } - onSwitchChange = (val) => { + onSwitchChange = (val, label) => { const { col, record } = this.props this.setState({editing: false}) @@ -221,12 +222,22 @@ setTimeout(() => { if (col.enter === '$next') { MKEmitter.emit('nextLine', col, record.$$uuid) - } else { + } else if (col.enter === '$sub') { + MKEmitter.emit('subLine', col, record) + } else if (col.enter !== '$noAct') { MKEmitter.emit('tdFocus', col.enter + record.$$uuid) } }, 50) - MKEmitter.emit('changeRecord', col.tableId, {...record, [col.field]: val}) + let values = {} + if (col.editField) { + values[col.field] = label + values[col.editField] = val + } else { + values[col.field] = val + } + + MKEmitter.emit('changeRecord', col.tableId, {...record, ...values}) } onSelectChange = (val, option) => { @@ -255,7 +266,9 @@ setTimeout(() => { if (col.enter === '$next') { MKEmitter.emit('nextLine', col, record.$$uuid) - } else { + } else if (col.enter === '$sub') { + MKEmitter.emit('subLine', col, record) + } else if (col.enter !== '$noAct') { MKEmitter.emit('tdFocus', col.enter + record.$$uuid) } }, 50) @@ -287,9 +300,13 @@ 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)}` + } else if (col.textFormat === 'encryption') { + content = <span>{col.prefix || ''}<Encrypts value={content} />{col.postfix || ''}</span> } - content = (col.prefix || '') + content + (col.postfix || '') + if (col.textFormat !== 'encryption') { + content = (col.prefix || '') + content + (col.postfix || '') + } } if (col.marks) { @@ -299,10 +316,12 @@ if (mark.icon) { if (mark.position === 'front') { - content = <span><MkIcon style={{color: mark.color}} type={mark.icon} /> {content}</span> + content = <span><MkIcon style={mark.innerStyle} type={mark.icon} /> {content}</span> } else { - content = <span>{content} <MkIcon style={{color: mark.color}} type={mark.icon} /></span> + content = <span>{content} <MkIcon style={mark.innerStyle} type={mark.icon} /></span> } + } else if (mark.innerStyle) { + content = <span style={mark.innerStyle}>{content}</span> } } @@ -314,16 +333,28 @@ {err ? <Tooltip title={err}><ExclamationCircleOutlined /></Tooltip> : null} </td>) } else if (col.editType === 'switch') { - let _value = record[col.field] !== undefined ? record[col.field] : '' + let _value = '' + if (col.editField) { + _value = record[col.editField] !== undefined ? record[col.editField] : '' + } else { + _value = record[col.field] !== undefined ? record[col.field] : '' + } return (<td 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] : '' + let _value = '' + if (col.editField) { + _value = record[col.editField] !== undefined ? record[col.editField] : '' + } else { + _value = record[col.field] !== undefined ? record[col.field] : '' + } return (<td className="editing_table_cell"> <Select showSearch defaultValue={_value} + dropdownClassName="edit-table-dropdown" + dropdownMatchSelectWidth={col.dropdown === 'fixed'} id={col.uuid + record.$$uuid} onBlur={() => this.setState({editing: false})} filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} @@ -355,21 +386,23 @@ } if (content !== '') { - let decimal = col.decimal || 0 + if (col.round) { + content = Math.round(content * col.round) / col.round + } if (col.format === 'percent') { content = content * 100 - decimal = decimal > 2 ? decimal - 2 : 0 } else if (col.format === 'abs') { content = Math.abs(content) } - - content = content.toFixed(decimal) + if (col.round) { + content = content.toFixed(col.decimal) + } if (col.format === 'thdSeparator') { content = content.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,') } - content = col.prefix + content + col.postfix + content = (col.prefix || '') + content + (col.postfix || '') } if (col.marks) { @@ -379,10 +412,12 @@ if (mark.icon) { if (mark.position === 'front') { - content = <span><MkIcon style={{color: mark.color}} type={mark.icon} /> {content}</span> + content = <span><MkIcon style={mark.innerStyle} type={mark.icon} /> {content}</span> } else { - content = <span>{content} <MkIcon style={{color: mark.color}} type={mark.icon} /></span> + content = <span>{content} <MkIcon style={mark.innerStyle} type={mark.icon} /></span> } + } else if (mark.innerStyle) { + content = <span style={mark.innerStyle}>{content}</span> } } @@ -409,7 +444,7 @@ } if (content) { - content = col.prefix + content + col.postfix + content = (col.prefix || '') + content + (col.postfix || '') } children = ( @@ -451,10 +486,12 @@ if (mark.icon) { if (mark.position === 'front') { - content = <span><MkIcon style={{color: mark.color}} type={mark.icon} /> {content}</span> + content = <span><MkIcon style={mark.innerStyle} type={mark.icon} /> {content}</span> } else { - content = <span>{content} <MkIcon style={{color: mark.color}} type={mark.icon} /></span> + content = <span>{content} <MkIcon style={mark.innerStyle} type={mark.icon} /></span> } + } else if (mark.innerStyle) { + content = <span style={mark.innerStyle}>{content}</span> } } @@ -469,7 +506,10 @@ <CardCellComponent data={record} cards={config} elements={col.elements}/> ) } else if (col.type === 'action') { - style.padding = '0px 5px' + style.padding = '0px' + if (col.style) { + style = {...style, ...col.style} + } children = ( <CardCellComponent data={record} cards={config} elements={col.elements}/> ) @@ -522,7 +562,9 @@ setTimeout(() => { if (col.enter === '$next') { MKEmitter.emit('nextLine', col, record.$$uuid) - } else { + } else if (col.enter === '$sub') { + MKEmitter.emit('subLine', col, record) + } else if (col.enter !== '$noAct') { MKEmitter.emit('tdFocus', col.enter + record.$$uuid) } }, 50) @@ -581,18 +623,28 @@ MKEmitter.emit('changeRecord', col.tableId, {...record, [col.field]: val}) } - onSwitchChange = (val) => { + onSwitchChange = (val, label) => { const { col, record } = this.props setTimeout(() => { if (col.enter === '$next') { MKEmitter.emit('nextLine', col, record.$$uuid) - } else { + } else if (col.enter === '$sub') { + MKEmitter.emit('subLine', col, record) + } else if (col.enter !== '$noAct') { MKEmitter.emit('tdFocus', col.enter + record.$$uuid) } }, 50) - MKEmitter.emit('changeRecord', col.tableId, {...record, [col.field]: val}) + let values = {} + if (col.editField) { + values[col.field] = label + values[col.editField] = val + } else { + values[col.field] = val + } + + MKEmitter.emit('changeRecord', col.tableId, {...record, ...values}) } onSelectChange = (val, option) => { @@ -619,7 +671,9 @@ setTimeout(() => { if (col.enter === '$next') { MKEmitter.emit('nextLine', col, record.$$uuid) - } else { + } else if (col.enter === '$sub') { + MKEmitter.emit('subLine', col, record) + } else if (col.enter !== '$noAct') { MKEmitter.emit('tdFocus', col.enter + record.$$uuid) } }, 50) @@ -634,7 +688,13 @@ let children = null if (col.type === 'text') { if (col.editable === 'true') { - let _value = record[col.field] !== undefined ? record[col.field] : '' + let _value = '' + if (col.editField) { + _value = record[col.editField] !== undefined ? record[col.editField] : '' + } else { + _value = record[col.field] !== undefined ? record[col.field] : '' + } + if (!col.editType || col.editType === 'text') { children = (<> <Input id={col.uuid + record.$$uuid} defaultValue={_value} onChange={(e) => this.onChange(e.target.value)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> @@ -648,9 +708,10 @@ children = (<> <Select showSearch + dropdownClassName="edit-table-dropdown" + dropdownMatchSelectWidth={col.dropdown === 'fixed'} defaultValue={_value} id={col.uuid + record.$$uuid} - onBlur={() => this.setState({editing: false})} filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} onSelect={this.onSelectChange} > @@ -669,9 +730,13 @@ 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)}` + } else if (col.textFormat === 'encryption') { + content = <span>{col.prefix || ''}<Encrypts value={content} />{col.postfix || ''}</span> } - content = (col.prefix || '') + content + (col.postfix || '') + if (col.textFormat !== 'encryption') { + content = (col.prefix || '') + content + (col.postfix || '') + } } if (col.marks) { @@ -681,10 +746,12 @@ if (mark.icon) { if (mark.position === 'front') { - content = <span><MkIcon style={{color: mark.color}} type={mark.icon} /> {content}</span> + content = <span><MkIcon style={mark.innerStyle} type={mark.icon} /> {content}</span> } else { - content = <span>{content} <MkIcon style={{color: mark.color}} type={mark.icon} /></span> + content = <span>{content} <MkIcon style={mark.innerStyle} type={mark.icon} /></span> } + } else if (mark.innerStyle) { + content = <span style={mark.innerStyle}>{content}</span> } } children = content @@ -708,21 +775,23 @@ } if (content !== '') { - let decimal = col.decimal || 0 + if (col.round) { + content = Math.round(content * col.round) / col.round + } if (col.format === 'percent') { content = content * 100 - decimal = decimal > 2 ? decimal - 2 : 0 } else if (col.format === 'abs') { content = Math.abs(content) } - - content = content.toFixed(decimal) + if (col.round) { + content = content.toFixed(col.decimal) + } if (col.format === 'thdSeparator') { content = content.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,') } - content = col.prefix + content + col.postfix + content = (col.prefix || '') + content + (col.postfix || '') } if (col.marks) { @@ -732,10 +801,12 @@ if (mark.icon) { if (mark.position === 'front') { - content = <span><MkIcon style={{color: mark.color}} type={mark.icon} /> {content}</span> + content = <span><MkIcon style={mark.innerStyle} type={mark.icon} /> {content}</span> } else { - content = <span>{content} <MkIcon style={{color: mark.color}} type={mark.icon} /></span> + content = <span>{content} <MkIcon style={mark.innerStyle} type={mark.icon} /></span> } + } else if (mark.innerStyle) { + content = <span style={mark.innerStyle}>{content}</span> } } children = content @@ -747,7 +818,7 @@ } if (content) { - content = col.prefix + content + col.postfix + content = (col.prefix || '') + content + (col.postfix || '') } children = ( @@ -789,10 +860,12 @@ if (mark.icon) { if (mark.position === 'front') { - content = <span><MkIcon style={{color: mark.color}} type={mark.icon} /> {content}</span> + content = <span><MkIcon style={mark.innerStyle} type={mark.icon} /> {content}</span> } else { - content = <span>{content} <MkIcon style={{color: mark.color}} type={mark.icon} /></span> + content = <span>{content} <MkIcon style={mark.innerStyle} type={mark.icon} /></span> } + } else if (mark.innerStyle) { + content = <span style={mark.innerStyle}>{content}</span> } } @@ -821,15 +894,16 @@ static propTpyes = { statFValue: PropTypes.any, // 鍚堣瀛楁鏁版嵁 MenuID: PropTypes.string, // 鑿滃崟Id - setting: PropTypes.object, // 琛ㄦ牸鍏ㄥ眬璁剧疆锛歵ableType锛堣〃鏍兼槸鍚﹀彲閫夈�佸崟閫夈�佸閫夛級銆乧olumnfixed锛堝垪鍥哄畾锛夈�乤ctionfixed锛堟寜閽浐瀹氾級 + setting: PropTypes.object, // 琛ㄦ牸鍏ㄥ眬璁剧疆锛歵ableType锛堣〃鏍兼槸鍚﹀彲閫夈�佸崟閫夈�佸閫夛級銆乤ctionfixed锛堟寜閽浐瀹氾級 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, // 琛ㄦ牸涓帓搴忓垪銆侀〉鐮佺殑鍙樺寲鏃跺埛鏂� + changeLock: PropTypes.func, + chgSelectData: PropTypes.func, } state = { @@ -846,12 +920,12 @@ pickup: false, // 鏀惰捣鏈�夋嫨椤� orderfields: {}, // 鎺掑簭id涓巉ield杞崲 loading: false, - editable: 'false', + editable: false, pageOptions: [] } UNSAFE_componentWillMount () { - const { setting, fields, columns, data } = this.props + const { setting, fields, columns } = this.props let orderfields = {} let initEditLine = null let edColumns = [] @@ -865,6 +939,10 @@ if (item.type === 'text' && item.editable === 'true' && item.editType === 'select' && item.resourceType === '1') { let _option = Utils.getSelectQueryOptions(item) + + if (window.GLOB.debugger === true || window.debugger === true) { + console.info(_option.sql) + } item.base_sql = window.btoa(window.encodeURIComponent(_option.sql)) item.arr_field = _option.field @@ -915,12 +993,12 @@ }) } - if (setting.borderColor) { // 杈规棰滆壊 - let style = `#${setting.tableId} table, #${setting.tableId} tr, #${setting.tableId} th, #${setting.tableId} td {border-color: ${setting.borderColor}}` - let ele = document.createElement('style') - ele.innerHTML = style - document.getElementsByTagName('head')[0].appendChild(ele) - } + // if (setting.borderColor) { // 杈规棰滆壊 + // let style = `#${setting.tableId} table, #${setting.tableId} tr, #${setting.tableId} th, #${setting.tableId} td {border-color: ${setting.borderColor}}` + // let ele = document.createElement('style') + // ele.innerHTML = style + // document.getElementsByTagName('head')[0].appendChild(ele) + // } let size = (setting.pageSize || 10) + '' let pageOptions = ['10', '25', '50', '100', '500', '1000'] @@ -933,17 +1011,22 @@ this.setState({ pageSize: setting.pageSize || 10, pageOptions, - data, columns: _columns, edColumns, tableId: setting.tableId, orderfields, initEditLine, - editable: setting.editable + editable: setting.editable === 'true' }, () => { if (deForms.length > 0) { this.improveActionForm(deForms) } + + const element = document.getElementById(setting.tableId) + element && element.style.setProperty('--mk-table-border-color', setting.borderColor || '#e8e8e8') + element && element.style.setProperty('--mk-table-color', setting.color || 'rgba(0, 0, 0, 0.65)') + element && element.style.setProperty('--mk-table-font-size', setting.fontSize || '14px') + element && element.style.setProperty('--mk-table-font-weight', setting.fontWeight || 'normal') }) } @@ -953,23 +1036,17 @@ componentDidMount () { const { fields, setting } = this.props - const { data, editable } = this.state this.setState({ fields: fields.filter(item => item.field !== setting.primaryKey), }) - if (editable === 'true' && data && data.length > 0) { - this.setState({editable: 'false'}) - setTimeout(() => { - this.pickupChange() - }, 200) - } - + MKEmitter.addListener('subLine', this.subLine) MKEmitter.addListener('nextLine', this.nextLine) MKEmitter.addListener('addRecord', this.addLine) MKEmitter.addListener('delRecord', this.delRecord) MKEmitter.addListener('resetTable', this.resetTable) + MKEmitter.addListener('transferData', this.transferData) MKEmitter.addListener('changeRecord', this.changeRecord) } @@ -980,23 +1057,45 @@ this.setState = () => { return } + MKEmitter.removeListener('subLine', this.subLine) MKEmitter.removeListener('nextLine', this.nextLine) MKEmitter.removeListener('addRecord', this.addLine) MKEmitter.removeListener('delRecord', this.delRecord) MKEmitter.removeListener('resetTable', this.resetTable) + MKEmitter.removeListener('transferData', this.transferData) 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' && !this.state.pickup) { - this.setState({editable: 'false'}) + transferData = (menuid, data, type) => { + if (menuid !== this.props.MenuID) return + + if (type !== 'line') { + this.setState({data: data || []}) + + if (this.state.editable && !this.state.pickup) { setTimeout(() => { this.pickupChange() }, 200) } + } else if (type === 'line' && data.$$uuid) { + let _data = this.state.data.map(item => { + if (item.$$uuid === data.$$uuid) { + return data + } else { + return item + } + }) + let _edData = this.state.edData.map(item => { + if (item.$$uuid === data.$$uuid) { + return data + } else { + return item + } + }) + + this.setState({edData: _edData, data: _data}) } + this.setState({editable: false}) } improveActionForm = (deForms) => { @@ -1014,11 +1113,6 @@ localItems.push(`select '${item.uuid}' as obj_name,'${item.arr_field}' as arr_field,'${item.base_sql}' as LText`) } }) - - if (options.sysType !== 'local') { - localItems = [...localItems, ...mainItems] - mainItems = [] - } // 鏈湴璇锋眰 let param = { @@ -1109,16 +1203,24 @@ if (item.resourceType === '1' && result[item.uuid] && result[item.uuid].length > 0) { let options = [] let _map = new Map() + let all = false result[item.uuid].forEach(cell => { let _cell = {key: Utils.getuuid()} _cell.value = cell[item.valueField] _cell.label = cell[item.valueText] - if (!_cell.label && _cell.label !== 0) return + if (!_cell.label && _cell.label !== 0) { + if (!all) { + _cell.label = '鍏ㄩ儴' + all = true + } else { + return + } + } if (_map.has(_cell.value)) return - _map.set(_cell.value, true) + _map.set(_cell.value, 0) if (item.linkSubField) { item.linkSubField.forEach(m => { @@ -1172,15 +1274,86 @@ if (next && initEditLine) { MKEmitter.emit('tdFocus', initEditLine.uuid + next.$$uuid) - } else if (col.footEnter === 'add' && setting.addable === 'true') { + } else if (setting.addable === 'true') { setTimeout(() => { this.plusLine() }, 10) - } else if (col.footEnter === 'sub') { + } else if (edData[index]) { setTimeout(() => { - this.checkData() + this.subLine(col, edData[index]) }, 10) } + } + + subLine = (col, record) => { + const { tableId, fields, edData } = this.state + + if (col && col.tableId !== tableId) return + + if (edData.filter(item => !item.$origin).length > 1) { + setTimeout(() => { + this.submit(edData) + }, 10) + return + } + + setTimeout(() => { + let item = fromJS(record).toJS() + 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 + } + }) + + let err = line.join('锛�') + + if (err) { + notification.warning({ + top: 92, + message: err, + duration: 5 + }) + } else { + this.submit([item], 'simple') + } + }, 10) } plusLine = () => { @@ -1213,6 +1386,7 @@ } delRecord = (id, record) => { + const { setting } = this.props const { tableId, edData } = this.state if (id !== tableId) return @@ -1232,6 +1406,10 @@ return item } }) + + if (setting.commit === 'simple' && record.$deleted) { + this.subLine(null, record) + } } this.setState({edData: _data}) @@ -1401,11 +1579,11 @@ } } - submit = (data) => { + submit = (data, type) => { const { submit, BID, setting } = this.props const { fields } = this.state - if (setting.commit === 'change') { + if (type !== 'simple' && (setting.commit === 'change' || setting.commit === 'simple')) { data = data.filter(item => !item.$origin) } @@ -1457,7 +1635,12 @@ Api.genericInterface(param).then((res) => { if (res.status) { - this.execSuccess(res) + if (type === 'simple') { + this.updataLine(data[0]) + this.execSuccess(res, type) + } else { + this.execSuccess(res) + } } else { this.execError(res) } @@ -1469,7 +1652,12 @@ Api.genericInterface(param).then((res) => { if (res.status) { - this.execSuccess(res) + if (type === 'simple') { + this.updataLine(data[0]) + this.execSuccess(res, type) + } else { + this.execSuccess(res) + } } else { this.execError(res) } @@ -1479,7 +1667,26 @@ } } - execSuccess = (res) => { + updataLine = (item) => { + if (item.$type === 'del') { + let _data = this.state.edData.filter(m => m.$$uuid !== item.$$uuid) + + this.setState({edData: _data}) + } else { + let _data = this.state.edData.map(m => { + if (m.$$uuid === item.$$uuid) { + item.$origin = true + return item + } + return m + }) + + this.setState({edData: _data}) + } + MKEmitter.emit('reloadData', this.props.MenuID, item.$$uuid, item) + } + + execSuccess = (res, type) => { const { submit } = this.props if (res && res.ErrCode === 'S') { // 鎵ц鎴愬姛 @@ -1499,6 +1706,8 @@ this.setState({ loading: false }) + + if (type === 'simple') return if (submit.closetab === 'true') { MKEmitter.emit('popclose') @@ -1544,8 +1753,14 @@ } repick = () => { + const { setting } = this.props const { data } = this.state + if (setting.submittal === 'true') { + this.setState({editable: true}) + } + + this.props.changeLock(false) this.setState({ data: [], edData: [], @@ -1658,7 +1873,7 @@ } pickupChange = () => { - const { submit, MenuID } = this.props + const { submit, MenuID, setting } = this.props const { data } = this.state let pickup = !this.state.pickup @@ -1672,7 +1887,7 @@ return } - if (!pickup && !is(fromJS(data), fromJS(this.state.edData))) { + if (!pickup && this.state.edData.filter(item => !item.$origin).length > 0) { const _this = this confirm({ title: '鏁版嵁宸蹭慨鏀癸紝纭畾鏀惧純淇濆瓨鍚楋紵', @@ -1692,19 +1907,35 @@ }) } else { pickup && MKEmitter.emit('resetSelectLine', MenuID, '', '') + pickup && this.props.chgSelectData([]) + let keys = this.state.selectedRowKeys this.setState({ data: [], edData: [], + selectedRowKeys: [], pickup, loading: false, - editable: 'false' + editable: false }, () => { - this.setState({ - data: data, - edData: pickup ? fromJS(data).toJS() : [] - }) + if (pickup && setting.tableType === 'checkbox' && keys.length > 0) { + this.setState({ + data: data, + edData: fromJS(data).toJS().filter(item => { + item.$origin = false + + return keys.includes(item.$$uuid) + }) + }) + } else { + this.setState({ + data: data, + edData: pickup ? fromJS(data).toJS() : [] + }) + } }) + } + this.props.changeLock(pickup) } render() { @@ -1759,33 +1990,41 @@ let height = setting.height || false return ( - <div className={`edit-custom-table ${pickup ? 'editable' : ''} ${setting.tableHeader || ''} ${setting.operType || ''} ${height ? 'fixed-height' : ''} ${setting.mode || ''}`} id={tableId}> - <Switch title="缂栬緫" className="main-pickup" checkedChildren="寮�" unCheckedChildren="鍏�" disabled={loading || this.props.loading} 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 - rowKey="$$uuid" - components={components} - style={setting.style} - size={setting.size || 'middle'} - bordered={setting.bordered !== 'false'} - rowSelection={rowSelection} - columns={_columns} - dataSource={_data} - loading={this.props.loading} - scroll={{ x: '100%', y: height }} - onRow={(record, index) => { - return { - lineMarks, - data: record, - onClick: () => {this.changeRow(record.$$uuid)}, - } - }} - onChange={this.changeTable} - pagination={_pagination} - /> - {_footer ? <div className={'normal-table-footer ' + (_pagination ? 'pagination' : '')}>{_footer}</div> : null} - {pickup && setting.addable === 'true' ? <Button className="mk-add-line" onClick={() => this.addLine()} disabled={this.props.loading} type="link"><PlusOutlined /></Button> : null} - </div> + <> + {submit.hasAction && pickup ? <div className="edit-custom-table-leftbtn-wrap"> + <Button style={submit.style} onClick={() => setTimeout(() => {this.checkData()}, 10)} loading={loading} className="submit-table" type="link">鎻愪氦</Button> + </div> : null} + <div className="edit-custom-table-btn-wrap" style={submit.wrapStyle}> + {!submit.hasAction && pickup ? <Button style={submit.style} onClick={() => setTimeout(() => {this.checkData()}, 10)} loading={loading} className="submit-table" type="link">鎻愪氦</Button> : null} + <Switch title="缂栬緫" className="main-pickup" checkedChildren="寮�" unCheckedChildren="鍏�" disabled={loading || this.props.loading} checked={pickup} onChange={this.pickupChange} /> + </div> + <div className={`edit-custom-table ${pickup ? 'editable' : ''} ${setting.tableHeader || ''} ${setting.operType || ''} ${height ? 'fixed-height' : ''} ${setting.mode || ''} table-vertical-${setting.vertical || ''}`} id={tableId}> + <Table + rowKey="$$uuid" + components={components} + // style={setting.style} + size={setting.size || 'middle'} + bordered={setting.bordered !== 'false'} + rowSelection={rowSelection} + columns={_columns} + dataSource={_data} + loading={this.props.loading} + scroll={{ x: '100%', y: height }} + onRow={(record, index) => { + return { + lineMarks, + data: record, + onClick: () => {this.changeRow(record.$$uuid)}, + } + }} + onChange={this.changeTable} + pagination={_pagination} + /> + {_footer ? <div className={'normal-table-footer ' + (_pagination ? 'pagination' : '')}>{_footer}</div> : null} + {pickup && setting.addable === 'true' ? <Button className="mk-add-line" onClick={() => this.addLine()} disabled={this.props.loading} type="link"><PlusOutlined /></Button> : null} + {pickup && _data.length > 10 ? <Button style={submit.style} onClick={() => setTimeout(() => {this.checkData()}, 10)} loading={loading} className="submit-footer-table" type="link">鎻愪氦</Button> : null} + </div> + </> ) } } -- Gitblit v1.8.0