天天看点

react antd Table封装的可编辑组件 Radio 与 input 联动点击后input 发生改变

 React  antd Table  组件上

{
          title: '是否为小微企业',
          dataIndex: 'isXw',
          align: 'center',
          width: 150,
          onCell: (record, index) => ({
            index,
            record,
            dataIndex: 'isXw',
            inputType: 'isRadio',
            handleOnChange: (dataIndex, value) => handleCellChange(index, dataIndex, value),
          }),
        },
        {
          title: `属于小微企业产品价格合计`,
          dataIndex: 'de181Xw',
          align: 'center',
          onCell: (record, index) => ({
            index,
            record,
            dataIndex: 'de181Xw',
            inputType: 'money',
            max: record.de181Bj,
            width: 230,
            handleOnChange: (dataIndex, value) => handleCellChange(index, dataIndex, value),
          }),
        },
      
// input选择变化
  function handleCellChange(index, dataIndex, value) {
    const newList = tableList.slice();
    if (dataIndex === 'isXw') {
      if (value === 1) {
        newList[index] = { ...newList[index], [dataIndex]: value, de181Xw: 9000 };
        form.setFieldsValue(newList);
      } else {
        newList[index] = { ...newList[index], [dataIndex]: value, de181Xw: 0 };
        form.setFieldsValue(newList);
      }
    } else {
      form.setFieldsValue(newList);
      newList[index] = { ...newList[index], [dataIndex]: value };
      setTableList(newList);
    }
    setTableList(newList);
  }