import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
// import { is, fromJS } from 'immutable'
|
import { Button, Affix, Modal, notification } from 'antd'
|
import MutilForm from '@/components/mutilform'
|
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 // 字典项
|
}
|
|
state = {
|
visible: false,
|
formdata: null,
|
tabledata: null,
|
confirmLoading: false,
|
execAction: null
|
}
|
|
refreshdata = () => {
|
this.props.refreshdata()
|
}
|
actionTrigger = (item) => {
|
let _this = this
|
let data = this.props.gettableselected() || []
|
if (item.Ot === 'required' && data.length === 0) {
|
// 需要选择行时,校验数据
|
notification.warning({
|
top: 92,
|
message: this.props.dict['main.action.confirm.selectline']
|
})
|
return
|
} else if (item.Ot === 'pop' && data.length !== 1) {
|
if (data.length === 0) {
|
// 需要选择行时,校验数据
|
notification.warning({
|
top: 92,
|
message: this.props.dict['main.action.confirm.selectline']
|
})
|
return
|
} else {
|
// 需要选择单行时,校验数据
|
notification.warning({
|
top: 92,
|
message: this.props.dict['main.action.confirm.selectSingleLine']
|
})
|
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() {}
|
})
|
} else if (item.Action === 'Update') {
|
Api.getModelFormData(item.MenuID).then(res => {
|
if (res.status) {
|
this.setState({
|
formdata: res.data.map(input => {
|
let validate = input.Validate && JSON.parse(input.Validate)
|
input.DynOptions = JSON.parse(input.DynOptions)
|
input.required = (validate && validate.required) || false
|
return input
|
}),
|
visible: true,
|
execAction: item,
|
tabledata: data[0]
|
})
|
}
|
})
|
}
|
}
|
|
getModels = () => {
|
return (
|
<Modal
|
wrapClassName='action-modal'
|
title={(this.state.execAction && this.state.execAction.MenuName) || ''}
|
visible={this.state.visible}
|
width={(this.state.execAction && +this.state.execAction.PopWidth) || 520}
|
onOk={this.handleOk}
|
confirmLoading={this.state.confirmLoading}
|
onCancel={this.handleCancel}
|
>
|
{this.state.formdata &&
|
<MutilForm
|
dict={this.props.dict}
|
formlist={this.state.formdata}
|
data={this.state.tabledata}
|
wrappedComponentRef={(inst) => this.formRef = inst}
|
/>}
|
</Modal>
|
)
|
}
|
|
handleOk = () => {
|
this.formRef.handleConfirm().then(res => {
|
this.setState({
|
confirmLoading: true
|
})
|
console.log(res)
|
Api.setActionSubmit({
|
func: 'SetActionSubmitSuccess'
|
}).then((res) => {
|
if (res.status) {
|
notification.success({
|
top: 92,
|
message: this.props.dict['main.action.confirm.success']
|
})
|
this.setState({
|
confirmLoading: false,
|
visible: false
|
})
|
} else {
|
notification.error({
|
top: 92,
|
message: res.message
|
})
|
}
|
})
|
}, () => {})
|
}
|
|
handleCancel = () => {
|
this.setState({
|
visible: false
|
})
|
this.formRef.handleReset()
|
}
|
|
UNSAFE_componentWillMount () {
|
|
}
|
|
// shouldComponentUpdate (nextProps, nextState) {
|
// console.log(!is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)))
|
// return true
|
// }
|
|
render() {
|
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 + ' mk-' + item.CssClass}
|
icon={item.Icon}
|
key={'action' + index}
|
onClick={() => {this.actionTrigger(item)}}
|
>{item.MenuName}</Button>
|
)
|
})}
|
{this.getModels()}
|
</div>
|
</Affix>
|
)
|
}
|
}
|
|
export default MainAction
|