SearchResults.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. import React, { Component } from 'react'
  2. import {
  3. StyleSheet,
  4. View,
  5. StatusBar,
  6. Dimensions,
  7. ScrollView,
  8. FlatList,
  9. PixelRatio,
  10. TouchableOpacity,
  11. Text,
  12. } from 'react-native'
  13. import { connect } from 'react-redux'
  14. import { NavigationActions, createAction, Storage } from '../../utils'
  15. import Input from '../../components/input/index'
  16. import Icon from '../../components/Iconfont/Iconfont'
  17. import ModalEcx from '../../components/Modal'
  18. const { width, height } = Dimensions.get('window')
  19. // @connect(({ theme }) => ({ ...theme }))
  20. class SearchResults extends Component {
  21. constructor(props) {
  22. super(props)
  23. this.state = {
  24. data: [],
  25. rowPrice: 0,
  26. autoFocusBool: true,
  27. isShow: '请输入商品名称或商品编码',
  28. defaultValue: '',
  29. }
  30. }
  31. componentDidMount() {
  32. this.storageOperate()
  33. }
  34. async storageOperate(e) {
  35. let searchVals = []
  36. let SearchData = await Storage.get('queryCondition', false)
  37. if (SearchData) {
  38. searchVals = searchVals.concat(SearchData)
  39. }
  40. if (e && e.replace(/(^s*)|(s*$)/g, ' ') != ' ') {
  41. searchVals = searchVals.concat(e.replace(/(^\s*)|(\s*$)/g, ''))
  42. Storage.set('queryCondition', searchVals)
  43. }
  44. searchVals = Array.from(new Set(searchVals))
  45. this.setState({ data: searchVals })
  46. }
  47. _closeModal() {
  48. this.mdl._setModalVisible(false)
  49. }
  50. _openModal = va => {
  51. this.mdl._setModalVisible(true)
  52. // if (va) {
  53. this.setState({ defaultValue: va })
  54. // }
  55. }
  56. recentRender(item, index) {
  57. return (
  58. <TouchableOpacity
  59. onPress={() => {
  60. if (this.props.comFrom && this.props.comFrom == 'CommodityShowbase') {
  61. this.props.cb(item.item)
  62. } else {
  63. this.props.dispatch(
  64. NavigationActions.navigate({
  65. routeName: 'CommodityShowbase',
  66. params: { searchval: item.item },
  67. })
  68. )
  69. }
  70. this._closeModal()
  71. this.storageOperate(item.item)
  72. }}
  73. style={{
  74. paddingHorizontal: 16,
  75. paddingVertical: 4,
  76. backgroundColor: '#EEE',
  77. borderRadius: 100,
  78. marginRight: 10,
  79. marginTop: 13,
  80. }}
  81. >
  82. <Text style={{ fontSize: 12, color: '#666', lineHeight: 17 }}>
  83. {item.item}
  84. </Text>
  85. </TouchableOpacity>
  86. )
  87. }
  88. _renderModalContent() {
  89. return (
  90. <View
  91. style={{
  92. height: height,
  93. width: width,
  94. backgroundColor: '#EEE',
  95. }}
  96. >
  97. <StatusBar
  98. animated={true}
  99. // barStyle={appTheme.barStyle}
  100. barStyle={'dark-content'}
  101. backgroundColor={'transparent'}
  102. translucent={true}
  103. />
  104. <View
  105. style={{
  106. backgroundColor: '#FFF',
  107. height: HEADERSTYLE.height,
  108. // height: 68,
  109. borderBottomColor: '#DDD',
  110. borderBottomWidth: 1 / PixelRatio.get(),
  111. flexDirection: 'row',
  112. justifyContent: 'center',
  113. }}
  114. >
  115. <Input
  116. autoFocus={true}
  117. style={{
  118. height: 28,
  119. width: width / 1.2,
  120. borderRadius: width / 2,
  121. alignSelf: 'flex-end',
  122. marginBottom: 8,
  123. paddingLeft: 14,
  124. }}
  125. blurOnSubmit={true}
  126. placeholder={this.state.isShow}
  127. defaultValue={this.state.defaultValue}
  128. textInputBacg={'#EEE'}
  129. iconColor={'#999'}
  130. placeholderTextColor={'#999'}
  131. isBlurTrue={false}
  132. onchangeFn={e => {
  133. if (
  134. this.props.comFrom &&
  135. this.props.comFrom == 'CommodityShowbase'
  136. ) {
  137. this.props.cb(e)
  138. } else {
  139. this.props.dispatch(
  140. NavigationActions.navigate({
  141. routeName: 'CommodityShowbase',
  142. params: { searchval: e },
  143. // params: { searchval: e ? e : this.state.defaultValue }
  144. })
  145. )
  146. }
  147. this._closeModal()
  148. this.storageOperate(e)
  149. }}
  150. />
  151. <TouchableOpacity
  152. style={{ alignSelf: 'flex-end', marginBottom: 15, marginLeft: 7 }}
  153. onPress={() => {
  154. this._closeModal()
  155. }}
  156. >
  157. <Text style={{ color: '#333' }}>取消</Text>
  158. </TouchableOpacity>
  159. </View>
  160. <View
  161. style={{
  162. width: width,
  163. backgroundColor: '#FFF',
  164. paddingVertical: 10,
  165. paddingLeft: 10,
  166. paddingRight: 15,
  167. }}
  168. >
  169. <Text style={{ fontSize: 14, color: '#333', lineHeight: 20 }}>
  170. 最近搜索
  171. </Text>
  172. <FlatList
  173. data={this.state.data}
  174. keyExtractor={(item, index) => index}
  175. renderItem={(item, index) => this.recentRender(item, index)}
  176. columnWrapperStyle={{ flexWrap: 'wrap' }}
  177. numColumns={4}
  178. />
  179. <TouchableOpacity
  180. onPress={() => {
  181. Storage.set('queryCondition', false)
  182. this.storageOperate()
  183. }}
  184. style={{
  185. marginTop: 60,
  186. alignSelf: 'center',
  187. justifyContent: 'center',
  188. flexDirection: 'row',
  189. }}
  190. >
  191. <Icon name="icon-icon-qingkong" size={24} color={'#999'} />
  192. <Text
  193. style={{
  194. fontSize: 12,
  195. color: '#999',
  196. lineHeight: 17,
  197. marginLeft: 3,
  198. alignSelf: 'center',
  199. marginBottom: 3,
  200. }}
  201. >
  202. 清空历史记录
  203. </Text>
  204. </TouchableOpacity>
  205. </View>
  206. </View>
  207. )
  208. }
  209. render() {
  210. return (
  211. <ModalEcx
  212. ref={mdl => (this.mdl = mdl)}
  213. content={this._renderModalContent()}
  214. />
  215. )
  216. }
  217. }
  218. const styles = StyleSheet.create({
  219. container: {
  220. flex: 1,
  221. alignItems: 'center',
  222. justifyContent: 'center',
  223. },
  224. icon: {
  225. width: 32,
  226. height: 32,
  227. },
  228. })
  229. export default SearchResults