import React, { PureComponent } from 'react'; import { routerRedux } from 'dva/router'; import PropTypes from 'prop-types'; import queryString from 'query-string'; import { connect } from 'dva'; import { Spin, Popover, Badge, Table, Radio, Card, Form, Input, Icon, Button, Select } from 'antd'; import PageHeaderLayout from '../../../layouts/PageHeaderLayout'; import SupportSelectSortModal from './supportModal'; import ResourceSelectModal from './resourceModal'; import { Codes } from '../../../utils/config'; const FormItem = Form.Item; const Option = Select.Option; const { TextArea } = Input; @Form.create() @connect(state => ({ resource: state.resource, support: state.support, supportDetail: state.supportDetail, })) export default class SupportDetail extends PureComponent { static propTypes = { supportDetail: PropTypes.object, }; state = { curClickedBtn: null, //记录点击的按钮 }; // 展示选择模态框 - 加载第一页数据 handleModalShow = (btnName) => { this.setState({ curClickedBtn: btnName, }, () => { const { dispatch } = this.props; if (btnName === 'supportBtn') { dispatch({ type: 'supportDetail/showSupportModal' }); dispatch({ type: 'support/query', payload: { pageNo: 1, pageSize: 10, status: Codes.CODE_NORMAL, } }); } if (btnName === 'imgBtn') { dispatch({ type: 'supportDetail/showResourceModal' }); dispatch({ type: 'resource/query', payload: { pageNo: 1, pageSize: 10, status: Codes.CODE_NORMAL, type: Codes.CODE_IMAGE, } }); } }) } // 取消/关闭 - 隐藏选择模态框 handleModalCancel = () => { const { curClickedBtn } = this.state; const { dispatch } = this.props; if (curClickedBtn === 'supportBtn') { dispatch({ type: 'supportDetail/hideSupportModal' }); } if (curClickedBtn === 'imgBtn') { dispatch({ type: 'supportDetail/hideResourceModal' }); } } // 提交 - 保存选择和排序完的数据到model中 handleModalOk = (data) => { const { curClickedBtn } = this.state; const { dispatch } = this.props; if (curClickedBtn === 'supportBtn') { dispatch({ type: 'supportDetail/saveSupportList', payload: { supportList: data } }); } else if (curClickedBtn === 'imgBtn') { dispatch({ type: 'supportDetail/saveImgList', payload: { imgList: data }, }); } } // 搜索 handleModalSearch = (data) => { const { curClickedBtn } = this.state; const { dispatch } = this.props; const newData = { ...data }; if (newData.keyword) { newData[newData.field] = newData.keyword; delete newData.field; delete newData.keyword; } else { delete newData.field; delete newData.keyword; } if (curClickedBtn === 'supportBtn') { dispatch({ type: `support/query`, payload: { ...newData, pageNo: 1, pageSize: 10, status: Codes.CODE_NORMAL }, }); } else if (curClickedBtn === 'imgBtn') { dispatch({ type: `resource/query`, payload: { ...newData, pageNo: 1, pageSize: 10, status: Codes.CODE_NORMAL, type: Codes.CODE_IMAGE }, }); } } // 翻页 - 资源列表 handleModalTableChange = (pagination, filterArgs, filters) => { const { curClickedBtn } = this.state; const { dispatch } = this.props; const newFilters = { ...filters }; if (newFilters.keyword) { newFilters[newFilters.field] = newFilters.keyword; delete newFilters.field; delete newFilters.keyword; } else { delete newFilters.field; delete newFilters.keyword; } const getValue = obj => Object.keys(obj).map(key => obj[key]).join(','); const tableFilters = Object.keys(filterArgs).reduce((obj, key) => { const newObj = { ...obj }; newObj[key] = getValue(filterArgs[key]); return newObj; }, {}); const data = { ...newFilters, ...tableFilters, pageNo: pagination.current, pageSize: pagination.pageSize }; Object.keys(data).map(key => data[key] ? null : delete data[key]); if (curClickedBtn === 'supportBtn') { dispatch({ type: `support/query`, payload: { ...data, status: Codes.CODE_NORMAL } }); } else if (curClickedBtn === 'imgBtn') { dispatch({ type: `resource/query`, payload: { ...data, status: Codes.CODE_NORMAL, type: Codes.CODE_IMAGE } }); } } handlePageSubmit = (e) => { e.preventDefault() const { dispatch, form: { validateFields, getFieldsValue, resetFields }, supportDetail: { operType, currentItem, filters, } } = this.props; validateFields((errors) => { if (errors) { return; } const data = { ...currentItem, ...getFieldsValue(), }; dispatch({ type: `supportDetail/${operType}`, payload: data, callback: () => { dispatch( routerRedux.push({ pathname: '/product/support', search: queryString.stringify(filters), }) ); } }) resetFields(); }); } handlePageCancel = () => { const { dispatch, supportDetail: { filters } } = this.props; dispatch({ type: 'supportDetail/clearPage' }); dispatch( routerRedux.push({ pathname: '/product/support', search: queryString.stringify(filters), }) ); } render() { const { dispatch, form: { getFieldDecorator }, resource, support, supportDetail } = this.props; const { itemLoading, currentItem, filters, supportModalVisible, resourceModalVisible } = supportDetail; const { imgList = [], supportList = [], name, code, digest } = currentItem; // 待选表格去掉分页的跳转及变换页码 if (resource && resource.pagination) { delete resource.pagination.showQuickJumper; delete resource.pagination.showSizeChanger; } const supportTableColumns = [{ title: '配套编号', dataIndex: 'code', key: 'code', },{ title: '配套名称', dataIndex: 'name', key: 'name', }]; const imgTableColumns = [{ title: '缩略图', dataIndex: 'url', key: 'url', render: (text, record) => ( } title={record.name} > ), },{ title: '图片编号', dataIndex: 'code', key: 'code', },{ title: '图片名称', dataIndex: 'name', key: 'name', }]; const formItemLayout = { labelCol: { span: 7, }, wrapperCol: { span: 12, }, }; const submitFormLayout = { wrapperCol: { xs: { span: 24, offset: 0 }, sm: { span: 10, offset: 7 }, }, }; return (
{getFieldDecorator('code', { rules: [{ required: true, type: 'string', message: "编号为必填项!" }], initialValue: code, })()} {getFieldDecorator('name', { rules: [{ required: true, type: 'string', message: "名称为必填项!" }], initialValue: name, })()} {getFieldDecorator('digest', { initialValue: digest, })(