import React from 'react';
import PandaImageSelect from '../index';
import request from 'umi-request';

class Demo extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      dataSource: [],
    };
  }

  onSelect = (value) => {
    console.log(value, 'PandaImageSelect-value');
  };

  fetchData = (params = {}) => {
    const _this = this;
    request(baseUrl + '/Publish/OMS/FileCenter/GetImageOrderByPath', {
      method: 'get',
      params: {
        path: 'assets/images/appMenu',
        maxLength: 279.1525423728813,
        fileName: params.fileName ? params.fileName : '',
      },
    }).then(function (response) {
      _this.setState({
        dataSource: response.data,
      });
    });
  };

  // 获取token
  componentDidMount() {
    this.fetchData();
  }

  render() {
    return (
      <PandaImageSelect
        onSearch={(params) => this.fetchData(params)}
        dataSource={this.state.dataSource}
        onSelect={(value) => this.onSelect(value)}
        url={imgUrl}
      />
    );
  }
}

export default Demo;

const imgUrl = 'http://192.168.10.150:8777';
const baseUrl = 'https://www.fastmock.site/mock/162c15dca15c4dba9ba51e0a0b76929b/api';
