salary-management-front/pc4mobx/hrmSalary/pages/salaryItem/formalFormModal.js

209 lines
7.8 KiB
JavaScript
Raw Normal View History

2022-04-18 11:42:45 +08:00
import React from 'react'
2022-04-18 15:33:19 +08:00
import {Modal, Button, Icon } from 'antd'
2022-05-05 09:13:38 +08:00
import { WeaTextarea, WeaInput } from 'ecCom'
2022-04-18 11:42:45 +08:00
import { inject, observer } from 'mobx-react';
2022-05-06 10:11:45 +08:00
import ValidRuleEditModal from '../ledger/step5/ValidRuleEditModal';
2022-04-18 11:42:45 +08:00
@inject('salaryItemStore')
@observer
export default class FormalFormModal extends React.Component {
constructor(props) {
super(props)
this.state = {
2022-05-05 09:13:38 +08:00
value: '',
returnValue: ""
2022-04-18 11:42:45 +08:00
}
2022-04-18 15:33:19 +08:00
this.group = {};
this.field = {};
this.parameters = []
2022-04-27 14:25:59 +08:00
this.referenceType = ""
2022-04-18 11:42:45 +08:00
}
2022-04-18 15:33:19 +08:00
2022-04-18 11:42:45 +08:00
componentWillMount() {
const { salaryItemStore } = this.props;
2022-04-20 15:28:40 +08:00
const { salaryAcctImportTemplateParam, setSearchFields, detailFormual } = salaryItemStore;
2022-04-18 15:33:19 +08:00
setSearchFields([])
2022-04-20 15:28:40 +08:00
if(this.props.formulaId) {
detailFormual(this.props.formulaId).then(data => {
this.setState({
value: data.formula
})
this.parameters = data.parameters
2022-04-27 14:25:59 +08:00
this.referenceType = data.referenceType
2022-05-05 09:13:38 +08:00
this.extendParam = data.extendParam
if(this.extendParam && this.extendParam.length > 0) {
this.extendParam.replace("\'", "\"")
let extendParam = {}
try {
extendParam = JSON.parse(this.extendParam)
} catch (ex) {
}
this.setState({
returnValue: extendParam.sqlReturnKey ? extendParam.sqlReturnKey : ""
})
}
let groupParams = {}
if(this.referenceType == 'sql') {
groupParams = {'referenceType':'sql'}
}
salaryAcctImportTemplateParam(groupParams);
2022-04-20 15:28:40 +08:00
})
2022-05-05 09:13:38 +08:00
} else {
let groupParams = {}
if(this.props.valueType == "3") {
groupParams = {'referenceType':'sql'}
}
salaryAcctImportTemplateParam(groupParams);
2022-04-20 15:28:40 +08:00
}
2022-04-18 11:42:45 +08:00
}
2022-04-20 15:28:40 +08:00
2022-04-18 11:42:45 +08:00
// 多行文本编辑
handleChange(value) {
2022-05-06 10:11:45 +08:00
if(value && value.trim() == "") {
this.parameters = []
}
2022-04-18 11:42:45 +08:00
this.setState({
value
})
2022-04-18 15:33:19 +08:00
}
2022-05-06 10:11:45 +08:00
// 获取光标位置
getPositionForTextArea(ctrl) {
let CaretPos = {
start:0,
end:0
};
if (ctrl.selectionStart) {// Firefox support
CaretPos.start = ctrl.selectionStart;
}
if(ctrl.selectionEnd){
CaretPos.end = ctrl.selectionEnd
}
return (CaretPos);
}
2022-04-18 15:33:19 +08:00
// 分组项被点击
handleItemClick(item) {
const { salaryItemStore } = this.props;
const { formualSearchField } = salaryItemStore;
this.group = item;
2022-05-05 09:13:38 +08:00
let params = {}
if(this.props.valueType == '3' || this.referenceType == "sql") {
params = {
extendParam: {
'referenceType':'sql'
}
}
}
formualSearchField(item.key, params)
2022-04-18 15:33:19 +08:00
}
// 保存
handleSave() {
const { salaryItemStore } = this.props;
const { saveFormual } = salaryItemStore
2022-05-06 10:11:45 +08:00
this.parameters = this.parameters.filter(item => this.state.value.indexOf(item.name) > -1)
2022-04-18 15:33:19 +08:00
let params = {
name:'公式1',
description:'备注',
module:'salary',
useFor:'salaryitem',
referenceType:'',
returnType:'number',
validateType:'number',
2022-05-05 09:13:38 +08:00
extendParam: this.state.returnValue && this.state.returnValue !== '' ? '{"sqlReturnKey":"'+this.state.returnValue+'"}' : "{}",
2022-04-18 15:33:19 +08:00
formula: this.state.value,
2022-04-27 14:25:59 +08:00
parameters: this.parameters,
2022-04-27 19:27:23 +08:00
referenceType: this.referenceType == "" ? this.props.valueType == "2" ? "formula" : this.props.valueType == "3" ? "sql" : "" : this.referenceType
2022-04-18 15:33:19 +08:00
}
2022-04-18 16:57:42 +08:00
saveFormual(params).then(data => {
this.props.onSaveFormal(data)
this.props.onCancel()
})
2022-04-18 11:42:45 +08:00
}
2022-04-18 15:33:19 +08:00
// 字段点击回调
handleFieldClick(item) {
this.field = item;
let fieldName = "{"+this.group.value+"."+this.field.name+"}"
let parameterItem = {
name: item.name,
fieldId: item.fieldId,
fieldName: fieldName,
fieldType: item.fieldType,
source: item.source,
orderIndex: this.parameters.length
}
this.parameters.push(parameterItem)
this.setState({
value: this.state.value + fieldName
})
}
2022-04-18 11:42:45 +08:00
render() {
const {salaryItemStore} = this.props;
2022-04-18 15:33:19 +08:00
const { searchGroup, searchFields } = salaryItemStore
2022-04-18 11:42:45 +08:00
const { value } = this.state;
return (
2022-04-18 15:33:19 +08:00
<Modal title="函数公式" visible={this.props.visible}
2022-05-06 10:11:45 +08:00
maskClosable={false}
2022-04-18 15:33:19 +08:00
width={800}
footer={
<Button type="primary" onClick={() => {this.handleSave()}}>保存</Button>
}
onCancel={() => {this.props.onCancel()}}>
2022-05-05 09:13:38 +08:00
{
(this.props.valueType == "3" || this.referenceType == 'sql') && <div style={{marginBottom: '10px', lineHeight: "30px"}}>
返回字段<WeaInput style={{width: '150px'}} value={this.state.returnValue} onChange={(value) => {this.setState({returnValue: value})}} />
</div>
}
2022-04-18 11:42:45 +08:00
<div>
2022-04-18 15:33:19 +08:00
<WeaTextarea
2022-05-06 10:11:45 +08:00
ref={(input) => this.contentProps = input}
2022-04-18 15:33:19 +08:00
minRows={8}
maxRows={8}
value={value} onChange={(value) => this.handleChange(value)}
noResize={true}
style={{fontSize: "14px", lineHeight: 1.2}}
/>
2022-04-18 11:42:45 +08:00
</div>
2022-04-18 15:33:19 +08:00
<div style={{display: "flex", height: "300px", marginTop: "10px" }}>
<div style={{flex: 1, height: "300px", overflowY: "scroll", padding: "10px", border: "1px solid rgb(217, 217, 217)", marginRight: '10px'}} >
2022-04-18 11:42:45 +08:00
<div>
2022-04-18 15:33:19 +08:00
<div style={{marginBottom: "10px", fontSize: "14px"}}>变量</div>
2022-04-18 11:42:45 +08:00
<div>
{
2022-04-18 15:33:19 +08:00
searchGroup && searchGroup.map(item => {
return <div style={{height: "25px", lineHeight: '25px', cursor: "pointer", overflow: "hidden"}} key={item.key} onClick={() => {this.handleItemClick(item)}}>
2022-04-18 11:42:45 +08:00
{item.value}
2022-04-18 15:33:19 +08:00
<Icon type="right" style={{float: "right", marginLeft: "10px", color: "#eee"}}/>
<span style={{color: "#999", float: 'right'}}>{item.value} 的字段</span>
2022-04-18 11:42:45 +08:00
</div>
})
}
</div>
</div>
</div>
2022-04-18 15:33:19 +08:00
<div style={{flex: 1, height: "300px", overflowY: "scroll", border: "1px solid rgb(217, 217, 217)", padding: "10px"}}>
{
searchFields && searchFields.map(item => {
return (
<div style={{height: "25px", lineHeight: "25px", cursor: "pointer"}} key={item.fieldId} onClick={() => {this.handleFieldClick(item)}}>
{item.name}
</div>
)
})
}
2022-04-18 11:42:45 +08:00
</div>
</div>
</Modal>
)
}
}