import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
// import { is, fromJS } from 'immutable'
|
import { Button, Affix, Modal, notification } from 'antd'
|
import Api from '@/api'
|
import './index.scss'
|
|
const { confirm } = Modal
|
|
class MainAction extends Component {
|
static propTpyes = {
|
MenuNo: PropTypes.string,
|
actions: PropTypes.array, // 搜索条件列表
|
dict: PropTypes.object, // 字典项
|
fixed: PropTypes.any
|
}
|
|
state = {
|
|
}
|
|
refreshdata = () => {
|
this.props.refreshdata()
|
}
|
actionTrigger = (item) => {
|
let _this = this
|
let data = this.props.gettableselected()
|
if (item.Ot === 'required' && (!data || data.length === 0)) {
|
// 需要选择行时,校验数据
|
notification.warning({
|
top: 92,
|
message: this.props.dict['main.action.confirm.selectline']
|
})
|
return
|
}
|
|
if (item.Action === 'Prompt' || item.Action === 'Delete') {
|
confirm({
|
title: this.props.dict['main.action.confirm.tip'],
|
onOk() {
|
return Api.setActionSubmit({
|
func: 'SetActionSubmitSuccess'
|
// func: 'SetActionSubmitError'
|
}).then((res) => {
|
if (res.status) {
|
notification.success({
|
top: 92,
|
message: _this.props.dict['main.action.confirm.success']
|
// duration: 0
|
// description:
|
})
|
_this.refreshdata()
|
} else {
|
notification.error({
|
top: 92,
|
message: res.message
|
})
|
}
|
})
|
},
|
onCancel() {}
|
})
|
}
|
}
|
|
UNSAFE_componentWillMount () {
|
|
}
|
|
// shouldComponentUpdate (nextProps, nextState) {
|
// console.log(!is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)))
|
// return true
|
// }
|
|
render() {
|
if (this.props.fixed) { // 按钮是否固定在头部
|
return (
|
<Affix offsetTop={48}>
|
<div className="button-list" id={this.props.MenuNo + 'mainaction'}>
|
{this.props.actions.map((item, index) => {
|
return (
|
<Button
|
className={'mk-btn ' + item.CssClass}
|
icon={item.Icon}
|
key={'action' + index}
|
onClick={() => {this.actionTrigger(item)}}
|
>{item.MenuName}</Button>
|
)
|
})}
|
</div>
|
</Affix>
|
)
|
}
|
return (
|
<div className="button-list">
|
{this.props.actions.map((item, index) => {
|
return (
|
<Button
|
className={'mk-btn ' + item.CssClass}
|
icon={item.Icon}
|
key={'action' + index}
|
onClick={() => {this.actionTrigger(item)}}
|
>{item.MenuName}</Button>
|
)
|
})}
|
</div>
|
)
|
}
|
}
|
|
export default MainAction
|