SearchProcess.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import React, {Component} from 'react';
  2. import {
  3. View,
  4. FlatList,
  5. Text, StyleSheet, StatusBar,
  6. } from 'react-native';
  7. import {connect} from 'react-redux';
  8. import TreeSelect from 'react-native-tree-select';
  9. @connect(customer => ({...customer}))
  10. class SearchProcess extends Component {
  11. // 搜索进度
  12. constructor(props) {
  13. super(props);
  14. this.state = {
  15. callback: this.props.navigation.state.params.callback,
  16. data: [],
  17. StageCount: [],
  18. field: '',
  19. field_name: '',
  20. store_id: '',
  21. };
  22. }
  23. componentDidMount() {
  24. this._fetchData();
  25. this._fetchStageCount();
  26. }
  27. _fetchData = () => {
  28. this.props.dispatch({
  29. type: 'customer/fetchEmployeeTree',
  30. callback: (data) => {
  31. this.setState({data: data});
  32. },
  33. });
  34. };
  35. _fetchStageCount = (type, id) => {
  36. this.props.dispatch({
  37. type: 'customer/queryStageCount',
  38. payload: {type, id},
  39. callback: (data) => {
  40. this.setState({StageCount: data});
  41. },
  42. });
  43. };
  44. _onClickLeaf = (item) => {
  45. this._fetchStageCount(item.item.field, item.item.id);
  46. this.setState({field: item.item.field, field_name: item.item.name, store_id: item.item.id});
  47. };
  48. _onStagePress = (stage_id, event, text) => {
  49. const {field, store_id, field_name} = this.state;
  50. let param = '';
  51. if (field && store_id) {
  52. param = field + '_' + store_id;
  53. }
  54. const searchText = field_name + '-' + text
  55. this.state.callback(stage_id, event, param, searchText);
  56. this.props.navigation.goBack();
  57. };
  58. renderItem = (data, index) => {
  59. return (
  60. <View style={index % 2 === 0 ? styles.tableRowOdd : styles.tableRowEven}>
  61. <Text
  62. onPress={() => this._onStagePress(data.stage_id, 'stage', '总数')}
  63. style={[styles.tableCell, {width: '30%'}]}>{data.stage}</Text>
  64. <Text
  65. onPress={() => this._onStagePress(data.stage_id, 'total', '总数')}
  66. style={[styles.tableCell, {width: '20%'}]}>{data.total_count}</Text>
  67. <Text
  68. onPress={() => this._onStagePress(data.stage_id, 'today', '今日')}
  69. style={[styles.tableCell, {width: '25%'}]}>{data.today_count}</Text>
  70. <Text
  71. onPress={() => this._onStagePress(data.stage_id, 'overdue', '逾期')}
  72. style={[styles.tableCell, {width: '25%'}]}>{data.overdue_count}</Text>
  73. </View>
  74. );
  75. };
  76. render() {
  77. return (
  78. <View style={{flex: 1, backgroundColor: '#fff'}}>
  79. <StatusBar backgroundColor={'#fff'} barStyle='dark-content'/>
  80. <TreeSelect
  81. data={this.state.data}
  82. // isOpen={true}
  83. // openIds={[3]}
  84. // defaultSelectedId={['B062']}
  85. isShowTreeId={false}
  86. selectType="single"
  87. itemStyle={{
  88. marginVertical: 10,
  89. // backgroudColor: '#8bb0ee',
  90. fontSize: 14,
  91. // color: '#2b90ea',
  92. }}
  93. selectedItemStyle={{
  94. backgroudColor: '#f7edca',
  95. fontSize: 14,
  96. // color: '#171e99'
  97. }}
  98. leafCanBeSelected={true}
  99. // onClickLeaf={this._onClickLeaf}
  100. onClick={this._onClickLeaf}
  101. treeNodeStyle={{
  102. openIcon: <Text style={{fontFamily: 'iconfont'}}>{'\ue617'}</Text>,
  103. closeIcon: <Text style={{fontFamily: 'iconfont'}}>{'\ue601'}</Text>,
  104. }}
  105. />
  106. <View>
  107. <View style={styles.tableHeader}>
  108. <Text style={[styles.tableHeaderItem, {width: '30%'}]}>阶段</Text>
  109. <Text style={[styles.tableHeaderItem, {width: '20%'}]}>总数</Text>
  110. <Text style={[styles.tableHeaderItem, {width: '25%'}]}>今日</Text>
  111. <Text style={[styles.tableHeaderItem, {width: '25%'}]}>逾期</Text>
  112. </View>
  113. <FlatList
  114. data={this.state.StageCount}
  115. renderItem={({item, index}) => this.renderItem(item, index)}
  116. keyExtractor={(item, index) => index.toString()}
  117. />
  118. </View>
  119. </View>
  120. );
  121. }
  122. }
  123. const styles = StyleSheet.create({
  124. icon: {
  125. fontFamily: 'iconfont',
  126. fontSize: 14,
  127. color: '#2b90ea',
  128. padding: 3,
  129. },
  130. tableHeader: {
  131. backgroundColor: '#03C762',
  132. flexDirection: 'row',
  133. },
  134. tableHeaderItem: {
  135. color: '#fff',
  136. paddingVertical: 10,
  137. textAlign: 'center',
  138. // flex: 1
  139. },
  140. tableRowOdd: {
  141. flexDirection: 'row',
  142. },
  143. tableRowEven: {
  144. flexDirection: 'row',
  145. backgroundColor: '#f8f8f8',
  146. },
  147. tableCell: {
  148. color: '#666',
  149. padding: 10,
  150. textAlign: 'center',
  151. // flex: 1
  152. },
  153. });
  154. export default SearchProcess;