add 房屋相关单位信息维护
This commit is contained in:
36
Api/Ewide.Application/Entity/BsHouseCompany.cs
Normal file
36
Api/Ewide.Application/Entity/BsHouseCompany.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Ewide.Application
|
||||||
|
{
|
||||||
|
[Table("bs_house_company")]
|
||||||
|
[Comment("房屋相关单位表")]
|
||||||
|
public class BsHouseCompany : Core.DEntityBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 单位类型,多选
|
||||||
|
/// </summary>
|
||||||
|
[Comment("单位类型,多选")]
|
||||||
|
[MaxLength(20)]
|
||||||
|
public string Type { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 单位名称
|
||||||
|
/// </summary>
|
||||||
|
[Comment("单位名称")]
|
||||||
|
[MaxLength(200)]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 信息
|
||||||
|
/// </summary>
|
||||||
|
[Comment("信息")]
|
||||||
|
public string Info { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Ewide.Application.Entity
|
|
||||||
{
|
|
||||||
public class BsHouseCompany : Core.DEntityBase
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 单位类型,多选
|
|
||||||
/// </summary>
|
|
||||||
[Comment("单位类型,多选")]
|
|
||||||
[MaxLength(20)]
|
|
||||||
public string Type { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 单位名称
|
|
||||||
/// </summary>
|
|
||||||
[Comment("单位名称")]
|
|
||||||
[MaxLength(200)]
|
|
||||||
public string CompanyName { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 单位负责人
|
|
||||||
/// </summary>
|
|
||||||
[Comment("单位负责人")]
|
|
||||||
[MaxLength(100)]
|
|
||||||
public string ChargePerson { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 单位负责人电话
|
|
||||||
/// </summary>
|
|
||||||
[Comment("单位负责人电话")]
|
|
||||||
[MaxLength(50)]
|
|
||||||
public string ChargePersonTel { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 单位联系人
|
|
||||||
/// </summary>
|
|
||||||
[Comment("单位联系人")]
|
|
||||||
[MaxLength(100)]
|
|
||||||
public string ContactPerson { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 单位联系人电话
|
|
||||||
/// </summary>
|
|
||||||
[Comment("单位联系人电话")]
|
|
||||||
[MaxLength(50)]
|
|
||||||
public string ContactPersonTel { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,6 +4,21 @@
|
|||||||
<name>Ewide.Application</name>
|
<name>Ewide.Application</name>
|
||||||
</assembly>
|
</assembly>
|
||||||
<members>
|
<members>
|
||||||
|
<member name="P:Ewide.Application.BsHouseCompany.Type">
|
||||||
|
<summary>
|
||||||
|
单位类型,多选
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:Ewide.Application.BsHouseCompany.Name">
|
||||||
|
<summary>
|
||||||
|
单位名称
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:Ewide.Application.BsHouseCompany.Info">
|
||||||
|
<summary>
|
||||||
|
信息
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="P:Ewide.Application.BsHouseInfo.HouseCodeId">
|
<member name="P:Ewide.Application.BsHouseInfo.HouseCodeId">
|
||||||
<summary>
|
<summary>
|
||||||
HouseCode主键ID
|
HouseCode主键ID
|
||||||
@@ -329,36 +344,6 @@
|
|||||||
主管部门
|
主管部门
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:Ewide.Application.Entity.BsHouseCompany.Type">
|
|
||||||
<summary>
|
|
||||||
单位类型,多选
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="P:Ewide.Application.Entity.BsHouseCompany.CompanyName">
|
|
||||||
<summary>
|
|
||||||
单位名称
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="P:Ewide.Application.Entity.BsHouseCompany.ChargePerson">
|
|
||||||
<summary>
|
|
||||||
单位负责人
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="P:Ewide.Application.Entity.BsHouseCompany.ChargePersonTel">
|
|
||||||
<summary>
|
|
||||||
单位负责人电话
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="P:Ewide.Application.Entity.BsHouseCompany.ContactPerson">
|
|
||||||
<summary>
|
|
||||||
单位联系人
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="P:Ewide.Application.Entity.BsHouseCompany.ContactPersonTel">
|
|
||||||
<summary>
|
|
||||||
单位联系人电话
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="P:Ewide.Application.BsHouseTask.HouseCodeId">
|
<member name="P:Ewide.Application.BsHouseTask.HouseCodeId">
|
||||||
<summary>
|
<summary>
|
||||||
bs_house_code主键Id
|
bs_house_code主键Id
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
using Ewide.Core;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Ewide.Application
|
||||||
|
{
|
||||||
|
public class HouseCompanyInput
|
||||||
|
{
|
||||||
|
[Required(ErrorMessage = "Id不能为空")]
|
||||||
|
public string Id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class HouseCompanyInfoInput
|
||||||
|
{
|
||||||
|
[Required(ErrorMessage = "信息名称不能为空")]
|
||||||
|
public string Name { get; set; }
|
||||||
|
[Required(ErrorMessage = "信息内容不能为空")]
|
||||||
|
public string Value { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class HouseCompanyPageInput : PageInputBase {}
|
||||||
|
|
||||||
|
public class HouseCompanyAddInput
|
||||||
|
{
|
||||||
|
[Required(ErrorMessage = "名称不能为空")]
|
||||||
|
public virtual string Name { get; set; }
|
||||||
|
|
||||||
|
private string _Type { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "类型不能为空")]
|
||||||
|
public virtual string Type
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _Type;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_Type = String.Join(",", value.Split(',').Select(p => $"[{p}]"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual List<HouseCompanyInfoInput> Info { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class HouseCompanyEditInput : HouseCompanyAddInput
|
||||||
|
{
|
||||||
|
[Required(ErrorMessage = "Id不能为空")]
|
||||||
|
public string Id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class HouseCompanyListInput
|
||||||
|
{
|
||||||
|
[Required(ErrorMessage = "类型不能为空")]
|
||||||
|
public string Type { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Ewide.Application
|
||||||
|
{
|
||||||
|
public class HouseCompanyInfoOutput
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string Value { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class HouseCompanyDetailOutput
|
||||||
|
{
|
||||||
|
public string Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
private string _Type { get; set; }
|
||||||
|
public string Type
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _Type;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_Type = String.Join(",", value.Split(',').Select(p => p.Replace("[", "").Replace("]", "")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public List<HouseCompanyInfoOutput> Info { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
using Ewide.Core.Extension;
|
||||||
|
using Furion.DatabaseAccessor;
|
||||||
|
using Furion.DatabaseAccessor.Extensions;
|
||||||
|
using Furion.DependencyInjection;
|
||||||
|
using Furion.DynamicApiController;
|
||||||
|
using Mapster;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Ewide.Application.Service
|
||||||
|
{
|
||||||
|
[ApiDescriptionSettings(Name = "HouseCompany")]
|
||||||
|
public class HouseCompanyService : IHouseCompanyService, IDynamicApiController, ITransient
|
||||||
|
{
|
||||||
|
private readonly IRepository<BsHouseCompany> _bsHouseCompanyRep;
|
||||||
|
|
||||||
|
public HouseCompanyService(IRepository<BsHouseCompany> bsHouseCompanyRep)
|
||||||
|
{
|
||||||
|
_bsHouseCompanyRep = bsHouseCompanyRep;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("/houseCompany/page")]
|
||||||
|
public async Task<dynamic> Page([FromBody] HouseCompanyPageInput input)
|
||||||
|
{
|
||||||
|
var config = new TypeAdapterConfig().ForType<BsHouseCompany, HouseCompanyDetailOutput>()
|
||||||
|
.Map(target => target.Info, src => JsonConvert.DeserializeObject<List<HouseCompanyInfoOutput>>(src.Info))
|
||||||
|
.Config;
|
||||||
|
return await _bsHouseCompanyRep.DetachedEntities.ToPageData<BsHouseCompany, HouseCompanyDetailOutput>(input, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("/houseCompany/add")]
|
||||||
|
public async Task Add([FromBody] HouseCompanyAddInput input)
|
||||||
|
{
|
||||||
|
var info = JsonConvert.SerializeObject(input.Info);
|
||||||
|
var config = new TypeAdapterConfig().ForType<HouseCompanyAddInput, BsHouseCompany>()
|
||||||
|
.Map(target => target.Info, src => JsonConvert.SerializeObject(src.Info))
|
||||||
|
.Config;
|
||||||
|
var company = input.Adapt<BsHouseCompany>(config);
|
||||||
|
await company.InsertAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("/houseCompany/edit")]
|
||||||
|
public async Task Edit([FromBody] HouseCompanyEditInput input)
|
||||||
|
{
|
||||||
|
var config = new TypeAdapterConfig().ForType<HouseCompanyEditInput, BsHouseCompany>()
|
||||||
|
.Map(target => target.Info, src => JsonConvert.SerializeObject(src.Info))
|
||||||
|
.Config;
|
||||||
|
var company = input.Adapt<BsHouseCompany>(config);
|
||||||
|
await company.UpdateAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("/houseCompany/delete")]
|
||||||
|
public async Task Delete([FromBody] HouseCompanyInput input)
|
||||||
|
{
|
||||||
|
var company = await _bsHouseCompanyRep.FirstOrDefaultAsync(p => p.Id.Equals(input.Id));
|
||||||
|
await company.DeleteAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("/houseCompany/detail")]
|
||||||
|
public async Task<HouseCompanyDetailOutput> Detail([FromQuery] HouseCompanyInput input)
|
||||||
|
{
|
||||||
|
var company = await _bsHouseCompanyRep.FirstOrDefaultAsync(p => p.Id.Equals(input.Id));
|
||||||
|
var config = new TypeAdapterConfig().ForType<BsHouseCompany, HouseCompanyDetailOutput>()
|
||||||
|
.Map(target => target.Info, src => JsonConvert.DeserializeObject<List<HouseCompanyInfoOutput>>(src.Info))
|
||||||
|
.Config;
|
||||||
|
var output = company.Adapt<HouseCompanyDetailOutput>(config);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("/houseCompany/list")]
|
||||||
|
public async Task<dynamic> List([FromQuery] HouseCompanyListInput input)
|
||||||
|
{
|
||||||
|
var types = input.Type.Split(',');
|
||||||
|
var result = new List<HouseCompanyDetailOutput>();
|
||||||
|
var config = new TypeAdapterConfig().ForType<BsHouseCompany, HouseCompanyDetailOutput>()
|
||||||
|
.Map(target => target.Info, src => JsonConvert.DeserializeObject<List<HouseCompanyInfoOutput>>(src.Info))
|
||||||
|
.Config;
|
||||||
|
foreach (var type in types)
|
||||||
|
{
|
||||||
|
var list = (await _bsHouseCompanyRep.DetachedEntities
|
||||||
|
.Where(p => EF.Functions.Like(p.Type, $"%[{type.Trim()}]%"))
|
||||||
|
.OrderBy(p => p.Name)
|
||||||
|
.ToListAsync())
|
||||||
|
.Select(p =>
|
||||||
|
{
|
||||||
|
var output = p.Adapt<HouseCompanyDetailOutput>(config);
|
||||||
|
return output;
|
||||||
|
});
|
||||||
|
result.AddRange(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.Distinct();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Ewide.Application.Service
|
||||||
|
{
|
||||||
|
public interface IHouseCompanyService
|
||||||
|
{
|
||||||
|
Task<dynamic> Page([FromBody] HouseCompanyPageInput input);
|
||||||
|
Task Add([FromBody] HouseCompanyAddInput input);
|
||||||
|
Task Edit([FromBody] HouseCompanyEditInput input);
|
||||||
|
Task Delete([FromBody] HouseCompanyInput input);
|
||||||
|
Task<HouseCompanyDetailOutput> Detail([FromQuery] HouseCompanyInput input);
|
||||||
|
Task<dynamic> List([FromQuery] HouseCompanyListInput input);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -125,6 +125,11 @@ namespace Ewide.Core.Extension
|
|||||||
return source.OrderBy(OrderBuilder<T>(input)).Select(u => u.Adapt<O>()).ToPagedListAsync(input.PageIndex, input.PageSize);
|
return source.OrderBy(OrderBuilder<T>(input)).Select(u => u.Adapt<O>()).ToPagedListAsync(input.PageIndex, input.PageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Task<PagedList<O>> ToPageData<T, O>(this IQueryable<T> source, PageInputBase input, TypeAdapterConfig config) where O : new()
|
||||||
|
{
|
||||||
|
return source.OrderBy(OrderBuilder<T>(input)).Select(u => u.Adapt<O>(config)).ToPagedListAsync(input.PageIndex, input.PageSize);
|
||||||
|
}
|
||||||
|
|
||||||
#region DAPPER
|
#region DAPPER
|
||||||
public async static Task<PagedList> QueryPageDataDynamic(this IDapperRepository source, string baseSql, PageInputBase input, object param = null, IEnumerable<string> filterFields = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
|
public async static Task<PagedList> QueryPageDataDynamic(this IDapperRepository source, string baseSql, PageInputBase input, object param = null, IEnumerable<string> filterFields = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
const urls = {
|
||||||
|
houseCompanyPage: ['/houseCompany/page', 'post'],
|
||||||
|
houseCompanyAdd: ['/houseCompany/add', 'post'],
|
||||||
|
houseCompanyEdit: ['/houseCompany/edit', 'post'],
|
||||||
|
houseCompanyDelete: ['/houseCompany/delete', 'post'],
|
||||||
|
houseCompanyDetail: '/houseCompany/detail',
|
||||||
|
houseCompanyList: '/houseCompany/list'
|
||||||
|
}
|
||||||
|
|
||||||
|
export default urls
|
||||||
@@ -6,6 +6,7 @@ import houseSelector from './houseSelector'
|
|||||||
import houseTask from './houseTask'
|
import houseTask from './houseTask'
|
||||||
import houseInfo from './houseInfo'
|
import houseInfo from './houseInfo'
|
||||||
import houseQuery from './houseQuery'
|
import houseQuery from './houseQuery'
|
||||||
|
import houseCompany from './houseCompany'
|
||||||
|
|
||||||
const urls = {
|
const urls = {
|
||||||
...houseProjectInfo,
|
...houseProjectInfo,
|
||||||
@@ -15,7 +16,8 @@ const urls = {
|
|||||||
...houseSelector,
|
...houseSelector,
|
||||||
...houseTask,
|
...houseTask,
|
||||||
...houseInfo,
|
...houseInfo,
|
||||||
...houseQuery
|
...houseQuery,
|
||||||
|
...houseCompany
|
||||||
}
|
}
|
||||||
|
|
||||||
export default urls
|
export default urls
|
||||||
@@ -18,7 +18,7 @@ function renderModal(props, on, childWithProps) {
|
|||||||
const { buttons } = this.props
|
const { buttons } = this.props
|
||||||
|
|
||||||
const _buttons = [
|
const _buttons = [
|
||||||
<Button onClick={() => on.onClose()}>取消</Button>,
|
<Button onClick={() => on.onCancel()}>取消</Button>,
|
||||||
<Button loading={props.confirmLoading} onClick={() => on.onOk()} type="primary">
|
<Button loading={props.confirmLoading} onClick={() => on.onOk()} type="primary">
|
||||||
确认
|
确认
|
||||||
</Button>,
|
</Button>,
|
||||||
|
|||||||
180
web-react/src/pages/business/house/company/form.jsx
Normal file
180
web-react/src/pages/business/house/company/form.jsx
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
import React, { Component } from 'react'
|
||||||
|
import { Button, Col, Form, Input, Row, Select, Spin } from 'antd'
|
||||||
|
import { AntIcon } from 'components'
|
||||||
|
import { api } from 'common/api'
|
||||||
|
import getDictData from 'util/dic'
|
||||||
|
|
||||||
|
const initialValues = {}
|
||||||
|
|
||||||
|
export default class form extends Component {
|
||||||
|
state = {
|
||||||
|
// 加载状态
|
||||||
|
loading: true,
|
||||||
|
|
||||||
|
codes: {
|
||||||
|
houseCompanyType: [],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// 表单实例
|
||||||
|
form = React.createRef()
|
||||||
|
|
||||||
|
// 初始化数据
|
||||||
|
record = {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mount后回调
|
||||||
|
*/
|
||||||
|
componentDidMount() {
|
||||||
|
this.props.created && this.props.created(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 填充数据
|
||||||
|
* 可以在设置this.record之后对其作出数据结构调整
|
||||||
|
* [异步,必要]
|
||||||
|
* @param {*} params
|
||||||
|
*/
|
||||||
|
async fillData(params) {
|
||||||
|
const state = { loading: false }
|
||||||
|
//#region 从后端转换成前段所需格式,也可以在此处调用获取详细数据接口
|
||||||
|
state.codes = await getDictData('house_company_type')
|
||||||
|
if (params.id) {
|
||||||
|
this.record = (await api.houseCompanyDetail({ id: params.id })).data
|
||||||
|
const { type, info } = this.record
|
||||||
|
if (type) {
|
||||||
|
this.record.type = type.split(',')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//#endregion
|
||||||
|
this.form.current.setFieldsValue(this.record)
|
||||||
|
|
||||||
|
this.setState(state)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据
|
||||||
|
* 可以对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 从前段转换后端所需格式
|
||||||
|
const { type, info } = postData
|
||||||
|
if (Array.isArray(type)) {
|
||||||
|
postData.type = type.join(',')
|
||||||
|
}
|
||||||
|
//#endregion
|
||||||
|
return postData
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//#region 自定义方法
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { codes } = this.state
|
||||||
|
|
||||||
|
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="name"
|
||||||
|
rules={[{ required: true, message: '请输入名称' }]}
|
||||||
|
>
|
||||||
|
<Input autoComplete="off" placeholder="请输入名称" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
label="类型"
|
||||||
|
name="type"
|
||||||
|
rules={[{ required: true, message: '请选择类型' }]}
|
||||||
|
>
|
||||||
|
<Select mode="multiple" placeholder="请选择类型">
|
||||||
|
{codes.houseCompanyType.map(item => (
|
||||||
|
<Select.Option key={item.code} value={item.code}>
|
||||||
|
{item.value}
|
||||||
|
</Select.Option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</Form.Item>
|
||||||
|
<div className="yo-form--fluid">
|
||||||
|
<Form.List name="info">
|
||||||
|
{(fields, { add, remove }) => (
|
||||||
|
<>
|
||||||
|
{fields.map(({ key, name, fieldKey, ...restField }) => (
|
||||||
|
<Row key={key} align="middle">
|
||||||
|
<Col flex="30px" className="text-right">
|
||||||
|
<AntIcon
|
||||||
|
type="minus-circle"
|
||||||
|
onClick={() => remove(name)}
|
||||||
|
/>
|
||||||
|
</Col>
|
||||||
|
<Col flex="187px">
|
||||||
|
<Form.Item
|
||||||
|
{...restField}
|
||||||
|
name={[name, 'name']}
|
||||||
|
fieldKey={[fieldKey, 'name']}
|
||||||
|
rules={[
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
message: '请输入信息名称',
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Input
|
||||||
|
autoComplete="off"
|
||||||
|
placeholder="请输入信息名称"
|
||||||
|
style={{ minWidth: 0 }}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</Col>
|
||||||
|
<Col flex="1">
|
||||||
|
<Form.Item
|
||||||
|
{...restField}
|
||||||
|
name={[name, 'value']}
|
||||||
|
fieldKey={[fieldKey, 'value']}
|
||||||
|
rules={[
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
message: '请输入信息内容',
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Input
|
||||||
|
autoComplete="off"
|
||||||
|
placeholder="请输入信息内容"
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
))}
|
||||||
|
<Form.Item>
|
||||||
|
<Button
|
||||||
|
type="dashed"
|
||||||
|
onClick={() => add()}
|
||||||
|
block
|
||||||
|
icon={<AntIcon type="plus" />}
|
||||||
|
>
|
||||||
|
添加单位信息
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Form.List>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Spin>
|
||||||
|
</Form>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
295
web-react/src/pages/business/house/company/index.jsx
Normal file
295
web-react/src/pages/business/house/company/index.jsx
Normal file
@@ -0,0 +1,295 @@
|
|||||||
|
import React, { Component } from 'react'
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
Descriptions,
|
||||||
|
Form,
|
||||||
|
Input,
|
||||||
|
message as Message,
|
||||||
|
Popconfirm,
|
||||||
|
Select,
|
||||||
|
} 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'
|
||||||
|
import FormBody from './form'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注释段[\/**\/]为必须要改
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置页面所需接口函数
|
||||||
|
*/
|
||||||
|
const apiAction = {
|
||||||
|
page: api.houseCompanyPage,
|
||||||
|
add: api.houseCompanyAdd,
|
||||||
|
edit: api.houseCompanyEdit,
|
||||||
|
delete: api.houseCompanyDelete,
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用于弹窗标题
|
||||||
|
* [必要]
|
||||||
|
*/
|
||||||
|
const name = '单位'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一配置权限标识
|
||||||
|
* [必要]
|
||||||
|
*/
|
||||||
|
const authName = 'houseCompany'
|
||||||
|
|
||||||
|
export default class index extends Component {
|
||||||
|
state = {
|
||||||
|
codes: {
|
||||||
|
houseCompanyType: [],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// 表格实例
|
||||||
|
table = React.createRef()
|
||||||
|
|
||||||
|
// 新增窗口实例
|
||||||
|
addForm = React.createRef()
|
||||||
|
// 编辑窗口实例
|
||||||
|
editForm = React.createRef()
|
||||||
|
|
||||||
|
columns = [
|
||||||
|
{
|
||||||
|
title: '名称',
|
||||||
|
width: 300,
|
||||||
|
dataIndex: 'name',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '类型',
|
||||||
|
width: 300,
|
||||||
|
dataIndex: 'type',
|
||||||
|
render: text =>
|
||||||
|
text
|
||||||
|
.split(',')
|
||||||
|
.map(p => this.bindCodeValue(p, 'house_company_type'))
|
||||||
|
.join(' / '),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造函数,在渲染前动态添加操作字段等
|
||||||
|
* @param {*} props
|
||||||
|
*/
|
||||||
|
constructor(props) {
|
||||||
|
super(props)
|
||||||
|
|
||||||
|
const flag = auth({ [authName]: [['edit'], ['delete']] })
|
||||||
|
|
||||||
|
if (flag) {
|
||||||
|
this.columns.push({
|
||||||
|
title: '操作',
|
||||||
|
width: 150,
|
||||||
|
dataIndex: 'actions',
|
||||||
|
render: (text, { id }) => (
|
||||||
|
<QueryTableActions>
|
||||||
|
<Auth auth={{ [authName]: 'edit' }}>
|
||||||
|
<a onClick={() => this.onOpen(this.editForm, id)}>编辑</a>
|
||||||
|
</Auth>
|
||||||
|
<Auth auth={{ [authName]: 'delete' }}>
|
||||||
|
<Popconfirm
|
||||||
|
placement="topRight"
|
||||||
|
title="是否确认删除"
|
||||||
|
onConfirm={() => this.onDelete(id)}
|
||||||
|
>
|
||||||
|
<a>删除</a>
|
||||||
|
</Popconfirm>
|
||||||
|
</Auth>
|
||||||
|
</QueryTableActions>
|
||||||
|
),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阻止外部组件引发的渲染,提升性能
|
||||||
|
* 可自行添加渲染条件
|
||||||
|
* [必要]
|
||||||
|
* @param {*} props
|
||||||
|
* @param {*} state
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
shouldComponentUpdate(props, state) {
|
||||||
|
return !isEqual(this.state, state)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载字典数据,之后开始加载表格数据
|
||||||
|
* 如果必须要加载字典数据,可直接对表格设置autoLoad=true
|
||||||
|
*/
|
||||||
|
componentDidMount() {
|
||||||
|
const { onLoading, onLoadData } = this.table.current
|
||||||
|
onLoading()
|
||||||
|
api.houseCompanyList({ type: '1' })
|
||||||
|
getDictData('house_company_type').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 {*} id
|
||||||
|
*/
|
||||||
|
onOpen(modal, id) {
|
||||||
|
modal.current.open({ id })
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对表格上的操作进行统一处理
|
||||||
|
* [异步]
|
||||||
|
* @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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
* @param {*} id
|
||||||
|
*/
|
||||||
|
onDelete(id) {
|
||||||
|
this.onAction(apiAction.delete({ id }), '删除成功')
|
||||||
|
}
|
||||||
|
|
||||||
|
//#region 自定义方法
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { codes } = this.state
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Container mode="fluid">
|
||||||
|
<br />
|
||||||
|
<Card bordered={false}>
|
||||||
|
<QueryTable
|
||||||
|
ref={this.table}
|
||||||
|
autoLoad={false}
|
||||||
|
loadData={this.loadData}
|
||||||
|
columns={this.columns}
|
||||||
|
query={
|
||||||
|
<Auth auth={{ [authName]: 'page' }}>
|
||||||
|
<Form.Item label="名称" name="name">
|
||||||
|
<Input
|
||||||
|
autoComplete="off"
|
||||||
|
placeholder="请输入名称"
|
||||||
|
className="w-200"
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label="类型" name="type">
|
||||||
|
<Select placeholder="请选择类型" className="w-200" allowClear>
|
||||||
|
{codes.houseCompanyType.map(item => (
|
||||||
|
<Select.Option key={item.code} value={item.code}>
|
||||||
|
{item.value}
|
||||||
|
</Select.Option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</Form.Item>
|
||||||
|
</Auth>
|
||||||
|
}
|
||||||
|
operator={
|
||||||
|
<Auth auth={{ [authName]: 'add' }}>
|
||||||
|
<Button
|
||||||
|
icon={<AntIcon type="plus" />}
|
||||||
|
onClick={() => this.onOpen(this.addForm)}
|
||||||
|
>
|
||||||
|
新增{name}
|
||||||
|
</Button>
|
||||||
|
</Auth>
|
||||||
|
}
|
||||||
|
expandedRowRender={record => (
|
||||||
|
<Descriptions bordered labelStyle={{ width: 200 }}>
|
||||||
|
{record.info.map((item, i) => (
|
||||||
|
<Descriptions.Item key={i} label={item.name}>
|
||||||
|
{item.value}
|
||||||
|
</Descriptions.Item>
|
||||||
|
))}
|
||||||
|
</Descriptions>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Auth auth={{ [authName]: 'add' }}>
|
||||||
|
<ModalForm
|
||||||
|
width={600}
|
||||||
|
title={`新增${name}`}
|
||||||
|
action={apiAction.add}
|
||||||
|
ref={this.addForm}
|
||||||
|
onSuccess={() => this.table.current.onReloadData()}
|
||||||
|
>
|
||||||
|
<FormBody />
|
||||||
|
</ModalForm>
|
||||||
|
</Auth>
|
||||||
|
|
||||||
|
<Auth auth={{ [authName]: 'edit' }}>
|
||||||
|
<ModalForm
|
||||||
|
width={600}
|
||||||
|
title={`编辑${name}`}
|
||||||
|
action={apiAction.edit}
|
||||||
|
ref={this.editForm}
|
||||||
|
onSuccess={() => this.table.current.onReloadData()}
|
||||||
|
>
|
||||||
|
<FormBody />
|
||||||
|
</ModalForm>
|
||||||
|
</Auth>
|
||||||
|
</Container>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user