MapAddressBtn.jsx 1.1 KB
Newer Older
DarkForst's avatar
DarkForst 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
import React, {useState} from 'react';
import { Row, Col, Input, Button } from 'antd';
import MapSelectAddress from './MapSelectAddress';

const MapAddressBtn = (props) => {
  const [pos, setPos] = useState({});
  const [address, setAddress] = useState();
  const [mapVisible, setMapVisible] = useState(false);


  const changeAddress = (pos, address) => {
    console.log(pos)
    setPos(pos);
    setAddress(address);
    // this.props.onChange({...pos, address,});
  }

  const changeMapVisible = () => {
    setMapVisible(!mapVisible)
  }
  return (
    <div>
      <Row gutter={8}>
        <Col span={19}>
          <Input readOnly={true} value={address} allowClear={true}/>
        </Col>
        <Col span={4}>
          <Button onClick={changeMapVisible}>选择</Button>
        </Col>
      </Row>

      <MapSelectAddress
        visible={mapVisible}
        onChangeMapVisible={changeMapVisible}
        initMarker={[pos.latitude || 0, pos.longitude || 0]}
        address={ address || '' }
        onChange={ (pos, addr)=> changeAddress(pos, addr) }
      />
    </div>
  );
};

export default MapAddressBtn;