import React, { useState, useEffect } from 'react';
import { Form, Input, Button, Icon, Select, Tabs, Radio, DatePicker,message,Checkbox,Row, Col  } from 'antd';
import { FormattedMessage } from 'umi-plugin-react/locale';
import styles from '../style/GoodsList.less';
import moment from 'moment';
import router from 'umi/router';
import BuildSelect from '../../components/SelectButton/BuildSelect'
import XForm, { FieldTypes } from '../../components/XForm';
import Wangedit from '../../components/Wangedit/Wangedit'
import apis from '../../services/apis';
import request from '../../utils/request'

const { MonthPicker, RangePicker, WeekPicker } = DatePicker;
/**
 *
 *
 * @param {*} props
 * @returns
 */
 const Edit = (props) => {
  const [ data, setData ] = useState([])
  const [ checkData, setCheckData ] = useState([])

  useEffect(() => {
    getReportList();
    getCheckedList();
  },[])

  // 查询数据
  const getReportList = () => {
    request({ ...apis.system.tdReports, }).then((data) => {
        setData((data.records || []).map(x => ({label: x.reportName, value: x.reportCode}) ))
    })
  }

  const getCheckedList = () => {
    request({ ...apis.system.taBuildingReports, }).then((data) => {
      setCheckData((data.records || []).map((x) => x.reportCode))
    })
  }
   
  const onChange = (checkedValues) => {
    console.log('checked = ', checkedValues);
    setCheckData(checkedValues)
  }

  const saveCheckedReport = () => {
    console.log(checkData)
    request({ ...apis.system.addTaBuildingReports, data: {list: checkData}}).then((data) => {
      message.info("保存成功")
    })
  }

  return (
    <>
      <Row>
        <Checkbox.Group options={data} value={checkData} onChange={onChange} />
      </Row>
      <Button type="primary" className={styles.searchBtn} onClick={saveCheckedReport}>提交</Button>
    </>
  );
 }



export default Edit
