import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import {connect} from 'react-redux'
|
import { is, fromJS } from 'immutable'
|
import { Button, BackTop, notification } from 'antd'
|
import {refreshTabView, modifyTabview} from '@/store/action'
|
import MutilForm from '@/components/mutilform'
|
import Api from '@/api'
|
import './index.scss'
|
|
class TabForm extends Component {
|
static propTpyes = {
|
MenuNo: PropTypes.string, // 菜单参数
|
MenuID: PropTypes.string, // 菜单Id
|
param: PropTypes.object // 菜单参数
|
}
|
|
state = {
|
loading: false
|
}
|
|
handleOk = () => {
|
this.setState({
|
loading: true
|
})
|
this.formRef.handleConfirm().then(res => {
|
let values = []
|
this.props.param.formdata.forEach(column => {
|
let value = ''
|
if (res[column.FieldName] || res[column.FieldName] === 0) { // 依次选取表单值、表格数据值、初始值
|
value = res[column.FieldName]
|
} else if (this.state.tabledata && this.state.tabledata[column.FieldName]) {
|
value = this.state.tabledata[column.FieldName]
|
} else if (column.InitVal) {
|
value = column.InitVal
|
}
|
values.push(column.FieldName + 'equal\'' + value + '\'')
|
})
|
Api.submitInterface({
|
func: this.props.param.execAction.AuditProc || this.props.param.defaultproc[this.props.param.execAction.Action],
|
UptLongText: values.join(','), // 表单数据
|
ID: (this.props.param.tabledata && this.props.param.primarykey) ? this.props.param.tabledata[this.props.param.primarykey] : '', // 主键字段
|
BID: (this.props.param.tabledata && this.props.param.bidkey) ? this.props.param.tabledata[this.props.param.bidkey] : '' // BID字段
|
}).then(result => {
|
if (result.status) {
|
notification.success({
|
top: 92,
|
message: this.props.param.dict['main.action.confirm.success']
|
})
|
|
// 刷新主列表页面
|
if (this.props.param.execAction.ReloadForm && this.props.param.execAction.ReloadForm !== 'false' && this.props.param.execAction.ReloadForm !== 'singlegrid') {
|
this.props.refreshTabView({
|
MenuNo: this.props.MenuNo,
|
ReloadForm: this.props.param.execAction.ReloadForm
|
})
|
}
|
|
this.handleCancel()
|
} else {
|
notification.error({
|
top: 92,
|
message: result.message,
|
duration: 15
|
})
|
}
|
this.setState({
|
loading: false
|
})
|
})
|
}, () => {})
|
}
|
|
handleCancel = () => {
|
// 关闭当前窗口,返回原列表页
|
let tabs = JSON.parse(JSON.stringify(this.props.tabviews))
|
tabs = tabs.filter(tab => {
|
if (tab.MenuNo === this.props.MenuNo && tab.type !== 'TabForm') {
|
tab.selected = true
|
} else {
|
tab.selected = false
|
}
|
return tab.MenuID !== this.props.MenuID
|
})
|
this.props.modifyTabview(tabs)
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
render() {
|
let cols = +this.props.param.execAction.FormLineQty
|
if (![1, 2, 3].includes(cols)) {
|
cols = 2
|
}
|
return (
|
<div className="tabform">
|
<MutilForm
|
dict={this.props.param.dict}
|
formlist={this.props.param.formdata}
|
data={this.props.param.tabledata}
|
cols={cols}
|
wrappedComponentRef={(inst) => this.formRef = inst}
|
/>
|
<div className="operation">
|
<Button type="primary" htmlType="submit" onClick={() => {this.handleOk()}} loading={this.state.loading}>
|
{this.props.param.dict['main.confirm']}
|
</Button>
|
<Button onClick={() => {this.handleCancel()}}>
|
{this.props.param.dict['main.return']}
|
</Button>
|
</div>
|
<BackTop>
|
<div className="ant-back-top">
|
<div className="ant-back-top-content">
|
<div className="ant-back-top-icon"></div>
|
</div>
|
</div>
|
</BackTop>
|
</div>
|
)
|
}
|
}
|
|
const mapStateToProps = (state) => {
|
return {
|
tabviews: state.tabviews
|
}
|
}
|
|
const mapDispatchToProps = (dispatch) => {
|
return {
|
refreshTabView: (refreshTab) => dispatch(refreshTabView(refreshTab)),
|
modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews))
|
}
|
}
|
|
export default connect(mapStateToProps, mapDispatchToProps)(TabForm)
|