115 lines
3.4 KiB
JavaScript
115 lines
3.4 KiB
JavaScript
/*
|
|
* Author: 黎永顺
|
|
* name: 考勤数据引用
|
|
* Description:
|
|
* Date: 2023/3/1
|
|
*/
|
|
import React, { Component } from "react";
|
|
import { inject, observer } from "mobx-react";
|
|
import { WeaDialog } from "ecCom";
|
|
import { Button, message } from "antd";
|
|
import { reFrenceConditions } from "../columns";
|
|
import { getSearchs } from "../../../../util";
|
|
import { checkOperation, getLedgerList, syncAttendanceRefer } from "../../../../apis/attendance";
|
|
import "./index.less";
|
|
|
|
@inject("attendanceStore")
|
|
@observer
|
|
class AttendanceRefrenceDataModal extends Component {
|
|
constructor(props) {
|
|
super(props);
|
|
this.state = {
|
|
loading: false,
|
|
condition: []
|
|
};
|
|
}
|
|
|
|
componentDidMount() {
|
|
this.getLedgerList();
|
|
}
|
|
|
|
componentWillReceiveProps(nextProps, nextContext) {
|
|
if (nextProps.visible !== this.props.visible && nextProps.visible) this.handleResetForm();
|
|
}
|
|
|
|
getLedgerList = () => {
|
|
const { attendanceStore: { refenceform } } = this.props;
|
|
getLedgerList().then(({ status, data }) => {
|
|
if (status) {
|
|
this.setState({
|
|
condition: _.map(reFrenceConditions, (item) => {
|
|
const { items } = item;
|
|
return {
|
|
...item,
|
|
items: _.map(items, child => {
|
|
const { domkey } = child;
|
|
if (domkey[0] === "salarySobId") {
|
|
return { ...child, options: _.map(data, it => ({ key: it.id, showname: it.content })) };
|
|
}
|
|
return { ...child };
|
|
})
|
|
};
|
|
})
|
|
}, () => refenceform.initFormFields(this.state.condition));
|
|
}
|
|
});
|
|
};
|
|
/*
|
|
* Author: 黎永顺
|
|
* Description: 同步考勤数据
|
|
* Params:
|
|
* Date: 2023/3/1
|
|
*/
|
|
handleSubmitFields = () => {
|
|
const { attendanceStore: { refenceform }, onCancel } = this.props;
|
|
refenceform.validateForm().then(f => {
|
|
if (f.isValid) {
|
|
const payload = refenceform.getFormParams();
|
|
const checkPayload = { salaryYearMonthStr: payload.salaryYearMonth, salarySobId: payload.salarySobId };
|
|
this.setState({ loading: true });
|
|
checkOperation(checkPayload).then(({ status, errormsg: errormessage }) => {
|
|
if (status) {
|
|
syncAttendanceRefer(payload).then(({ status, errormsg }) => {
|
|
this.setState({ loading: false });
|
|
if (status) {
|
|
message.success("同步成功");
|
|
onCancel(true);
|
|
} else {
|
|
message.error(errormsg || "同步失败");
|
|
}
|
|
}).catch(() => this.setState({ loading: false }));
|
|
} else {
|
|
this.setState({ loading: false });
|
|
message.error(errormessage);
|
|
}
|
|
}).catch(() => this.setState({ loading: false }));
|
|
} else {
|
|
f.showErrors();
|
|
}
|
|
});
|
|
};
|
|
handleResetForm = () => {
|
|
const { attendanceStore: { refenceform } } = this.props;
|
|
refenceform.resetForm();
|
|
};
|
|
|
|
render() {
|
|
const { condition, loading } = this.state;
|
|
const { attendanceStore: { refenceform } } = this.props;
|
|
const buttons = [
|
|
<Button type="primary" onClick={this.handleSubmitFields} loading={loading}>同步</Button>
|
|
];
|
|
return (
|
|
<WeaDialog
|
|
{...this.props} style={{ width: 440, height: 156 }}
|
|
buttons={buttons} hasScroll initLoadCss
|
|
className="modalWrapper"
|
|
>
|
|
{getSearchs(refenceform, condition, 1)}
|
|
</WeaDialog>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default AttendanceRefrenceDataModal;
|