index.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import React, { Component } from 'react';
  2. import './index.less';
  3. import { Icon } from 'antd';
  4. import Assets from '@src/components/Assets';
  5. import Select from '../Select';
  6. import CheckboxItem from '../CheckboxItem';
  7. import { Icon as GIcon } from '../Icon';
  8. import { Button } from '../Button';
  9. export default class UserAction extends Component {
  10. constructor(props) {
  11. super(props);
  12. this.state = { showInput: false, searchText: '' };
  13. }
  14. onAction(key) {
  15. const { onAction } = this.props;
  16. if (onAction) onAction(key);
  17. }
  18. onAll(checked) {
  19. const { onAll } = this.props;
  20. if (onAll) onAll(checked);
  21. }
  22. onSearchKey(e) {
  23. if (e.keyCode === 13) {
  24. const { onSearch } = this.props;
  25. if (onSearch) onSearch(this.state.searchText);
  26. }
  27. }
  28. onSearch(value) {
  29. this.setState({ searchText: value });
  30. }
  31. onFilter(key, value) {
  32. const { filterMap = {}, onFilter } = this.props;
  33. filterMap[key] = value;
  34. if (onFilter) onFilter(filterMap);
  35. }
  36. onSort(key, value) {
  37. const { onSort, sortMap = {} } = this.props;
  38. sortMap[key] = value;
  39. if (onSort) onSort(sortMap);
  40. }
  41. render() {
  42. const {
  43. allCheckbox,
  44. allChecked,
  45. help,
  46. btnList = [],
  47. search,
  48. selectList = [],
  49. sortList = [],
  50. sortMap = [],
  51. right,
  52. left,
  53. } = this.props;
  54. const { showInput, searchText } = this.state;
  55. return (
  56. <div className="user-action">
  57. {left && <div className="left">{left}</div>}
  58. {allCheckbox && (
  59. <div className="all">
  60. <CheckboxItem theme="white" checked={allChecked} onClick={value => this.onAll(value)} />
  61. 全选
  62. </div>
  63. )}
  64. <div hidden={btnList.length === 0} className="button-list">
  65. {btnList.map(btn => {
  66. return (
  67. <Button disabled={btn.disabled} radius size="small" onClick={() => this.onAction(btn.key)}>
  68. {btn.title}{' '}
  69. {btn.tag === 'vip' && <Assets name={btn.disabled ? 'VIP_small_gray' : 'VIP_small_yellow'} />}
  70. </Button>
  71. );
  72. })}
  73. {help && (
  74. <div className="help">
  75. <Icon type="question-circle" theme="filled" onClick={() => this.onAction('help')} />
  76. </div>
  77. )}
  78. </div>
  79. <div hidden={selectList.length === 0 && sortList.length === 0} className="item-list">
  80. {selectList.map(item => {
  81. return (
  82. <div className={`item select-item ${item.right ? 'right' : ''}`}>
  83. <span>{item.label}</span>
  84. {item.select && this.renderSelect(item)}
  85. {item.children && item.children.map(child => this.renderSelect(child))}
  86. </div>
  87. );
  88. })}
  89. {sortList.map(item => {
  90. return (
  91. <div className={`item sort-item ${item.right ? 'right' : ''}`}>
  92. {item.label}
  93. {item.fixed ? (
  94. sortMap[item.key] ? (
  95. <GIcon active name="arrow-down" onClick={() => this.onSort(item.key, '')} />
  96. ) : (
  97. <GIcon name="arrow-up" onClick={() => this.onSort(item.key, 'desc')} />
  98. )
  99. ) : sortMap[item.key] ? (
  100. <Assets
  101. name={sortMap[item.key] === 'asc' ? 'seqencing2_up_select' : 'seqencing2_down_select'}
  102. onClick={() => this.onSort(item.key, sortMap[item.key] === 'asc' ? 'desc' : '')}
  103. />
  104. ) : (
  105. <Assets name="seqencing2_normal" onClick={() => this.onSort(item.key, 'asc')} />
  106. )}
  107. </div>
  108. );
  109. })}
  110. </div>
  111. {search && (
  112. <div className="search">
  113. {showInput && (
  114. <input
  115. className="search-input"
  116. placeholder="请输入您想搜索的内容"
  117. value={searchText}
  118. onChange={e => this.onSearch(e.target.value)}
  119. onKeyUp={e => this.onSearchKey(e)}
  120. />
  121. )}
  122. {!showInput && <Icon type="search" onClick={() => this.setState({ showInput: true })} />}
  123. </div>
  124. )}
  125. {right && (
  126. <div
  127. className={`right ${
  128. btnList.length === 0 && selectList.length === 0 && sortList.length === 0 ? 'only' : ''
  129. }`}
  130. >
  131. {right}
  132. </div>
  133. )}
  134. </div>
  135. );
  136. }
  137. renderSelect(item) {
  138. const { filterMap = {} } = this.props;
  139. return (
  140. <Select
  141. size="small"
  142. theme="default"
  143. value={filterMap[item.key]}
  144. placeholder={item.placeholder}
  145. list={item.be ? item.selectMap[filterMap[item.be]] || [] : item.select}
  146. onChange={({ key }) => this.onFilter(item.key, key)}
  147. />
  148. );
  149. }
  150. }