import React, { useState, useEffect } from 'react';
import {
  Button,
  Radio,
  Modal,
  notification,
} from 'antd';
import request from '@/utils/request';
import apis from '@/services/apis';

const ChangeStatus = props => {
  console.log(props, 'props');

  const [value, setValue] = useState();

  const { visible, data } = props.modelProps || {};

  useEffect(() => {
    console.log(data, 'data');
    setValue(data?.status);
  }, [data]);

  const openNotificationWithIcon = (type, message) => {
    notification[type]({
      message,
      description: '',
    });
  };

const  submitButton = () => {
    // 网路请求
    request({
      ...apis.customer.recommendEdit,
      urlData: { id: data.customerId },
      data: { customerId: data.customerId, status: value },
    })
      .then(() => {
        // eslint-disable-next-line no-unused-expressions
        openNotificationWithIcon('success', '操作成功');
        props.handleCancel()
      })
      .catch(err => {
        // eslint-disable-next-line no-unused-expressions
        openNotificationWithIcon('error', err);
      });
  };

  return (
    <>
      <Modal
        title="变更状态"
        width={800}
        destroyOnClose="true"
        footer={null}
        visible={visible}
        // onOk={() => this.handleOk()}
        onCancel={() => props.onCancel()}
      >
        {data && (
          <>
            <Radio.Group value={value} onChange={e => setValue(e.target.value)}>
              <Radio value={1}>客户报备</Radio>
              <Radio value={2}>客户到访</Radio>
              <Radio value={3}>客户认购</Radio>
              <Radio value={4}>客户签约</Radio>
            </Radio.Group>
            <Button type="primary" onClick={submitButton}>
              确定
            </Button>
          </>
        )}
      </Modal>
    </>
  );
};

export default ChangeStatus;
