index.jsx 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import React,{Component} from 'react';
  2. import PropTypes from 'prop-types';
  3. import style from './index.less';
  4. import Select from '../CheckBox/Select';
  5. import Radio from '../RadioB';
  6. import Normal from '../Normal';
  7. import CheckBox from '../CheckBox';
  8. import className from 'classnames';
  9. import Multiple from '../CheckBox/Multiple';
  10. /***
  11. 单选多选混合组件
  12. 接收参数:
  13. datas:数据源,为数组,必须;
  14. showDrop:控制填写单显示与隐藏,必须;
  15. confirmCheckBox:点击确定,必须
  16. clearCheckBox:点击清空,必须
  17. noSpecial:无殊选中标识,true为选中,有无殊时必须;
  18. noSpecialFlag:互斥标识,2选中其他 1选中无殊 0默认无选中;
  19. noSpecialClick:无殊点击事件;
  20. handleRadioClick:单选点击事件,有单选列时必须;
  21. handleCheckBoxClick:多选点击事件,有多选时必须;
  22. **/
  23. class MixCheckBox extends React.Component{
  24. constructor(props){
  25. super(props);
  26. this.handleBtnConfirm = this.handleBtnConfirm.bind(this);
  27. this.handleBtnClear = this.handleBtnClear.bind(this);
  28. }
  29. getLabs(){
  30. const {datas,noSpecial,noSpecialFlag,noSpecialClick,checkBoxId,flag} = this.props;
  31. let list = datas && datas.map((v,i)=>{
  32. if(+v.formPosition == 1){//正常无殊
  33. return <Normal datas={v.questionDetailList} noSpecialFlag={noSpecialFlag} noSpecial={noSpecial} noSpecialClick={noSpecialClick}/>
  34. }else{
  35. if(v.controlType==1 && v.formPosition !== 1){//单选
  36. return <Radio datas={v.questionDetailList} handleClick={this.props.handleCheckBoxClick} parentId={v.id} disabled={noSpecialFlag}/>;
  37. }else if(v.controlType==2){//2多选
  38. return <Select datas={v.questionDetailList} handleClick={this.props.handleCheckBoxClick} parentId={v.id} noSpecialFlag={noSpecialFlag} checkBoxId={checkBoxId} flag={flag}/>
  39. }
  40. /*else if(v.controlType==4 || v.controlType==99){//4 伴/无 99推送
  41. return <Multiple datas={v.questionDetailList} handleClick={this.props.handleCheckBoxClick} parentId={v.id} />
  42. }*/
  43. }
  44. })
  45. return list;
  46. }
  47. handleBtnConfirm(e){//确定
  48. e.stopPropagation();
  49. const {confirmCheckBox,checkBoxId,flag} = this.props;
  50. let item = {
  51. checkBoxId,
  52. flag
  53. };
  54. confirmCheckBox && confirmCheckBox(item);
  55. }
  56. handleBtnClear(e){//清空
  57. e.stopPropagation();
  58. const {clearCheckBox,checkBoxId,flag} = this.props;
  59. let item = {
  60. checkBoxId,
  61. flag
  62. };
  63. clearCheckBox && clearCheckBox(item);
  64. }
  65. getContainerStyle(){
  66. const {showDrop} = this.props;
  67. const isShow = showDrop?'':style['ishide'];
  68. return className(style['cb-container'],isShow);
  69. }
  70. render(){
  71. return <div className={this.getContainerStyle()} >
  72. <div style={{whiteSpace: 'nowrap'}}>{this.getLabs()}</div>
  73. <div className={style['btn']}>
  74. <button onClick={this.handleBtnClear} className={style['clear']}>清空选项</button>
  75. <button onClick={this.handleBtnConfirm} className={style['confirm']}>确定</button>
  76. </div>
  77. </div>
  78. }
  79. }
  80. MixCheckBox.propTypes = {
  81. handleClick:PropTypes.func,
  82. items:PropTypes.array
  83. };
  84. export default MixCheckBox;