2023-04-11 13:41:56 +08:00
|
|
|
/*
|
|
|
|
|
* Author: 黎永顺
|
|
|
|
|
* name: 新增统计维度弹框
|
|
|
|
|
* Description:
|
|
|
|
|
* Date: 2023/4/11
|
|
|
|
|
*/
|
|
|
|
|
import React, { Component } from "react";
|
2023-04-19 09:29:38 +08:00
|
|
|
import { WeaDialog, WeaLocaleProvider, WeaSearchGroup } from "ecCom";
|
2023-04-12 15:53:32 +08:00
|
|
|
import { Button, message, Modal } from "antd";
|
2023-04-12 10:47:51 +08:00
|
|
|
import { dimensionGetForm, dimensionSave } from "../../../apis/statistics";
|
2023-04-11 13:41:56 +08:00
|
|
|
import { getSearchs } from "../../../util";
|
2023-04-12 15:53:32 +08:00
|
|
|
import GroupSpacingEditTable from "./groupSpacingEditTable";
|
|
|
|
|
import GroupIndividualEditTable from "./groupIndividualEditTable";
|
2023-04-11 13:41:56 +08:00
|
|
|
import "../index.less";
|
|
|
|
|
|
2023-04-17 17:32:16 +08:00
|
|
|
const { getLabel } = WeaLocaleProvider;
|
2023-04-12 15:53:32 +08:00
|
|
|
const keyObj = {
|
|
|
|
|
"RATION_GROUP_SPACING": "setting4RationGroupSpacing",
|
|
|
|
|
"RATION_GROUP_INDIVIDUAL": "setting4RationGroupIndividual"
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-11 13:41:56 +08:00
|
|
|
class DimensionSlide extends Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
2023-04-12 10:47:51 +08:00
|
|
|
loading: false,
|
2023-04-12 15:53:32 +08:00
|
|
|
dimType: "QUALITATIVE",
|
|
|
|
|
setting4RationGroupSpacing: [],
|
|
|
|
|
setting4RationGroupIndividual: []
|
2023-04-11 13:41:56 +08:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-12 10:47:51 +08:00
|
|
|
componentDidMount() {
|
|
|
|
|
this.props.initCondition();
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-11 13:41:56 +08:00
|
|
|
componentWillReceiveProps(nextProps, nextContext) {
|
2023-04-12 10:47:51 +08:00
|
|
|
if (nextProps.visible !== this.props.visible && nextProps.formId) this.dimensionGetForm({ id: nextProps.formId });
|
|
|
|
|
if (nextProps.visible !== this.props.visible && !nextProps.formId) {
|
|
|
|
|
nextProps.form.updateFields({
|
|
|
|
|
dimType: "QUALITATIVE"
|
|
|
|
|
});
|
|
|
|
|
nextProps.onChangeCondition("QUALITATIVE");
|
2023-04-11 13:41:56 +08:00
|
|
|
}
|
2023-04-12 15:53:32 +08:00
|
|
|
if (nextProps.visible !== this.props.visible && !nextProps.visible) {
|
|
|
|
|
this.setState({
|
|
|
|
|
loading: false,
|
|
|
|
|
dimType: "QUALITATIVE",
|
|
|
|
|
setting4RationGroupSpacing: [],
|
|
|
|
|
setting4RationGroupIndividual: []
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-04-11 13:41:56 +08:00
|
|
|
}
|
|
|
|
|
|
2023-04-12 15:53:32 +08:00
|
|
|
|
2023-04-12 10:47:51 +08:00
|
|
|
dimensionGetForm = (payload) => {
|
|
|
|
|
dimensionGetForm(payload).then(({ status, data }) => {
|
|
|
|
|
if (status) {
|
|
|
|
|
const { baseForm: { data: formData } } = data;
|
2023-04-19 09:29:38 +08:00
|
|
|
const setting = formData.setting ? JSON.parse(formData.setting) : {};
|
2023-04-12 10:47:51 +08:00
|
|
|
this.props.onChangeCondition(formData["dimType"], 1);
|
2023-04-12 15:53:32 +08:00
|
|
|
this.setState({
|
|
|
|
|
dimType: formData.dimType,
|
|
|
|
|
[keyObj[formData["dimType"]]]: setting
|
|
|
|
|
}, () => {
|
|
|
|
|
const fields = _.map(this.props.condition[0].items, it => {
|
|
|
|
|
return it.domkey[0];
|
|
|
|
|
});
|
|
|
|
|
fields.map(item => {
|
|
|
|
|
if (item !== "setting4Qualitative") {
|
|
|
|
|
this.props.form.updateFields({
|
|
|
|
|
[item]: formData[item] || ""
|
|
|
|
|
});
|
|
|
|
|
} else if (item === "setting4Qualitative" && formData.statsDim) {
|
|
|
|
|
this.props.form.updateFields({
|
|
|
|
|
setting4Qualitative: formData.statsDim
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2023-04-12 10:47:51 +08:00
|
|
|
}
|
|
|
|
|
});
|
2023-04-11 13:41:56 +08:00
|
|
|
};
|
|
|
|
|
handleSave = () => {
|
2023-04-12 15:53:32 +08:00
|
|
|
const { dimType } = this.state;
|
2023-04-12 10:47:51 +08:00
|
|
|
const { condition, onCancel, formId } = this.props;
|
2023-04-12 15:53:32 +08:00
|
|
|
const { setting4Qualitative, dimCode, ...extraParams } = this.props.form.getFormParams();
|
|
|
|
|
let payload = { id: formId, ...extraParams };
|
|
|
|
|
if (dimType === "QUALITATIVE") {
|
|
|
|
|
if (!setting4Qualitative || !extraParams.dimName) {
|
|
|
|
|
Modal.warning({
|
2023-04-17 17:32:16 +08:00
|
|
|
title: getLabel(111, "信息确认"),
|
|
|
|
|
content: getLabel(111, "必要信息不完整,红色*为必填项!")
|
2023-04-12 15:53:32 +08:00
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const tjOptions = _.find(condition[0].items, item => item.domkey[0] === "setting4Qualitative").options;
|
|
|
|
|
const tjObj = _.find(tjOptions, item => item.key === setting4Qualitative);
|
|
|
|
|
payload = { ...payload, setting4Qualitative: { id: tjObj.key, name: tjObj.showname } };
|
|
|
|
|
} else {
|
|
|
|
|
if (!extraParams.dimName) {
|
|
|
|
|
Modal.warning({
|
2023-04-17 17:32:16 +08:00
|
|
|
title: getLabel(111, "信息确认"),
|
|
|
|
|
content: getLabel(111, "必要信息不完整,红色*为必填项!")
|
2023-04-12 15:53:32 +08:00
|
|
|
});
|
2023-04-12 10:47:51 +08:00
|
|
|
return;
|
2023-04-12 15:53:32 +08:00
|
|
|
}
|
|
|
|
|
if (dimType === "RATION_GROUP_SPACING") {
|
|
|
|
|
const { setting4RationGroupSpacing } = this.state;
|
|
|
|
|
const bool = _.every(setting4RationGroupSpacing, it => it.startValue !== "" && it.endValue !== "" && it.startValue <= it.endValue);
|
|
|
|
|
if (_.isEmpty(setting4RationGroupSpacing) || !bool) {
|
2023-04-17 17:32:16 +08:00
|
|
|
message.warning(getLabel(111, "请完善分组设置相关数据!分组设置不能为空,起始值结束值必填,且起始值需小于结束值!"));
|
2023-04-12 15:53:32 +08:00
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
payload = {
|
|
|
|
|
...payload, dimCode,
|
|
|
|
|
setting4RationGroupSpacing: _.map(setting4RationGroupSpacing, (it, index) => ({
|
|
|
|
|
id: index + 1,
|
|
|
|
|
endValue: it.endValue,
|
|
|
|
|
startValue: it.startValue,
|
|
|
|
|
includeEnd: it.includeEnd === "1",
|
|
|
|
|
includeStart: it.includeStart === "1"
|
|
|
|
|
}))
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
} else if (dimType === "RATION_GROUP_INDIVIDUAL") {
|
|
|
|
|
const { setting4RationGroupIndividual } = this.state;
|
|
|
|
|
const bool = _.every(setting4RationGroupIndividual, it => it.value !== "");
|
|
|
|
|
if (_.isEmpty(setting4RationGroupIndividual) || !bool) {
|
2023-04-17 17:32:16 +08:00
|
|
|
message.warning(getLabel(111, "请完善分组设置相关数据!分组设置不能为空,且数值必填"));
|
2023-04-12 15:53:32 +08:00
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
payload = {
|
|
|
|
|
...payload, dimCode,
|
|
|
|
|
setting4RationGroupIndividual: _.map(setting4RationGroupIndividual, (it, index) => ({ id: index + 1, ...it }))
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.setState({ loading: true });
|
|
|
|
|
dimensionSave(payload).then(({ status, errormsg }) => {
|
|
|
|
|
this.setState({ loading: false });
|
|
|
|
|
if (status) {
|
2023-04-17 17:32:16 +08:00
|
|
|
message.success(getLabel(111, "保存成功"));
|
2023-04-12 15:53:32 +08:00
|
|
|
onCancel(true);
|
|
|
|
|
this.props.form.resetForm();
|
2023-04-11 13:41:56 +08:00
|
|
|
} else {
|
2023-04-17 17:32:16 +08:00
|
|
|
message.error(errormsg || getLabel(111, "保存失败"));
|
2023-04-11 13:41:56 +08:00
|
|
|
}
|
2023-04-12 15:53:32 +08:00
|
|
|
}).catch(() => this.setState({ loading: false }));
|
2023-04-11 13:41:56 +08:00
|
|
|
};
|
2023-04-12 10:47:51 +08:00
|
|
|
formItemChange = (formObj) => {
|
|
|
|
|
const { onChangeCondition } = this.props;
|
|
|
|
|
const filedKey = _.keys(formObj)[0];
|
2023-04-12 15:53:32 +08:00
|
|
|
if (filedKey === "dimType") {
|
|
|
|
|
this.setState({
|
|
|
|
|
dimType: formObj[filedKey].value,
|
|
|
|
|
setting4RationGroupSpacing: [],
|
|
|
|
|
setting4RationGroupIndividual: []
|
|
|
|
|
}, () => onChangeCondition(formObj[filedKey].value));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
handleConvertGroupDatasource = (data) => {
|
|
|
|
|
const { dimType } = this.state;
|
|
|
|
|
this.setState({ [keyObj[dimType]]: data });
|
2023-04-12 10:47:51 +08:00
|
|
|
};
|
2023-04-11 13:41:56 +08:00
|
|
|
|
|
|
|
|
render() {
|
2023-04-12 15:53:32 +08:00
|
|
|
const { loading, dimType, setting4RationGroupSpacing, setting4RationGroupIndividual } = this.state;
|
2023-04-28 10:08:14 +08:00
|
|
|
const { form, condition, formId } = this.props;
|
2023-04-11 13:41:56 +08:00
|
|
|
return (
|
|
|
|
|
<WeaDialog
|
|
|
|
|
{...this.props}
|
|
|
|
|
initLoadCss hasScroll
|
2023-04-28 10:00:10 +08:00
|
|
|
style={{ width: 900, height: 450 }}
|
2023-04-11 13:41:56 +08:00
|
|
|
className="dimensionSlideWrapper"
|
|
|
|
|
title={
|
|
|
|
|
<div className="dimensionTitle">
|
2023-04-28 10:08:14 +08:00
|
|
|
<span>{formId ? getLabel(111, "编辑统计维度") : getLabel(111, "新建统计维度")}</span>
|
2023-04-17 17:32:16 +08:00
|
|
|
<Button type="primary" onClick={this.handleSave} loading={loading}>{getLabel(111, "保存")}</Button>
|
2023-04-11 13:41:56 +08:00
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
>
|
2023-04-12 10:47:51 +08:00
|
|
|
{getSearchs(form, condition, 1, false, this.formItemChange)}
|
2023-04-12 15:53:32 +08:00
|
|
|
{
|
|
|
|
|
dimType !== "QUALITATIVE" &&
|
2023-04-17 17:32:16 +08:00
|
|
|
<WeaSearchGroup title={getLabel(111, "分组设置")} showGroup>
|
2023-04-12 15:53:32 +08:00
|
|
|
{
|
|
|
|
|
dimType === "RATION_GROUP_SPACING" &&
|
|
|
|
|
<GroupSpacingEditTable onChange={this.handleConvertGroupDatasource}
|
|
|
|
|
setting4RationGroupSpacing={setting4RationGroupSpacing}/>
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
dimType === "RATION_GROUP_INDIVIDUAL" &&
|
|
|
|
|
<GroupIndividualEditTable onChange={this.handleConvertGroupDatasource}
|
|
|
|
|
setting4RationGroupIndividual={setting4RationGroupIndividual}/>
|
|
|
|
|
}
|
|
|
|
|
</WeaSearchGroup>
|
|
|
|
|
}
|
2023-04-11 13:41:56 +08:00
|
|
|
</WeaDialog>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default DimensionSlide;
|