import React, { useEffect, useState } from 'react';
import { Input, Button, message, Checkbox, Row, Col, Card } from 'antd';
import styles from '../style/GoodsList.less';
import BuildSelect from '../../components/SelectButton/BuildSelect'
import apis from '../../services/apis';
import request from '../../utils/request'
import AuthButton from '@/components/AuthButton';

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


  const changBuilding = (buildingId) => {

    // setBuildingIdData(buildingId)
    request({ ...apis.system.tdBizEventIntention, 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({ ...apis.system.taBuildingIntentionAddOrUpdate, urlData: { id: -1 }, data, }).then((data) => {
      message.info("保存成功")
    })
  }

  useEffect(()=>{
    changBuilding('-1')
  },[])

  return (
    <Card>
      <Row >
        <Col span={6}>
          {/* <BuildSelect onChange={changBuilding} value={buildingIdValue} /> */}
        </Col>
        <Col span={5} style={{ lineHeight: '30px' }}>
          用户操作
        </Col>
        <Col span={5} offset={2} style={{ lineHeight: '30px' }}>
          意向值
        </Col>
        <Col span={2} offset={4}>
          <AuthButton name="admin.taBuildingIntentionAddOrUpdate.buildingId.post" noRight={null}>
            <Button type="primary" className={styles.searchBtn} onClick={submitValue}>确定</Button>
          </AuthButton>
        </Col>
      </Row>
      {data.map((x) => {
        return <Row style={{margin:'5px 0'}}>
          <Col span={6}>

          </Col>
          <Col span={5} >
            <Checkbox checked={x.checkbox} onChange={changeBox(x)}>{x.eventName}</Checkbox>
          </Col>
          <Col span={5} offset={2}>
            <Input value={x.intention} onChange={changeInput(x)} />
          </Col>
          <Col span={2} offset={4}>

          </Col>

        </Row>
      })}
    </Card>
  );
}



export default Edit
