forked from huge/frontEnd/hugeOA

Mr Ke
2020-05-29 a4f102defd2c7918617717f3307b6a3ef63859ff
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
219
/* eslint-disable */
/**liuwh
 * 5/29/2020, 11:49:58 AM
 * doc comment for the file goes here
 */
 
/** 绩效指标 */
import React, { ReactNode, ReactEventHandler, Component } from 'react';
import { Input, Row, InputNumber, Tag, Popconfirm, Divider, message } from 'antd';
import TableView from '../../../common/TableView';
import SearchFormView from '../../../common/SearchFormView';
import fetch from '../../../../api/request'
 
import './index.scss';
 
export default class MeritsDispose extends Component {
  constructor(props) {
    super(props);
    this.config = {
    };
    this.state = {
      formData: {
        __key: Date.now(),
      },
      selectData: null,//岗位下拉
    };
  }
 
  componentWillMount() { }
 
  componentDidMount() {
 
    fetch({
      url: `api/merits/index/queryMeritsPost`,
    }).then(res => {
      console.log('res', res);
      if (res) {
        this.setState({
          selectData: res.map(({ name, id }) => ({ name, value: id })),
          formData: {
            ...this.state.formData,
            meritsPostId: res[0].id
          }
        })
      }
    })
  }
 
  setFormData = data => {
    console.log('form', data);
    this.setState({
      formData: data,
    });
  }
 
  // 启用/禁用功能
  openCloseIndex = (item) => {
    let { selectData } = this.state;
    let { validStatus, meritsPostRelationId, meritsPostId, id } = item;
    fetch({
      url: `api/merits/index/openCloseIndex/${!validStatus}`,
      method: 'POST',
      data: {
        ...item,
        id: meritsPostRelationId,
        validStatus: !validStatus ? 1 : 2,
        meritsIndexId: id,
        meritsPostName: selectData.find(({ value }) => value == meritsPostId).name
      }
    }).then(res => {
      console.log('res', res);
      if (res) {
        message.success(validStatus ? '禁用成功' : '启用成功');
        this.setState({
          formData: {
            ...this.state.formData,
            __key: Date.now()
          }
        })
      }
    })
  }
 
  // 保存处于启用状态的的设置值
  saveOpenIndex = (item) => {
    let { selectData } = this.state;
 
    let { validStatus, meritsPostRelationId, meritsPostId, id } = item;
    fetch({
      url: `api/merits/index/openCloseIndex/${validStatus}`,
      method: 'POST',
      data: {
        ...item,
        id: meritsPostRelationId,
        validStatus: validStatus ? 1 : 2,
        meritsIndexId: id,
        meritsPostName: selectData.find(({ value }) => value == meritsPostId).name
      }
    }).then(res => {
      console.log('res', res);
      if (res) {
        message.success('保存成功');
        this.setState({
          formData: {
            ...this.state.formData,
            __key: Date.now()
          }
        })
      }
    })
  }
 
  renderColumns = () => {
    return [
      { 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%', render: (cur, item, index) => {
          return <InputNumber size="small" min={0} disabled={item.validStatus ? false : true}
            max={100} formatter={cur => `${cur}%`} parser={value => value.replace('%', '')} value={cur || 0} onChange={(value) => {
              item['weight'] = value;
              this.refs['table-view'].onSetDataSource({ index, data: item })
            }} />
        }
      },
      {
        title: '配分(分)', dataIndex: 'allotment', width: '6%', render: (cur, item, index) => {
          return <InputNumber size="small" min={0} disabled={item.validStatus ? false : true}
            max={100} formatter={cur => `${cur}分`} parser={value => value.replace('分', '')} value={cur || 0} onChange={(value) => {
              item['allotment'] = value;
              this.refs['table-view'].onSetDataSource({ index, data: item })
            }} />
        }
      },
      {
        title: '操作', dataIndex: 'operation', width: '10%', render: (cur, item) => {
          return <Row>
            {/* 有效状态 */}
 
            {item.validStatus && <Popconfirm placement="topRight" title={'您确定要禁用吗?'} onConfirm={() => {
              this.openCloseIndex(item);
            }} okText="是" cancelText="否">
              <Tag>禁用</Tag>
            </Popconfirm>}
            {!item.validStatus && <Popconfirm placement="topRight" title={'您确定要启用吗?'} onConfirm={() => {
              this.openCloseIndex(item);
            }} okText="是" cancelText="否">
              <Tag color="#58bc58">启用</Tag>
            </Popconfirm>}
 
            {/* 待启用状态--保存功能 */}
            {item.validStatus && <React.Fragment>
              <Divider type="vertical" />
              <a onClick={() => {
                this.saveOpenIndex(item)
              }}>保存</a>
            </React.Fragment>}
 
          </Row>
        }
      },
    ];
  }
 
  render() {
    const { formData, selectData } = this.state;
    let tableParams = {
      url: `api/merits/index/queryMeritsIndex`,
      formData,
      key: formData.__key,
      columns: this.renderColumns(),
      extraFromData: {},
      setFormData: this.setFormData,
      showPagination: false,
    }
 
    return (
      <div className="merits-dispose-main">
        {
          selectData &&
          <React.Fragment>
            <SearchFormView
              formData={formData}
              setFormData={this.setFormData}
              showReset={false}
              data={[
                { type: 'select', name: '岗位', label: '岗位', key: 'meritsPostId', list: selectData, },
              ]} />
            <TableView {...tableParams} ref={'table-view'} />
          </React.Fragment>
        }
      </div>
    )
  }
}