/* eslint-disable */ import React, { PureComponent, Fragment } from 'react'; import { connect } from 'dva'; import { Card, Form, Input, Button, Modal, message, Table, Divider, Tree, Spin, Row, Col, Select, Icon, InputNumber } from 'antd'; import { checkTypeWithEnglishAndNumbers } from '../../../helpers/validator' import PageHeaderWrapper from '@/components/PageHeaderWrapper'; import styles from './BannerList.less'; import moment from "moment"; import PaginationHelper from "../../../helpers/PaginationHelper"; import PicturesWall from "../../components/Image/PicturesWall"; const FormItem = Form.Item; const status = ['未知', '正常', '禁用']; // 列表 function List ({ dataSource, loading, pagination, searchParams, dispatch, handleModalVisible}) { function handleStatus(record) { Modal.confirm({ title: record.status === 1 ? '确认禁用' : '取消禁用', content: `${record.username}`, onOk() { dispatch({ type: 'bannerList/updateStatus', payload: { id: record.id, status: record.status === 1 ? 2 : 1, }, }); }, onCancel() {}, }); } function handleDelete(record) { Modal.confirm({ title: `确认删除?`, content: `${record.title}`, onOk() { dispatch({ type: 'bannerList/delete', payload: { id: record.id, }, }); }, onCancel() {}, }); } const columns = [ { title: '标题', dataIndex: 'title', width: 120, }, { title: '跳转链接', dataIndex: 'url', width: 120, }, { title: '图片', dataIndex: 'picUrl', render(val) { return ; }, }, { title: '排序值', dataIndex: 'sort', }, { title: '状态', dataIndex: 'status', render(val) { return {status[val]}; // TODO 芋艿,此处要改 }, }, { title: '备注', dataIndex: 'memo', width: 150, }, { title: '创建时间', dataIndex: 'createTime', width: 120, render: val => {moment(val).format('YYYY-MM-DD')}, }, { title: '操作', width: 150, render: (text, record) => { const statusText = record.status === 1 ? '禁用' : '开启'; // TODO 芋艿,此处要改 return ( handleModalVisible(true, 'update', record)}>编辑 handleStatus(record)}> {statusText} { record.status === 2 ? handleDelete(record)}> 删除 : null } ); }, }, ]; function onPageChange(page) { // 翻页 dispatch({ type: 'bannerList/query', payload: { pageNo: page.current, pageSize: page.pageSize, ...searchParams } }) } return ( ) } // 搜索表单 // TODO 芋艿,有没办法换成上面那种写法 const SearchForm = Form.create()(props => { const { form, form: { getFieldDecorator }, dispatch } = props; function search() { dispatch({ type: 'bannerList/query', payload: { ...PaginationHelper.defaultPayload, ...form.getFieldsValue() } }) } // 提交搜索 function handleSubmit(e) { // 阻止默认事件 e.preventDefault(); // 提交搜索 search(); } // 重置搜索 function handleReset() { // 重置表单 form.resetFields(); // 执行搜索 search(); } return ( {getFieldDecorator('title')()} ); }); // 添加 or 修改 Form 表单 const AddOrUpdateForm = Form.create()(props => { const { dispatch, modalVisible, form, handleModalVisible, modalType, formVals } = props; let picturesWall = null; const okHandle = () => { form.validateFields((err, fields) => { if (err) return; // 添加表单 if (modalType === 'add') { dispatch({ type: 'bannerList/add', payload: { body: { ...fields, picUrl: picturesWall ? picturesWall.getUrl() : undefined, }, callback: () => { // 清空表单 form.resetFields(); // 提示 message.success('添加成功'); // 关闭弹窗 handleModalVisible(); }, }, }); // 修改表单 } else { dispatch({ type: 'bannerList/update', payload: { body: { id: formVals.id, ...fields, picUrl: picturesWall ? picturesWall.getUrl() : undefined, }, callback: () => { // 清空表单 form.resetFields(); // 提示 message.success('编辑成功'); // 关闭弹窗 handleModalVisible(); }, }, }); } }); }; const title = modalType === 'add' ? '新建广告' : '编辑广告'; return ( handleModalVisible()} > {form.getFieldDecorator('title', { rules: [{ required: true, message: '请输入标题!'}, {max: 32, min:2, message: '长度为 2-32 位'}, ], initialValue: formVals.title, })()} {form.getFieldDecorator('url', { rules: [{ required: true, message: '请输入跳转链接!'}, { type: 'url', message: '必须是 URL!'}, {max: 255, message: '最大长度为 255 位'}, ], initialValue: formVals.picUrl, })()} picturesWall = node} maxLength={1} /> {form.getFieldDecorator('sort', { rules: [{ required: true, message: '请输入排序值!' }], initialValue: formVals.sort, })()} {form.getFieldDecorator('memo', { rules: [{ required: false, message: '请输入备注!' }, {max: 255, message: '最大长度为 255 位'}, ], initialValue: formVals.memo, })()} ); }); @connect(({ bannerList }) => ({ // list: bannerList.list, // pagination: bannerList.pagination, ...bannerList, })) // 主界面 @Form.create() class BannerList extends PureComponent { componentDidMount() { const { dispatch } = this.props; dispatch({ type: 'bannerList/query', payload: { ...PaginationHelper.defaultPayload }, }); } handleModalVisible = (modalVisible, modalType, record) => { const { dispatch } = this.props; dispatch({ type: 'bannerList/setAll', payload: { modalVisible, modalType, formVals: record || {} }, }); }; render() { // let that = this; const { dispatch, list, listLoading, searchParams, pagination, modalVisible, modalType, formVals, confirmLoading,} = this.props; // 列表属性 const listProps = { dataSource: list, pagination, searchParams, dispatch, loading: listLoading, confirmLoading, handleModalVisible: this.handleModalVisible, // Function }; // 搜索表单属性 const searchFormProps = { dispatch, }; // 添加 or 编辑表单属性 const addOrUpdateFormProps = { modalVisible, modalType, formVals, dispatch, handleModalVisible: this.handleModalVisible, // Function }; return (
); } } export default BannerList;