import React from "react"; import { inject, observer } from "mobx-react"; import { WeaHelpfulTip, WeaTab } from "ecCom"; import { Button, Spin } from "antd"; import { getQueryString } from "../../../util/url"; import { removePropertyCondition } from "../../../util/response"; import { getSearchs } from "../../../util"; import { getPayrollDetailList, getPayrollDetailSa, getPayrollInfo } from "../../../apis/payroll"; import "./index.less"; @inject("payrollStore") @observer export default class PayrollDetail extends React.Component { constructor(props) { super(props); this.state = { salarySendDetailBaseInfo: {}, loading: false, condition: [], dataSource: [], columns: [], pageInfo: { current: 1, pageSize: 10, total: 0 } }; } componentWillMount() { this.getPayrollDetailList(); } componentDidMount() { this.getPayrollInfo(); this.getPayrollDetailSa(); window.addEventListener("message", this.handleReceiveMessage, false); } componentWillUnmount() { window.removeEventListener("message", this.handleReceiveMessage, false); } handleReceiveMessage = async ({ data }) => { const { dataSource, columns, pageInfo } = this.state; const childFrameObj = document.getElementById("atdTable"); const { type, payload } = data; if (type === "turn") { const { id, params: { size: pageSize, pageNum: current, total } } = payload; if (id && id === "PAGEINFO") { this.setState({ pageInfo: { ...pageInfo, current, pageSize, total } }, () => this.getPayrollDetailList({ child: id })); } } if (type === "init") { childFrameObj.contentWindow.postMessage(JSON.stringify({ dataSource, columns, pageInfo, sumpayload: { salarySendId: getQueryString("id") } }), "*"); this.getPayrollDetailList({ child: type }); } }; getPayrollInfo = () => { const id = getQueryString("id"); getPayrollInfo({ id }).then(({ status, data }) => { if (status) { this.setState({ salarySendDetailBaseInfo: data }); } }); }; getPayrollDetailSa = () => { const { payrollStore } = this.props; const { detailListConditionForm } = payrollStore; getPayrollDetailSa().then(({ status, data }) => { if (status) { const condition = removePropertyCondition(data.condition); this.setState({ condition }, () => { detailListConditionForm.initFormFields(this.state.condition); }); } }); }; getPayrollDetailList = (extra = {}) => { const childFrameObj = document.getElementById("atdTable"); const { pageInfo } = this.state; const { child, ...extraParams } = extra; const salarySendId = getQueryString("id"); const { payrollStore } = this.props; const { detailListConditionForm: form } = payrollStore; const payload = { salarySendId, ...pageInfo, ...extraParams, ...form.getFormParams() }; this.setState({ loading: true }); getPayrollDetailList(payload).then(({ status, data }) => { this.setState({ loading: false }); if (status) { const { columns, datas: dataSource, pageInfo: pages } = data; const { pageNum: current, pageSize, total } = pages; this.setState({ dataSource, columns: _.map(columns, (item, index) => ({ dataIndex: item.column, title: item.text, width: item.width, fixed: index <= 2 ? "left" : null })), pageInfo: { ...pageInfo, current, pageSize, total } }, () => { const { pageInfo, dataSource, columns } = this.state; (child === "PAGEINFO" || child === "init") && childFrameObj.contentWindow.postMessage(JSON.stringify({ dataSource, columns, pageInfo, sumpayload: { salarySendId: getQueryString("id") } }), "*"); }); } }).catch(() => this.setState({ loading: false })); }; handleExportAll = () => { const salarySendId = getQueryString("id"); const url = `${window.location.origin}/api/bs/hrmsalary/salaryBill/send/exportDetailList?salarySendId=${salarySendId}`; window.open(url, "_self"); }; handleSearch = () => this.getPayrollDetailList({ child: "PAGEINFO", current: 1 }); render() { const { salarySendDetailBaseInfo, condition, loading } = this.state; const { payrollStore } = this.props; const { setDetailListShowSearchAd, detailListShowSearchAd, detailListConditionForm } = payrollStore; const { salaryMonth, template, sendNum, sendTotal } = salarySendDetailBaseInfo; const adBtn = [ , , ]; return (