update 完善编码信息读取
This commit is contained in:
@@ -1,5 +1,16 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Button, Card, Cascader, Form, Input, InputNumber, Popconfirm, message as Message, Radio, Select } from 'antd'
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Cascader,
|
||||
Form,
|
||||
Input,
|
||||
InputNumber,
|
||||
Popconfirm,
|
||||
message as Message,
|
||||
Radio,
|
||||
Select,
|
||||
} from 'antd'
|
||||
import { isEqual } from 'lodash'
|
||||
import { AntIcon, Auth, Container, QueryTable, QueryTableActions } from 'components'
|
||||
import { api } from 'common/api'
|
||||
@@ -10,25 +21,24 @@ import { getSearchInfo } from 'util/query'
|
||||
|
||||
// 配置页面所需接口函数
|
||||
const apiAction = {
|
||||
page: api.houseCodePage
|
||||
page: api.houseCodePage,
|
||||
}
|
||||
|
||||
// 用于弹窗标题
|
||||
const name = '房屋编码'
|
||||
|
||||
export default class index extends Component {
|
||||
|
||||
state = {
|
||||
codes: {
|
||||
dicHouseType: [],
|
||||
dicHouseIndustry: []
|
||||
dicHouseIndustry: [],
|
||||
},
|
||||
|
||||
options: {
|
||||
areaTree: []
|
||||
areaTree: [],
|
||||
},
|
||||
|
||||
type: ''
|
||||
type: '',
|
||||
}
|
||||
|
||||
// 表格实例
|
||||
@@ -41,14 +51,21 @@ export default class index extends Component {
|
||||
dataIndex: 'houseCode',
|
||||
sorter: true,
|
||||
width: 300,
|
||||
render: (text, record) => `${record.areaName}-${record.roadName}-${record.commName}-${record.note}-${record.no.toString().padStart(3, '0')}`
|
||||
render: (text, record) =>
|
||||
`${record.areaName}-${record.roadName}-${record.commName}-${record.note}-${record.no
|
||||
.toString()
|
||||
.padStart(3, '0')}`,
|
||||
},
|
||||
{
|
||||
title: '房屋性质及行业',
|
||||
dataIndex: 'type',
|
||||
sorter: true,
|
||||
width: 150,
|
||||
render: (text, record) => this.bindCodeValue(text, 'dic_house_type') + (text === 2 ? `(${this.bindCodeValue(record.industry, 'dic_house_industry')})` : '')
|
||||
render: (text, record) =>
|
||||
this.bindCodeValue(text, 'dic_house_type') +
|
||||
(text === 2
|
||||
? `(${this.bindCodeValue(record.industry, 'dic_house_industry')})`
|
||||
: ''),
|
||||
},
|
||||
{
|
||||
title: '地址',
|
||||
@@ -65,7 +82,7 @@ export default class index extends Component {
|
||||
|
||||
/**
|
||||
* 构造函数,在渲染前动态添加操作字段等
|
||||
* @param {*} props
|
||||
* @param {*} props
|
||||
*/
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -77,20 +94,22 @@ export default class index extends Component {
|
||||
title: '操作',
|
||||
width: 150,
|
||||
dataIndex: 'actions',
|
||||
render: (text, record) => (<QueryTableActions>
|
||||
<Auth auth="houseCode:edit">
|
||||
<a onClick={() => this.onOpen(record)}>编辑</a>
|
||||
</Auth>
|
||||
<Auth auth="houseCode:delete">
|
||||
<Popconfirm
|
||||
placement="topRight"
|
||||
title="是否确认删除"
|
||||
onConfirm={() => this.onDelete(record)}
|
||||
>
|
||||
<a>删除</a>
|
||||
</Popconfirm>
|
||||
</Auth>
|
||||
</QueryTableActions>)
|
||||
render: (text, record) => (
|
||||
<QueryTableActions>
|
||||
<Auth auth="houseCode:edit">
|
||||
<a onClick={() => this.onOpen(record)}>编辑</a>
|
||||
</Auth>
|
||||
<Auth auth="houseCode:delete">
|
||||
<Popconfirm
|
||||
placement="topRight"
|
||||
title="是否确认删除"
|
||||
onConfirm={() => this.onDelete(record)}
|
||||
>
|
||||
<a>删除</a>
|
||||
</Popconfirm>
|
||||
</Auth>
|
||||
</QueryTableActions>
|
||||
),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -99,9 +118,9 @@ export default class index extends Component {
|
||||
* 阻止外部组件引发的渲染,提升性能
|
||||
* 可自行添加渲染条件
|
||||
* [必要]
|
||||
* @param {*} props
|
||||
* @param {*} state
|
||||
* @returns
|
||||
* @param {*} props
|
||||
* @param {*} state
|
||||
* @returns
|
||||
*/
|
||||
shouldComponentUpdate(props, state) {
|
||||
return !isEqual(this.state, state)
|
||||
@@ -114,28 +133,30 @@ export default class index extends Component {
|
||||
componentDidMount() {
|
||||
const { onLoading, onLoadData } = this.table.current
|
||||
onLoading()
|
||||
getDictData('dic_house_type', 'dic_house_industry').then(async (res) => {
|
||||
getDictData('dic_house_type', 'dic_house_industry').then(async res => {
|
||||
const { data } = await api.getAreaTree()
|
||||
this.setState({
|
||||
codes: res,
|
||||
options: {
|
||||
areaTree: data
|
||||
this.setState(
|
||||
{
|
||||
codes: res,
|
||||
options: {
|
||||
areaTree: data,
|
||||
},
|
||||
},
|
||||
() => {
|
||||
onLoadData()
|
||||
}
|
||||
}, () => {
|
||||
onLoadData()
|
||||
})
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用加载数据接口,可在调用前对query进行处理
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
* @param {*} query
|
||||
* @returns
|
||||
* @param {*} params
|
||||
* @param {*} query
|
||||
* @returns
|
||||
*/
|
||||
loadData = async (params, query) => {
|
||||
|
||||
if (query.areaCode) {
|
||||
query.areaCode = query.areaCode.pop()
|
||||
}
|
||||
@@ -146,8 +167,8 @@ export default class index extends Component {
|
||||
no: '=',
|
||||
type: '=',
|
||||
address: 'like',
|
||||
houseCode: 'like'
|
||||
}
|
||||
houseCode: 'like',
|
||||
},
|
||||
})
|
||||
|
||||
const { data } = await apiAction.page({
|
||||
@@ -159,15 +180,15 @@ export default class index extends Component {
|
||||
|
||||
/**
|
||||
* 绑定字典数据
|
||||
* @param {*} code
|
||||
* @param {*} name
|
||||
* @returns
|
||||
* @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)
|
||||
const c = codes.find(p => p.code == code)
|
||||
if (c) {
|
||||
return c.value
|
||||
}
|
||||
@@ -177,8 +198,8 @@ export default class index extends Component {
|
||||
|
||||
/**
|
||||
* 打开新增/编辑弹窗
|
||||
* @param {*} modal
|
||||
* @param {*} record
|
||||
* @param {*} modal
|
||||
* @param {*} record
|
||||
*/
|
||||
onOpen(record) {
|
||||
const path = 'business/house/code/form'
|
||||
@@ -187,11 +208,13 @@ export default class index extends Component {
|
||||
title: record ? '修改房屋编码' : '新增房屋编码',
|
||||
subTitle:
|
||||
record &&
|
||||
`${record.areaName}-${record.roadName}-${record.commName}-${record.note}-${record.no.toString().padStart(3, '0')}`,
|
||||
`${record.areaName}-${record.roadName}-${record.commName}-${record.note}-${record.no
|
||||
.toString()
|
||||
.padStart(3, '0')}`,
|
||||
path,
|
||||
param: {
|
||||
record
|
||||
}
|
||||
id: record.id,
|
||||
},
|
||||
})
|
||||
// modal.current.open({
|
||||
// record
|
||||
@@ -201,8 +224,8 @@ export default class index extends Component {
|
||||
/**
|
||||
* 对表格上的操作进行统一处理
|
||||
* [异步]
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
*/
|
||||
async onAction(action, successMessage) {
|
||||
const { onLoading, onLoaded, onReloadData } = this.table.current
|
||||
@@ -222,20 +245,16 @@ export default class index extends Component {
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param {*} record
|
||||
* @param {*} record
|
||||
*/
|
||||
onDelete(record) {
|
||||
this.onAction(
|
||||
apiAction.delete(record),
|
||||
'删除成功'
|
||||
)
|
||||
this.onAction(apiAction.delete(record), '删除成功')
|
||||
}
|
||||
|
||||
//#region 自定义方法
|
||||
//#endregion
|
||||
|
||||
render() {
|
||||
|
||||
const { options, codes, type } = this.state
|
||||
|
||||
return (
|
||||
@@ -248,9 +267,9 @@ export default class index extends Component {
|
||||
loadData={this.loadData}
|
||||
columns={this.columns}
|
||||
queryInitialValues={{
|
||||
type: ''
|
||||
type: '',
|
||||
}}
|
||||
onQueryChange={(values) => {
|
||||
onQueryChange={values => {
|
||||
if (values.hasOwnProperty('type')) {
|
||||
this.setState({ type: values.type })
|
||||
}
|
||||
@@ -259,11 +278,11 @@ export default class index extends Component {
|
||||
<Auth auth="houseCode:page">
|
||||
<Form.Item name="areaCode">
|
||||
<Cascader
|
||||
displayRender={(labels) => labels.join(' - ')}
|
||||
displayRender={labels => labels.join(' - ')}
|
||||
fieldNames={{
|
||||
label: 'name',
|
||||
value: 'code',
|
||||
children: 'children'
|
||||
children: 'children',
|
||||
}}
|
||||
options={options.areaTree}
|
||||
className="w-400"
|
||||
@@ -273,7 +292,7 @@ export default class index extends Component {
|
||||
</Form.Item>
|
||||
<Form.Item label="编号" name="no">
|
||||
<InputNumber
|
||||
formatter={(value) => value && value.padStart(3, '0')}
|
||||
formatter={value => value && value.padStart(3, '0')}
|
||||
max={999}
|
||||
min={1}
|
||||
precision={0}
|
||||
@@ -284,31 +303,28 @@ export default class index extends Component {
|
||||
<Form.Item label="房屋性质" name="type">
|
||||
<Radio.Group buttonStyle="solid">
|
||||
<Radio.Button value="">全部</Radio.Button>
|
||||
{
|
||||
codes.dicHouseType.map(item => (
|
||||
<Radio.Button
|
||||
key={item.code}
|
||||
value={item.code}
|
||||
>{item.value}</Radio.Button>
|
||||
))
|
||||
}
|
||||
{codes.dicHouseType.map(item => (
|
||||
<Radio.Button key={item.code} value={item.code}>
|
||||
{item.value}
|
||||
</Radio.Button>
|
||||
))}
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
{
|
||||
type == 2 &&
|
||||
{type == 2 && (
|
||||
<Form.Item label="行业" name="industry">
|
||||
<Select allowClear className="w-150" placeholder="请选择行业">
|
||||
{
|
||||
codes.dicHouseIndustry.map(item => (
|
||||
<Select.Option
|
||||
key={item.code}
|
||||
value={item.code}
|
||||
>{item.value}</Select.Option>
|
||||
))
|
||||
}
|
||||
<Select
|
||||
allowClear
|
||||
className="w-150"
|
||||
placeholder="请选择行业"
|
||||
>
|
||||
{codes.dicHouseIndustry.map(item => (
|
||||
<Select.Option key={item.code} value={item.code}>
|
||||
{item.value}
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
}
|
||||
)}
|
||||
<Form.Item label="地址" name="address">
|
||||
<Input autoComplete="off" placeholder="请输入地址" />
|
||||
</Form.Item>
|
||||
@@ -322,7 +338,9 @@ export default class index extends Component {
|
||||
<Button
|
||||
icon={<AntIcon type="plus" />}
|
||||
onClick={() => this.onOpen()}
|
||||
>新增{name}</Button>
|
||||
>
|
||||
新增{name}
|
||||
</Button>
|
||||
</Auth>
|
||||
}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user