diff --git a/web-react/src/assets/style/lib/form-page.less b/web-react/src/assets/style/lib/form-page.less index 5446b96..ae47a95 100644 --- a/web-react/src/assets/style/lib/form-page.less +++ b/web-react/src/assets/style/lib/form-page.less @@ -12,8 +12,9 @@ height: 100%; >.ant-tabs { - >.ant-tabs-bar { + >.ant-tabs-nav { margin-bottom: 0; + padding: 0 @padding-md; background-color: @white; diff --git a/web-react/src/assets/style/lib/width-height.less b/web-react/src/assets/style/lib/width-height.less index ecf56c9..ae39ddc 100644 --- a/web-react/src/assets/style/lib/width-height.less +++ b/web-react/src/assets/style/lib/width-height.less @@ -3,13 +3,30 @@ .width-height (@i) when (@i <=20) { @n : @i * 50; + @px : @n * 1px; .w-@{n} { - width: @n * 1px !important; + width: @px !important; + } + + .w-@{n}-min { + min-width: @px !important; + } + + .w-@{n}-max { + max-width: @px !important; } .h-@{n} { - height: @n * 1px !important; + height: @px !important; + } + + .h-@{n}-min { + min-height: @px !important; + } + + .h-@{n}-max { + max-height: @px !important; } .w-@{n}-p { diff --git a/web-react/src/pages/business/house/code/form/index.jsx b/web-react/src/pages/business/house/code/form/index.jsx index 865b1b1..c6028dc 100644 --- a/web-react/src/pages/business/house/code/form/index.jsx +++ b/web-react/src/pages/business/house/code/form/index.jsx @@ -4,14 +4,15 @@ import { ComponentDynamic, Container } from 'components' import { isEqual } from 'lodash' import { api } from 'common/api' -const parts = [{ - component: () => import('./part') -}] +const parts = [ + { + component: () => import('./part'), + }, +] export default class index extends Component { - state = { - saving: false + saving: false, } children = [] @@ -28,10 +29,10 @@ export default class index extends Component { const data = await child.getData() this.formData = { ...this.formData, - ...data + ...data, } - } catch { - return + } catch (e) { + return e } } @@ -44,12 +45,10 @@ export default class index extends Component { Message.success('保存成功') Modal.confirm({ content: '已添加成功,是否继续添加?', - onOk: () => { - - }, + onOk: () => {}, onCancel: () => { window.closeContentWindow() - } + }, }) } } finally { @@ -69,7 +68,6 @@ export default class index extends Component { } render() { - const { id, param } = this.props return ( @@ -78,14 +76,16 @@ export default class index extends Component {
- { - parts.map((item, i) => ( -
- {item.title &&
{parts.title}
} - this.children.push(r)} /> -
- )) - } + {parts.map((item, i) => ( +
+ {item.title &&
{parts.title}
} + this.children.push(r)} + /> +
+ ))}
@@ -94,7 +94,13 @@ export default class index extends Component { - +
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 b193da6..39823bb 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 @@ -2,154 +2,159 @@ import React, { Component } from 'react' import { Row, Col, Form, Input, InputNumber, Radio, Checkbox, Switch, DatePicker, Spin } from 'antd' import { cloneDeep, isEqual } from 'lodash' import { api } from 'common/api' +import { AntIcon } from 'components' +import getDictData from 'util/dic' +import moment from 'moment' const layout = { labelCol: { flex: '150px' }, - wrapperCol: { flex: '1' } + wrapperCol: { flex: '1' }, } export default class building extends Component { - state = { loading: true, codes: { - landAttribute: [], - houseStructureType: [], - houseSseismicGrade: [], - houseBaseInfo: [], - houseInsulationMaterial: [], - houseWallMaterial: [], - houseFireproofGrade: [], - houseBuildingCurtainWall: [], - houseElevator: [], - } + dicLandAttribute: [], + dicHouseStructureType: [], + dicHouseAseismicGrade: [], + dicHouseBaseInfo: [], + dicHouseInsulationMaterial: [], + dicHouseWallMaterial: [], + dicHouseFireproofGrade: [], + dicHouseBuildingCurtainWall: [], + dicHouseElevator: [], + }, } + form = React.createRef() - constructor(props) { - super(props) - - // 使父组件获取到当前组件实例 - if (props.onRef) { - props.onRef(this) - } - } - shouldComponentUpdate(props, state) { - // 在上级页签切换时,阻止当前组件渲染,以保证性能 return !isEqual(this.state, state) } componentDidMount() { - this.onFillData() + if (this.props.onRef) { + this.props.onRef(this) + } + this.fillData({ + record: this.props.record, + }) } - onFillData = async () => { - await this.loadCodes() + /** + * 填充数据 + * 可以在设置this.record之后对其作出数据结构调整 + * [异步,必要] + * @param {*} params + */ + async fillData(params) { + this.record = cloneDeep(params.record) + //#region 从后端转换成前段所需格式 + if (this.record) { + const { completedDate } = this.record.houseInfo + this.record.houseInfo.completedDate = completedDate + ? moment(completedDate) + : completedDate + } + const codes = await getDictData( + 'dic_land_attribute', + 'dic_house_structure_type', + 'dic_house_aseismic_grade', + 'dic_house_base_info', + 'dic_house_insulation_material', + 'dic_house_wall_material', + 'dic_house_fireproof_grade', + 'dic_house_building_curtain_wall', + 'dic_house_elevator' + ) this.setState({ - loading: false + codes, + }) + //#endregion + this.form.current.setFieldsValue(this.record) + this.setState({ + loading: false, }) } - onGetData = () => { - return new Promise((resolve, reject) => { - this.form.current.validateFields() - .then(values => { - const record = cloneDeep(values) + /** + * 获取数据 + * 可以对postData进行数据结构调整 + * [异步,必要] + * @returns + */ + async getData() { + const form = this.form.current - resolve(record) - }).catch(err => { - reject(err) - }) - }) + const valid = await form.validateFields() + if (valid) { + const postData = form.getFieldsValue() + //#region 从前段转换后端所需格式 + if (postData.houseInfo.completedDate) { + postData.houseInfo.completedDate = + postData.houseInfo.completedDate.format('YYYY-MM-DD') + } + //#endregion + return postData + } } - loadCodes = async () => { - await api - .sysDictTypeDropDowns({ - code: [ - 'dic_land_attribute', - 'dic_house_structure_type', - 'dic_house_aseismic_grade', - 'dic_house_base_info', - 'dic_house_insulation_material', - 'dic_house_wall_material', - 'dic_house_fireproof_grade', - 'dic_house_building_curtain_wall', - 'dic_house_elevator', - ], - }) - .then( - ({ - data: { - dic_land_attribute, - dic_house_structure_type, - dic_house_aseismic_grade, - dic_house_base_info, - dic_house_insulation_material, - dic_house_wall_material, - dic_house_fireproof_grade, - dic_house_building_curtain_wall, - dic_house_elevator, - }, - }) => { - this.setState({ - codes: { - landAttribute: dic_land_attribute, - houseStructureType: dic_house_structure_type, - houseSseismicGrade: dic_house_aseismic_grade, - houseBaseInfo: dic_house_base_info, - houseInsulationMaterial: dic_house_insulation_material, - houseWallMaterial: dic_house_wall_material, - houseFireproofGrade: dic_house_fireproof_grade, - houseBuildingCurtainWall: dic_house_building_curtain_wall, - houseElevator: dic_house_elevator, - } - }) - } - ) - } + //#region 自定义方法 + //#endregion render() { return ( - -
- + }> + + - + - + - + - { - this.state.codes.landAttribute.map(item => { - return ( - {item.value} - ) - }) - } + {this.state.codes.dicLandAttribute.map(item => { + return ( + + {item.value} + + ) + })} - + - - + - - +
- +
- - - { - this.state.codes.houseStructureType.map(item => { - return ( - {item.value} - ) - }) - } + + + {this.state.codes.dicHouseStructureType.map(item => { + return ( + + {item.value} + + ) + })} - - - { - this.state.codes.houseSseismicGrade.map(item => { - return ( - {item.value} - ) - }) - } + + + {this.state.codes.dicHouseAseismicGrade.map(item => { + return ( + + {item.value} + + ) + })} - - - { - this.state.codes.houseBaseInfo.map(item => { - return ( - {item.value} - ) - }) - } + + + {this.state.codes.dicHouseBaseInfo.map(item => { + return ( + + {item.value} + + ) + })} - { - this.state.codes.houseInsulationMaterial.map(item => { - return ( - {item.value} - ) - }) - } - { + return ( + + {item.value} + + ) + })} + @@ -254,131 +271,156 @@ export default class building extends Component { - + - { - this.state.codes.houseWallMaterial.map(item => { - return ( - {item.value} - ) - }) - } + {this.state.codes.dicHouseWallMaterial.map(item => { + return ( + + {item.value} + + ) + })} - 外墙外保温材料
防火等级}> + + 外墙外保温材料 +
+ 防火等级 + + } + name={['houseInfo', 'fireproofGrade']} + > - { - this.state.codes.houseFireproofGrade.map(item => { - return ( - {item.value} - ) - }) - } + {this.state.codes.dicHouseFireproofGrade.map(item => { + return ( + + {item.value} + + ) + })}
- + - { - this.state.codes.houseBuildingCurtainWall.map(item => { - return ( - {item.value} - ) - }) - } + {this.state.codes.dicHouseBuildingCurtainWall.map(item => { + return ( + + {item.value} + + ) + })} - + - + - + - + - { - this.state.codes.houseElevator.map(item => { - return ( - {item.value} - ) - }) - } - + {this.state.codes.dicHouseElevator.map(item => { + return ( + + {item.value} + + ) + })} - + { /*$root.transfer.completedYear = date.format('YYYY') */ }} + onChange={date => { + /*$root.transfer.completedYear = date.format('YYYY') */ + }} className="w-100-p" placeholder="请选择竣工日期" /> - - - + + + - - - - - - + + + + + +
- - - + + + - - - - - - +
+ + + + +
- - - + + + - - - - - - + + + + + +
- - - + + + - - - 单元 - - - + + + + 单元 + + - - - + + + - - - - - - + + + + + + - + - + - + - + - + - +
- - - + + + - - - - - - - - - + + + + + + + + + + - - - - - - - - - + + + + + + + + + + - - - - - - + + + + + +
- + 地上第 - + 层,至 - + - + 地上 - + - + 地上第 - + 层,至 - + import('./building'), }, - { - title: '建筑物基本信息', - component: () => import('./building'), - }, - { - title: '建筑物基本信息', - component: () => import('./building'), - }, - { - title: '建筑物基本信息', - component: () => import('./building'), - }, - { - title: '建筑物基本信息', - component: () => import('./building'), - }, - { - title: '建筑物基本信息', - component: () => import('./building'), - }, ] export default class index extends Component { - container = window - forms = [] - constructor(props) { - super(props) + children = [] - // 使父组件获取到当前组件实例 - if (props.onRef) { - props.onRef(this) + formData = {} + + shouldComponentUpdate(props) { + return this.props.loading !== props.loading + } + + componentDidMount() { + if (this.props.onRef) { + this.props.onRef(this) } } @@ -49,68 +32,63 @@ export default class index extends Component { return this.container } - setContainer = (container) => { + setContainer = container => { this.container = (ReactDOM.findDOMNode(container) || {}).parentNode } - onGetData = () => { - return new Promise(async (resolve, reject) => { - let formData = {}, - flag = true - for (let i = 0; i < this.forms.length; i++) { - const form = this.forms[i] - try { - const data = await form.onGetData() - formData = defaultsDeep(formData, data) - } catch (err) { - flag = false - reject(err) - } + async getData() { + for (const child of this.children) { + const data = await child.getData() + this.formData = { + ...this.formData, + ...data, } - if (flag) { - resolve(formData) - } - }) + } + + return this.formData } render() { + const { id, loading } = this.props + return (
+
- { - parts.map((part, i) => { - return ( -
- {part.title &&
{part.title}
} - this.forms.push(c)} /> -
- ) - }) - } + {parts.map((part, i) => ( +
+ {part.title &&
{part.title}
} + } + wrapperClassName="h-400-min" + > + {!loading && ( + this.children.push(c)} + /> + )} + +
+ ))}
e.preventDefault()} + onClick={e => e.preventDefault()} > - { - parts.map((part, i) => { - return ( - - ) - }) - } + {parts.map((part, i) => ( + + ))} diff --git a/web-react/src/pages/business/house/info/form/index.jsx b/web-react/src/pages/business/house/info/form/index.jsx index 9c4eeba..3641db9 100644 --- a/web-react/src/pages/business/house/info/form/index.jsx +++ b/web-react/src/pages/business/house/info/form/index.jsx @@ -1,7 +1,8 @@ import React, { Component } from 'react' -import { Tabs, Button, message } from 'antd' -import { defaultsDeep } from 'lodash' -import { ComponentDynamic, Container } from 'components' +import { Button, Descriptions, message as Message, Spin, Tabs } from 'antd' +import { defaultsDeep, isEqual } from 'lodash' +import { AntIcon, ComponentDynamic, Container } from 'components' +import { api } from 'common/api' const tabs = [ { @@ -48,97 +49,151 @@ const tabs = [ ] export default class index extends Component { - state = { - actived: '0' - } - forms = [] + actived: '0', - onSubmit = async () => { - let formData = {}, - flag = true - for (let i = 0; i < this.forms.length; i++) { - const form = this.forms[i] + loading: true, + record: null, + } + + children = [] + + formData = {} + + shouldComponentUpdate(props, state) { + return !isEqual(this.state, state) + } + + componentDidMount() { + const { taskId } = this.props.param + + if (taskId) { + api.houseInfoGetByTaskId({ taskId }).then(({ data }) => { + this.setState({ + record: data, + loading: false, + }) + }) + } + } + + async onSubmit() { + for (const child of this.children) { try { - const data = await form.onGetData() - formData = defaultsDeep(formData, data) - } catch (err) { - if (err) { - err.errorFields.forEach(p => { - message.error(p.errors[0]) - }) + const data = await child.getData() + this.formData = { + ...this.formData, + ...data, } - flag = false + } catch (e) { + return e } } - if (!flag) { - return - } + console.log(this.formData) - console.log(formData) - - message.success('提交成功') + Message.success('提交成功') } render() { + const { loading, record } = this.state + return (
{/* 底部工具栏(需放在前面) */}
- +
+ {/* 可以在工具栏中增加其他控件(只能在一行内) */} - {/* 可以在工具栏中增加其他控件(只能在一行内) */} - - - - + +
-
+
+ + }> + + + {record && record.houseCode.areaName} + + + {record && record.houseCode.roadName} + + + {record && record.houseCode.commName} + + + {record && record.houseCode.zoneName} + + + {record && + `${record.houseCode.areaName}-${ + record.houseCode.roadName + }-${record.houseCode.commName}-${ + record.houseCode.projectFullName + }-${record.houseCode.no.toString().padStart(3, '0')}`} + + + {record && record.houseCode.houseCode} + + + + +
{ this.setState({ actived: activeKey }) }} + onChange={activeKey => { + this.setState({ actived: activeKey }) + }} > - { - tabs.map((tab, i) => { - if (tab.show) { - return ( - - ) - } - return <> - }) - } + {tabs.map((tab, i) => { + if (tab.show) { + return ( + + ) + } + return <> + })}
- { - tabs.map((tab, i) => { - if (tab.show) { - return ( -
- this.forms.push(c)} /> -
- ) - } - return <> - }) - } + {tabs.map((tab, i) => { + if (tab.show) { + return ( +
+ this.children.push(c)} + /> +
+ ) + } + return <> + })}
diff --git a/web-react/src/pages/business/house/task/index.jsx b/web-react/src/pages/business/house/task/index.jsx new file mode 100644 index 0000000..9d8570b --- /dev/null +++ b/web-react/src/pages/business/house/task/index.jsx @@ -0,0 +1,265 @@ +import React, { Component } from 'react' +import { Button, Card, Form, Input, message as Message, Popconfirm, Radio, Select, Tag } from 'antd' +import { AntIcon, Auth, Container, ModalForm, QueryTable, QueryTableActions } from 'components' +import { api } from 'common/api' +import auth from 'components/authorized/handler' +import { isEqual } from 'lodash' +import getDictData from 'util/dic' +import { toCamelCase } from 'util/format' + +/** + * 注释段[\/**\/]为必须要改 + */ + +/** + * 配置页面所需接口函数 + */ +const apiAction = { + page: api.houseTaskPage, +} + +/** + * 统一配置权限标识 + * [必要] + */ +const authName = 'houseTask' + +export default class index extends Component { + state = { + codes: { + dicHouseType: [], + dicHouseIndustry: [], + }, + + type: '', + } + + // 表格实例 + table = React.createRef() + + // 新增窗口实例 + addForm = React.createRef() + // 编辑窗口实例 + editForm = React.createRef() + + columns = [ + { + title: '房屋编码', + dataIndex: 'houseCode', + sorter: true, + width: 300, + render: (text, record) => ( + <> + {`${record.areaName}-${record.roadName}-${record.commName}-${ + record.note + }-${record.no.toString().padStart(3, '0')}`} +
+ {text} + + ), + }, + { + title: '房屋性质及行业', + dataIndex: 'type', + sorter: true, + width: 150, + render: text => this.bindCodeValue(text, 'dic_house_type'), + }, + { + title: '地址', + dataIndex: 'address', + sorter: true, + }, + { + title: '任务截止时间', + dataIndex: 'endTime', + sorter: true, + width: 150, + }, + ] + + /** + * 构造函数,在渲染前动态添加操作字段等 + * @param {*} props + */ + constructor(props) { + super(props) + + const flag = auth({ houseInfo: 'getByTaskId' }) + + if (flag) { + this.columns.push({ + title: '操作', + width: 150, + dataIndex: 'actions', + render: (text, record) => ( + + + this.onOpen(record.id)}>登记 + + + ), + }) + } + } + + /** + * 阻止外部组件引发的渲染,提升性能 + * 可自行添加渲染条件 + * [必要] + * @param {*} props + * @param {*} state + * @returns + */ + shouldComponentUpdate(props, state) { + return !isEqual(this.state, state) + } + + /** + * 加载字典数据,之后开始加载表格数据 + * 如果必须要加载字典数据,可直接对表格设置autoLoad=true + */ + componentDidMount() { + const { onLoading, onLoadData } = this.table.current + onLoading() + getDictData('dic_house_type', 'dic_house_industry').then(codes => { + this.setState({ codes }, () => { + onLoadData() + }) + }) + } + + /** + * 调用加载数据接口,可在调用前对query进行处理 + * [异步,必要] + * @param {*} params + * @param {*} query + * @returns + */ + loadData = async (params, query) => { + const { data } = await apiAction.page({ + ...params, + ...query, + }) + return data + } + + /** + * 绑定字典数据 + * @param {*} code + * @param {*} name + * @returns + */ + bindCodeValue(code, name) { + name = toCamelCase(name) + const codes = this.state.codes[name] + if (codes) { + const c = codes.find(p => p.code == code) + if (c) { + return c.value + } + } + return null + } + + /** + * 打开新增/编辑弹窗 + * @param {*} modal + * @param {*} record + */ + onOpen(taskId) { + window.openContentWindow({ + title: '房屋登记', + path: 'business/house/info/form', + param: { + taskId, + }, + }) + } + + /** + * 对表格上的操作进行统一处理 + * [异步] + * @param {*} action + * @param {*} successMessage + */ + async onAction(action, successMessage) { + const { onLoading, onLoaded, onReloadData } = this.table.current + onLoading() + try { + if (action) { + await action + } + if (successMessage) { + Message.success(successMessage) + } + onReloadData() + } catch { + onLoaded() + } + } + + //#region 自定义方法 + //#endregion + + render() { + const { codes, type } = this.state + + return ( + +
+ + { + if (values.hasOwnProperty('type')) { + this.setState({ type: values.type }) + } + }} + query={ + + + + 全部 + {codes.dicHouseType.map(item => ( + + {item.value} + + ))} + + + {type == 2 && ( + + + + )} + + + + + + + + } + /> + +
+ ) + } +}