productionHeader.js
8.7 KB
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
/**
* Created by mar105 on 2019-02-27.
*/
/* eslint-disable object-curly-newline,prefer-destructuring */
import React, { Component } from 'react';
import { ExportOutlined, PrinterOutlined, SaveOutlined } from '@ant-design/icons';
import { Row, Col } from 'antd';
import styles from '../Common/ToolBar/index.less';
import ShowType from '../Common/CommonComponent';
import * as commonUtils from '../../utils/utils';/* 通用方法 */
import AffixMenu from '../../routes/common/AffixMenu';
import ProductionPlan1 from '../../assets/ProductionPlan-1.svg';
import ProductionPlan2 from '../../assets/ProductionPlan-2.svg';
import ProductionPlan7 from '../../assets/ProductionPlan-7.svg';
import ProductionPlan8 from '../../assets/ProductionPlan-8.svg';
import ProductionPlan11 from '../../assets/ProductionPlan-11.svg';
export default class productionHeader extends Component {
/** 构造函数 */
constructor(props) {
super(props);
this.state = {
enabled: props.enabled,
masterConfig: props.masterConfig,
stateValue: props.stateValue,
masterData: props.masterData,
};
}
/** 渲染前只执行一次 */
componentWillMount() {
/* state和this属性赋值 */
this.assignmentWillProps(this.props);
}
/** props改变的时候触发 */
componentWillReceiveProps(nextProps) {
/* state和this属性赋值 */
this.assignmentWillProps(nextProps);
}
/** 返回true执行渲染,返回false不渲染 */
shouldComponentUpdate(nextProps, nextState) {
const {
masterConfig, stateValue, enabled, masterData,
} = this.state;
const ret = enabled !== nextState.enabled || JSON.stringify(masterConfig) !== JSON.stringify(nextState.masterConfig) ||
JSON.stringify(masterData) !== JSON.stringify(nextState.masterData) ||
JSON.stringify(stateValue) !== JSON.stringify(nextState.stateValue);
return ret;
}
assignmentWillProps = (props) => {
this.setState({
enabled: props.enabled,
masterConfig: props.masterConfig,
masterData: props.masterData,
stateValue: props.stateValue,
});
}
// 获取header按钮状态 stateValue
HandlerHeaderButtonShowState = (props) => {
const { masterData, searchSolution } = props;
let filterCondition = [];
let stateValue = 99;
if (commonUtils.isNotEmptyObject(masterData) && commonUtils.isNotEmptyObject(masterData.sSearchSolutionId)) {
const iIndex = searchSolution.findIndex(item => item.sId === masterData.sSearchSolutionId);
if (iIndex > -1) {
filterCondition = JSON.parse(searchSolution[iIndex].sCondition);
let state = '';
let frozen = '';
filterCondition.forEach((item) => {
if (item.bFilterName === 'sState') {
state = item.bFilterValue;
}
if (item.bFilterName === 'bFrozen') {
frozen = item.bFilterValue;
}
});
if (commonUtils.isEmptyObject(frozen) && commonUtils.isNotEmptyObject(state)) {
if (state === '未排程') {
stateValue = 0;
} else if (state === '未下达' || state === '已排程') {
stateValue = 1;
} else if (state === '已下达') {
stateValue = 2;
} else if (state === '已暂停') {
stateValue = 3;
} else if (state === '已完成') {
stateValue = 5;
}
} else if (commonUtils.isNotEmptyObject(frozen)) {
stateValue = 4;
} else if (commonUtils.isNotEmptyObject(frozen) && commonUtils.isNotEmptyObject(state)) {
stateValue = 99;
}
}
}
return { stateValue };
}
handleClick = (iTag) => {
this.props.onButtonClick(iTag);
}
handleSwitchChange = (value) => {
this.props.onSwitchChange(value);
}
rowReturnType = (child, i) => {
const { enabled, stateValue } = this.state;
const sMemo = child.sName.toLowerCase().endsWith('memo');
const iColValue = sMemo ? 21 : child.iColValue * 2;
const iOrder = sMemo ? 100 : child.iOrder > 100 ? 100 : child.iOrder;
const enabledNew = (enabled && !child.bReadonly && !child.specialControl);
const type = commonUtils.isNotEmptyObject(child.sControlName) && child.sControlName.toLowerCase().startsWith('btn');
let showTypeProps = {};
if (!type) {
const switchBtn = child.sControlName.toLowerCase().startsWith('switch');
if (!switchBtn) {
showTypeProps = {
name: 'master',
form: this.props.form,
formId: this.props.sModelsId,
getSqlDropDownData: this.props.getSqlDropDownData,
getSqlCondition: this.props.getSqlCondition,
handleSqlDropDownNewRecord: this.props.handleSqlDropDownNewRecord,
getFloatNum: this.props.getFloatNum,
getDateFormat: this.props.getDateFormat,
onChange: this.props.onChange,
showConfig: child,
textArea: sMemo,
enabled: enabledNew,
dataValue: commonUtils.isNotEmptyObject(this.props.masterData) ? this.props.masterData[child.sName] : '',
bTable: false,
};
return (
<Col key={i} span={iColValue} order={iOrder} style={{ margin: 1, backgroundColor: 'rgb(100, 100, 100)', color: '#fff' }}>
<ShowType {...showTypeProps} style={{ height: 20, lineHeight: '20px' }} />
</Col>
);
} else {
return '';
}
} else {
let displayFlag = false;
let disabledFlag = true;
if ((stateValue === '0' && child.iTag === 3) || (stateValue === '1' && child.iTag === 5)
|| (stateValue === '0' && child.iTag === 5) || (stateValue === '2' && child.iTag === 4)
|| (stateValue === '2' && child.iTag === 5)
|| (stateValue === '2' && child.iTag === 17)
|| (stateValue === '3' && child.iTag === 6)
|| (child.iTag === 1) || (child.iTag === 2)
|| (child.iTag === 7) || (child.iTag === 8) || (child.iTag === 11)
|| (child.iTag === 12) || (child.iTag === 13) || (child.iTag === 14) || (child.iTag === 15) || (child.iTag === 16)
) {
displayFlag = true;
}
if ((child.iTag === 1 && (stateValue === '0' || stateValue === '1')) ||
(child.iTag === 2 && (stateValue === '0' || stateValue === '1' || stateValue === '2')) ||
(child.iTag === 3 && (stateValue === '0' || stateValue === '1')) ||
(child.iTag === 4 && stateValue === '2') ||
(child.iTag === 5 && stateValue === '2') ||
(child.iTag === 6 && stateValue === '3') ||
(child.iTag === 7 && stateValue === '2') ||
(child.iTag === 8 && stateValue === '2') ||
(child.iTag === 11 && (stateValue === '0' || stateValue === '1' || stateValue === '2')) ||
((child.iTag === 12 || child.iTag === 13 || child.iTag === 14) && stateValue !== '99')
) {
disabledFlag = false;
}
// console.log(child.showName, ' disabledFlag:', disabledFlag, 'displayFlag:', displayFlag);
return displayFlag ? (
<span key={i} order={iOrder} style={{ margin: '0 15px', float: 'left', display: displayFlag ? 'inline-block' : 'none', color: '#fff', lineHeight: '30px' }} disabled={disabledFlag}onClick={this.handleClick.bind(this, child.iTag)} >
{(() => {
switch (child.iTag) {
case 1: return <img src={ProductionPlan1} disabled={disabledFlag} alt="" />;
case 2: return <img src={ProductionPlan2} disabled={disabledFlag} style={{ width: '13px', height: '13px' }} alt="" />;
case 7: return <img src={ProductionPlan7} disabled={disabledFlag} alt="" />;
case 8: return <img src={ProductionPlan8} disabled={disabledFlag} alt="" />;
case 11: return <img src={ProductionPlan11} disabled={disabledFlag} style={{ width: '15px', height: '15px' }} alt="" />;
case 12: return <SaveOutlined disabled={disabledFlag} />;
case 13: return <PrinterOutlined disabled={disabledFlag} />;
case 14: return <ExportOutlined disabled={disabledFlag} />;
default: return null;
}
}
)()}
{child.showName}
</span>
) : '';
}
}
render() {
const { masterConfig } = this.state;
const teamMachineProps = masterConfig === undefined ? undefined : masterConfig.gdsconfigformslave;
return (
<div className={styles.toolBar}>
<Row style={{ backgroundColor: 'rgb(100, 100, 100)', margin: '0 10px', height: 30 }} id="product-info-header">
{
commonUtils.isNotEmptyObject(teamMachineProps) ? teamMachineProps.map((child, i) => {
return this.rowReturnType(child, i);
}) : ''
}
</Row>
<AffixMenu />
</div>
);
}
}