ContextMenuModal.js
7.31 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
/**
* 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 { Row, Col, Radio } from 'antd-v4';
import * as commonUtils from '../../utils/utils';
import ShowType from './CommonComponent';/* 通用方法 */
import AntdDraggableModal from '../Common/AntdDraggableModal';
import * as commonFunc from './commonFunc';
const FormItem = Form.Item;
export default class ContextMenuModal extends Component {
/** 构造函数 */
constructor(props) {
super(props);
this.state = {
contextMenuValue: null,
contextType: 1,
};
this.form = {};
/* 表单对象 */
}
handleViewClick = (name, sName, sId) => {
this.props.onViewClick(name, sName, sId);
};
/* 右击弹出窗确定 取表单值 */
handleContextMenuOk= () => {
const { contextMenuTbName } = this.props;
const {
masterData,
contextMenuConfig,
[`${contextMenuTbName}Data`]: tableData,
[`${contextMenuTbName}SelectedRowKeys`]: selectedRowKeys,
} = this.props;
if (commonUtils.isNotEmptyObject(masterData) && commonUtils.isNotEmptyArr(contextMenuConfig)) {
const showConfig = contextMenuConfig[0];
if (commonUtils.isNotEmptyObject(showConfig.sName)) {
// const contextMenuValue = masterData[showConfig.sName]; /* 取弹窗框的值 */
let { contextMenuData } = this.state;
const { contextMenuValue, contextType } = this.state;
console.log('dddd', contextType);
const contextMenuType = commonUtils.isNotEmptyNumber(contextType) ? contextType : 1;
if (!commonUtils.isEmpty(contextMenuValue)) {
if (!contextMenuData) {
let tableDataRow = {};
if (commonUtils.isNotEmptyArr(tableData)) {
const tableFilterData = tableData.filter(item => selectedRowKeys.includes(item.sId));
if (commonUtils.isNotEmptyArr(tableFilterData)) {
tableDataRow = tableFilterData[0];
tableDataRow.contextType = commonUtils.isNotEmptyNumber(contextType) ? contextType : 1;
}
}
contextMenuData = commonFunc.getAssignFieldValue(showConfig.sAssignField, tableDataRow);
}
console.log('ddda1a', contextMenuData, contextMenuType);
this.props.onContextMenuOk(contextMenuValue, contextMenuData, contextMenuType);
}
}
}
}
handleModalCancel = (modelVisible) => {
this.props.onSaveState({
[modelVisible]: false,
});
};
handleRdoChange = (e) => {
this.setState({ contextType: e.target.value });
};
/** 渲染 */
render() {
const {
contextMenuModalVisible,
contextMenuTbName,
contextMenuConfig,
contextMenuName,
app,
form,
sTabId,
[`${contextMenuTbName}Data`]: tableData, [`${contextMenuTbName}SelectedRowKeys`]: selectedRowKeys,
} = this.props;
const { contextMenuValue, contextType } = this.state;
let tableDataRow = {};
if (commonUtils.isNotEmptyArr(tableData)) {
const tableFilterData = tableData.filter(item => selectedRowKeys.includes(item.sId));
if (commonUtils.isNotEmptyArr(tableFilterData)) {
tableDataRow = tableFilterData[0];
}
}
if (contextMenuValue === null && commonUtils.isNotEmptyObject(tableDataRow) && commonUtils.isNotEmptyArr(contextMenuConfig)) {
this.setState({
contextMenuValue: tableDataRow[contextMenuConfig[0].sName],
});
}
const radioValue = commonUtils.isNotEmptyNumber(contextType) ? contextType : 1;
const pane = app.panes.filter(paneTmp => paneTmp.key === sTabId)[0];
return (
<div>
{
(pane.notCurrentPane ? false : contextMenuModalVisible) ?
<AntdDraggableModal
title={`更新:${contextMenuName}`}
visible={contextMenuModalVisible}
onOk={this.handleContextMenuOk}
onCancel={this.handleModalCancel.bind(this, 'contextMenuModalVisible')}
width={380}
okButtonProps={{ style: { marginRight: '5px' } }}
// cancelButtonProps={{ style: { marginRight: '10px' } }}
bodyStyle={{ paddingLeft: '3px', paddingRight: '3px' }}
>
<div className="contextMenuStyle" >
<div className="xly_radio" style={{ padding: '5px 20px' }} >
<Radio.Group onChange={this.handleRdoChange} value={radioValue}>
<Radio value={1}>全部更新</Radio>
<Radio value={2}>当前数据往下更新</Radio>
</Radio.Group>
</div>
<FormItem className="searchMainForm">
<Row type="flex" style={{ height: 'auto', overflow: 'hidden' }}>
{ commonUtils.isNotEmptyArr(contextMenuConfig) ?
contextMenuConfig.map((child) => {
const sMemo = child.sName.toLowerCase().endsWith('memo');
let enabledNew = !child.bReadonly;
if (child.iTag === 1) {
enabledNew = false;
} else if (child.iTag === 3) {
enabledNew = true;
}
const showTypeProps = {
name: 'slave',
app,
form,
record: tableDataRow,
sId: commonUtils.createSid(),
getSqlDropDownData: this.props.getSqlDropDownData,
getSqlCondition: this.props.getSqlCondition,
handleSqlDropDownNewRecord: this.props.handleSqlDropDownNewRecord,
getFloatNum: this.props.getFloatNum,
onChange: (name, sFieldName, changeValue) => {
this.setState({
contextMenuValue: changeValue[sFieldName],
contextMenuData: changeValue,
});
},
onViewClick: this.handleViewClick,
getDateFormat: this.props.getDateFormat,
showConfig: child,
textArea: sMemo,
enabled: enabledNew,
dataValue: !commonUtils.isEmpty(contextMenuValue) ? contextMenuValue : commonUtils.isNotEmptyObject(tableDataRow) ? tableDataRow[child.sName] : '',
bTable: true,
formRoute: this.props.formRoute,
formItemLayout: {},
onExecInstructSet: this.props.onExecInstructSet,
};
return (
<Col key={child.sId} span={24} order={child.iOrder} className="ContextMenuCol" style={{ border: '1px solid #d3d3d3' }}>
<ShowType {...showTypeProps} />
</Col>
);
}) : ''
}
</Row>
</FormItem>
</div>
</AntdDraggableModal>
: ''
}
</div>
);
}
}