import React, { PureComponent, Fragment, Component } from 'react'; import { Form, Card, Table, Button, Divider, Modal, Input } from 'antd'; import moment from 'moment'; import { connect } from 'dva'; import PageHeaderWrapper from '@/components/PageHeaderWrapper'; import PaginationHelper from '../../../helpers/PaginationHelper'; import styles from './ProductAttrList.less'; const FormItem = Form.Item; const CreateForm = Form.create()(props => { const { modalVisible, form, handleAdd, handleModalVisible, modalType, initValues } = props; const okHandle = () => { form.validateFields((err, fieldsValue) => { if (err) return; let pid = fieldsValue.pid; if (fieldsValue.pid) { pid = pid.split('-')[1]; fieldsValue.pid = pid; } form.resetFields(); handleAdd({ fields: fieldsValue, modalType, initValues, }); }); }; const selectStyle = { width: 200, }; function onTypeChange(event) { initValues.type = parseInt(event.target.value); } const title = modalType === 'add' ? '添加规格' : '编辑规格'; const okText = modalType === 'add' ? '添加' : '编辑'; return ( handleModalVisible()} > {form.getFieldDecorator('name', { initialValue: initValues ? initValues.name : null, rules: [{ required: true, message: '请输入规格名称!', min: 2 }], })()} ); }); @connect(({ productAttrList, loading }) => ({ productAttrList, attrData: productAttrList.attrData, loading: loading.models.productAttrList, })) @Form.create() export default class ProductAttrList extends PureComponent { state = { modalVisible: false, modalType: 'add', //add or update initValues: {}, }; componentDidMount() { const { dispatch } = this.props; dispatch({ type: 'productAttrList/page', payload: { ...PaginationHelper.defaultPayload, }, }); } handleModalVisible = (flag, modalType, initValues) => { this.setState({ modalVisible: !!flag, initValues: initValues || {}, modalType: modalType || 'add', }); }; render() { const { attrData, productAttrList, loading, pagination } = this.props; const columns = [ { title: '规格名称', dataIndex: 'name', }, { title: '状态', dataIndex: 'status', render: val => {val === 1 ? '开启' : '禁用'}, }, { title: '创建时间', dataIndex: 'createTime', sorter: true, render: val => {moment(val).format('YYYY-MM-DD')}, }, { title: '操作', render: (text, record) => ( this.handleModalVisible(true, 'update', record)}>编辑 this.handleDelete(record)}> 删除 ), }, ]; const { modalVisible, modalType, initValues } = this.state; const parentMethods = { handleAdd: this.handleAdd, handleModalVisible: this.handleModalVisible, modalType, initValues, }; return ( this.handleModalVisible(true, 'add', {})} > 新建规格 {modalVisible ? : null} ); } }