import React from 'react';
import { Tabs } from 'antd';
import './index.less';
import Page from '@src/containers/Page';
import Block from '@src/components/Block';
import ShowImage from '@src/components/ShowImage';
import ActionLayout from '@src/layouts/ActionLayout';
import TableLayout from '@src/layouts/TableLayout';
// import { formatDate } from '@src/services/Tools';
import { asyncSMessage, asyncForm, asyncDelConfirm } from '@src/services/AsyncTools';
import { Ready } from '../../../stores/ready';
import { System } from '../../../stores/system';
export default class extends Page {
init() {
this.itemList = [{
key: 'id',
type: 'hidden',
}, {
key: 'title',
type: 'input',
name: '标题',
}, {
key: 'content',
type: 'textarea',
name: '内容',
}, {
key: 'cover',
type: 'image',
name: '封面图片',
onUpload: ({ file }) => {
return System.uploadImage(file).then(result => { return result; });
},
}];
this.columns = [{
title: '资料封面',
dataIndex: 'cover',
render: (text) => {
return ;
},
}, {
title: '资料标题',
dataIndex: 'title',
}, {
title: '内容',
dataIndex: 'content',
}, {
title: '操作',
dataIndex: 'handler',
render: (text, record) => {
return
;
},
}];
this.actionList = [{
key: 'add',
name: '增加',
}];
}
initData() {
this.refreshTab(this.state.search.tab || 'official');
}
refreshTab(tab) {
const { search } = this.state;
search.tab = tab;
this.setState({ search });
if (tab === 'official') {
return this.refreshOfficial();
}
if (tab === 'unofficial') {
return this.refreshUnofficial();
}
return Promise.reject();
}
refreshOfficial() {
return Ready.listData({ isOfficial: true }).then((result) => {
this.setState({ list: result.list, total: result.total });
});
}
refreshUnofficial() {
return Ready.listData({ isOfficial: false }).then((result) => {
this.setState({ list: result.list, total: result.total });
});
}
addAction() {
asyncForm('创建资料', this.itemList, {}, data => {
data.isOfficial = this.state.search.tab === 'official' ? 1 : 0;
return Ready.addData(data).then(() => {
asyncSMessage('添加成功!');
this.refresh();
});
});
}
editAction(row) {
asyncForm('编辑资料', this.itemList, row, data => {
return Ready.editData(data).then(() => {
asyncSMessage('编辑成功!');
this.refresh();
});
});
}
deleteAction(row) {
asyncDelConfirm('删除确认', '是否删除选中?', () => {
const handler = Ready.delData({ id: row.id });
return handler.then(() => {
asyncSMessage('删除成功!');
this.refresh();
});
});
}
renderOfficial() {
return
this.onAction(key)}
/>
;
}
renderUnofficial() {
return this.renderOfficial();
}
renderView() {
const { search } = this.state;
const { tab } = search;
return
{
this.search({ tab: value });
}}>
{this.renderOfficial()}
{this.renderUnofficial()}
;
}
}