forked from huge/frontEnd/hugeOA

Mr Ke
2020-06-01 3410959e2feaf93734b4ae90f045593e3467ab9a
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/* eslint-disable */
/**liuwh
 * 5/29/2020, 10:38:14 AM
 * doc comment for the file goes here
 */
 
/** 绩效详情 */
import React, { ReactNode, ReactEventHandler, Component } from 'react';
import TableView from '../../../common/TableView';
import { Row, Col, Button, InputNumber, message, DatePicker } from 'antd';
import { createHashHistory } from 'history';
import './index.scss';
const history = createHashHistory();
 
import fetch from '../../../../api/request';
import moment from 'moment';
const { MonthPicker } = DatePicker;
 
 
export default class MeritsDetail extends Component {
  constructor(props) {
    super(props);
    this.config = {
    };
    this.state = {
      formData: {
        __key: Date.now(),
        // userId: this.props.match.params.userId || loginUser.userId,
        meritsMonth: this.props.match.params.meritsMonth || moment().month(moment().month() - 1).format('YYYY-MM')
      },
      title: null,
      boolean: this.props.match.params.boolean || false
    };
  }
 
  componentDidMount() {
    var loginUser = window.localStorage.getItem('loginUser') || '{}';
    loginUser = JSON.parse(loginUser);
    this.setState({
      formData: {
        ...this.state.formData,
        userId: this.props.match.params.userId || loginUser.userId
      }
    }, () => {
      this.findTitle();
    })
  }
 
  findTitle = () => {
    fetch({
      url: `api/merits/assess/findTitle`,
      params: {
        userId: this.state.formData.userId
      }
    }).then(res => {
      if (res) {
        this.setState({
          title: res
        })
      }
    })
  }
 
  setFormData = data => {
    console.log('form', data);
    this.setState({
      formData: data,
    });
  }
 
  // 保存操作
  onSave = (item) => {
    console.log('item', item);
    let { id, meritsGrade } = item;
    fetch({
      url: `api/merits/assess/modifyGrade`,
      params: {
        id,
        meritsGrade
      }
    }).then(res => {
      if (res) {
        message.success('保存成功');
        this.setState({
          formData: {
            ...this.state.formData,
            __key: Date.now()
          }
        })
      }
    })
  }
 
  renderColumns = () => {
    var cols = [
      { title: '编号', dataIndex: 'id', width: '3%' },
      { title: '评分项目', dataIndex: 'scoreItems', width: '6%' },
      { title: '评分目标', dataIndex: 'scoreTarget', width: '10%' },
      {
        title: '定义与标准', dataIndex: 'standard', width: '25%', render: (cur, item) => {
          return <div dangerouslySetInnerHTML={{
            __html: cur.replace(/\n/g, "<br/>")
          }}></div>
        }
      },
      {
        title: '系统取数指标', dataIndex: 'systemStandard', width: '10%', render: (cur, item) => {
          return <div dangerouslySetInnerHTML={{
            __html: cur.replace(/\n/g, "<br/>")
          }}></div>
        }
      },
      { title: '数据来源', dataIndex: 'dataSources', width: '8%' },
      { title: '取值范围', dataIndex: 'valueRange', width: '5%' },
      {
        title: '计算方式', dataIndex: 'countMethod', width: '8%', render: (cur, item) => {
          return <div dangerouslySetInnerHTML={{
            __html: cur.replace(/\n/g, "<br/>")
          }}></div>
        }
      },
      {
        title: '权重(%)', dataIndex: 'weight', width: '6%'
      },
      {
        title: '配分(分)', dataIndex: 'allotment', width: '6%'
      },
      {
        title: '考评得分(分)', dataIndex: 'meritsGrade', width: '6%', render: (cur, item, index) => {
          return <InputNumber size="small" min={0}
            max={100} formatter={cur => `${cur}分`} parser={value => value.replace('分', '')} value={cur || 0} onChange={(value) => {
              item['meritsGrade'] = value;
              this.refs['table-view'].onSetDataSource({ index, data: item })
            }} />
        }
      },
 
    ];
    if (this.props.match.params.boolean) {
      return cols.concat({
        title: '操作', dataIndex: 'operation', width: '10%', render: (cur, item) => {
          return <a onClick={() => { this.onSave(item) }}>保存</a>
        }
      })
    } else {
      return cols
    }
  }
 
  onBack = () => {
    history.goBack();
  }
 
  monthPickerChange = (m, d) => {
    let { formData } = this.state;
    this.setState({
      formData: {
        ...formData,
        meritsMonth: d
      }
    }, () => {
      this.setState({
        formData: {
          ...this.state.formData,
          __key: Date.now()
        }
      })
    })
  }
 
  render() {
    const { formData, title, boolean } = this.state;
 
    let tableParams = {
      url: `api/merits/assess/findMeritsDetail`,
      formData: {
        ...formData,
        userId: this.props.match.params.userId || JSON.parse(window.localStorage.getItem('loginUser')).userId
      },
      key: formData.__key,
      columns: this.renderColumns(),
      extraFromData: {},
      setFormData: this.setFormData,
      showPagination: false,
    }
 
    function disabledDate(current) {
      return current && current >= moment().endOf('day');
    }
 
    return (
      <div className="merits-detail-main">
 
        <Row className="margin-bottom" type="flex" justify="center" gutter={20}>
          <Col>
            <MonthPicker value={formData.meritsMonth ? moment(formData.meritsMonth, 'YYYY-MM') : ''} format={'YYYY-MM'} onChange={this.monthPickerChange} disabledDate={disabledDate} />
          </Col>
          {
            title &&
            <Col>
              <h2>{title}</h2>
            </Col>
          }
        </Row>
 
        <TableView {...tableParams} ref="table-view" />
        {
          boolean &&
          <Row className="margin-top">
            <Col>
              <Button onClick={this.onBack}>返回</Button>
            </Col>
          </Row>
        }
      </div>
    )
  }
}