import React, { Component } from "react"; import { connect } from "dva"; import moment from "moment"; import { Form, Input, Checkbox, Button, Row, Steps, DatePicker, Tag, message, notification, Col } from "antd"; import { taskSaveStepOneDetail, taskGetStepOneDetail, } from "../../../services/api"; // import "../Task.less"; import {formItemLayout1,minSubmitFormLayout} from '../../../constants/formItemLayout'; import $perModal from '../../../utils/modal/perModal'; const FormItem = Form.Item; const { Step } = Steps; const { TextArea } = Input; const dateFormat = "YYYY-MM-DD"; @connect(state => ({ profile: state.profile })) @Form.create() export default class CreateTaskInformation extends Component { state = { taskStatus: '', //驻勤状态 chargePerId: '',//选中的负责人的id comTaskId: this.props.dataSource.comTaskId || this.props.comTaskId || "", param: { chargePerName: '',//负责人名称 taskName: "", taskLevel: "", serviceType: [], taskNature: "", urgentLevel: "", taskStatus: null, startDate: moment().format('YYYY-MM-DD') + " 00:00:00", endDate: moment().format('YYYY-MM-DD') + " 00:00:00", }, startDate: moment().format('YYYY-MM-DD'), endDate: moment().format('YYYY-MM-DD'), }; componentWillMount() { // this.taskGetTaskById(); } componentWillReceiveProps(nextProps) { if (this.state.comTaskId !== nextProps.dataSource.comTaskId) { this.setState({ comTaskId: nextProps.dataSource.comTaskId }, () => { if (this.state.comTaskId) { this.taskGetTaskById() } else { this._reset() } }) } } componentDidMount() { if (this.state.comTaskId) { this.taskGetTaskById() } } _reset() { this.props.form.resetFields(); this.setState({ param: { chargePerName: '',//负责人名称 taskName: "", taskLevel: "", serviceType: [], taskNature: "", urgentLevel: "", taskStatus: null, startDate: moment().format('YYYY-MM-DD') + " 00:00:00", endDate: moment().format('YYYY-MM-DD') + " 00:00:00", } }) } /* 基础信息 */ taskGetTaskById = () => { let comTaskId = this.state.comTaskId; if (comTaskId == '') { return; } // 获取页面详情 taskGetStepOneDetail({ comTaskId }).then( data => { // data.data.serviceType = data.data.serviceType.split(','); const param = { ...this.state.param }; for (const key in data.data) { if (data.data.hasOwnProperty(key) === true) { param[key] = data.data[key]; } } this.setState({ param, taskStatus: data.data.taskStatus, startDate: param.startDate, endDate: param.endDate, chargePerId: data.data.chargePerId, taskContent: data.data.taskContent }) }, err => { console.log(err, "taskGetStepOneDetail-err"); } ); }; handleSubmit = e => { e.preventDefault(); this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { if (this.state.comTaskId != '') { values.comTaskId = this.state.comTaskId; } values.chargePerId = this.state.chargePerId // values.taskNature = '1'; // values.urgentLevel = '1'; // values.serviceType = '1010009'; // values.taskLevel = '1'; // 时间处理 if (values.startDate.valueOf() >= values.endDate.valueOf()) { return message.error("结束时间不能小于开始时间"); } values.startDate = values.startDate.format(dateFormat); values.endDate = values.endDate.format(dateFormat); this.taskManagementAddTaskStepOne(values); } }); }; //创建驻勤第一个步骤 taskManagementAddTaskStepOne = (postdata) => { taskSaveStepOneDetail(postdata).then( data => { this.props.updateTable && this.props.updateTable(); const comTaskId = this.state.comTaskId === '' ? data.data : this.state.comTaskId; if (this.props.onClose) { notification.success({ // message: data.msg message: '保存成功' }); this.props.form.resetFields(); this.props.onClose(); } else { this.props.switchStep && this.props.switchStep(1, comTaskId, this.state.taskStatus); } }, err => { console.log(err, "taskSaveStepOneDetail-err"); } ); }; //返回上一个页面 returnLastPage = () => { this.props.history.push('/taskmanager/tasklist') } render() { const { submitting } = this.props; const { getFieldDecorator } = this.props.form; const { startDate, endDate } = this.state.param; return (