import QRCode from 'qrcode.react';
import React, { useEffect, useState } from 'react';
import { Spin } from 'antd';
import { connect } from 'dva';

let timer;
function DDCode(props) {
  const {
    value,
    onChange,
    currentUser: { DingUserId },
  } = props;
  const [loading, setLoading] = useState(false);
  // const [time, setTime] = useState(0);

  // const queryCode = async () => {
  //   setLoading(true);
  //   // TODO 查询接口获得code

  //   setLoading(false);
  //   clearInterval(timer);
  //   onChange({
  //     code: '',
  //   });
  //   let second = 60 * 5;
  //   if (second <= 0) return;
  //   setTime(second);

  //   timer = setInterval(() => {
  //     setTime(time => {
  //       if (time > 0) {
  //         return time--;
  //       }
  //       return time;
  //     });
  //   }, second * 1000);
  // };
  if (!DingUserId) return <div>未知用户，请联系管理员。</div>;
  return (
    <div>
      <Spin spinning={loading}>
        <QRCode size={128} value={`http://47.96.12.136:8896/#/bom/dd-login/${DingUserId}`} />
        请使用钉钉扫码授权
      </Spin>
    </div>
  );
}

export default connect(({ user }) => ({ currentUser: user.currentUser }))(DDCode);
