import React from 'react'; import moment from 'moment'; import { Form, Input, Button, Row, Col, InputNumber, DatePicker } from 'antd'; import './index.less'; import Editor from '@src/components/Editor'; import Page from '@src/containers/Page'; import Block from '@src/components/Block'; import Select from '@src/components/Select'; // import FileUpload from '@src/components/FileUpload'; import { formatFormError, generateSearch } from '@src/services/Tools'; import { asyncSMessage } from '@src/services/AsyncTools'; import { PrepareStatus, ExperienceScoreRange, ExperiencePercent } from '../../../../Constant'; import { Course } from '../../../stores/course'; import { User } from '../../../stores/user'; const [minScore, maxScore, step] = ExperienceScoreRange; let tmp = minScore; const ExperienceScore = []; while (tmp <= maxScore) { ExperienceScore.push({ label: `${tmp}`, value: tmp }); tmp += step; } export default class extends Page { initState() { return { showNickname: true }; } initData() { const { id } = this.params; const { form } = this.props; let handler; if (id) { handler = Course.getExperience({ id }); } else { handler = Promise.resolve({}); } handler .then(result => { if (result.userId) { this.setState({ showNickname: false }); } result.experienceTime = moment(result.experienceTime); generateSearch('userId', { allowClear: true, }, this, (search) => { return User.list(search); }, (row) => { return { title: `${row.nickname}(${row.mobile})`, value: row.id, }; }, result.userId, null); form.setFieldsValue(result); }); } submit() { const { form } = this.props; form.validateFields((err) => { if (!err) { const data = form.getFieldsValue(); let handler; data.description = (data.content || '').replace(/<[^>]+>/g, '').substr(0, 200); if (data.id) { handler = Course.editExperience(data); } else { handler = Course.addExperience(data); } handler.then(() => { asyncSMessage('保存成功'); goBack(); }).catch((e) => { if (e.result) form.setFields(formatFormError(data, e.result)); }); } }); } renderBase() { const { getFieldDecorator } = this.props.form; const { showNickname } = this.state; return
{getFieldDecorator('id')()} {getFieldDecorator('title', { rules: [ { required: true, message: '请输入名称' }, ], })()} {getFieldDecorator('userId', { rules: [ { required: !showNickname, message: '请选择作者' }, ], })( , )} {getFieldDecorator('prepareStatus', { rules: [{ required: true, message: '请选择', }], })( , )} {getFieldDecorator('experiencePercent', { rules: [{ required: true, message: '请选择', }], })( , )} {getFieldDecorator('content', { })( , )}
; } renderView() { return
{this.renderBase()}
; } }