SlaveMemo1.js
10.5 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/**
* Created by mar105 on 2019-02-13.
*/
/* eslint-disable no-undef,import/first,prefer-destructuring,jsx-a11y/alt-text */
import React, { Component } from 'react';
import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import { Input } from 'antd-v4';
import * as commonUtils from '../../utils/utils';
import ShowType from './CommonComponent';/* 通用方法 */
import AntdDraggableModal from '../Common/AntdDraggableModal';
import moment from 'moment';
const { TextArea } = Input;
const FormItem = Form.Item;
export default class SlaveMemo extends Component {
/** 构造函数 */
constructor(props) {
super(props);
this.handleTextareaChange = this.handleTextareaChange.bind(this);
this.state = { textareaValue: '' };
this.max = 2000;
this.min = 0;
this.sDateFormat = 'YYYY-MM-DD';
this.bInit = true; // 是否初始化
// this.isChoosedate = btnName.toLowerCase().endsWith('choosedate');
}
componentWillMount() {
this.componentWillReceiveProps(this.props);
}
componentWillReceiveProps(nextProps) {
/* state和this属性赋值 */
const { sCurrMemoProps1 } = nextProps;
if (this.bInit && sCurrMemoProps1 && sCurrMemoProps1.bVisibleMemo) {
this.bInit = false;
if (commonUtils.isNotEmptyObject(sCurrMemoProps1) && sCurrMemoProps1.btnName === undefined) {
this.setState({ textareaValue: nextProps.sCurrMemoProps1.sValue });
} else {
this.setState({ textareaValue: nextProps.sValue });
}
if (commonUtils.isNotEmptyObject(sCurrMemoProps1)) {
this.max = commonUtils.convertStrToNumber(commonUtils.isNotEmptyObject(nextProps.sCurrMemoProps1.sMemoConfig) && commonUtils.isNotEmptyObject(nextProps.sCurrMemoProps1.sMemoConfig.sMaxValue) ? nextProps.sCurrMemoProps1.sMemoConfig.sMaxValue : this.max); /* 最大值(数据格式:数字) */
this.min = commonUtils.convertStrToNumber(commonUtils.isNotEmptyObject(nextProps.sCurrMemoProps1.sMemoConfig) && commonUtils.isNotEmptyObject(nextProps.sCurrMemoProps1.sMemoConfig.sMinValue) ? nextProps.sCurrMemoProps1.sMemoConfig.sMinValue : this.min); /* 最小值(数据格式:数字) */
}
}
}
handleOk = () => {
const { sCurrMemoProps1, slaveMemoConfig, masterData } = this.props;
const sValue = {};
const name = sCurrMemoProps1.name;
const bVisibleMemo = sCurrMemoProps1.bVisibleMemo;
const sMemoField = sCurrMemoProps1.sMemoField;
const sRecord = sCurrMemoProps1.sRecord;
const btnName = sCurrMemoProps1.btnName ? sCurrMemoProps1.btnName : '';
let valueKey = '';
if (commonUtils.isNotEmptyArr(slaveMemoConfig) && commonUtils.isNotEmptyObject(masterData)) {
// eslint-disable-next-line array-callback-return
slaveMemoConfig.map((item) => {
/**
* 修改日期:2021-03-24
* 修改人:吕杰
* 区域:以下 18 行
* BUG:
* 说明:过滤伪字段,为下拉框时替换为id
* 原代码:
*/
let realName = item.sName;
if (item.sRelation && item.sRelation !== 'noQuery') { // 伪字段处理
if (item.sDropDownType && item.sDropDownType === 'sql') { // 下拉框处理
/** 此处存在替换隐患,暂无好的解决方案(存在多个Name且需要替换的位置不确定时,无解决方案) */
realName = realName.replace('Name', 'Id');
} else { // 过滤
// eslint-disable-next-line array-callback-return
return;
}
}
sValue[realName] = masterData[realName];
if (btnName.toLowerCase().endsWith('choosedate') && realName.length > 0 && realName.substring(0, 1) === 'p') {
const tStartDate = moment(sValue[realName][0]).format(this.sDateFormat);
const tEndDate = moment(sValue[realName][1]).add(1, 'days').format(this.sDateFormat);
sValue[realName][0] = tStartDate;
sValue[realName][1] = tEndDate;
}
valueKey += `${realName},`;
});
sValue.valueKey = valueKey;
}
sValue.textareaValue = this.state.textareaValue;
if (btnName.indexOf('BtnRepair') > -1) {
const btnConfig = this.props.masterConfig.gdsconfigformslave.filter(item => (item.sControlName === btnName))[0];
if (commonUtils.isNotEmptyObject(btnConfig)) {
this.props.onBtnEent(btnConfig, btnName, sValue);
}
if (btnName.toLowerCase().endsWith('choosedate')) {
const iIndex = slaveMemoConfig.findIndex(item => item.sName === 'pChooseDate');
if (iIndex > -1) {
/* 日期凭证调用存储过程后清除时间区间 */
masterData.pChooseDate = null;
}
}
} else if (btnName.indexOf('BtnForceComplete') > -1) {
this.props.onGetMemo(name, sValue, sMemoField, sRecord, bVisibleMemo, btnName);
} else {
this.props.onGetMemo(name, this.state.textareaValue, sMemoField, sRecord, bVisibleMemo, btnName);
}
this.bInit = true;
};
handleSlaveMemoMasterChange = async (name, sFieldName, changeValue, sId, dropDownData, isWait, masterDataNew) => {
const { masterData: masterDataOld, enabled } = this.props;
const addState = { enabled };
const masterData = masterDataNew === undefined ? masterDataOld === undefined ? {} : masterDataOld : masterDataNew;
const returnData = await this.props.onChange(name, sFieldName, changeValue, sId, dropDownData, true, masterData);
if (isWait) {
return { ...returnData, ...addState };
} else {
this.props.onSaveState({ ...returnData, ...addState });
return returnData;
}
}
handleCancel = () => {
this.bInit = true;
this.props.onGetMemoCancel();
};
/* 设置textareaValue */
handleTextareaChange(e) {
this.setState({
textareaValue: e.target.value,
});
}
handleViewClick = (name, sName, sId) => {
this.props.onViewClick(name, sName, sId);
};
/** 渲染 */
render() {
const {
sCurrMemoProps1,
masterData,
app,
sModelsId,
form,
slaveMemoConfig,
} = this.props;
let bVisibleMemo;
let sMemoField;
let btnName = '';
const title = '详细';
let bEnabledTextArea = false; /* 多行文本默认可输入 非编辑状态多行文本禁止输入 */
if (commonUtils.isNotEmptyObject(sCurrMemoProps1)) {
bVisibleMemo = sCurrMemoProps1.bVisibleMemo;
sMemoField = sCurrMemoProps1.sMemoField;
btnName = sCurrMemoProps1.btnName ? sCurrMemoProps1.btnName : '';
if (sCurrMemoProps1.bOnlyShow !== undefined) { /* 查看状态下备注弹窗只能查看不能修改 */
bEnabledTextArea = sCurrMemoProps1.bOnlyShow;
}
}
let bVisibleTextArea = true;
if (commonUtils.isNotEmptyArr(slaveMemoConfig)) {
if (slaveMemoConfig[0].sName === 'sDevelopMemo') {
bVisibleTextArea = false; /* 开发备注多行文本不显示 */
}
}
// const tStartDate = moment(); /* 开始时间 */
// 判断是否备注双击弹出的弹窗
// if (fromToorBar) {
// bVisibleMemo = false;
// }
const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 18 } };
return (
<div>
{
bVisibleMemo ?
<AntdDraggableModal
className="slaveMemo"
zIndex={1000}
title={title}
visible={bVisibleMemo}
onOk={this.handleOk}
width={btnName.toLowerCase().endsWith('choosedate') ? 778 : '70%'}
bodyStyle={{
height: '60vh',
}}
onCancel={this.handleCancel}
>
<div>
{
btnName.indexOf('BtnRepair') > -1 ?
<Form>
<FormItem>
{ commonUtils.isNotEmptyArr(slaveMemoConfig) ?
slaveMemoConfig.map((child) => {
const sMemo = child.sName.toLowerCase().endsWith('memo');
let enabledNew = !child.bReadonly;
const iColValue = sMemo ? 21 : child.iColValue * 6;
if (child.iTag === 1) {
enabledNew = false;
} else if (child.iTag === 3) {
enabledNew = true;
}
const showTypeProps = {
app,
iColValue,
record: masterData,
name: 'master',
form,
formId: sModelsId,
getSqlDropDownData: this.props.getSqlDropDownData,
getSqlCondition: this.props.getSqlCondition,
handleSqlDropDownNewRecord: this.props.handleSqlDropDownNewRecord,
getFloatNum: this.props.getFloatNum,
getDateFormat: this.props.getDateFormat,
onChange: this.handleSlaveMemoMasterChange,
showConfig: child,
formItemLayout,
textArea: sMemo,
enabled: enabledNew,
dataValue: masterData ? masterData[child.sName] : undefined,
bTable: false,
onFilterDropDownData: this.props.onFilterDropDownData,
onViewClick: this.handleViewClick,
onSaveState: this.props.onSaveState,
style: { backgroundColor: '#eaeaea' },
bInSlaveMemo: true,
};
return <ShowType {...showTypeProps} />;
}) : ''
}
</FormItem>
</Form>
: ''
}
{sMemoField !== undefined && !btnName.toLowerCase().endsWith('choosedate') ? (
<TextArea
value={this.state.textareaValue}
maxLength={this.max}
minLength={this.min}
rows={18}
style={{ display: bVisibleTextArea ? 'block' : 'none' }}
onChange={this.handleTextareaChange}
disabled={bEnabledTextArea}
/>
) : null}
</div>
</AntdDraggableModal>
: ''
}
</div>
);
}
}