trunk/pc4mobx/organization/components/postNumberSet/index.js

312 lines
9.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Author: 黎永顺
* Description: 岗位编号设置
* Date: 2022-06-06 09:37:39
* LastEditTime: 2022-06-07 18:13:32
*/
import React, { Component, Fragment } from "react";
import { inject, observer } from "mobx-react";
import { Button, message } from "antd";
import {
WeaTop,
WeaFormItem,
WeaCheckbox,
WeaSearchGroup,
WeaSelect,
WeaHelpfulTip,
} from "ecCom";
import StartReservedNumberSet from "../branchNumSetting/components/startReservedNumberSet";
import NumberComposition from "../branchNumSetting/components/numberComposition";
import { i18n } from "../../public/i18n";
import moment from "moment";
import "../branchNumSetting/index.less";
@inject("numberSet")
@observer
export default class PostNumberSet extends Component {
constructor() {
super();
this.state = {
options: [],
loading: false,
dataSource: [],
startNumberInfo: {
columns: [],
dataSource: [],
},
subCompanyInfo: {
details: [],
serialenable: "0",
dateSerial: {
enable: "0",
key: "",
},
},
};
}
componentDidMount() {
this.getCodeSetting();
}
getCodeSetting = () => {
const { numberSet } = this.props;
numberSet
.getCodeSetting({ serialtype: "JOBTITLES" })
.then(({ api_status, details, serialenable, dateSerial = {} }) => {
if (api_status && !_.isEmpty(details)) {
this.setState({
subCompanyInfo: { details, serialenable, dateSerial },
});
}
});
};
handleSubmit = () => {
const { numberSet } = this.props;
const { dataSource, subCompanyInfo } = this.state;
const { serialenable, dateSerial } = subCompanyInfo;
const details = _.map(dataSource, (it, showorder) => {
const { numField, value: rulevalue } = it;
return {
ruletype: _.upperCase(numField),
rulevalue,
showorder,
};
});
const payload = {
datas: JSON.stringify({
serialenable,
details,
dateSerial,
serialtype: "JOBTITLES",
}),
};
this.setState({ loading: true });
numberSet.saveOrUpdateCodeSetting(payload).then(({ api_status }) => {
this.setState({ loading: false });
if (api_status) {
message.success("保存成功");
}
});
};
handleChangeCode = (data) => {
const tmpV = _.filter(
data,
(it) =>
it.numField === "year" ||
it.numField === "month" ||
it.numField === "day"
);
this.setState({
dataSource: _.cloneDeep(data),
options: _.map(tmpV, (it) => {
const { numFieldName: showname, numField: key } = it;
return { key: _.upperCase(key), showname };
}),
});
};
handleSetNumber = (type) => {
this.handleSubmit();
const { numberSet } = this.props;
if (type === "start") {
const payload = {
coderuleid: 3,
type: "",
dateStart: moment().format("YYYY"),
dateEnd: moment().format("YYYY"),
subCompanyId: "",
deptId: "",
jobtitlesId: "",
};
numberSet
.getStartNumForm(payload)
.then(({ api_status, columns, dataSource }) => {
if (api_status) {
this.setState({
startNumberInfo: { columns, dataSource },
});
}
});
}
};
handleChangeTable = (newColumns, datas) => {
this.setState({
startNumberInfo: {
...this.state.startNumberInfo,
columns: newColumns,
dataSource: datas,
},
});
};
handleSubmitStartNumber = () => {
const { numberSet } = this.props;
const payload = {
datas: JSON.stringify({
coderuleid: 3,
...this.state.startNumberInfo,
}),
};
numberSet.saveStartNum(payload).then(({ api_status }) => {
if (api_status) {
message.success("保存成功");
this.numberSetRef.handleClose();
}
});
};
/**
* name:提示文本
* return {*}
*/
helpContent = () => {
return (
<div>
<p>开启后可根据设置的岗位编号规则自动生成岗位编号涉及场景如下</p>
<p>1.新建岗位和编辑岗位时可选择重新生成编号和选择预留编号</p>
<p>2.导入人员-添加时新创建的岗位可自动生成岗位编号</p>
<p>3.岗位导入新岗位且岗位编号列为空时可自动生成编号</p>
</div>
);
};
render() {
const { options, subCompanyInfo, loading, startNumberInfo } = this.state;
const { details, serialenable, dateSerial } = subCompanyInfo;
const btns = [
<Button type="primary" onClick={this.handleSubmit} loading={loading}>
保存
</Button>,
];
const dropMenuDatas = [
{
key: "save",
disabled: false,
icon: <i className="icon-coms-Preservation" />,
content: "保存",
onClick: (key) => this.handleSubmit(),
},
];
return (
<div className="dept-number-set">
<WeaTop
title={i18n.label.postNumSetting()}
icon={<i className="icon-coms-hrm" />}
iconBgcolor="#217346"
buttons={btns}
showDropIcon={true}
dropMenuDatas={dropMenuDatas}
/>
<div className="dept-content">
<div className="switch-wrapper">
<WeaFormItem
label="岗位编号自动生成"
labelCol={{ span: 8 }}
wrapperCol={{ span: 16 }}>
<WeaCheckbox
value={serialenable}
helpfulTip={this.helpContent}
helpfulTipProps={{ placement: "top" }}
display="switch"
id="num-set-switch"
onChange={(checkVal) =>
this.setState({
subCompanyInfo: {
...subCompanyInfo,
serialenable: checkVal,
},
})
}
/>
</WeaFormItem>
</div>
{/* 内容区 */}
{serialenable === "1" && (
<Fragment>
<div className="numberComposition">
<WeaSearchGroup title={"编号组成"} showGroup>
<NumberComposition
onChange={this.handleChangeCode}
dataSource={details}
/>
</WeaSearchGroup>
</div>
{!_.isEmpty(options) && (
<div className="codeNumbering">
<WeaSearchGroup title={"编号流水规则"} showGroup>
<div className="switch-wrapper">
<WeaFormItem
label="日期单独流水"
labelCol={{ span: 8 }}
wrapperCol={{ span: 16 }}>
<div className="codeNumbering-operateWapper">
<WeaCheckbox
value={dateSerial.enable ? dateSerial.enable : "0"}
display="switch"
id="dept-date-set-switch"
onChange={(isSingle) =>
this.setState({
subCompanyInfo: {
...subCompanyInfo,
dateSerial: {
...dateSerial,
enable: isSingle,
},
},
})
}
/>
{dateSerial.enable == "1" && (
<WeaSelect
options={options}
value={dateSerial.key}
detailtype={3}
supportCancel
onChange={(key) =>
this.setState({
subCompanyInfo: {
...subCompanyInfo,
dateSerial: {
...dateSerial,
key,
},
},
})
}
/>
)}
<WeaHelpfulTip
width={200}
title="开启后可设置按年、按月或按天单独流水如设置按年单独流水那每年的1月1日开始流水号从001开始重新流水。"
placement="topLeft"
/>
</div>
</WeaFormItem>
</div>
</WeaSearchGroup>
</div>
)}
<div className="startReservedNumberSet">
<WeaSearchGroup
title={"起始编号及预留编号设置"}
showGroup
center>
<StartReservedNumberSet
ref={(dom) => (this.numberSetRef = dom)}
onSet={this.handleSetNumber}
startNumberInfo={startNumberInfo}
onChange={this.handleChangeTable}
onSaveStartNumber={this.handleSubmitStartNumber}
/>
</WeaSearchGroup>
</div>
</Fragment>
)}
</div>
</div>
);
}
}