This commit is contained in:
MustangDeng 2022-04-18 15:33:19 +08:00
parent 082cbe1955
commit d5588c19f7
4 changed files with 133 additions and 29 deletions

View File

@ -136,7 +136,7 @@ export const formualSearchField = params => {
// /api/bs/hrmsalary/formula/save
// 保存公式
export const saveFormual = parmas => {
export const saveFormual = params => {
return fetch('/api/bs/hrmsalary/formula/save', {
method: 'POST',
mode: 'cors',

View File

@ -14,12 +14,9 @@ export default class CustomSalaryItemSlide extends React.Component {
formalModalVisible: false
}
}
handleChange(params) {
let request = {...this.props.request, ...params}
this.setState({
request,
showForm: e.target.value == 2 ? true: false
})
this.props.onChange(request)
}
@ -30,7 +27,7 @@ export default class CustomSalaryItemSlide extends React.Component {
}
render() {
const { request, editable } = this.props;
const { editable, request } = this.props;
const { name, useDefault, useInEmployeeSalary, roundingMode, pattern, valueType, description, dataType } = request;
const { formalModalVisible } = this.state;
return (
@ -103,27 +100,23 @@ export default class CustomSalaryItemSlide extends React.Component {
<Col span={4}>取值方式<RequiredLabelTip /></Col>
<Col span={20}>
<Radio.Group disabled={editable? false: true} value={valueType} onChange={(e) => {
this.handleChange({valueType: e.target.value}, e.target.value)
this.handleChange({valueType: e.target.value})
}}>
<Radio value={1}>输入</Radio>
<Radio value={2}>公式</Radio>
</Radio.Group>
</Col>
</Row>
{
this.state.showForm &&
<Row className="formItem">
valueType == 2 && <Row className="formItem">
<Col span={4}>公式</Col>
<Col span={20}>
<div style={{width: "100%", height: "40px", border: "1px solid #eee"}}
onClick={this.handleShowFormal()}
<div style={{width: "100%", height: "30px", border: "1px solid rgb(217, 217, 217)"}}
onClick={() => this.handleShowFormal()}
></div>
</Col>
</Row>
}
<Row className="formItem">
<Col span={4}>备注</Col>
@ -137,8 +130,8 @@ export default class CustomSalaryItemSlide extends React.Component {
formalModalVisible &&
<FormalFormModal
visible={formalModalVisible}
onCancel={this.setState({
formalModalVisible: false
onCancel={() => this.setState({
formalModalVisible: false
})}
/>
}

View File

@ -1,5 +1,5 @@
import React from 'react'
import {Modal} from 'antd'
import {Modal, Button, Icon } from 'antd'
import { WeaTextarea } from 'ecCom'
import { inject, observer } from 'mobx-react';
@ -11,44 +11,118 @@ export default class FormalFormModal extends React.Component {
this.state = {
value: ''
}
this.group = {};
this.field = {};
this.parameters = []
}
componentWillMount() {
const { salaryItemStore } = this.props;
const { salaryAcctImportTemplateParam } = salaryItemStore;
const { salaryAcctImportTemplateParam, setSearchFields } = salaryItemStore;
salaryAcctImportTemplateParam();
setSearchFields([])
}
// 多行文本编辑
handleChange(value) {
this.setState({
value
})
}
// 分组项被点击
handleItemClick(item) {
const { salaryItemStore } = this.props;
const { formualSearchField } = salaryItemStore;
this.group = item;
formualSearchField(item.key)
}
// 保存
handleSave() {
const { salaryItemStore } = this.props;
const { saveFormual } = salaryItemStore
let params = {
name:'公式1',
description:'备注',
module:'salary',
useFor:'salaryitem',
referenceType:'',
returnType:'number',
validateType:'number',
extendParam:'{}',
formula: this.state.value,
parameters: this.parameters
}
saveFormual(params)
}
// 字段点击回调
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
})
}
render() {
const {salaryItemStore} = this.props;
const { searchGroup } = salaryItemStore
const { searchGroup, searchFields } = salaryItemStore
const { value } = this.state;
return (
<Modal title="函数公式" visible={this.props.visible} width={800} height={900} onCancel={() => {this.props.onCancel()}}>
<Modal title="函数公式" visible={this.props.visible}
width={800}
footer={
<Button type="primary" onClick={() => {this.handleSave()}}>保存</Button>
}
onCancel={() => {this.props.onCancel()}}>
<div>
<WeaTextarea style={{width: "100%", height: "300px"}} value={value} onChange={this.handleChange} />
<WeaTextarea
minRows={8}
maxRows={8}
value={value} onChange={(value) => this.handleChange(value)}
noResize={true}
style={{fontSize: "14px", lineHeight: 1.2}}
/>
</div>
<div style={{display: "flex", height: "500px"}}>
<div style={{flex: 1, height: "100%", overflowY: "scroll"}} >
<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'}} >
<div>
<div>变量</div>
<div style={{marginBottom: "10px", fontSize: "14px"}}>变量</div>
<div>
{
searchGroup.map(item => {
return <div key={item.key}>
searchGroup && searchGroup.map(item => {
return <div style={{height: "25px", lineHeight: '25px', cursor: "pointer", overflow: "hidden"}} key={item.key} onClick={() => {this.handleItemClick(item)}}>
{item.value}
<Icon type="right" style={{float: "right", marginLeft: "10px", color: "#eee"}}/>
<span style={{color: "#999", float: 'right'}}>{item.value} 的字段</span>
</div>
})
}
</div>
</div>
</div>
<div style={{flex: 1, height: "100%"}}>
<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>
)
})
}
</div>
</div>

View File

@ -33,7 +33,20 @@ export class SalaryItemStore {
@observable tableDataSource = []; // 主列表
@observable tableColumns = []; // 主列表列
@observable searchGroup = []
// ** 公式 **
// 类型列表
@observable searchGroup = [];
// 字段列表
@observable searchFields = [];
// 设置字段列表
@action
setSearchFields = (searchFields) => {
this.searchFields = searchFields
}
@action
@ -248,4 +261,28 @@ export class SalaryItemStore {
}
})
}
// 获取公式变量字段
@action
formualSearchField = (sourceId) => {
API.formualSearchField({sourceId}).then(res => {
if(res.status) {
this.searchFields = res.data
} else {
message.error(res.errormsg || "获取失败")
}
})
}
// 保存公式
@action
saveFormual = (params) => {
API.saveFormual(params).then(res => {
if(res.status) {
message.success("保存成功");
} else {
message.error(res.errormsg || "保存失败");
}
})
}
}