import React from 'react';
import { connect } from 'dva';
import { Button, Card, Checkbox,message } from 'antd';
import styles from './index.less';

const Register = ({ dispatch, register, loading }) => {
  const {  edpPbSupp, items } = register;

  const domain = 'register';
  const CheckboxGroup = Checkbox.Group;

  let options = [];
  items.length && items.map((status, index) => {
    options.push(
      {
        label: status.name,
        value: status.code,
      });
  });

  const options1 = [
    { label: '蔬菜', value: '012' },
    { label: '净菜', value: '013' },
    { label: '水果', value: '014' },
    { label: '粮油', value: '007' },
    { label: '农副产品', value: '002' },
    { label: '五谷杂粮', value: '005' },
    { label: '酒水饮料', value: '011' },
    { label: '海鲜', value: '015' },
    { label: '鲜鱼', value: '016' },
    { label: '干货', value: '004' },
    { label: '冻货', value: '001' },
    { label: '特产物资', value: '006' },
    { label: '用品用具', value: '008' },
    { label: '物流配送', value: '017' },
    { label: '调料', value: '003' },
    { label: '面制品', value: '010' },
    { label: '低值易耗品', value: '009' },
    { label: '其它', value: '018' },
  ];

  function onChange(checkedValues) {
    const key = 'gysylsx';

    dispatch({
      type: `${domain}/updateForm`,
      payload: {
        key,
        value: checkedValues,
      },
    });
  }

  const prev = () => {
    dispatch({
      type: `${domain}/minusCurrent`,
    });
  };

  const next = () => {
    // formUtils.validateForm([...supp,], Object.assign(getDefaultValues(), formData),() => {
    //   //dispatch({ type: `${domain}/save`, payload: getDefaultValues() });
    //   dispatch(routerRedux.push(`/register/qualify`));
    // });
    // if (!edpPbSupp.gysylsx || edpPbSupp.gysylsx.length === 0) {
    //   message.error('请至少选择一项物料', 3);
    //   return 0;
    // }
    dispatch({
      type: `${domain}/addCurrent`,
    });
  };

  return (
    <div>
      <Card  id="feedback">
        <CheckboxGroup className={styles.checkbox} options={options} value={edpPbSupp.gysylsx}
          onChange={onChange} />
      </Card>

      <div className={styles.registerButton}>
        <Button  onClick={prev}> 返回 </Button>
        <Button style={{ marginLeft: 8 }} type="primary" onClick={next}>下一步</Button>

      </div>
    </div>
  );
};

export default connect(({ register, loading }) => ({ register, loading }))(Register);
