From a9b02f6862522b54d0824152017bf2acfec2af7b Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 21 三月 2024 10:29:50 +0800 Subject: [PATCH] 2024-03-21 --- src/tabviews/custom/components/card/data-card/index.jsx | 783 ++++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 540 insertions(+), 243 deletions(-) diff --git a/src/tabviews/custom/components/card/data-card/index.jsx b/src/tabviews/custom/components/card/data-card/index.jsx index 5d917d4..9bc199c 100644 --- a/src/tabviews/custom/components/card/data-card/index.jsx +++ b/src/tabviews/custom/components/card/data-card/index.jsx @@ -1,11 +1,10 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' -import { Spin, Empty, notification, message, Row, Col, Pagination, Modal } from 'antd' +import { Spin, Empty, notification, message, Row, Col, Pagination, Modal, Switch } from 'antd' import { DownOutlined } from '@ant-design/icons' import Api from '@/api' -import Utils from '@/utils/utils.js' import UtilsDM from '@/utils/utils-datamanage.js' import preImg from '@/assets/img/prev.png' import nextImg from '@/assets/img/next.png' @@ -15,14 +14,13 @@ import './index.scss' const CardItem = asyncComponent(() => import('../cardItem')) +const TableHeader = asyncComponent(() => import('../tableHeader')) const MainAction = asyncComponent(() => import('@/tabviews/zshare/actionList')) const NormalHeader = asyncComponent(() => import('@/tabviews/custom/components/share/normalheader')) class DataCard extends Component { static propTpyes = { - data: PropTypes.array, // 缁熶竴鏌ヨ鏁版嵁 - config: PropTypes.object, // 缁勪欢閰嶇疆淇℃伅 - mainSearch: PropTypes.any, // 澶栧眰鎼滅储鏉′欢 + config: PropTypes.object } state = { @@ -31,27 +29,30 @@ config: null, // 鍥捐〃閰嶇疆淇℃伅 search: null, // 鎼滅储鏉′欢 pageIndex: 1, // 椤电爜 - activeKey: '', // 閫変腑鍗� - selectKeys: [], // 澶氶�夋椂閫変腑鍗$墖 - selectedData: [], // 閫変腑鏁版嵁锛岀敤浜庡伐鍏锋爮鎸夐挳 - loading: false, // 鏁版嵁鍔犺浇鐘舵�� - sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 - card: null, // 鍗$墖璁剧疆 - data: null, // 鏁版嵁 - total: null, + pageSize: 10, + orderBy: '', + pageOptions: [], + activeKey: '', + selectKeys: [], + selectedData: [], + loading: false, + card: null, + data: [], + total: 0, precards: [], nextcards: [], selected: 'false', supNodes: [], - supComs: null + supComs: null, + pickup: false } loaded = false UNSAFE_componentWillMount () { - const { data, initdata } = this.props - let _config = fromJS(this.props.config).toJS() + const { config } = this.props + let _config = fromJS(config).toJS() let BID = '' let BData = '' @@ -76,6 +77,9 @@ } } + _config.$extend = false + _config.$empty = true + _config.subcards.forEach(item => { if (item.setting.click === 'button' && !item.setting.linkbtn) { item.elements.forEach(ele => { @@ -88,59 +92,36 @@ } } + if (item.style.clear === 'left') { + item.wStyle = {clear: 'left'} + } else if (item.style.clear === 'right') { + item.wStyle = {float: 'right'} + } + + delete item.style.clear + if (item.$cardType !== 'extendCard') { _card = item } else if (!_card) { + _config.$extend = true + if (item.setting.width !== 24) { + _config.$empty = false + } precards.push(item) } else { + _config.$extend = true + _config.$empty = false nextcards.push(item) } }) _config.subcards = null - - let _data = null - let _sync = _config.setting.sync === 'true' - - if (_sync && data) { - _data = data[_config.dataName] || [] - _sync = false - } else if (_sync && initdata) { - _data = initdata || [] - _sync = false - } let selected = 'false' if (_config.wrap.selected === 'always' || _config.wrap.selected === 'init' || _config.wrap.selected === 'sign') { selected = _config.wrap.selected } else { _config.wrap.selected = 'false' - } - - if (_data) { - _data = _data.map((item, index) => { - item.key = index - item.$$uuid = item[_config.setting.primaryKey] || '' - item.$$BID = BID || '' - item.$$BData = BData || '' - item.$Index = index + 1 + '' - - if (_config.wrap.controlField) { - if (_config.wrap.controlVal.includes(item[_config.wrap.controlField])) { - item.$disabled = true - } - } - return item - }) - - if (selected !== 'false') { - setTimeout(() => { - this.checkTopLine() - }, 200) - if (selected === 'init') { - selected = 'false' - } - } } let supComs = null @@ -153,29 +134,79 @@ _config.wrap.scale = _config.wrap.scale === 'true' ? 'scale' : '' _config.wrap.layout = (_config.wrap.layout || 'grid') + '-layout float-' + (_config.wrap.cardFloat || 'left') - _config.wrap.wrapClass = `${_config.wrap.selStyle} ${_config.wrap.cardType || ''} ${_config.wrap.scale}` + _config.wrap.wrapClass = `${_config.wrap.selStyle} ${_config.wrap.cardType || ''} ${_config.wrap.scale} ${config.wrap.hover === 'true' ? 'mk-hover' : ''}` - this.loaded = _data !== null + if (_config.wrap.shifting === 'true') { + _config.wrap.shifting = 'shifting' + } else { + _config.wrap.shifting = '' + } + + let pageOptions = ['10', '25', '50', '100', '500', '1000'] + + if (!_config.setting.laypage) { + _config.wrap.pagestyle = 'none' + } + + if (_config.wrap.pagestyle === 'page') { + let size = (_config.setting.pageSize || 10) + '' + if (!pageOptions.includes(size)) { + pageOptions.push(size) + pageOptions = pageOptions.sort((a, b) => a - b) + } + + if (_config.wrap.maxPageSize) { + pageOptions = pageOptions.filter(item => item <= _config.wrap.maxPageSize) + } + } + + let _data = [] + if (_config.setting.sync === 'true') { + _config.setting.onload = 'false' + + if (window.GLOB.SyncData.has(_config.dataName)) { + _data = window.GLOB.SyncData.get(_config.dataName) || [] + + if (_config.$cache) { + Api.writeCacheConfig(_config.uuid, fromJS(_data).toJS(), BID) + } + + _config.setting.sync = 'false' + + _data = _data.map((item, index) => { + item.key = index + item.$$uuid = item[_config.setting.primaryKey] || '' + item.$$BID = BID || '' + item.$$BData = BData || '' + item.$Index = index + 1 + '' + + if (_config.wrap.controlField) { + if (_config.wrap.controlVal.includes(item[_config.wrap.controlField] + '')) { + item.$disabled = true + } + } + return item + }) + + this.loaded = true + + window.GLOB.SyncData.delete(_config.dataName) + } + } this.setState({ + pageSize: _config.setting.pageSize || 10, + pageOptions, supComs, selected, precards, nextcards, - sync: _sync, data: _data, BID: BID || '', BData: BData || '', config: _config, card: _card, - search: Utils.initMainSearch(_config.search), - arr_field: _config.columns.map(col => col.field).join(','), - }, () => { - if (_config.setting.sync !== 'true' && _config.setting.onload === 'true') { - setTimeout(() => { - this.loadData() - }, _config.setting.delay || 0) - } + search: _config.$searches }) } @@ -184,9 +215,18 @@ MKEmitter.addListener('reloadData', this.reloadData) MKEmitter.addListener('mkCheckAll', this.mkCheckAll) + MKEmitter.addListener('refreshLineData', this.refreshLineData) MKEmitter.addListener('resetSelectLine', this.resetParentParam) MKEmitter.addListener('queryModuleParam', this.queryModuleParam) MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult) + + if (config.setting.useMSearch) { + MKEmitter.addListener('searchRefresh', this.searchRefresh) + } + + if (config.setting.sync === 'true') { + MKEmitter.addListener('transferSyncData', this.transferSyncData) + } if (config.timer) { this.timer = new TimerTask() @@ -199,73 +239,13 @@ }) } - if (config.$cache && !this.loaded) { - Api.getLCacheConfig(config.uuid).then(res => { - if (!res || this.loaded) return - let _data = res.map((item, index) => { - item.key = index - item.$$uuid = item[config.setting.primaryKey] || '' - item.$Index = index + 1 + '' + this.initExec() - if (config.wrap.controlField) { - if (config.wrap.controlVal.includes(item[config.wrap.controlField])) { - item.$disabled = true - } - } - - return item - }) - - this.setState({data: _data}) - }) - } + this.autoExec() } shouldComponentUpdate (nextProps, nextState) { return !is(fromJS(this.state), fromJS(nextState)) - } - - UNSAFE_componentWillReceiveProps (nextProps) { - const { sync, config, BID, BData, selected } = this.state - - if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) { - let _data = [] - if (nextProps.data && nextProps.data[config.dataName]) { - _data = nextProps.data[config.dataName] || [] - _data = _data.map((item, index) => { - item.key = index - item.$$uuid = item[config.setting.primaryKey] || '' - item.$$BID = BID || '' - item.$$BData = BData || '' - item.$Index = index + 1 + '' - - if (config.wrap.controlField) { - if (config.wrap.controlVal.includes(item[config.wrap.controlField])) { - item.$disabled = true - } - } - - return item - }) - - if (selected !== 'false') { - setTimeout(() => { - this.checkTopLine() - }, 200) - if (selected === 'init') { - this.setState({selected: 'false'}) - } - } - } - - this.loaded = true - - this.setState({sync: false, data: _data}) - } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - this.setState({pageIndex: 1}, () => { - this.loadData() - }) - } } componentWillUnmount () { @@ -274,11 +254,155 @@ } MKEmitter.removeListener('reloadData', this.reloadData) MKEmitter.removeListener('mkCheckAll', this.mkCheckAll) + MKEmitter.removeListener('searchRefresh', this.searchRefresh) + MKEmitter.removeListener('refreshLineData', this.refreshLineData) MKEmitter.removeListener('resetSelectLine', this.resetParentParam) + MKEmitter.removeListener('transferSyncData', this.transferSyncData) MKEmitter.removeListener('queryModuleParam', this.queryModuleParam) MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult) this.timer && this.timer.stop() + } + + initExec = () => { + const { config, BID } = this.state + + this.loaded && this.prevCheck() + + if (config.$cache) { + if (config.$time && !config.setting.laypage) { + if (!this.loaded) { + Api.getLCacheConfig(config.uuid, config.$time, BID).then(res => { + if (!res.valid && config.setting.onload === 'true') { + setTimeout(() => { + this.loadData('', 'init') + }, config.setting.delay || 0) + } + + if (!res.data || this.loaded) return + + let _data = res.data.map((item, index) => { + item.key = index + item.$$uuid = item[config.setting.primaryKey] || '' + item.$Index = index + 1 + '' + + if (config.wrap.controlField) { + if (config.wrap.controlVal.includes(item[config.wrap.controlField] + '')) { + item.$disabled = true + } + } + + return item + }) + + this.setState({data: _data}, () => { + this.prevCheck() + }) + }) + } + } else { + if (!this.loaded) { + Api.getLCacheConfig(config.uuid, 0, BID).then(res => { + if (!res.data || this.loaded) return + + let _data = res.data.map((item, index) => { + item.key = index + item.$$uuid = item[config.setting.primaryKey] || '' + item.$Index = index + 1 + '' + + if (config.wrap.controlField) { + if (config.wrap.controlVal.includes(item[config.wrap.controlField] + '')) { + item.$disabled = true + } + } + + return item + }) + + this.setState({data: _data}) + }) + } + + if (config.setting.onload === 'true') { + setTimeout(() => { + this.loadData('', 'init') + }, config.setting.delay || 0) + } + } + } else if (config.setting.onload === 'true') { + setTimeout(() => { + this.loadData() + }, config.setting.delay || 0) + } + } + + autoExec = (times) => { + const { config } = this.state + + if (!config.wrap.autoExec) return + + let btn = document.getElementById('button' + config.wrap.autoExec) + + this.autoTimer && clearTimeout(this.autoTimer) + + if (btn) { + MKEmitter.emit('triggerBtnId', config.wrap.autoExec, []) + } else if (!times || times < 20) { + times = times ? times + 1 : 1 + this.autoTimer = setTimeout(() => { + this.autoExec(times) + }, 1000) + } + } + + transferSyncData = (syncId) => { + const { config } = this.state + + if (config.$syncId !== syncId) return + + const { BID, BData } = this.state + + let _data = window.GLOB.SyncData.get(config.dataName) || [] + + if (config.$cache) { + Api.writeCacheConfig(config.uuid, fromJS(_data).toJS(), BID) + } + + _data = _data.map((item, index) => { + item.key = index + item.$$uuid = item[config.setting.primaryKey] || '' + item.$$BID = BID || '' + item.$$BData = BData || '' + item.$Index = index + 1 + '' + + if (config.wrap.controlField) { + if (config.wrap.controlVal.includes(item[config.wrap.controlField] + '')) { + item.$disabled = true + } + } + + return item + }) + + this.prevCheck() + + this.loaded = true + + this.setState({data: _data}) + + window.GLOB.SyncData.delete(config.dataName) + + MKEmitter.removeListener('transferSyncData', this.transferSyncData) + } + + searchRefresh = (searchId) => { + const { config } = this.state + + if (config.$searchId !== searchId) return + + this.setState({pageIndex: 1}, () => { + this.loadData() + }) } /** @@ -305,9 +429,9 @@ }, i * 10) }) } else { - if (position === 'line') { + if (position === 'line' || position === 'line_grid') { if (lines && lines.length === 1) { - this.loadLinedata(lines[0].$$uuid) + this.loadLinedata(lines[0].$$uuid, position) } else { this.loadData(id) } @@ -324,9 +448,9 @@ } else { let supModule = config.setting.supModule - if (position === 'line') { + if (position === 'line' || position === 'line_grid') { if (lines && lines.length === 1) { - this.loadLinedata(lines[0].$$uuid) + this.loadLinedata(lines[0].$$uuid, position) } else { this.loadData(id) } @@ -342,16 +466,43 @@ this.loadData(id) } } + } - if (position === 'popclose') { // 鎵ц鍚姩寮圭獥鐨勬寜閽墍閫夋嫨鐨勫埛鏂伴」 - btn.$tabId && MKEmitter.emit('refreshPopButton', btn.$tabId) + refreshLineData = (menuId, btn, uuid, count) => { + const { config, data } = this.state + + if (config.uuid !== menuId) return + + let _data = fromJS(data).toJS().map(item => { + if (item.$$uuid === uuid) { + item[btn.field] = count + } + return item + }) + + this.setState({ + data: _data + }) + } + + prevCheck = (id) => { + const { selected } = this.state + + if (selected === 'false' && !id) return + + setTimeout(() => { + this.checkTopLine(id) + }, 10) + + if (selected === 'init') { + this.setState({selected: 'false'}) } } checkTopLine = (id) => { const { config, data, selected } = this.state - if (!data || data.length === 0) { + if (data.length === 0) { this.setState({ activeKey: '', selectKeys: [], @@ -472,7 +623,8 @@ checkAll = () => { const { config, data, selectedData } = this.state - if (!data || data.length === 0) return + if (config.wrap.cardType !== 'checkbox') return + if (data.length === 0) return if (selectedData.length === 0 || selectedData.length < data.length) { let index = '' @@ -553,7 +705,9 @@ if (!config.setting.supModule || config.setting.supModule !== MenuID) return if (id !== this.state.BID || id !== '') { this.setState({ BID: id, BData: data, pageIndex: 1 }, () => { - this.loadData() + if (!config.checkBid) { + this.loadData() + } }) } } @@ -563,35 +717,33 @@ * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁� */ queryModuleParam = (menuId, callback) => { - const { mainSearch } = this.props - const { arr_field, config, search } = this.state + const { config, search, orderBy } = this.state if (config.uuid !== menuId) return - let searches = search ? fromJS(search).toJS() : [] - if (config.setting.useMSearch && mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 - let keys = searches.map(item => item.key.toLowerCase()) + let searches = fromJS(search).toJS() + if (config.setting.useMSearch) { // 涓昏〃鎼滅储鏉′欢 + let mainSearch = window.GLOB.SearchBox.get(config.$searchId) || [] + let keys = config.$s_keys || [] mainSearch.forEach(item => { - if (!keys.includes(item.key.toLowerCase())) { - searches.push(item) - } + if (keys.includes(item.key.toLowerCase())) return + + searches.push(item) }) } callback({ - arr_field: arr_field, - orderBy: config.setting.order || '', - search: searches, - menuName: config.name + orderBy: orderBy || config.setting.order || '', + search: searches }) } async loadData (id, type) { - const { mainSearch } = this.props - const { config, arr_field, pageIndex, search, BID, BData, selected } = this.state + const { config, pageIndex, pageSize, search, BID, BData, selected, orderBy } = this.state if (config.setting.supModule && !BID && config.wrap.supKey !== 'false') { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇� this.loaded = true + this.requestId = '' this.setState({ activeKey: '', @@ -604,12 +756,7 @@ }) if (selected !== 'false' || (id && config.wrap.selected !== 'false')) { - setTimeout(() => { - this.checkTopLine(id) - }, 200) - if (selected === 'init') { - this.setState({selected: 'false'}) - } + this.prevCheck(id) } else { MKEmitter.emit('resetSelectLine', config.uuid, '', '') if (config.setting.$hasSyncModule) { @@ -620,17 +767,17 @@ } let searches = fromJS(search).toJS() - if (config.setting.useMSearch && mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 - let keys = searches.map(item => item.key.toLowerCase()) + if (config.setting.useMSearch) { // 涓昏〃鎼滅储鏉′欢 + let mainSearch = window.GLOB.SearchBox.get(config.$searchId) || [] + let keys = config.$s_keys || [] mainSearch.forEach(item => { - if (!keys.includes(item.key.toLowerCase())) { - searches.push(item) - } + if (keys.includes(item.key.toLowerCase())) return + + searches.push(item) }) } - let requireFields = searches.filter(item => item.required && item.value === '') - if (requireFields.length > 0) { + if (config.$s_req && searches.filter(item => item.required && item.value === '').length > 0) { return } @@ -640,28 +787,27 @@ }) } - let _orderBy = config.setting.order || '' - let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, pageIndex, config.setting.pageSize, BID) + let _orderBy = orderBy || config.setting.order || '' + let param = UtilsDM.getQueryDataParams(config.setting, searches, _orderBy, pageIndex, pageSize, BID) - let result = await Api.genericInterface(param) + this.requestId = config.uuid + new Date().getTime() + + let result = await Api.genericInterface(param, '', '', this.requestId) if (result.status) { + if (result.$requestId && this.requestId !== result.$requestId) return + let start = 1 if (config.setting.laypage) { - start = config.setting.pageSize * (pageIndex - 1) + 1 + start = pageSize * (pageIndex - 1) + 1 } this.loaded = true - if (config.$cache && pageIndex === 1) { - Api.writeCacheConfig(config.uuid, result.data || '') + if (config.$cache && type === 'init') { + Api.writeCacheConfig(config.uuid, result.data || [], BID) } if (selected !== 'false' || (id && config.wrap.selected !== 'false')) { - setTimeout(() => { - this.checkTopLine(id) - }, 200) - if (selected === 'init') { - this.setState({selected: 'false'}) - } + this.prevCheck(id) } else { MKEmitter.emit('resetSelectLine', config.uuid, '', '') if (config.setting.$hasSyncModule) { @@ -681,7 +827,7 @@ item.$Index = index + 1 + '' if (config.wrap.controlField) { - if (config.wrap.controlVal.includes(item[config.wrap.controlField])) { + if (config.wrap.controlVal.includes(item[config.wrap.controlField] + '')) { item.$disabled = true } } @@ -696,7 +842,7 @@ item.$Index = index + start + '' if (config.wrap.controlField) { - if (config.wrap.controlVal.includes(item[config.wrap.controlField])) { + if (config.wrap.controlVal.includes(item[config.wrap.controlField] + '')) { item.$disabled = true } } @@ -704,24 +850,52 @@ }) } + let total = result.total || 0 + if (config.setting.custompage && data.length) { + total = data[data.length - 1].mk_total || 0 + } + this.setState({ activeKey: '', selectKeys: [], selectedData: [], data: data, - total: result.total, + total: total, + pickup: false, loading: false }) + + if (config.timer && config.clearField && result.data && result.data[0]) { + let vals = (config.clearValue || '').split(',') + if (vals.includes(result.data[0][config.clearField])) { + this.timer && this.timer.stop() + } + } + if (result.message) { + if (result.ErrCode === 'Y') { + Modal.success({ + title: result.message + }) + } else if (result.ErrCode === 'S') { + notification.success({ + top: 92, + message: result.message, + duration: 2 + }) + } + } } else { this.setState({ loading: false }) this.timer && this.timer.stop() + + if (!result.message) return if (result.ErrCode === 'N') { Modal.error({ title: result.message, }) - } else { + } else if (result.ErrCode !== '-2') { notification.error({ top: 92, message: result.message, @@ -734,17 +908,26 @@ /** * @description 鑾峰彇鍗曡鏁版嵁 */ - async loadLinedata (id) { - const { mainSearch } = this.props - const { config, arr_field, pageIndex, search, BID, BData } = this.state + async loadLinedata (id, position) { + const { config, pageIndex, pageSize, search, BID, BData, orderBy } = this.state + + if (config.forbidLine) { + this.setState({ + pageIndex: 1 + }, () => { + this.loadData() + }) + return + } let searches = fromJS(search).toJS() - if (config.setting.useMSearch && mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 - let keys = searches.map(item => item.key.toLowerCase()) + if (config.setting.useMSearch) { // 涓昏〃鎼滅储鏉′欢 + let mainSearch = window.GLOB.SearchBox.get(config.$searchId) || [] + let keys = config.$s_keys || [] mainSearch.forEach(item => { - if (!keys.includes(item.key.toLowerCase())) { - searches.push(item) - } + if (keys.includes(item.key.toLowerCase())) return + + searches.push(item) }) } @@ -752,39 +935,110 @@ loading: true }) - let _orderBy = config.setting.order || '' - let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, pageIndex, config.setting.pageSize, BID, id) + let _orderBy = orderBy || config.setting.order || '' + let param = UtilsDM.getQueryDataParams(config.setting, searches, _orderBy, pageIndex, pageSize, BID, id) let result = await Api.genericInterface(param) if (result.status) { - let data = fromJS(this.state.data).toJS() - if (result.data && result.data[0]) { - let _data = result.data[0] - - try { - data = data.map(item => { - if (item[config.setting.primaryKey] === _data[config.setting.primaryKey]) { - _data.key = item.key - _data.$$uuid = _data[config.setting.primaryKey] || '' - _data.$$BID = BID || '' - _data.$$BData = BData || '' - _data.$Index = item.$Index - return _data - } else { - return item - } - }) - } catch (e) { - console.warn('鏁版嵁鏌ヨ閿欒') - } - - MKEmitter.emit('resetSelectLine', config.uuid, _data.$$uuid || '', _data) + if (position === 'line_grid' && (!result.data || !result.data[0])) { + this.loadData() + return } - this.setState({ - data: data, - loading: false - }) + let data = fromJS(this.state.data).toJS() + let selectedData = fromJS(this.state.selectedData).toJS() + let selectKeys = fromJS(this.state.selectKeys).toJS() + let activeKey = this.state.activeKey + + if (result.data && result.data[0]) { + let _data = result.data[0] + _data.$$uuid = _data[config.setting.primaryKey] || '' + _data.$$BID = BID || '' + _data.$$BData = BData || '' + + data = data.map(item => { + if (item.$$uuid === _data.$$uuid) { + _data.key = item.key + _data.$Index = item.$Index + return _data + } + return item + }) + + if (!_data.$Index) { + this.setState({ + loading: false + }) + return + } + + selectedData = selectedData.map(item => { + if (item.$$uuid === _data.$$uuid) { + return _data + } + return item + }) + + this.setState({ + data: data, + selectedData: selectedData, + loading: false + }) + + if (_data.key === activeKey) { + MKEmitter.emit('resetSelectLine', config.uuid, _data.$$uuid || '', _data) + } + if (config.setting.$hasSyncModule) { + MKEmitter.emit('syncBalconyData', config.uuid, selectedData, data.length === selectedData.length) + } + } else { + let index = data.findIndex(item => item.$$uuid === id) + + if (index === -1) { + this.setState({ + loading: false + }) + return + } + + data = data.filter(item => item.$$uuid !== id) + data = data.map((item, i) => { + item.key = i + return item + }) + + let trans = activeKey === index + let _item = null + + if (config.wrap.cardType) { + selectKeys = selectKeys.filter(key => key !== index) + selectKeys = selectKeys.map(key => key > index ? key - 1 : key) + + selectedData = selectKeys.map(key => data[key]).filter(Boolean) + + activeKey = selectKeys.length ? selectKeys[selectKeys.length - 1] : '' + + if (trans && selectedData.length) { + _item = selectedData[selectedData.length - 1] + } + } + + this.setState({ + data: data, + activeKey: activeKey, + selectKeys: selectKeys, + selectedData: selectedData, + loading: false + }) + + if (trans) { + MKEmitter.emit('resetSelectLine', config.uuid, (_item ? _item.$$uuid : ''), _item) + } + + if (config.setting.$hasSyncModule) { + MKEmitter.emit('syncBalconyData', config.uuid, selectedData, data.length === selectedData.length) + } + } } else { this.setState({ loading: false @@ -798,9 +1052,9 @@ } loadMore = () => { - const { total, pageIndex, loading, config } = this.state + const { total, pageIndex, pageSize, loading } = this.state - if (loading || config.setting.pageSize * pageIndex >= total) { + if (loading || pageSize * pageIndex >= total) { return } @@ -824,8 +1078,8 @@ } nextPage = () => { - const { config, pageIndex, total } = this.state - let _total = config.setting.pageSize * pageIndex + const { pageIndex, pageSize, total } = this.state + let _total = pageSize * pageIndex if (_total >= total) return @@ -848,6 +1102,15 @@ this.setState({ search: list, pageIndex: 1 + }, () => { + this.loadData() + }) + } + + pageSizeChange = (current, size) => { + this.setState({ + pageIndex: current, + pageSize: size }, () => { this.loadData() }) @@ -883,6 +1146,7 @@ if (activeKey === index) return _selectedData = [item] + _selectKeys = [index] _activeKey = index } @@ -898,22 +1162,46 @@ } } - render() { - const { config, precards, nextcards, loading, data, pageIndex, total, card, activeKey, BID, BData, selectedData, selectKeys } = this.state + refreshByHeader = (sorter) => { + this.setState({ + orderBy: sorter || '' + }, () => { + this.loadData() + }) + } - if (config.wrap.empty === 'hidden' && (!data || data.length === 0)) return null + pickupChange = () => { + this.setState({ + pickup: !this.state.pickup + }) + } + + render() { + const { config, precards, nextcards, loading, pageIndex, pageSize, total, card, activeKey, BID, BData, selectedData, selectKeys, pickup } = this.state + + let data = this.state.data + + if (config.wrap.empty === 'hidden' && data.length === 0) return null let _total = 0 let switchable = false - if (config.wrap.pagestyle === 'switch' && config.pageable && config.setting.laypage && total > config.setting.pageSize && data) { - _total = config.setting.pageSize * pageIndex + if (config.wrap.pagestyle === 'switch' && total > pageSize) { + _total = pageSize * pageIndex switchable = true } - let extendData = {$$BID: BID, $$BData: BData, $$selectedData: selectedData, $$type: 'extendCard'} + let extendData = null - if (data && data[0]) { - extendData = {...extendData, ...data[0]} + if (config.$extend) { + extendData = {$$BID: BID, $$BData: BData, $$selectedData: selectedData, $$type: 'extendCard'} + + if (data[0]) { + if (selectedData[0]) { + extendData = {...extendData, ...selectedData[0]} + } else { + extendData = {...extendData, ...data[0]} + } + } } let checkAll = '' @@ -923,11 +1211,15 @@ } } + if (pickup) { + data = data.filter(item => selectKeys.includes(item.key)) + } + return ( - <div className="custom-data-card-box" id={'anchor' + config.uuid} style={config.style}> + <div className={'custom-data-card-box ' + config.wrap.shifting} id={'anchor' + config.uuid} style={config.style}> {loading ? <div className="loading-mask"> - {data ? <div className="ant-spin-blur"></div> : null} + {data.length ? <div className="ant-spin-blur"></div> : null} <Spin /> </div> : null } @@ -942,52 +1234,57 @@ selectedData={selectedData} /> : null } + {config.wrap.pickup === 'true' && this.state.data.length > 0 ? <div className="pickup-wrap"><Switch title="鏀惰捣" checkedChildren="寮�" unCheckedChildren="鍏�" checked={pickup} onChange={this.pickupChange} /></div> : null} <div className={`data-zoom ${config.wrap.wrapClass}`}> {switchable ? <div className={'prev-page ' + (pageIndex === 1 ? 'disabled' : '')} onClick={this.prevPage}><div><div><img src={preImg} alt=""/></div></div></div> : null} <Row className={'card-row-list ' + config.wrap.layout}> {precards.map((item, index) => ( - <Col key={'pre' + index} className="extend-card" span={item.setting.width || 6}> - <CardItem card={item} cards={config} data={extendData}> + <Col key={'pre' + index} className="extend-card" style={item.wStyle} span={item.setting.width || 6}> + {item.setting.cardRole === 'header' ? <TableHeader card={item} data={extendData} refresh={this.refreshByHeader}> {item.setting.checkAll === 'show' ? <span onClick={this.checkAll} className={'circle-select' + checkAll}></span> : null} - </CardItem> + </TableHeader> : <CardItem card={item} cards={config} data={extendData}> + {item.setting.checkAll === 'show' ? <span onClick={this.checkAll} className={'circle-select' + checkAll}></span> : null} + </CardItem>} </Col> ))} - {data && data.map((item, index) => { + {data.map((item, index) => { let className = 'mk-card ' if (config.wrap.parity === 'true') { if (index % 2 === 1) { - className += 'mk-parity-bg ' + className += 'mk-even-line ' } } if (item.$disabled) { className = 'mk-disabled' - } else if (activeKey === index) { + } else if (activeKey === item.key) { className += 'active' - } else if (selectKeys.indexOf(index) > -1) { + } else if (selectKeys.indexOf(item.key) > -1) { className += 'selected' } return ( - <Col className={className} key={index} span={card.setting.width}> - <CardItem card={card} cards={config} data={item} onClick={() => {this.changeCard(index, item)}}> + <Col className={className} key={index} style={card.wStyle} span={card.setting.width}> + <CardItem card={card} cards={config} data={item} onClick={() => {this.changeCard(item.key, item)}}> <span className="circle-select"></span> </CardItem> </Col> ) })} {nextcards.map((item, index) => ( - <Col key={'next' + index} className="extend-card" span={item.setting.width || 6}> - <CardItem card={item} cards={config} data={extendData}> + <Col key={'next' + index} className="extend-card" style={item.wStyle} span={item.setting.width || 6}> + {item.setting.cardRole === 'header' ? <TableHeader card={item} data={extendData} refresh={this.refreshByHeader}> {item.setting.checkAll === 'show' ? <span onClick={this.checkAll} className={'circle-select' + checkAll}></span> : null} - </CardItem> + </TableHeader> : <CardItem card={item} cards={config} data={extendData}> + {item.setting.checkAll === 'show' ? <span onClick={this.checkAll} className={'circle-select' + checkAll}></span> : null} + </CardItem>} </Col> ))} </Row> {switchable ? <div className={'prev-page ' + (total <= _total ? 'disabled' : '')} onClick={this.nextPage}><div><div><img src={nextImg} alt=""/></div></div></div> : null} - {precards.length === 0 && nextcards.length === 0 && (!data || data.length === 0) ? <Empty description={false}/> : null} </div> - {config.wrap.pagestyle === 'page' && config.setting.laypage && data ? <Pagination size="small" total={total} showTotal={t => `鍏� ${t} 鏉} pageSize={config.setting.pageSize} onChange={this.changePageIndex} current={pageIndex}/> : null} - {config.wrap.pagestyle === 'more' && config.setting.laypage && data && data.length > 0 ? <div className={'mk-more' + (config.setting.pageSize * pageIndex >= total ? ' disabled' : '')} onClick={this.loadMore}>鏌ョ湅鏇村<DownOutlined/></div> : null} + {config.$empty && data.length === 0 ? <Empty description={false}/> : null} + {config.wrap.pagestyle === 'page' ? <Pagination size="small" total={total} showTotal={(t, range) => total > 0 ? `${range[0]}-${range[1]} 鍏� ${total} 鏉 : `鍏� ${total} 鏉} pageSize={pageSize} showSizeChanger={true} pageSizeOptions={this.state.pageOptions} onChange={this.changePageIndex} onShowSizeChange={this.pageSizeChange} current={pageIndex}/> : null} + {config.wrap.pagestyle === 'more' && data.length > 0 ? <div className={'mk-more' + (pageSize * pageIndex >= total ? ' disabled' : '')} onClick={this.loadMore}>鏌ョ湅鏇村<DownOutlined/></div> : null} </div> ) } -- Gitblit v1.8.0