index.tsx 2.67 KB
import React, { useState } from 'react';
import { Form, message, Card, Button, Row, Col, Input } from 'antd';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import * as api from '../../api';
import AuthTableList from './components/AuthTableList';
import { history } from 'umi';
import RenderSelectGoos from './components/RenderSelectGoos';

const formItemLayout =
{
  labelCol: { span: 4 },
  wrapperCol: { span: 20 },
};
interface Props {
  match?: any
}

export default function Index(props: Props) {
  const { match } = props;
  const { id, name } = match.params;
  const [form] = Form.useForm();
  const [confirmloading, setConfirmloading] = useState(false);

  function onSave(feildValue: any) {
    const params = {
      standardIds: id ? [id] : feildValue.standardIds.map((i: { id: any; }) => i.id),
      shopAuthPostList: feildValue.shopAuthPostList.map(i => ({
        shopIds: i.shopIds.map((shop: { value: any; }) => shop.value),
        postList: i.postList.map((post: { value: any; label: any; }) => ({ postId: post.value, postName: post.label })),
        periodDto: { maxNum: i.maxNum, periodType: i.periodType, period: i.period }
      })),
    };
    setConfirmloading(true);
    api.saveGoodsDimension(params).then(res => {
      message.success('保存成功');
      history.goBack();
    }).catch(e => {
      message.error(e.message);
    }).finally(() => {
      setConfirmloading(false);
    });
  }

  return (
    <PageHeaderWrapper
      title="按物品维度授权"
      content={<a onClick={(e) => { e.preventDefault(); history.go(-1); }}>返回资产列表</a>}
    >
      <Card>
        <Form form={form} {...formItemLayout} onFinish={onSave}>
          {!name ? (
            <Form.Item label="选择物品" name="standardIds" rules={[{ required: true, message: '请选择' }]}>
              <RenderSelectGoos />
            </Form.Item>
          ) : (
            // <Form.Item label="物品名称">
            //   <Input bordered={false} value={name} />
            // </Form.Item>
            null
          )}
          <Form.Item label="按门店授权" name="shopAuthPostList" rules={[{ required: true, message: '添加授权信息' }]}>
            <AuthTableList />
          </Form.Item>
        </Form>
        <Row gutter={16} justify="center">
          <Col span={4} style={{ textAlign: 'center' }}>
            <Button size="middle" type="default" onClick={() => history.go(-1)}>返回</Button>
          </Col>
          <Col span={4} style={{ textAlign: 'center' }}>
            <Button size="middle" type="primary" loading={confirmloading} onClick={() => form.submit()}>提交</Button>
          </Col>
        </Row>
      </Card>
    </PageHeaderWrapper>
  );
}