| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Spin, notification, Timeline, Empty } from 'antd' |
| | | import { Spin, notification, Timeline, Empty, Modal } from 'antd' |
| | | |
| | | import Api from '@/api' |
| | | import MkIcon from '@/components/mk-icon' |
| | | import asyncComponent from '@/utils/asyncComponent' |
| | | import UtilsDM from '@/utils/utils-datamanage.js' |
| | | import MKEmitter from '@/utils/events.js' |
| | | import TimerTask from '@/utils/timer-task.js' |
| | | import './index.scss' |
| | | |
| | | const CardCellComponent = asyncComponent(() => import('@/tabviews/custom/components/card/cardcellList')) |
| | |
| | | |
| | | class NormalTimeline extends Component { |
| | | static propTpyes = { |
| | | BID: PropTypes.any, // 父级Id |
| | | data: PropTypes.array, // 统一查询数据 |
| | | config: PropTypes.object, // 组件配置信息 |
| | | mainSearch: PropTypes.any, // 外层搜索条件 |
| | | menuType: PropTypes.any, // 菜单类型 |
| | | } |
| | | |
| | | state = { |
| | |
| | | sync: false, // 是否统一请求数据 |
| | | data: null, // 数据 |
| | | BData: '', |
| | | card: null |
| | | card: null, |
| | | description: false |
| | | } |
| | | |
| | | /** |
| | |
| | | * 1、 initdata 为打印时使用的数据集 |
| | | */ |
| | | UNSAFE_componentWillMount () { |
| | | const { data, initdata, BID, BData } = this.props |
| | | const { data, initdata } = this.props |
| | | let _config = fromJS(this.props.config).toJS() |
| | | let _cols = new Map() |
| | | |
| | | let _data = null |
| | | let card = null |
| | | let _sync = _config.setting.sync === 'true' |
| | | |
| | | let BID = '' |
| | | let BData = '' |
| | | |
| | | if (_config.setting.supModule) { |
| | | BData = window.GLOB.CacheData.get(_config.setting.supModule) |
| | | } else { |
| | | BData = window.GLOB.CacheData.get(_config.$pageId) |
| | | } |
| | | if (BData) { |
| | | BID = BData.$BID || '' |
| | | } |
| | | |
| | | if (_config.setting.sync === 'true' && data) { |
| | | _data = data[_config.dataName] || [] |
| | |
| | | item.key = index |
| | | item.$$uuid = item[_config.setting.primaryKey] || '' |
| | | item.$$BID = BID || '' |
| | | item.$$BData = BData || '' |
| | | item.$Index = index + 1 + '' |
| | | return item |
| | | }) |
| | |
| | | _config.wrap.contentHeight = _config.wrap.title ? 'calc(100% - 45px)' : '100%' |
| | | |
| | | _config.columns.forEach(item => { |
| | | if (item.type !== 'number') return |
| | | _cols.set(item.field, item) |
| | | }) |
| | | |
| | | card = _config.subcards[0] |
| | | card.elements = card.elements.map(item => { |
| | | if (item.field && _cols.has(item.field)) { |
| | | item.col = _cols.get(item.field) |
| | | if (item.eleType === 'number' && item.field && _cols.has(item.field) && typeof(item.decimal) !== 'number') { |
| | | item.decimal = _cols.get(item.field).decimal || 0 |
| | | } |
| | | return item |
| | | }) |
| | |
| | | arr_field: _config.columns.map(col => col.field).join(','), |
| | | }, () => { |
| | | if (_config.setting.sync !== 'true' && _config.setting.onload === 'true') { |
| | | this.loadData() |
| | | setTimeout(() => { |
| | | this.loadData() |
| | | }, _config.setting.delay || 0) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | componentDidMount () { |
| | | const { config } = this.state |
| | | |
| | | MKEmitter.addListener('reloadData', this.reloadData) |
| | | MKEmitter.addListener('resetSelectLine', this.resetParentParam) |
| | | MKEmitter.addListener('queryModuleParam', this.queryModuleParam) |
| | | MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult) |
| | | |
| | | if (config.timer) { |
| | | this.timer = new TimerTask() |
| | | this.timer.init(config.uuid, config.timer, config.timerRepeats, () => { |
| | | this.loadData(true) |
| | | }) |
| | | } |
| | | } |
| | | |
| | | shouldComponentUpdate (nextProps, nextState) { |
| | |
| | | MKEmitter.removeListener('resetSelectLine', this.resetParentParam) |
| | | MKEmitter.removeListener('queryModuleParam', this.queryModuleParam) |
| | | MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult) |
| | | |
| | | this.timer && this.timer.stop() |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | if (config.uuid !== menuId) return |
| | | |
| | | this.loadData(btn) // 数据刷新 |
| | | |
| | | if (btn.syncComponentId && btn.syncComponentId !== config.uuid && btn.syncComponentId !== config.setting.supModule) { |
| | | MKEmitter.emit('reloadData', btn.syncComponentId) // 同级标签刷新 |
| | | if ((position === 'mainline' || position === 'popclose') && config.setting.supModule && BID) { // 刷新源组件时,附带刷新上级行与当前组件 |
| | | MKEmitter.emit('reloadData', config.setting.supModule, BID) |
| | | } else { |
| | | this.loadData() |
| | | } |
| | | |
| | | if (position === 'mainline' && config.setting.supModule) { // 主表行刷新 |
| | | MKEmitter.emit('reloadData', config.setting.supModule, (BID || 'empty')) |
| | | } else if (position === 'popclose') { // 标签关闭刷新 |
| | | config.setting.supModule && MKEmitter.emit('reloadData', config.setting.supModule, (BID || 'empty')) |
| | | if (position === 'popclose') { // 执行启动弹窗的按钮所选择的刷新项 |
| | | btn.$tabId && MKEmitter.emit('refreshPopButton', btn.$tabId) |
| | | } |
| | | } |
| | |
| | | /** |
| | | * @description 导出Excel时,获取页面搜索排序等参数 |
| | | */ |
| | | queryModuleParam = (menuId, btnId) => { |
| | | queryModuleParam = (menuId, callback) => { |
| | | const { mainSearch } = this.props |
| | | const { arr_field, config } = this.state |
| | | |
| | |
| | | }) |
| | | } |
| | | |
| | | MKEmitter.emit('returnModuleParam', config.uuid, btnId, { |
| | | callback({ |
| | | arr_field: arr_field, |
| | | orderBy: config.setting.order || '', |
| | | search: searches, |
| | |
| | | }) |
| | | } |
| | | |
| | | async loadData () { |
| | | const { mainSearch, menuType } = this.props |
| | | async loadData (hastimer) { |
| | | const { mainSearch } = this.props |
| | | const { config, arr_field, BID, BData } = this.state |
| | | |
| | | |
| | | if (config.setting.supModule && !BID) { // BID 不存在时,不做查询 |
| | | this.setState({ |
| | | data: [], |
| | | }) |
| | | return |
| | | } |
| | | |
| | | if (config.setting.interType === 'inner' && config.setting.innerFunc === 'z_mk_express') { |
| | | this.getExpress() |
| | | return |
| | | } |
| | | |
| | |
| | | return |
| | | } |
| | | |
| | | this.setState({ |
| | | loading: true |
| | | }) |
| | | if (!hastimer) { |
| | | this.setState({ |
| | | loading: true |
| | | }) |
| | | } |
| | | |
| | | let _orderBy = config.setting.order || '' |
| | | let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, 1, config.setting.pageSize, BID, menuType) |
| | | let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, 1, config.setting.pageSize, BID) |
| | | |
| | | let result = await Api.genericInterface(param) |
| | | if (result.status) { |
| | |
| | | this.setState({ |
| | | loading: false |
| | | }) |
| | | notification.error({ |
| | | top: 92, |
| | | message: result.message, |
| | | duration: 10 |
| | | this.timer && this.timer.stop() |
| | | |
| | | if (result.ErrCode === 'N') { |
| | | Modal.error({ |
| | | title: result.message, |
| | | }) |
| | | } else { |
| | | notification.error({ |
| | | top: 92, |
| | | message: result.message, |
| | | duration: 10 |
| | | }) |
| | | } |
| | | } |
| | | } |
| | | |
| | | getExpress = () => { |
| | | const { BData } = this.state |
| | | |
| | | let code = '' |
| | | let order = '' |
| | | if (BData) { |
| | | Object.keys(BData).forEach(key => { |
| | | if (key.toLowerCase() === 'expresscode') { |
| | | code = BData[key] |
| | | } else if (key.toLowerCase() === 'expressno') { |
| | | order = BData[key] |
| | | } |
| | | }) |
| | | } |
| | | |
| | | if (!code || !order) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '未获取到快递' + (!code ? '公司编码。' : '单号。'), |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } |
| | | |
| | | this.setState({ |
| | | loading: true |
| | | }) |
| | | Api.wxNginxRequest(`express/${code}/${order}`, 'get').then(res => { |
| | | if (!res || typeof(res) !== 'string') { |
| | | notification.error({ |
| | | top: 92, |
| | | message: '未获取到快递信息', |
| | | duration: 10 |
| | | }) |
| | | } else if (/查询无结果/.test(res)) { |
| | | this.setState({description: res, data: [], loading: false}) |
| | | } else { |
| | | let data = res.split(/\n/).filter(Boolean) |
| | | |
| | | data = data.map((item, i) => { |
| | | return { |
| | | $Index: i, |
| | | date: item.substr(0, 19), |
| | | content: item.substr(20) |
| | | } |
| | | }) |
| | | |
| | | this.setState({ |
| | | data: data, |
| | | loading: false |
| | | }) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | getnodes = (data) => { |
| | |
| | | </Timeline.Item>) |
| | | } |
| | | |
| | | getMknodes = (data) => { |
| | | const { config, card } = this.state |
| | | |
| | | let color = config.wrap.color |
| | | let dot = '' |
| | | let linebg = {} |
| | | if (config.wrap.node && card.nodes && card.nodes.length > 0) { |
| | | let sign = data[config.wrap.node] |
| | | card.nodes.some(item => { |
| | | if (sign === item.sign) { |
| | | color = item.color |
| | | |
| | | if (item.icon) { |
| | | dot = <MkIcon type={item.icon}/> |
| | | } |
| | | |
| | | if (item.linecolor) { |
| | | linebg = {borderColor: item.linecolor} |
| | | } |
| | | return true |
| | | } |
| | | return false |
| | | }) |
| | | } |
| | | |
| | | if (config.wrap.mode === 'down') { |
| | | return (<div className="mk-time-line-item" key={data.$Index}> |
| | | <div className="mk-timeline-item-content"> |
| | | <div className="card-item-box" style={card.style}> |
| | | <CardCellComponent data={data} cards={config} cardCell={card} elements={card.elements}/> |
| | | </div> |
| | | </div> |
| | | <div className="mk-timeline-item-head"> |
| | | <div className="mk-timeline-item-tail" style={linebg}></div> |
| | | <div className={'mk-dot ' + (dot ? 'mk-dot-icon' : '')} style={{background: color}}> |
| | | {dot} |
| | | </div> |
| | | </div> |
| | | </div>) |
| | | } else { |
| | | return (<div className="mk-time-line-item" key={data.$Index}> |
| | | <div className="mk-timeline-item-head"> |
| | | <div className="mk-timeline-item-tail" style={linebg}></div> |
| | | <div className={'mk-dot ' + (dot ? 'mk-dot-icon' : '')} style={{background: color}}> |
| | | {dot} |
| | | </div> |
| | | </div> |
| | | <div className="mk-timeline-item-content"> |
| | | <div className="card-item-box" style={card.style}> |
| | | <CardCellComponent data={data} cards={config} cardCell={card} elements={card.elements}/> |
| | | </div> |
| | | </div> |
| | | </div>) |
| | | } |
| | | } |
| | | |
| | | render() { |
| | | const { config, loading, data } = this.state |
| | | const { config, loading, data, description } = this.state |
| | | |
| | | return ( |
| | | <div className="normal-timeline-box" style={{...config.style}}> |
| | | <div className="normal-timeline-box" id={'anchor' + config.uuid} style={{...config.style}}> |
| | | {loading ? |
| | | <div className="loading-mask"> |
| | | {data ? <div className="ant-spin-blur"></div> : null} |
| | |
| | | </div> : null |
| | | } |
| | | <NormalHeader config={config} /> |
| | | {data && data.length > 0 ? <Timeline mode={config.wrap.mode} reverse={config.wrap.reverse === 'true'} className={'card-row-list ' + (config.wrap.line || '')} style={{height: config.wrap.contentHeight}}> |
| | | {config.wrap.direction !== 'horizontal' && data && data.length > 0 ? <Timeline mode={config.wrap.mode} className={'card-row-list ' + (config.wrap.line || '')} style={{height: config.wrap.contentHeight}}> |
| | | {data.map(item => this.getnodes(item))} |
| | | </Timeline> : null} |
| | | {config.wrap.direction === 'horizontal' && data && data.length > 0 ? <div className={'mk-time-line-wrap card-row-list ' + (config.wrap.line || '')} style={{height: config.wrap.contentHeight}}> |
| | | {data.map(item => this.getMknodes(item))} |
| | | </div> : null} |
| | | {data && data.length === 0 ? <div className="card-row-list" style={{height: config.wrap.contentHeight}}> |
| | | <Empty description={false}/> |
| | | <Empty description={description}/> |
| | | </div> : null} |
| | | </div> |
| | | ) |