import React, { useState, useEffect } from 'react'; import { Form, Icon, Input, Button, DatePicker, Select, Card, Row, Col, Pagination, Alert, Radio, Tag, Tooltip, Tabs, InputNumber, notification } from 'antd'; import moment from 'moment'; import request from '../../../../../utils/request'; import apis from '../../../../../services/apis'; import Styles from '../style.less'; import { router } from 'umi'; import ImageUpload from '../../../../../components/XForm/ImageUpload' import ImageListUpload from '../../../../../components/XForm/ImageListUpload' import Wangedit from '../../../../../components/Wangedit/Wangedit' import TagGroup from './tags' import Amap from './amap' import BudildingProjectType from './buildingProjectType' import SelectCity from '../../../../../components/SelectButton/CitySelect' const { Option } = Select const { TabPane } = Tabs; const formItemLayout = { labelCol: { xs: { span: 24 }, sm: { span: 2 }, }, wrapperCol: { xs: { span: 24 }, sm: { span: 16 }, }, }; function openNotificationWithIcon(type, message) { notification[type]({ message, description: '', }); } function AddBuilding(props) { const { getFieldDecorator } = props.form; if (props.building.buildingId !== undefined) { const { buildingId } = props.building if (buildingId !== '') { // eslint-disable-next-line react-hooks/rules-of-hooks useEffect(() => { getById(buildingId) }, []) } } // 获取详情信息 function getById(currentId) { request({ ...apis.building.buildingGetById, urlData: { id: currentId } }).then(res => { if (res.openingDate !== null) { res.openingDate = moment(res.openingDate) } if (res.receivedDate !== null) { res.receivedDate = moment(res.receivedDate) } if (res.buildingTag !== null) { res.tag = res.buildingTag.map((item, _) => item.tagName) } res.avatarImage = res.buildingImg.map(item => item.url) props.form.setFieldsValue(res) }) } function handleSubmit(e) { e.preventDefault(); props.form.validateFieldsAndScroll((err, values) => { if (!err) { addBuilding(values) } }); } function addBuilding(data) { data.openingDate = moment(data.openingDate, 'yyyy-MM-dd HH:mm:ss') data.receivedDate = moment(data.receivedDate, 'yyyy-MM-dd HH:mm:ss') // 项目主图 data.img = data.avatarImage && data.avatarImage.map((item, index) => ({ imgType: 'banner', url: item, orderNo: index + 1 })) if (data.tag) { data.tag = data.tag.map((item, _) => ({ tagName: item })) } const api = data.buildingId === undefined ? apis.building.addBuilding : apis.building.updateBuilding request({ ...api, data: { ...data } }).then(() => { openNotificationWithIcon('success', '操作成功') router.go(-1) }).catch(err => { openNotificationWithIcon('error', err.message) }) } return (