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 request from '../../utils/request'
import SelectCity from '../../components/SelectButton/CitySelect'

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

  const changBuilding = (buildingId) => {
    setBuildingIdData(buildingId)
    request({
      url: '/api/admin/tdBizEventIntention',
      method: 'GET',
      params: {pageNum: 1, pageSize: 999,buildingId}
    }).then((data) => {
      console.log(data)
      setData(data.records)
    })
  }

  const changeBox = (x) => (e) => {
    setData(data.map((item) => {
      return x.eventId === item.eventId ? {...item, checkbox: e.target.checked} : item
    }))
  }

  const changeInput = (x) => (e) => {
    setData(data.map((item) => {
      return x.eventId === item.eventId ? {...item, intention: e.target.value} : item
    }))
  }

  const submitValue = () => {
    console.log(buildingIdValue)
    if(buildingIdValue === ''){
      return
    }
    request({
      url: '/api/admin/taBuildingIntentionAddOrUpdate/' + buildingIdValue,
      method: 'POST',
      data
    }).then((data) => {
      message.info("保存成功")
    })
  }

  return (
    <>
    <Row>
      <Col span={12}>
        <BuildSelect onChange={changBuilding}/>
      </Col>
    </Row>
    <Row>
      <Col span={3} offset={3}>
        用户操作
      </Col>
      <Col span={3} offset={3}>
        意向值
      </Col>
    </Row>
    {data.map((x) => {
      return <Row>
                <Col span={3} offset={3}>
                  <Checkbox checked={x.checkbox} onChange={changeBox(x)}>{x.eventName}</Checkbox>
                </Col>
                <Col span={3} offset={3}>
                  <Input value={x.intention} onChange={changeInput(x)}/>
                </Col>
              </Row>
    })}
    <Row>
      <Button type="primary" className={styles.searchBtn} onClick={submitValue}>确定</Button>
    </Row>
    </>
  );
 }



export default Edit
