From 490298121ed7c75f3a123c812f299d7b95667a35 Mon Sep 17 00:00:00 2001 From: ky_yusj <2655568377@qq.com> Date: Wed, 23 Jun 2021 09:03:57 +0800 Subject: [PATCH] update patrol --- .../house/info/form/base/building.jsx | 15 ++ .../business/house/info/form/patrol/grade.jsx | 173 +++++++++++++++++- .../house/info/form/patrol/handling.jsx | 126 ++++++++++++- .../house/info/form/patrol/result.jsx | 97 +++++++++- web-react/src/store/reducer/business.js | 11 ++ web-react/src/store/reducer/index.js | 4 +- 6 files changed, 421 insertions(+), 5 deletions(-) create mode 100644 web-react/src/store/reducer/business.js diff --git a/web-react/src/pages/business/house/info/form/base/building.jsx b/web-react/src/pages/business/house/info/form/base/building.jsx index 52264fe..c3a66f1 100644 --- a/web-react/src/pages/business/house/info/form/base/building.jsx +++ b/web-react/src/pages/business/house/info/form/base/building.jsx @@ -17,6 +17,9 @@ import { AntIcon } from 'components' import getDictData from 'util/dic' import moment from 'moment' import { CITY } from 'util/global' +import store from 'store' + +const { dispatch } = store const layout = { labelCol: { flex: '150px' }, @@ -76,6 +79,11 @@ export default class building extends Component { const { houseInfo } = this.record if (houseInfo.completedDate) { houseInfo.completedDate = moment(houseInfo.completedDate) + debugger + dispatch({ + type: 'PATROL_INIT_GRADE_BY_COMPLETED_DATE', + value: +houseInfo.completedDate.format('YYYY'), + }) } // checkbox @@ -160,6 +168,13 @@ export default class building extends Component { showKeepWarmMaterialText: value.includes('100'), }) } + + if (houseInfo.hasOwnProperty('completedDate')) { + dispatch({ + type: 'PATROL_INIT_GRADE_BY_COMPLETED_DATE', + value: +houseInfo.completedDate.format('YYYY'), + }) + } } //#region 自定义方法 diff --git a/web-react/src/pages/business/house/info/form/patrol/grade.jsx b/web-react/src/pages/business/house/info/form/patrol/grade.jsx index 7d0b4cb..806ecae 100644 --- a/web-react/src/pages/business/house/info/form/patrol/grade.jsx +++ b/web-react/src/pages/business/house/info/form/patrol/grade.jsx @@ -1,7 +1,176 @@ import React, { Component } from 'react' +import { Form, Input, Radio, Spin } from 'antd' +import { AntIcon } from 'components' +import { cloneDeep, first, isEqual, last, sortBy } from 'lodash' +import getDictData from 'util/dic' +import store from 'store' + +const { getState, subscribe } = store + +const layout = { + labelCol: { flex: '150px' }, + wrapperCol: { flex: '1' }, +} + +export default class handling extends Component { + state = { + loading: true, + codes: { + dicHousePatrolInitGrade: [], + dicHousePatrolDamageGrade: [], + dicHouseGrade: [], + }, + } + form = React.createRef() + + constructor(props) { + super(props) + + this.unsubscribe = subscribe('business', business => { + const initGrade = this.getInitGrade(business.completedDate) + this.form.current.setFieldsValue({ + patrolInfo: { + initGrade, + }, + }) + }) + } + + shouldComponentUpdate(props, state) { + return !isEqual(this.state, state) + } + + componentDidMount() { + this.fillData({ + record: this.props.record, + }) + } + + componentWillUnmount() { + this.unsubscribe() + } + + call() { + if (this.props.onRef) { + this.props.onRef(this) + } + } + + /** + * 填充数据 + * 可以在设置this.record之后对其作出数据结构调整 + * [异步,必要] + * @param {*} params + */ + async fillData(params) { + this.record = cloneDeep(params.record) + const _state = { loading: false } + //#region 从后端转换成前段所需格式 + if (this.record) { + const { patrolInfo } = this.record + patrolInfo.initGrade = this.getInitGrade(getState('business').completedDate) + } + _state.codes = await getDictData( + 'dic_house_patrol_init_grade', + 'dic_house_patrol_damage_grade', + 'dic_house_grade' + ) + //#endregion + this.form.current.setFieldsValue(this.record) + + this.setState(_state) + this.call() + } + + /** + * 获取数据 + * 可以对postData进行数据结构调整 + * [异步,必要] + * @returns + */ + async getData() { + const form = this.form.current + + const valid = await form.validateFields() + if (valid) { + const postData = form.getFieldsValue() + //#region 从前段转换后端所需格式 + + //#endregion + return postData + } + } + + getInitGrade(year) { + if (year > 1999) { + return 1 + } + if (year > 1994 && year < 2000) { + return 2 + } + if (year > 1979 && year < 1995) { + return 3 + } + if (year < 1980) { + return 4 + } + } -export default class grade extends Component { render() { - return
1
+ const { loading, codes, initGradeValue } = this.state + console.log(initGradeValue) + return ( + }> +
+ + + {codes.dicHousePatrolInitGrade.map(item => { + return ( + + {item.value} + + ) + })} + + + + + + {codes.dicHousePatrolDamageGrade.map(item => { + return ( + + {item.value} + + ) + })} + + + + + + {codes.dicHouseGrade.map(item => { + return ( + + {item.value} + + ) + })} + + +
+
+ ) } } diff --git a/web-react/src/pages/business/house/info/form/patrol/handling.jsx b/web-react/src/pages/business/house/info/form/patrol/handling.jsx index 70134ec..d3d5ad1 100644 --- a/web-react/src/pages/business/house/info/form/patrol/handling.jsx +++ b/web-react/src/pages/business/house/info/form/patrol/handling.jsx @@ -1,7 +1,131 @@ import React, { Component } from 'react' +import { Form, Input, Radio, Spin } from 'antd' +import { AntIcon } from 'components' +import { cloneDeep, first, isEqual, last, sortBy } from 'lodash' +import getDictData from 'util/dic' + +const layout = { + labelCol: { flex: '150px' }, + wrapperCol: { flex: '1' }, +} export default class handling extends Component { + state = { + loading: true, + codes: { + dicHousePatrolHandlingOpinion: [], + dicHousePatrolRectifyReform: [], + }, + } + form = React.createRef() + + shouldComponentUpdate(props, state) { + return !isEqual(this.state, state) + } + + componentDidMount() { + this.fillData({ + record: this.props.record, + }) + } + + call() { + if (this.props.onRef) { + this.props.onRef(this) + } + } + + /** + * 填充数据 + * 可以在设置this.record之后对其作出数据结构调整 + * [异步,必要] + * @param {*} params + */ + async fillData(params) { + this.record = cloneDeep(params.record) + const _state = { loading: false } + //#region 从后端转换成前段所需格式 + _state.codes = await getDictData( + 'dic_house_patrol_handling_opinion', + 'dic_house_patrol_rectify_Reform' + ) + //#endregion + this.form.current.setFieldsValue(this.record) + + this.setState(_state) + this.call() + } + + /** + * 获取数据 + * 可以对postData进行数据结构调整 + * [异步,必要] + * @returns + */ + async getData() { + const form = this.form.current + + const valid = await form.validateFields() + if (valid) { + const postData = form.getFieldsValue() + //#region 从前段转换后端所需格式 + + //#endregion + return postData + } + } render() { - return
1
+ const { loading, codes } = this.state + return ( + }> +
+ + + {codes.dicHousePatrolHandlingOpinion.map(item => { + return ( + + {item.value} + + ) + })} + + + + + + + + + + {codes.dicHousePatrolRectifyReform.map(item => { + return ( + + {item.value} + + ) + })} + + + + + + +
+
+ ) } } diff --git a/web-react/src/pages/business/house/info/form/patrol/result.jsx b/web-react/src/pages/business/house/info/form/patrol/result.jsx index 74674ba..7b92e2c 100644 --- a/web-react/src/pages/business/house/info/form/patrol/result.jsx +++ b/web-react/src/pages/business/house/info/form/patrol/result.jsx @@ -1,7 +1,102 @@ import React, { Component } from 'react' +import { Form, Input, Radio, Spin } from 'antd' +import { AntIcon } from 'components' +import { cloneDeep, first, isEqual, last, sortBy } from 'lodash' + +const layout = { + labelCol: { flex: '150px' }, + wrapperCol: { flex: '1' }, +} export default class result extends Component { + state = { + loading: true, + codes: { + patrolResult: [ + { code: '0', value: '正常' }, + { code: '-1', value: '异常' }, + ], + }, + } + form = React.createRef() + + shouldComponentUpdate(props, state) { + return !isEqual(this.state, state) + } + + componentDidMount() { + this.fillData({ + record: this.props.record, + }) + } + + call() { + if (this.props.onRef) { + this.props.onRef(this) + } + } + + /** + * 填充数据 + * 可以在设置this.record之后对其作出数据结构调整 + * [异步,必要] + * @param {*} params + */ + async fillData(params) { + this.record = cloneDeep(params.record) + //#region 从后端转换成前段所需格式 + + //#endregion + this.form.current.setFieldsValue(this.record) + + this.setState({ loading: false }) + this.call() + } + + /** + * 获取数据 + * 可以对postData进行数据结构调整 + * [异步,必要] + * @returns + */ + async getData() { + const form = this.form.current + + const valid = await form.validateFields() + if (valid) { + const postData = form.getFieldsValue() + //#region 从前段转换后端所需格式 + + //#endregion + return postData + } + } render() { - return
+ const { loading, codes } = this.state + + return ( + }> +
+ + + {codes.patrolResult.map(item => { + return ( + + {item.value} + + ) + })} + + + + + +
+
+ ) } } diff --git a/web-react/src/store/reducer/business.js b/web-react/src/store/reducer/business.js new file mode 100644 index 0000000..7d63a84 --- /dev/null +++ b/web-react/src/store/reducer/business.js @@ -0,0 +1,11 @@ +const business = (state = {}, action) => { + switch (action.type) { + case 'PATROL_INIT_GRADE_BY_COMPLETED_DATE': + const _state = { ...state, completedDate: action.value } + return _state + default: + return state + } +} + +export default business \ No newline at end of file diff --git a/web-react/src/store/reducer/index.js b/web-react/src/store/reducer/index.js index cd269ca..17c4c65 100644 --- a/web-react/src/store/reducer/index.js +++ b/web-react/src/store/reducer/index.js @@ -3,12 +3,14 @@ import user from './user' import layout from './layout' import nav from './nav' import dictData from './dict-data' +import business from './business' const combine = combineReducers({ user, layout, nav, - dictData + dictData, + business }) export default combine \ No newline at end of file