king
2019-10-15 ee32a69f9a7f25c37757325dc28ac7b5127dceca
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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)