trunk/pc4mobx/organization/components/numberSetting/branchNumSetting/index.js

418 lines
13 KiB
JavaScript
Raw Normal View History

2022-05-30 10:25:30 +08:00
/*
* Author: 黎永顺
* Description: 分部编号设置
* Date: 2022-05-17 14:30:57
2022-06-15 13:17:33 +08:00
* LastEditTime: 2022-06-14 18:26:07
2022-05-30 10:25:30 +08:00
*/
import React, { Component, Fragment } from "react";
2022-06-07 18:01:50 +08:00
import { inject, observer } from "mobx-react";
import { Button, message } from "antd";
import {
WeaTop,
WeaFormItem,
WeaCheckbox,
WeaSearchGroup,
WeaSelect,
WeaHelpfulTip,
} from "ecCom";
2022-05-30 10:25:30 +08:00
import StartReservedNumberSet from "./components/startReservedNumberSet";
2022-06-15 13:17:33 +08:00
import { serialFieldOptions } from "../constants";
2022-05-30 10:25:30 +08:00
import NumberComposition from "./components/numberComposition";
2022-06-15 13:17:33 +08:00
import { i18n } from "../../../public/i18n";
2022-06-07 18:01:50 +08:00
import moment from "moment";
2022-05-30 10:25:30 +08:00
import "./index.less";
2022-05-17 18:32:09 +08:00
2022-06-07 18:01:50 +08:00
@inject("numberSet")
@observer
2022-05-30 10:25:30 +08:00
export default class BranchNumSetting extends Component {
2022-05-17 18:32:09 +08:00
constructor() {
super();
this.state = {
2022-06-07 18:01:50 +08:00
options: [],
loading: false,
dataSource: [],
startNumberInfo: {
columns: [],
dataSource: [],
},
subCompanyInfo: {
details: [],
serialenable: "0",
dateSerial: {
enable: "0",
key: "",
},
},
2022-05-17 18:32:09 +08:00
};
}
2022-06-07 18:01:50 +08:00
componentDidMount() {
this.getCodeSetting();
}
getCodeSetting = () => {
const { numberSet } = this.props;
numberSet
.getCodeSetting({ serialtype: "SUBCOMPANY" })
.then(({ api_status, details, serialenable, dateSerial = {} }) => {
if (api_status && !_.isEmpty(details)) {
this.setState({
subCompanyInfo: { details, serialenable, dateSerial },
});
}
});
};
handleSubmit = () => {
2022-06-15 13:17:33 +08:00
let promise = new Promise((resolve, reject) => {
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: "SUBCOMPANY",
}),
2022-06-07 18:01:50 +08:00
};
2022-06-15 13:17:33 +08:00
this.setState({ loading: true });
numberSet.saveOrUpdateCodeSetting(payload).then(({ api_status }) => {
this.setState({ loading: false });
if (api_status) {
message.success("保存成功");
resolve(api_status);
} else {
reject("接口调用失败");
}
});
2022-06-07 18:01:50 +08:00
});
2022-06-15 13:17:33 +08:00
return promise;
2022-06-07 18:01:50 +08:00
};
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 };
}),
});
};
2022-06-15 13:17:33 +08:00
handleSetNumber = (type, data = {}) => {
this.handleSubmit().then((res) => {
const { numberSet } = this.props;
const { subCompanyInfo } = this.state;
const { dateSerial } = subCompanyInfo;
if (type === "start") {
const formatVal = dateSerial.key === "YEAR" ? "YYYY" : dateSerial.key === "MONTH" ? "YYYY-MM" : "YYYY-MM-DD";
const payload = {
coderuleid: 1,
type: dateSerial.enable == '1' ? dateSerial.key : '',
dateStart: data.startDate ? data.startDate : moment().format(formatVal),
dateEnd: data.endDate ? data.endDate : moment().format(formatVal),
subCompanyId: "",
deptId: "",
jobtitlesId: "",
};
numberSet
.getStartNumForm(payload)
.then(({ api_status, columns, dataSource }) => {
if (api_status) {
this.setState({
startNumberInfo: { columns, dataSource },
});
}
});
} else {
numberSet.getAdvanceSearchCondition();
numberSet.getSearchReservedCodeList({
serialtype: "SUBCOMPANY",
checkboxType: "multi",
2022-06-07 18:01:50 +08:00
});
2022-06-15 13:17:33 +08:00
}
});
2022-06-07 18:01:50 +08:00
};
handleChangeTable = (newColumns, datas) => {
this.setState({
startNumberInfo: {
...this.state.startNumberInfo,
columns: newColumns,
dataSource: datas,
},
});
};
handleSubmitStartNumber = () => {
const { numberSet } = this.props;
const payload = {
datas: JSON.stringify({
coderuleid: 1,
...this.state.startNumberInfo,
}),
};
numberSet.saveStartNum(payload).then(({ api_status }) => {
if (api_status) {
message.success("保存成功");
this.numberSetRef.handleClose();
}
});
};
2022-05-23 17:40:49 +08:00
2022-06-15 13:17:33 +08:00
/**
* name: 删除预留编号
* param {*} ids
* return {*}
*/
deleteReservedNumber = (ids) => {
const { numberSet } = this.props;
numberSet.deleteReservedCodeById({ ids }).then(({ api_status }) => {
if (api_status) {
message.success("删除成功");
numberSet.getSearchReservedCodeList({
serialtype: "SUBCOMPANY",
checkboxType: "multi",
});
}
});
};
/**
* name:新增预留编号
* return {*}
*/
handleAddReservedNumber = () => {
const { numberSet } = this.props;
const { reservedForm } = numberSet;
const { options } = this.state;
numberSet.getReservedCodeFrom({ serialtype: "SUBCOMPANY" }).then(() => {
const type = _.get(_.last(options), ['key']);
const format = type === "YEAR" ? "YYYY" : type === "MONTH" ? "YYYY-MM" : "YYYY-MM-DD"
const payload = {
coderuleid: 1,
type,
dateStart: moment().format(format),
dateEnd: moment().format(format),
subCompanyId: "",
deptId: "",
jobtitlesId: "",
};
numberSet
.getStartNumForm(payload)
.then(({ api_status, dataSource }) => {
if (api_status && !_.isEmpty(dataSource)) {
const currentnumber = _.get(_.last(dataSource), ['startnum']);
reservedForm.updateFields({
currentnumber: {
value: currentnumber,
},
});
}
});
})
};
/**
* name: 保存预留设置
* param {*} params
* return {*}
*/
handleSubmitReservedNumber = (params) => {
const { numberSet } = this.props;
const payload = { ...params, serialtype: "SUBCOMPANY" };
this.setState({ loading: true });
numberSet.saveReservedCode(payload).then(({ api_status }) => {
this.setState({ loading: false });
if (api_status) {
message.success("保存成功");
this.numberSetRef.handleCloseReservedModal();
numberSet.getSearchReservedCodeList({
serialtype: "SUBCOMPANY",
checkboxType: "multi",
});
}
});
};
2022-05-30 10:25:30 +08:00
/**
* name:提示文本
* return {*}
*/
helpContent = () => {
return (
<div>
<p>开启后可根据设置的分部编号规则自动生成分部编号涉及场景如下</p>
<p>1.手动新建和手动编辑分部时可选择重新生成编号和选择预留分部编号</p>
<p>2.组织结构导入-添加新分部且分部编号列为空时会自动生成分部编号</p>
<p>3.导入人员-添加时新创建的分部可自动生成分部编号</p>
<p>注意开启前请先确认分部编号字段已启用</p>
</div>
);
2022-05-17 18:32:09 +08:00
};
render() {
2022-06-15 13:17:33 +08:00
const { numberSet } = this.props;
2022-06-07 18:01:50 +08:00
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(),
},
];
2022-05-17 18:32:09 +08:00
return (
2022-05-30 10:25:30 +08:00
<div className="branch-wapper">
<WeaTop
title={i18n.label.branchNumSetting()}
icon={<i className="icon-coms-hrm" />}
iconBgcolor="#217346"
buttons={btns}
showDropIcon={true}
dropMenuDatas={dropMenuDatas}
/>
<div className="branch-content">
<div className="switch-wrapper">
<WeaFormItem
label="分部编号自动生成"
labelCol={{ span: 8 }}
wrapperCol={{ span: 16 }}>
<WeaCheckbox
2022-06-07 18:01:50 +08:00
value={serialenable}
2022-05-30 10:25:30 +08:00
helpfulTip={this.helpContent}
helpfulTipProps={{ placement: "top" }}
display="switch"
id="num-set-switch"
2022-06-07 18:01:50 +08:00
onChange={(checkVal) =>
this.setState({
subCompanyInfo: {
...subCompanyInfo,
serialenable: checkVal,
},
})
}
2022-05-30 10:25:30 +08:00
/>
</WeaFormItem>
</div>
{/* 内容区 */}
2022-06-07 18:01:50 +08:00
{serialenable === "1" && (
2022-05-30 10:25:30 +08:00
<Fragment>
<div className="numberComposition">
<WeaSearchGroup title={"编号组成"} showGroup>
2022-06-07 18:01:50 +08:00
<NumberComposition
onChange={this.handleChangeCode}
dataSource={details}
2022-06-15 13:17:33 +08:00
options={serialFieldOptions}
2022-06-07 18:01:50 +08:00
/>
2022-05-30 10:25:30 +08:00
</WeaSearchGroup>
2022-05-18 14:15:10 +08:00
</div>
2022-06-07 18:01:50 +08:00
{!_.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,
2022-06-15 13:17:33 +08:00
key: isSingle == '0' ? 'YEAR' : dateSerial.key
2022-06-07 18:01:50 +08:00
},
},
})
}
/>
{dateSerial.enable == "1" && (
<WeaSelect
2022-06-15 13:17:33 +08:00
options={_.map(options, item => ({ ...item, showname: item.showname.substr(2, 1) }))}
2022-06-07 18:01:50 +08:00
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>
)}
2022-05-30 10:25:30 +08:00
<div className="startReservedNumberSet">
<WeaSearchGroup
title={"起始编号及预留编号设置"}
showGroup
center>
2022-06-07 18:01:50 +08:00
<StartReservedNumberSet
ref={(dom) => (this.numberSetRef = dom)}
2022-06-15 13:17:33 +08:00
loading={loading}
2022-06-07 18:01:50 +08:00
onSet={this.handleSetNumber}
2022-06-15 13:17:33 +08:00
companyInfo={subCompanyInfo}
2022-06-07 18:01:50 +08:00
startNumberInfo={startNumberInfo}
onChange={this.handleChangeTable}
onSaveStartNumber={this.handleSubmitStartNumber}
2022-06-15 13:17:33 +08:00
onDeleteReservedNumber={this.deleteReservedNumber}
onAddReservedNumber={this.handleAddReservedNumber}
onSubmitReservedNumber={this.handleSubmitReservedNumber}
onSearchReservedNumberset={() =>
numberSet.getSearchReservedCodeList({
serialtype: "SUBCOMPANY",
checkboxType: "multi",
})
}
2022-06-07 18:01:50 +08:00
/>
2022-05-30 10:25:30 +08:00
</WeaSearchGroup>
</div>
</Fragment>
)}
2022-05-17 18:32:09 +08:00
</div>
</div>
);
}
}