import React, { useState, useEffect } from 'react'; import { Form, Input, Button, Card, Radio, notification, Select, Checkbox } 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 AuthButton from '@/components/AuthButton'; const { TextArea } = Input; const { Option } = Select; const tailFormItemLayout = { labelCol: { xs: { span: 20 }, sm: { span: 3 }, }, wrapperCol: { xs: { span: 20 }, sm: { span: 16 }, }, }; const openNotificationWithIcon = (type, message) => { notification[type]({ message, description: '', }); }; const questionnaire = `[{"question":"你的租房预算是多少/月?","key":"minPrice","type":"range","result":500,"resultId":null,"options":[500,4500]},{"question":"你的租房预算是多少/月?","key":"maxPrice","type":"range","result":3016,"resultId":null,"options":[500,4500]},{"question":"你的租房偏好?","key":"preference","type":"checkbox","result":"整租","resultId":1,"options":[{"name":"整租","id":1},{"name":"合租","id":2},{"name":"不限","id":3}]},{"question":"你想租几居室的房子?","key":"layout","type":"checkbox","result":"二室","resultId":2,"options":[{"name":"一室","id":1},{"name":"二室","id":2},{"name":"三室","id":3},{"name":"四室","id":4},{"name":"五室及以上","id":5}]},{"question":"其他要求?","key":"purpose","type":"checkbox","result":"独立阳台","resultId":5,"options":[{"name":"独卫","id":1},{"name":"近地铁","id":2},{"name":"拎包入住","id":3},{"name":"精装修","id":4},{"name":"独立阳台","id":5},{"name":"集中供暖","id":6},{"name":"押一付一","id":7},{"name":"双卫","id":8},{"name":"新上","id":9},{"name":"认证公寓","id":10}]},{"question":"您还有哪些特殊要求?","key":"remark","type":"textarea","result":"12","resultId":null},{"result":null,"key":"intentArea","question":"意向区域"},{"question":"创建人小程序人员","result":"b47e82b90071ba6142c07436c80be81f","key":"personId"}]`; function body(props) { const { getFieldDecorator } = props.form; // eslint-disable-next-line react-hooks/rules-of-hooks const [visibleData, setVisibleData] = useState({ visible: false, customerId: '', realtyConsultant: '', buildingId: '', }); // eslint-disable-next-line react-hooks/rules-of-hooks const [dataSource, setDataSource] = useState({ picture: '' }); const { id, type } = props.location.query; const disabled = true; useEffect(() => { if (id !== '') { getById(id); } }, [id]); // 获取详情信息 function getById(currentId) { request({ ...apis.searchHouse.IdHouse, urlData: { id: currentId } }).then(res => { // res.reportDate = moment(res.reportDate) if (res) { const b = {}; console.log(JSON.parse(res.questionnaire),'---------') JSON.parse(res.questionnaire)?.map(x => { if (x.key === 'intentArea') { // b[x.key] = [x.resultId]; return; } // if (x.key === 'purpose') { // b[x.key] = [x.resultId]; // return; // } if (x.key === 'maxPrice') { b[x.key] = x.result; return; } if (x.type === 'checkbox') { b[x.key] = x.result; } else { b[x.key] = x.result; } }); // console.log(b, 'questionnaire'); props.form.setFieldsValue({ ...res, reportDate: moment(res.reportDate), ...b, intentArea: res.intentArea, }); // props.form.setFieldsValue({ ...res, reportDate: moment(res.reportDate) }); //包裹的没渲染完就执行set 导致在呈现字段之前无法设置表单字段 } }); } function submitDate(params) { // props.form.setFieldsValue(res) console.log(params, 'params'); request({ ...apis.searchHouse.reply, urlData: { id }, data: { auditRemark: props.form.getFieldValue('auditRemark'), status: params.status, }, }) .then(() => { // eslint-disable-next-line no-unused-expressions openNotificationWithIcon('success', '操作成功'); router.go(-1); }) .catch(err => { // eslint-disable-next-line no-unused-expressions }); } // 提交事件 function handleSubmit(e) { e.preventDefault(); props.form.validateFields((err, values) => { if (!err) { submitDate({ status: '1' }); // submitDate({ ...values }) } }); } return (
handleSubmit(e)} style={{ width: '800px', margin: 'auto' }} > {/* {getFieldDecorator('customerId')()} */} {/* ············分割线............. */} {getFieldDecorator('name')()} {getFieldDecorator('nickname')()} {getFieldDecorator('phone')()} {getFieldDecorator('gender')( , )} {getFieldDecorator('maxPrice')( , )} {getFieldDecorator('preference')( , )} {getFieldDecorator('layout')( , )} {getFieldDecorator('purpose')( 独卫 近地铁 拎包入住 精装修 独立阳台 集中供暖 押一付一 双卫 新上 认证公寓 , )} {getFieldDecorator('remark')(