OrderDelivery.js 4.4 KB
Newer Older
sin's avatar
sin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
import React from 'react';
import { Table, Modal, Card, Form, Input, message } from 'antd';
import DictionaryText from '@/components/Dictionary/DictionaryText';
import DictionarySelect from '@/components/Dictionary/DictionarySelect';
import dictionary from '@/utils/dictionary';
import styles from './OrderDelivery.less';

const OrderDelivery = Form.create()(props => {
  const columns = [
    {
      title: '商品',
      dataIndex: 'skuName',
      render: (text, row) => {
        return (
          <div>
            <img className={styles.goodImg} alt={row.skuName} src={row.skuImage} />
            <span>{row.skuName}</span>
          </div>
        );
      },
    },
    {
      title: '数量',
      dataIndex: 'quantity',
      render: quantity => <span>{quantity}</span>,
    },
    {
      title: '状态',
      dataIndex: 'status',
      sorter: true,
      render: status => <DictionaryText dicKey={dictionary.ORDER_STATUS} dicValue={status} />,
    },
    {
      title: '运输号',
      dataIndex: 'orderLogisticsId',
      width: 200,
      render: orderLogisticsId => {
        return <span>{orderLogisticsId || '-'}</span>;
      },
    },
  ];

  const handleCancel = () => {
    const { dispatch } = props;
    dispatch({
      type: 'orderDelivery/changeVisible',
      payload: {
        visible: false,
      },
    });
  };

  const handleOk = e => {
    e.preventDefault();
    const { dispatch, form } = props;
    const { selectedRowKeys, orderId } = props.orderDelivery;
    form.validateFields((err, fields) => {
      if (err) return;
      console.log('fields', fields);

      console.log('selectedRowKeys', selectedRowKeys);
      if (selectedRowKeys.length <= 0) {
        message.error('至少选择一个发货的商品!');
      } else {
        dispatch({
          type: 'orderDelivery/deliver',
          payload: {
            ...fields,
            orderId,
            orderItemIds: selectedRowKeys,
          },
        });
      }
    });
  };

  const { loading, orderDelivery } = props;
  const { getFieldDecorator } = props.form;
  const { list, visible, orderRecipient } = orderDelivery;
  const { name, mobile, address } = orderRecipient || {};

  // rowSelection objects indicates the need for row selection
  const rowSelection = {
    onChange: (selectedRowKeys, selectedRows) => {
      console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
      props.dispatch({
        type: 'orderDelivery/changeSelectedRowKeys',
        payload: {
          selectedRowKeys,
        },
      });
    },
    onSelect: (record, selected, selectedRows) => {
      console.log(record, selected, selectedRows);
    },
    onSelectAll: (selected, selectedRows, changeRows) => {
      console.log(selected, selectedRows, changeRows);
    },
  };

  return (
    <Modal
      destroyOnClose
      title="发货"
      visible={visible}
      onOk={handleOk}
      okText="保存"
      onCancel={handleCancel}
      confirmLoading={loading}
      width={800}
    >
      <Table
        rowKey="id"
        columns={columns}
        dataSource={list}
        loading={loading}
        pagination={false}
        rowSelection={rowSelection}
        // onSelectRow={handleSelectRows}
        // onChange={handleStandardTableChange}
      />

      <Card loading={loading}>
        <div>
          <h3>配送信息</h3>{' '}
        </div>
        <div>
          收货人: {name} ({mobile})
        </div>
        <div>配件方式: 快递 TODO暂时只有一种</div>
        <div>收件地址: {address}</div>
      </Card>

      <Card loading={loading}>
        <div>
          <h3>发货方式</h3>{' '}
        </div>
        <Form>
          <Form.Item label="物流">
            {getFieldDecorator('logistics', {
              rules: [{ required: true, message: '必选!' }],
            })(
              <DictionarySelect
                style={{ minWidth: '100%' }}
                dicKey={dictionary.LOGISTICS_COMPANY}
              />
            )}
          </Form.Item>
          <Form.Item label="快递号">
            {getFieldDecorator('logisticsNo', {
              rules: [{ required: true, message: '必选!' }],
            })(<Input placeholder="请输入快递号." />)}
          </Form.Item>
          <Form.Item>
            *请仔细填写物流公司及快递单号,发货后24小时内仅支持做一次更正,逾期不可修改
          </Form.Item>
        </Form>
      </Card>
    </Modal>
  );
});

export default OrderDelivery;