From 3ab54027f9bb24ef9a4cf0806a436ceccfda1079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E6=B0=B8=E9=A1=BA?= <971387674@qq.com> Date: Mon, 13 Nov 2023 14:13:03 +0800 Subject: [PATCH] =?UTF-8?q?feature/2.9.42311.02-=E6=88=91=E7=9A=84?= =?UTF-8?q?=E8=96=AA=E8=B5=84=E7=A6=8F=E5=88=A9=E7=A7=BB=E5=8A=A8=E7=AB=AF?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=9F=A5=E7=9C=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/mobileDatePicker/index.js | 65 +++++++---------- .../hrmSalary/pages/mySalaryMobile/index.js | 73 +++---------------- .../hrmSalary/pages/mySalaryMobile/index.less | 8 +- 3 files changed, 43 insertions(+), 103 deletions(-) diff --git a/pc4mobx/hrmSalary/pages/mySalaryMobile/components/mobileDatePicker/index.js b/pc4mobx/hrmSalary/pages/mySalaryMobile/components/mobileDatePicker/index.js index a17b065e..dde59609 100644 --- a/pc4mobx/hrmSalary/pages/mySalaryMobile/components/mobileDatePicker/index.js +++ b/pc4mobx/hrmSalary/pages/mySalaryMobile/components/mobileDatePicker/index.js @@ -16,60 +16,49 @@ class Index extends Component { constructor(props) { super(props); this.state = { - yearList: {}, monthList: {} + visible: false, + salaryYearMonth: { year: "", month: "" } }; } componentWillReceiveProps(nextProps, nextContext) { - if (nextProps.visible !== this.props.visible && nextProps.visible) { - this.setState({ - yearList: { - list: YearFn(Number(moment().subtract(100, "year").format("YYYY")), Number(moment().add(100, "year").format("YYYY"))), - defaultValue: nextProps[nextProps.type].defaultValueYear, - displayValue(name) { - return name; - } - }, - monthList: { - list: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"], - defaultValue: nextProps.type === "salaryStart" ? "0" : nextProps[nextProps.type].defaultValueMonth, - displayValue(name) { - return name; - } - } - }, () => { - console.log(this.state); - }); - } + const { value } = nextProps; + const [year, month] = value.split("-"); + this.setState({ + salaryYearMonth: { year, month } + }); } handleChangeYear = (year) => { - this.setState({ - yearList: { - ...this.state.yearList, - defaultValue: year - } - }, () => this.props.onChange(this.props.type, "defaultValueYear", year)); + this.setState({ salaryYearMonth: { ...this.state.salaryYearMonth, year } }); }; handleChangeMonth = (month) => { - this.setState({ - monthList: { - ...this.state.monthList, - defaultValue: "" - } - }, () => this.props.onChange(this.props.type, "defaultValueMonth", month)); + + this.setState({ salaryYearMonth: { ...this.state.salaryYearMonth, month: parseInt(month).toString() } }); + }; + handleCancel = () => { + this.setState({ visible: false }); + }; + handleConfirm = () => { + const { year, month } = this.state.salaryYearMonth; + this.setState({ visible: false }, () => { + this.props.onChange(moment(new Date(`${year}- ${month}`)).format("YYYY-MM")); + }); }; render() { - const { yearList, monthList } = this.state; + const { value } = this.props; + const { visible } = this.state; + const [year, month] = value.split("-"); return (