update 片区管理 项目管理
This commit is contained in:
@@ -807,6 +807,13 @@
|
||||
<param name="input"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Ewide.Application.Service.HouseZoneService.QueryZonePageList(Ewide.Core.Service.PageOrgInput)">
|
||||
<summary>
|
||||
分页查询片区
|
||||
</summary>
|
||||
<param name="input"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Ewide.Application.Service.HouseZoneService.GetZoneByUser(System.String)">
|
||||
<summary>
|
||||
根据用户Id获取所在片区的Id
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Ewide.Core;
|
||||
using Ewide.Core.Extension;
|
||||
using Ewide.Core.Service;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DependencyInjection;
|
||||
@@ -61,6 +62,32 @@ namespace Ewide.Application.Service
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询片区
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/houseZone/page")]
|
||||
public async Task<dynamic> QueryZonePageList([FromBody] PageOrgInput input)
|
||||
{
|
||||
var dataScopeList = _sysOrgService.GetDataScopeList(await _sysOrgService.GetUserDataScopeIdList());
|
||||
|
||||
var name = !string.IsNullOrEmpty(input.Name?.Trim());
|
||||
var id = !string.IsNullOrEmpty(input.Id?.Trim());
|
||||
var pId = !string.IsNullOrEmpty(input.Pid?.Trim());
|
||||
var orgs = await _sysOrgRep.DetachedEntities
|
||||
.Where((name, u => EF.Functions.Like(u.Name, $"%{input.Name.Trim()}%")), // 根据机构名称模糊查询
|
||||
(id, u => u.Id == input.Id.Trim()), // 根据机构id查询
|
||||
(pId, u => EF.Functions.Like(u.Pids, $"%[{input.Pid.Trim()}]%")
|
||||
|| u.Id == input.Pid.Trim())) // 根据父机构id查询
|
||||
.Where(dataScopeList.Count > 0, u => dataScopeList.Contains(u.Id)) // 非管理员范围限制
|
||||
.Where(u => u.Status != CommonStatus.DELETED)
|
||||
.Where(u => u.Type == (int)OrgType.片区)
|
||||
.OrderBy(u => u.Sort)
|
||||
.ToPageData<SysOrg, OrgOutput>(input);
|
||||
return PageDataResult<OrgOutput>.PageResult(orgs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据用户Id获取所在片区的Id
|
||||
/// </summary>
|
||||
|
||||
@@ -300,6 +300,7 @@ namespace Ewide.Core.Service
|
||||
}
|
||||
var orgs = await _sysOrgRep.DetachedEntities.Where(dataScopeList.Count > 0, u => dataScopeList.Contains(u.Id))
|
||||
.Where(u => u.Status == (int)CommonStatus.ENABLE).OrderBy(u => u.Sort)
|
||||
.Where(input.Type != 0 , u=>u.Type < input.Type)
|
||||
.Select(u => new OrgTreeNode
|
||||
{
|
||||
Id = u.Id,
|
||||
|
||||
@@ -28,7 +28,7 @@ module.exports = {
|
||||
],
|
||||
webpack: {
|
||||
plugins: [
|
||||
new MonacoWebpackPlugin()
|
||||
// new MonacoWebpackPlugin()
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,10 @@
|
||||
const urls = {
|
||||
/**
|
||||
* 获取机构列表
|
||||
*
|
||||
*/
|
||||
houseZonePage: ['/houseZone/page', 'post'],
|
||||
|
||||
houseZoneList: '/houseZone/list',
|
||||
houseZoneAutoIncrement: '/houseZone/autoIncrement',
|
||||
houseZoneAdd: ['/houseZone/add', 'post']
|
||||
|
||||
236
web-react/src/pages/business/house/project/form.jsx
Normal file
236
web-react/src/pages/business/house/project/form.jsx
Normal file
@@ -0,0 +1,236 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Cascader, Form, Input, InputNumber, Radio, Spin, TreeSelect } from 'antd'
|
||||
import { AntIcon } from 'components'
|
||||
import { cloneDeep } from 'lodash'
|
||||
import { api } from 'common/api'
|
||||
import { numberToChinese } from 'util/format';
|
||||
|
||||
const initialValues = {
|
||||
sort: 100,
|
||||
type: 1
|
||||
}
|
||||
export default class form extends Component {
|
||||
state = {
|
||||
// 加载状态
|
||||
loading: true,
|
||||
exist: false,
|
||||
|
||||
options: {
|
||||
areaData: []
|
||||
}
|
||||
}
|
||||
areaCode = ''
|
||||
houseType = 1
|
||||
// 表单实例
|
||||
form = React.createRef()
|
||||
|
||||
// 初始化数据
|
||||
record = {}
|
||||
initRecord = {}
|
||||
/**
|
||||
* mount后回调
|
||||
*/
|
||||
componentDidMount() {
|
||||
this.props.created && this.props.created(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充数据
|
||||
* 可以在设置this.record之后对其作出数据结构调整
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
*/
|
||||
async fillData(params) {
|
||||
const areaCodeDefault = params.record ? params.record.areaCode : params.pid ? params.pid : '';
|
||||
this.houseType = params.record ? params.record.type : 1;
|
||||
this.record = cloneDeep(params.record)
|
||||
this.initRecord = cloneDeep(params.record)
|
||||
//#region 从后端转换成前段所需格式
|
||||
const areaData = await this.loadAreaData()
|
||||
|
||||
this.setState({
|
||||
exist: !!params.record,
|
||||
options: { areaData }
|
||||
})
|
||||
|
||||
const areaCode = [];
|
||||
const findCode = (data, level) => {
|
||||
level = level || 0;
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
const item = data[i];
|
||||
areaCode[level] = item.code;
|
||||
|
||||
if (item.code === areaCodeDefault) {
|
||||
areaCode.length = level + 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (item.children && item.children.length) {
|
||||
const found = findCode(item.children, level + 1);
|
||||
if (found) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (areaCodeDefault) {
|
||||
findCode(areaData);
|
||||
this.areaCode = areaCodeDefault
|
||||
this.nextSort(this.areaCode, this.houseType);
|
||||
}
|
||||
|
||||
this.record = {
|
||||
pid: params.pid,
|
||||
...this.record,
|
||||
areaCode: areaCode.length == 4 ? areaCode : []
|
||||
}
|
||||
//#endregion
|
||||
|
||||
this.form.current.setFieldsValue(this.record)
|
||||
|
||||
this.setState({
|
||||
loading: false
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 获取数据
|
||||
* 可以对postData进行数据结构调整
|
||||
* [异步,必要]
|
||||
* @returns
|
||||
*/
|
||||
async getData() {
|
||||
const form = this.form.current
|
||||
|
||||
const valid = await form.validateFields()
|
||||
if (valid) {
|
||||
const postData = form.getFieldsValue()
|
||||
if (this.record) {
|
||||
postData.id = this.record.id
|
||||
}
|
||||
//#region 从前段转换后端所需格式
|
||||
postData.areaCode = postData.areaCode[postData.areaCode.length - 1]
|
||||
//#endregion
|
||||
return postData
|
||||
}
|
||||
}
|
||||
|
||||
async loadAreaData() {
|
||||
const { data } = await api.getAreaTree()
|
||||
const clearChiildren = (data) => {
|
||||
data.forEach((item) => {
|
||||
if (item.children && item.children.length) {
|
||||
clearChiildren(item.children);
|
||||
} else {
|
||||
delete item.children;
|
||||
}
|
||||
});
|
||||
};
|
||||
clearChiildren(data);
|
||||
return data
|
||||
}
|
||||
|
||||
async nextSort(areaCode, houseType) {
|
||||
this.loading = true;
|
||||
if (!!this.initRecord && this.initRecord.areaCode == areaCode && this.initRecord.type == houseType) {
|
||||
this.form.current.setFieldsValue({
|
||||
name: this.initRecord.name,
|
||||
sort: this.initRecord.sort
|
||||
})
|
||||
} else if (areaCode.length < 12) {
|
||||
this.form.current.setFieldsValue({
|
||||
name: '',
|
||||
sort: 0,
|
||||
areaCode: []
|
||||
})
|
||||
} else {
|
||||
await api.houseProjectNextSort({ areaCode, type: houseType })
|
||||
.then(({ data }) => {
|
||||
this.form.current.setFieldsValue({
|
||||
name: `项目${numberToChinese(data)}`,
|
||||
sort: data
|
||||
})
|
||||
})
|
||||
.catch(() => {
|
||||
this.form.current.setFieldsValue({
|
||||
name: '',
|
||||
sort: 0,
|
||||
areaCode: []
|
||||
})
|
||||
})
|
||||
.finally(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
onHouseTypeChange(e) {
|
||||
this.houseType = e.target.value;
|
||||
if (this.areaCode != '') {
|
||||
this.nextSort(this.areaCode, this.houseType);
|
||||
}
|
||||
}
|
||||
|
||||
onAreaCodeChange(value) {
|
||||
this.areaCode = value[value.length - 1]
|
||||
if (this.houseType > 0) {
|
||||
this.nextSort(this.areaCode, this.houseType);
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Form
|
||||
initialValues={initialValues}
|
||||
ref={this.form}
|
||||
className="yo-form"
|
||||
>
|
||||
<Spin spinning={this.state.loading} indicator={<AntIcon type="loading" />}>
|
||||
<div className="yo-form-group">
|
||||
<Form.Item label="类型" name="type" >
|
||||
<Radio.Group disabled={this.state.exist} buttonStyle="solid" onChange={(e) => this.onHouseTypeChange(e)}>
|
||||
<Radio.Button value={1}>
|
||||
<span>住宅</span>
|
||||
</Radio.Button>
|
||||
<Radio.Button value={2}>
|
||||
<span>非住宅</span>
|
||||
</Radio.Button>
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
<Form.Item label="所属区域" name="areaCode" rules={[{ required: true, message: '请选择所属区域' }]}>
|
||||
<Cascader
|
||||
options={this.state.options.areaData}
|
||||
fieldNames={{
|
||||
label: 'name',
|
||||
value: 'code',
|
||||
children: 'children'
|
||||
}}
|
||||
expandTrigger="hover"
|
||||
// changeOnSelect
|
||||
placeholder="请选择所属区域"
|
||||
onChange={(val, selectedOptions) => this.onAreaCodeChange(val)}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="项目名称" name="name" rules={[{ required: true, message: '片区名称', trigger: 'blur' }]}>
|
||||
<Input autoComplete="off" placeholder="选择所属区域和类型之后自动生成" disabled={true} />
|
||||
</Form.Item>
|
||||
<Form.Item label="序号" name="sort">
|
||||
<InputNumber
|
||||
max={1000}
|
||||
min={0}
|
||||
placeholder="选择所属区域和类型之后自动生成"
|
||||
className="w-100-p"
|
||||
disabled={true}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="备注" name="note">
|
||||
<Input.TextArea
|
||||
rows="4"
|
||||
placeholder="填写房屋所属单位的名称、道路的名称或大厦的名称,比如XX中学、XX大厦、XX小区等。登记项目时,应在项目备注中明确项目所指对象。" />
|
||||
</Form.Item>
|
||||
</div>
|
||||
</Spin>
|
||||
</Form>
|
||||
)
|
||||
}
|
||||
}
|
||||
281
web-react/src/pages/business/house/project/index.jsx
Normal file
281
web-react/src/pages/business/house/project/index.jsx
Normal file
@@ -0,0 +1,281 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Button, Card, Form, Input, message as Message, Popconfirm } from 'antd'
|
||||
import { AntIcon, Auth, Container, ModalForm, QueryTable, QueryTableActions, QueryTreeLayout } from 'components'
|
||||
import { api } from 'common/api'
|
||||
import auth from 'components/authorized/handler'
|
||||
import { toCamelCase } from 'util/format'
|
||||
import { isEqual } from 'lodash'
|
||||
import getDictData from 'util/dic'
|
||||
import FormBody from './form'
|
||||
|
||||
const apiAction = {
|
||||
tree: api.getAreaTree,
|
||||
page: api.getHouseProjectPage,
|
||||
add: api.houseProejctAdd,
|
||||
edit: api.houseProejctEdit,
|
||||
delete: api.houseProejctDelete
|
||||
}
|
||||
|
||||
const name = '项目'
|
||||
|
||||
export default class index extends Component {
|
||||
|
||||
state = {
|
||||
codes: {
|
||||
dicHouseType: []
|
||||
}
|
||||
}
|
||||
|
||||
// 表格实例
|
||||
table = React.createRef()
|
||||
|
||||
// 新增窗口实例
|
||||
addForm = React.createRef()
|
||||
// 编辑窗口实例
|
||||
editForm = React.createRef()
|
||||
|
||||
// 树选中节点
|
||||
selectCode = undefined
|
||||
columns = [
|
||||
|
||||
{
|
||||
title: '项目名称',
|
||||
dataIndex: 'name',
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '社区',
|
||||
dataIndex: 'areaName',
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '备注',
|
||||
dataIndex: 'note',
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '类型',
|
||||
dataIndex: 'type',
|
||||
sorter: true,
|
||||
render: text => (<>{this.bindCodeValue(text, 'dic_house_type')}</>)
|
||||
}
|
||||
]
|
||||
/**
|
||||
* 构造函数,在渲染前动态添加操作字段等
|
||||
* @param {*} props
|
||||
*/
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
const flag = auth({ sysArea: [['edit'], ['delete']] })
|
||||
|
||||
if (flag) {
|
||||
this.columns.push({
|
||||
title: '操作',
|
||||
width: 150,
|
||||
dataIndex: 'actions',
|
||||
render: (text, record) => (<QueryTableActions>
|
||||
<Auth auth="houseProjectInfo:edit">
|
||||
<a onClick={() => this.onOpen(this.editForm, record)}>编辑</a>
|
||||
</Auth>
|
||||
<Auth auth="houseProjectInfo:delete">
|
||||
<Popconfirm
|
||||
placement="topRight"
|
||||
title="是否确认删除"
|
||||
onConfirm={() => this.onDelete(record)}
|
||||
>
|
||||
<a>删除</a>
|
||||
</Popconfirm>
|
||||
</Auth>
|
||||
</QueryTableActions>)
|
||||
})
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 阻止外部组件引发的渲染,提升性能
|
||||
* 可自行添加渲染条件
|
||||
* [必要]
|
||||
* @param {*} props
|
||||
* @param {*} state
|
||||
* @returns
|
||||
*/
|
||||
shouldComponentUpdate(props, state) {
|
||||
return !isEqual(this.state, state)
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载字典数据,之后开始加载表格数据
|
||||
* 如果必须要加载字典数据,可直接对表格设置autoLoad=true
|
||||
*/
|
||||
componentDidMount() {
|
||||
this.table.current.onLoading()
|
||||
getDictData('dic_house_type').then(res => {
|
||||
this.setState({
|
||||
codes: res
|
||||
}, () => {
|
||||
this.table.current.onLoadData()
|
||||
})
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 调用加载数据接口,可在调用前对query进行处理
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
* @param {*} query
|
||||
* @returns
|
||||
*/
|
||||
loadData = async (params, query) => {
|
||||
|
||||
query = {
|
||||
...query,
|
||||
pid: this.selectCode
|
||||
}
|
||||
//首次加载根据code列升序排序
|
||||
// if (!params.sortField) {
|
||||
// params.sortField = 'code';
|
||||
// params.sortOrder = 'ascend';
|
||||
// }
|
||||
const { data } = await apiAction.page({
|
||||
...params,
|
||||
...query,
|
||||
})
|
||||
return data
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用树结构数据接口
|
||||
* [异步,必要]
|
||||
* @returns
|
||||
*/
|
||||
loadTreeData = async () => {
|
||||
const { data } = await apiAction.tree()
|
||||
return data
|
||||
}
|
||||
|
||||
/**
|
||||
* 树节点选中事件
|
||||
* [必要]
|
||||
* @param {*} id
|
||||
*/
|
||||
onSelectTree(code) {
|
||||
this.selectCode = code
|
||||
this.table.current.onReloadData()
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定字典数据
|
||||
* @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(modal, record) {
|
||||
modal.current.open({
|
||||
pid: this.selectCode,
|
||||
record
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 对表格上的操作进行统一处理
|
||||
* [异步]
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
*/
|
||||
async onAction(action, successMessage) {
|
||||
this.table.current.onLoading()
|
||||
try {
|
||||
await action
|
||||
Message.success(successMessage)
|
||||
this.table.current.onReloadData()
|
||||
} catch {
|
||||
this.table.current.onLoaded()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param {*} record
|
||||
*/
|
||||
onDelete(record) {
|
||||
this.onAction(
|
||||
apiAction.delete(record),
|
||||
'删除成功'
|
||||
)
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<QueryTreeLayout
|
||||
loadData={this.loadTreeData}
|
||||
defaultExpanded={true}
|
||||
onSelect={(key) => this.onSelectTree(key)}
|
||||
replaceFields={{ value: 'code', title: 'name', children: 'children' }}
|
||||
>
|
||||
<Container mode="fluid">
|
||||
<Card bordered={false}>
|
||||
<QueryTable
|
||||
ref={this.table}
|
||||
autoLoad={false}
|
||||
loadData={this.loadData}
|
||||
columns={this.columns}
|
||||
query={
|
||||
<Auth auth="houseProjectInfo:page">
|
||||
<Form.Item label="项目名称" name="name">
|
||||
<Input autoComplete="off" placeholder="请输入项目名称" />
|
||||
</Form.Item>
|
||||
<Form.Item label="项目备注" name="note">
|
||||
<Input autoComplete="off" placeholder="请输入项目备注" />
|
||||
</Form.Item>
|
||||
</Auth>
|
||||
}
|
||||
operator={
|
||||
<Auth auth="houseProjectInfo:add">
|
||||
<Button
|
||||
icon={<AntIcon type="plus" />}
|
||||
onClick={() => this.onOpen(this.addForm)}
|
||||
>新增{name}</Button>
|
||||
</Auth>
|
||||
}
|
||||
>
|
||||
|
||||
</QueryTable>
|
||||
</Card>
|
||||
</Container>
|
||||
<ModalForm
|
||||
title={`新增${name}`}
|
||||
action={apiAction.add}
|
||||
ref={this.addForm}
|
||||
onSuccess={() => this.table.current.onReloadData()}
|
||||
>
|
||||
<FormBody />
|
||||
</ModalForm>
|
||||
|
||||
<ModalForm
|
||||
title={`编辑${name}`}
|
||||
action={apiAction.edit}
|
||||
ref={this.editForm}
|
||||
onSuccess={() => this.table.current.onReloadData()}
|
||||
>
|
||||
<FormBody />
|
||||
</ModalForm>
|
||||
</QueryTreeLayout>
|
||||
)
|
||||
}
|
||||
}
|
||||
190
web-react/src/pages/business/house/zone/form.jsx
Normal file
190
web-react/src/pages/business/house/zone/form.jsx
Normal file
@@ -0,0 +1,190 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Cascader, Form, Input, InputNumber, Select, Spin, TreeSelect } from 'antd'
|
||||
import { AntIcon } from 'components'
|
||||
import { cloneDeep } from 'lodash'
|
||||
import getDictData from 'util/dic'
|
||||
import { api } from 'common/api'
|
||||
import { numberToChinese } from 'util/format';
|
||||
|
||||
const initialValues = {
|
||||
sort: 100
|
||||
}
|
||||
export default class form extends Component {
|
||||
state = {
|
||||
// 加载状态
|
||||
loading: true,
|
||||
|
||||
options: {
|
||||
areaData: []
|
||||
}
|
||||
}
|
||||
|
||||
// 表单实例
|
||||
form = React.createRef()
|
||||
|
||||
// 初始化数据
|
||||
record = {}
|
||||
|
||||
/**
|
||||
* mount后回调
|
||||
*/
|
||||
componentDidMount() {
|
||||
this.props.created && this.props.created(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充数据
|
||||
* 可以在设置this.record之后对其作出数据结构调整
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
*/
|
||||
async fillData(params) {
|
||||
|
||||
this.record = cloneDeep(params.record)
|
||||
//#region 从后端转换成前段所需格式
|
||||
const areaData = await this.loadAreaData()
|
||||
|
||||
this.setState({
|
||||
options: { areaData }
|
||||
})
|
||||
|
||||
const areaCode = [];
|
||||
const findCode = (data, level) => {
|
||||
level = level || 0;
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
const item = data[i];
|
||||
areaCode[level] = item.code;
|
||||
|
||||
if (item.code === params.record.areaCode) {
|
||||
areaCode.length = level + 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (item.children && item.children.length) {
|
||||
const found = findCode(item.children, level + 1);
|
||||
if (found) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (params.record && params.record.areaCode) {
|
||||
findCode(areaData);
|
||||
}
|
||||
|
||||
this.record = {
|
||||
pid: params.orgId,
|
||||
...this.record,
|
||||
areaCode
|
||||
}
|
||||
this.record.areaCode = areaCode
|
||||
//#endregion
|
||||
|
||||
this.form.current.setFieldsValue(this.record)
|
||||
|
||||
this.setState({
|
||||
loading: false
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 获取数据
|
||||
* 可以对postData进行数据结构调整
|
||||
* [异步,必要]
|
||||
* @returns
|
||||
*/
|
||||
async getData() {
|
||||
const form = this.form.current
|
||||
|
||||
const valid = await form.validateFields()
|
||||
if (valid) {
|
||||
const postData = form.getFieldsValue()
|
||||
if (this.record) {
|
||||
postData.id = this.record.id
|
||||
}
|
||||
//#region 从前段转换后端所需格式
|
||||
postData.areaCode = postData.areaCode[postData.areaCode.length - 1]
|
||||
//#endregion
|
||||
return postData
|
||||
}
|
||||
}
|
||||
|
||||
async loadAreaData() {
|
||||
const { data } = await api.getAreaTree({ level: 3 })
|
||||
const clearChiildren = (data) => {
|
||||
data.forEach((item) => {
|
||||
if (item.children && item.children.length) {
|
||||
clearChiildren(item.children);
|
||||
} else {
|
||||
delete item.children;
|
||||
}
|
||||
});
|
||||
};
|
||||
clearChiildren(data);
|
||||
return data
|
||||
}
|
||||
|
||||
onAreaCodeChange(value) {
|
||||
this.loading = true;
|
||||
// const { data } = api.houseZoneAutoIncrement({ code: selectedOptions[selectedOptions.length - 1] });
|
||||
|
||||
api.houseZoneAutoIncrement({ code: value[value.length - 1] })
|
||||
.then(({ data }) => {
|
||||
this.form.current.setFieldsValue({
|
||||
name: `片区${numberToChinese(data)}`
|
||||
})
|
||||
})
|
||||
.catch(() => {
|
||||
this.form.current.setFieldsValue({
|
||||
name: '',
|
||||
areaCode: []
|
||||
})
|
||||
})
|
||||
.finally(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Form
|
||||
initialValues={initialValues}
|
||||
ref={this.form}
|
||||
className="yo-form"
|
||||
>
|
||||
<Spin spinning={this.state.loading} indicator={<AntIcon type="loading" />}>
|
||||
<div className="yo-form-group">
|
||||
<Form.Item label="所属区域" name="areaCode" rules={[{ required: true, message: '请选择所属区域' }]}>
|
||||
<Cascader
|
||||
options={this.state.options.areaData}
|
||||
fieldNames={{
|
||||
label: 'name',
|
||||
value: 'code',
|
||||
children: 'children'
|
||||
}}
|
||||
expandTrigger="hover"
|
||||
// changeOnSelect
|
||||
placeholder="请选择所属区域"
|
||||
onChange={(val, selectedOptions) => this.onAreaCodeChange(val)}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="片区名称" name="name" rules={[{ required: true, message: '片区名称', trigger: 'blur' }]}>
|
||||
<Input autoComplete="off" placeholder="请输入机构名称" />
|
||||
</Form.Item>
|
||||
<Form.Item label="排序" name="sort">
|
||||
<InputNumber
|
||||
max={1000}
|
||||
min={0}
|
||||
placeholder="请输入排序"
|
||||
className="w-100-p"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="备注" name="remark">
|
||||
<Input.TextArea placeholder="请输入备注" />
|
||||
</Form.Item>
|
||||
</div>
|
||||
</Spin>
|
||||
</Form>
|
||||
)
|
||||
}
|
||||
}
|
||||
268
web-react/src/pages/business/house/zone/index.jsx
Normal file
268
web-react/src/pages/business/house/zone/index.jsx
Normal file
@@ -0,0 +1,268 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Button, Card, Form, Input, message as Message, Popconfirm } from 'antd'
|
||||
import { AntIcon, Auth, Container, ModalForm, QueryTable, QueryTableActions, QueryTreeLayout } from 'components'
|
||||
import { api } from 'common/api'
|
||||
import auth from 'components/authorized/handler'
|
||||
import { toCamelCase } from 'util/format'
|
||||
import { isEqual } from 'lodash'
|
||||
import getDictData from 'util/dic'
|
||||
import FormBody from './form'
|
||||
|
||||
const apiAction = {
|
||||
tree: api.getOrgTree,
|
||||
page: api.houseZonePage,
|
||||
add: api.houseZoneAdd,
|
||||
edit: api.sysOrgEdit,
|
||||
delete: api.sysOrgDelete
|
||||
}
|
||||
|
||||
const name = '片区'
|
||||
|
||||
export default class index extends Component {
|
||||
|
||||
// 树框架实例
|
||||
treeLayout = React.createRef()
|
||||
|
||||
// 表格实例
|
||||
table = React.createRef()
|
||||
|
||||
// 新增窗口实例
|
||||
addForm = React.createRef()
|
||||
// 编辑窗口实例
|
||||
editForm = React.createRef()
|
||||
|
||||
// 树选中节点
|
||||
selectId = undefined
|
||||
|
||||
// 表格字段
|
||||
columns = [
|
||||
{
|
||||
title: '片区名称',
|
||||
width: '400px',
|
||||
dataIndex: 'name',
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '排序',
|
||||
width: '80px',
|
||||
dataIndex: 'sort',
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '备注',
|
||||
width: '80px',
|
||||
dataIndex: 'remark',
|
||||
sorter: true,
|
||||
},
|
||||
]
|
||||
|
||||
/**
|
||||
* 构造函数,在渲染前动态添加操作字段等
|
||||
* @param {*} props
|
||||
*/
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
const flag = auth({ sysOrg: [['edit'], ['delete']] })
|
||||
|
||||
if (flag) {
|
||||
this.columns.push({
|
||||
title: '操作',
|
||||
width: 150,
|
||||
dataIndex: 'actions',
|
||||
render: (text, record) => (<QueryTableActions>
|
||||
<Auth auth="sysOrg:edit">
|
||||
<a onClick={() => this.onOpen(this.editForm, record)}>编辑</a>
|
||||
</Auth>
|
||||
<Auth auth="sysOrg:delete">
|
||||
<Popconfirm
|
||||
placement="topRight"
|
||||
title="是否确认删除"
|
||||
onConfirm={() => this.onDelete(record)}
|
||||
>
|
||||
<a>删除</a>
|
||||
</Popconfirm>
|
||||
</Auth>
|
||||
</QueryTableActions>)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 阻止外部组件引发的渲染,提升性能
|
||||
* 可自行添加渲染条件
|
||||
* [必要]
|
||||
* @param {*} props
|
||||
* @param {*} state
|
||||
* @returns
|
||||
*/
|
||||
shouldComponentUpdate(props, state) {
|
||||
return !isEqual(this.state, state)
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载字典数据,之后开始加载表格数据
|
||||
* 如果必须要加载字典数据,可直接对表格设置autoLoad=true
|
||||
*/
|
||||
componentDidMount() {
|
||||
this.table.current.onLoading()
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用加载数据接口,可在调用前对query进行处理
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
* @param {*} query
|
||||
* @returns
|
||||
*/
|
||||
loadData = async (params, query) => {
|
||||
query = {
|
||||
...query,
|
||||
pid: this.selectId
|
||||
}
|
||||
|
||||
const { data } = await apiAction.page({
|
||||
...params,
|
||||
...query,
|
||||
})
|
||||
return data
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用树结构数据接口
|
||||
* [异步,必要]
|
||||
* @returns
|
||||
*/
|
||||
loadTreeData = async () => {
|
||||
const { data } = await apiAction.tree({ type: 4 })
|
||||
return data
|
||||
}
|
||||
|
||||
/**
|
||||
* 树节点选中事件
|
||||
* [必要]
|
||||
* @param {*} id
|
||||
*/
|
||||
onSelectTree(id) {
|
||||
this.selectId = id
|
||||
this.table.current.onReloadData()
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定字典数据
|
||||
* @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(modal, record) {
|
||||
modal.current.open({
|
||||
orgId: this.selectId,
|
||||
record
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 对表格上的操作进行统一处理
|
||||
* [异步]
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
*/
|
||||
async onAction(action, successMessage) {
|
||||
this.table.current.onLoading()
|
||||
try {
|
||||
if (action) {
|
||||
await action
|
||||
}
|
||||
if (successMessage) {
|
||||
Message.success(successMessage)
|
||||
}
|
||||
this.treeLayout.current.onReloadData()
|
||||
this.table.current.onReloadData()
|
||||
} catch {
|
||||
this.table.current.onLoaded()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param {*} record
|
||||
*/
|
||||
onDelete(record) {
|
||||
this.onAction(
|
||||
apiAction.delete(record),
|
||||
'删除成功'
|
||||
)
|
||||
}
|
||||
|
||||
//#region 自定义方法
|
||||
//#endregion
|
||||
|
||||
render() {
|
||||
return (
|
||||
<QueryTreeLayout
|
||||
ref={this.treeLayout}
|
||||
loadData={this.loadTreeData}
|
||||
defaultExpanded={true}
|
||||
onSelect={(key) => this.onSelectTree(key)}
|
||||
>
|
||||
<Container mode="fluid">
|
||||
<Card bordered={false}>
|
||||
<QueryTable
|
||||
ref={this.table}
|
||||
loadData={this.loadData}
|
||||
columns={this.columns}
|
||||
query={
|
||||
<Auth auth="houseZone:page">
|
||||
<Form.Item label="片区名称" name="name">
|
||||
<Input autoComplete="off" placeholder="请输入片区名称" />
|
||||
</Form.Item>
|
||||
</Auth>
|
||||
}
|
||||
operator={
|
||||
<Button
|
||||
icon={<AntIcon type="plus" />}
|
||||
onClick={() => this.onOpen(this.addForm)}
|
||||
>新增{name}</Button>
|
||||
}
|
||||
/>
|
||||
</Card>
|
||||
</Container>
|
||||
|
||||
<ModalForm
|
||||
title={`新增${name}`}
|
||||
action={apiAction.add}
|
||||
ref={this.addForm}
|
||||
onSuccess={() => this.onAction()}
|
||||
>
|
||||
<FormBody />
|
||||
</ModalForm>
|
||||
|
||||
<ModalForm
|
||||
title={`编辑${name}`}
|
||||
action={apiAction.edit}
|
||||
ref={this.editForm}
|
||||
onSuccess={() => this.onAction()}
|
||||
>
|
||||
<FormBody />
|
||||
</ModalForm>
|
||||
</QueryTreeLayout>
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,166 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Form, Input, Radio, InputNumber, TreeSelect, Spin } from 'antd'
|
||||
import { AntIcon } from 'components'
|
||||
import { cloneDeep } from 'lodash'
|
||||
import getDictData from 'util/dic'
|
||||
import { EMPTY_ID } from 'util/global'
|
||||
import { api } from 'common/api'
|
||||
|
||||
const initialValues = {
|
||||
type: 1,
|
||||
sort: 100
|
||||
}
|
||||
export default class form extends Component {
|
||||
|
||||
state = {
|
||||
// 加载状态
|
||||
loading: true,
|
||||
options: {
|
||||
dicTreeData: []
|
||||
}
|
||||
}
|
||||
|
||||
// 表单实例
|
||||
form = React.createRef()
|
||||
|
||||
// 初始化数据
|
||||
record = {}
|
||||
|
||||
/**
|
||||
* mount后回调
|
||||
*/
|
||||
componentDidMount() {
|
||||
this.props.created && this.props.created(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充数据
|
||||
* 可以在设置this.record之后对其作出数据结构调整
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
*/
|
||||
async fillData(params) {
|
||||
this.record = cloneDeep(params.record)
|
||||
const treeData = await this.loadDicTreeData()
|
||||
this.setState({
|
||||
options: {
|
||||
dicTreeData: treeData
|
||||
}
|
||||
})
|
||||
|
||||
this.record = {
|
||||
pid: params.pid,
|
||||
...this.record
|
||||
}
|
||||
|
||||
if (this.record.code) {
|
||||
this.record.type = 2;
|
||||
this.setState({
|
||||
type: 2
|
||||
})
|
||||
}
|
||||
|
||||
this.form.current.setFieldsValue(this.record)
|
||||
|
||||
this.setState({
|
||||
loading: false
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据
|
||||
* 可以对postData进行数据结构调整
|
||||
* [异步,必要]
|
||||
* @returns
|
||||
*/
|
||||
async getData() {
|
||||
const form = this.form.current
|
||||
|
||||
const valid = await form.validateFields()
|
||||
if (valid) {
|
||||
const postData = form.getFieldsValue()
|
||||
if (this.record) {
|
||||
postData.id = this.record.id
|
||||
}
|
||||
//#region 从前段转换后端所需格式
|
||||
//#endregion
|
||||
return postData
|
||||
}
|
||||
}
|
||||
//#region 自定义方法
|
||||
async loadDicTreeData() {
|
||||
const { data } = await api.sysDictTypeTree()
|
||||
return [{
|
||||
id: EMPTY_ID,
|
||||
parentId: undefined,
|
||||
title: '顶级',
|
||||
value: EMPTY_ID,
|
||||
pid: undefined,
|
||||
children: data,
|
||||
}]
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
123
|
||||
<Form
|
||||
initialValues={initialValues}
|
||||
ref={this.form}
|
||||
className="yo-form"
|
||||
onValuesChange={(changeValues) => {
|
||||
if (changeValues.hasOwnProperty('type')) {
|
||||
this.setState({
|
||||
type: changeValues.type
|
||||
})
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Spin spinning={this.state.loading} indicator={<AntIcon type="loading" />}>
|
||||
<div className="yo-form-group">
|
||||
{/* 表单控件 */}
|
||||
<Form.Item label="类型名称" name="name" rules={[{ required: true, message: '请输入类型名称' }]}>
|
||||
<Input autoComplete="off" placeholder="请输入类型名称" />
|
||||
</Form.Item>
|
||||
<Form.Item label="类型" name="type" rules={[{ required: true, message: '请选择需要添加的数据类型' }]}>
|
||||
<Radio.Group>
|
||||
<Radio.Button value={1}>
|
||||
目录
|
||||
</Radio.Button>
|
||||
<Radio.Button value={2}>
|
||||
字典类型
|
||||
</Radio.Button>
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
<Form.Item label="父结点" name="pid" rules={[{ required: true, message: '请选择父结点' }]}>
|
||||
<TreeSelect
|
||||
treeData={this.state.options.dicTreeData}
|
||||
dropdownStyle={{ maxHeight: '300px', overflow: 'auto' }}
|
||||
treeDefaultExpandAll
|
||||
placeholder="请选择父结点"
|
||||
/>
|
||||
</Form.Item>
|
||||
{this.state.type == 2 &&
|
||||
<>
|
||||
<Form.Item label="唯一编码" name="code" rules={[{ required: true, message: '请输入唯一编码' }]}>
|
||||
<Input autoComplete="off" placeholder="请输入唯一编码" />
|
||||
</Form.Item>
|
||||
</>
|
||||
}
|
||||
<Form.Item label="排序" name="sort">
|
||||
<InputNumber
|
||||
min={0}
|
||||
placeholder="请输入排序"
|
||||
className="w-100-p"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="备注" name="remark">
|
||||
<Input.TextArea placeholder="请输入备注" />
|
||||
</Form.Item>
|
||||
{/* ... */}
|
||||
</div>
|
||||
</Spin>
|
||||
</Form>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ export default class index extends Component {
|
||||
*/
|
||||
onOpen(modal, record) {
|
||||
modal.current.open({
|
||||
orgId: this.selectId,
|
||||
pid: this.selectId,
|
||||
record
|
||||
})
|
||||
}
|
||||
@@ -285,6 +285,23 @@ export default class index extends Component {
|
||||
/>
|
||||
</Card>
|
||||
</Container>
|
||||
<ModalForm
|
||||
title={`新增${name}`}
|
||||
action={apiAction.add}
|
||||
ref={this.addForm}
|
||||
onSuccess={() => this.table.current.onReloadData()}
|
||||
>
|
||||
<FormBody />
|
||||
</ModalForm>
|
||||
|
||||
<ModalForm
|
||||
title={`编辑${name}`}
|
||||
action={apiAction.edit}
|
||||
ref={this.editForm}
|
||||
onSuccess={() => this.table.current.onReloadData()}
|
||||
>
|
||||
<FormBody />
|
||||
</ModalForm>
|
||||
</QueryTreeLayout>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user