import React from 'react'; import { Button, Form, Modal, DatePicker, Input, Upload, Checkbox, Switch } from 'antd'; import { Link } from 'react-router-dom'; import moment from 'moment'; import './index.less'; import Page from '@src/containers/Page'; import Block from '@src/components/Block'; // import FilterLayout from '@src/layouts/FilterLayout'; // import ActionLayout from '@src/layouts/ActionLayout'; import TableLayout from '@src/layouts/TableLayout'; // import { getMap, bindSearch, formatDate } from '@src/services/Tools'; import { asyncDelConfirm, asyncSMessage } from '@src/services/AsyncTools'; // import { TextbookType } from '../../../../Constant'; import { Textbook } from '../../../stores/textbook'; import { System } from '../../../stores/system'; import { formatDate } from '../../../../../src/services/Tools'; // import { Question } from '../../../stores/question'; // import { Slient } from '../../../stores/slient'; export default class extends Page { constructor(props) { super(props); this.actionList = [{ key: 'add', name: '新建', render: (item) => { return ; }, }]; this.columns = [{ title: '库头', dataIndex: 'startDate', render: (text) => { return formatDate(text, 'YYYY-MM-DD'); }, }, { title: '库尾', dataIndex: 'endDate', render: (text) => { return text ? formatDate(text, 'YYYY-MM-DD') : '-'; }, }, { title: '发布次数', dataIndex: 'historyNumber', render: (text, record) => { return text ? { this.loadHistory(record); }}>{text} : 0; }, }, { title: '开放问答', dataIndex: 'questionStatus', render: (text, record) => { return 0} onChange={(e) => { this.changeLibrary(record.id, { questionStatus: e.target.checked ? 1 : 0 }); }} />; }, }, { title: '操作', dataIndex: 'handler', render: (text, record) => { return
{( { this.setState({ post: record }); this.props.form.getFieldDecorator('post.libraryId'); this.props.form.setFieldsValue({ 'post.libraryId': record.id }); }}>发布机经 )} {( 录入机经 )}
; }, }]; } initData() { const { search } = this.state; const data = Object.assign({}, search); Textbook.listLibrary(data).then(result => { this.setTableData(result.list, result.total || 1); }); } loadHistory(record) { Textbook.listHistory({ libraryId: record.id }).then(result => { this.setState({ history: result.list }); }); } submit() { this.props.form.validateFields(['add'], (err, fieldsValue) => { if (err) { return; } const data = fieldsValue.add; data.startDate.local(); data.startDate = data.startDate.format('YYYY-MM-DDT00:00:00Z'); asyncDelConfirm('新增确认', '是否添加新的换库?', () => { return Textbook.addLibrary(data).then(() => { asyncSMessage('添加成功!'); this.refresh(); }); }); }); } submitPost() { this.props.form.validateFields(['post'], (err, fieldsValue) => { if (err) { return; } const data = fieldsValue.post; Textbook.postHistory(data).then(() => { asyncSMessage('发布成功!'); this.close('post', false); this.refresh(); }); }); } changeLibrary(id, data) { data.id = id; return Textbook.editLibrary(data).then(() => { this.refresh(); }); } renderView() { const { getFieldDecorator, setFieldsValue, getFieldValue } = this.props.form; const { postSwitch = {} } = this.state; const quant = getFieldValue('post.quant') || null; const ir = getFieldValue('post.ir') || null; const rc = getFieldValue('post.rc') || null; return
{getFieldDecorator('add.startDate', { initialValue: moment(new Date(), 'YYYY-mm-dd'), })( , )}
this.tableChange(pagination, filters, sorter)} onSelect={(keys, rows) => this.tableSelect(keys, rows)} selectedKeys={this.state.selectedKeys} /> {this.state.history && { this.close(false, 'history'); }} onOk={() => { this.close(false, 'history'); }}> {this.state.history.map(row => { const list = []; if (row.quant) { list.push(

{formatDate(row.createTime, 'YYYY-MM-DD HH:mm:ss')} - {row.quantContent}

); } if (row.ir) { list.push(

{formatDate(row.createTime, 'YYYY-MM-DD HH:mm:ss')} - {row.irContent}

); } if (row.rc) { list.push(

{formatDate(row.createTime, 'YYYY-MM-DD HH:mm:ss')} - {row.rcContent}

); } return list; })}
} {this.state.post && { this.close(false, 'post'); }} onOk={() => { this.submitPost(); }}>
{getFieldDecorator('post.libraryId')} 不更新,使用上一版本 { postSwitch.quant = !postSwitch.quant; this.setState({ postSwitch }); }} />
{!postSwitch.quant && !!this.state.post.quantVersion && `版本:${this.state.post.quantVersion}`}
{postSwitch.quant && {getFieldDecorator('post.quantContent')( , )} } {postSwitch.quant && {getFieldDecorator('post.quantDescription')( , )} } {postSwitch.quant && {getFieldDecorator('post.quant')( System.uploadImage(file).then((result) => { setFieldsValue({ 'post.quant': result.url }); return Promise.reject(); })} onChange={this.handleChange} > {
{quant && '已上传'}
}
, )}
} 不更新,使用上一版本 { postSwitch.rc = !postSwitch.rc; this.setState({ postSwitch }); }} />
{!postSwitch.rc && !!this.state.post.rcVersion && `版本:${this.state.post.rcVersion}`}
{postSwitch.rc && {getFieldDecorator('post.rcContent')( , )} } {postSwitch.rc && {getFieldDecorator('post.rcDescription')( , )} } {postSwitch.rc && {getFieldDecorator('post.rc')( System.uploadImage(file).then((result) => { setFieldsValue({ 'post.rc': result.url }); return Promise.reject(); })} onChange={this.handleChange} > {
{rc && '已上传'}
}
, )}
} 不更新,使用上一版本 { postSwitch.ir = !postSwitch.ir; this.setState({ postSwitch }); }} />
{!postSwitch.ir && !!this.state.post.irVersion && `版本:${this.state.post.irVersion}`}
{postSwitch.ir && {getFieldDecorator('post.irContent')( , )} } {postSwitch.ir && {getFieldDecorator('post.irDescription')( , )} } {postSwitch.ir && {getFieldDecorator('post.ir')( System.uploadImage(file).then((result) => { setFieldsValue({ 'post.ir': result.url }); return Promise.reject(); })} onChange={this.handleChange} > {
{ir && '已上传'}
}
, )}
}
}
; } }