GoodsFlatList.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. import React, { Component } from 'react'
  2. import {
  3. StyleSheet,
  4. View,
  5. Dimensions,
  6. TouchableOpacity,
  7. Text,
  8. FlatList,
  9. } from 'react-native'
  10. import Toast from 'react-native-root-toast'
  11. import { connect } from 'react-redux'
  12. import { createAction } from '../../../utils'
  13. import Input from '../../../components/input'
  14. import * as authService from '../../../services/auth'
  15. const { width, height } = Dimensions.get('window')
  16. // @connect(({ optional }) => ({ ...optional }))
  17. class GoodsFlatList extends Component {
  18. constructor(props) {
  19. super(props)
  20. this.state = { goodsList: [], kw: '', checkList: [] }
  21. }
  22. async componentDidMount() {
  23. this.getGoodsByKW('', true)
  24. }
  25. //颜色卡片列表
  26. _goodsList( item, index,goodsList) {
  27. return(
  28. <View>
  29. <TouchableOpacity
  30. disabled={false}
  31. key={item.attrValId}
  32. activeOpacity={1}
  33. style={{
  34. paddingHorizontal: 16,
  35. paddingVertical: 2,
  36. borderBottomColor: item.isChecked ? '#E14C46' : '#DDD',
  37. borderBottomWidth: item.isChecked ? 3 : 1,
  38. justifyContent: 'flex-start',
  39. alignItems: 'flex-start',
  40. marginRight: 15,
  41. width: 320,
  42. marginTop : 5
  43. }}
  44. onPress={() => {
  45. goodsList.forEach(e => {e.isChecked = false})
  46. item.isChecked = true
  47. goodsList.splice(goodsList.findIndex(e => e.code == item.code),1,item)
  48. this.setState({goodsList})
  49. if (item.basePrice) {
  50. this.props.addGoods && this.props.addGoods(item)
  51. } else {
  52. Toast.show("未获取该商品价格,请选择其他商品",{position : toastHeight});
  53. }
  54. }}
  55. >
  56. <View>
  57. <Text
  58. style={{
  59. color: item.isChecked ? '#E14C46' : '#333',
  60. fontSize: 12,
  61. lineHeight: 17,
  62. }}
  63. numberOfLines={1}
  64. >
  65. {item.name}
  66. </Text>
  67. </View>
  68. <View>
  69. <Text
  70. style={{
  71. color: item.isChecked ? '#E14C46' : '#333',
  72. fontSize: 12,
  73. lineHeight: 17,
  74. }}
  75. numberOfLines={1}
  76. >
  77. 编码:{item.code}
  78. </Text>
  79. </View>
  80. <View>
  81. <Text
  82. style={{
  83. color: item.isChecked ? '#E14C46' : '#333',
  84. fontSize: 12,
  85. lineHeight: 17,
  86. }}
  87. numberOfLines={1}
  88. >
  89. 型号:{item.specification}
  90. </Text>
  91. </View>
  92. <View>
  93. <Text
  94. style={{
  95. color: item.isChecked ? '#E14C46' : '#333',
  96. fontSize: 12,
  97. lineHeight: 17,
  98. }}
  99. numberOfLines={1}
  100. >
  101. 规格:{item.model}
  102. </Text>
  103. </View>
  104. <View>
  105. <Text
  106. style={{
  107. color: item.isChecked ? '#E14C46' : '#333',
  108. fontSize: 12,
  109. lineHeight: 17,
  110. }}
  111. numberOfLines={1}
  112. >
  113. 价格:¥ {item.basePrice || "--"}
  114. </Text>
  115. </View>
  116. </TouchableOpacity>
  117. </View>
  118. )
  119. }
  120. //根据色卡号查询调色
  121. async getGoodsByKW(kw,init) {
  122. if (!kw && !init) {
  123. Toast.show("请输入商品信息",{position : toastHeight});
  124. return
  125. }
  126. const search = {
  127. page: 0,
  128. size: 10,
  129. search_EQ_isEnable: 1,
  130. search_keywords: kw,
  131. search_customerId: CUSTOMERINFO.id,
  132. search_customerRankCode: CUSTOMERINFO.customerRankCode
  133. }
  134. const goodsData = await authService.searchCommodityList(search)
  135. console.log('goodsData=================>', goodsData)
  136. // const goodsData = {}
  137. if (goodsData.status == 200) {
  138. this.setState({goodsList: goodsData.data.content})
  139. } else {
  140. Toast.show("未搜索到商品信息",{position : toastHeight});
  141. return
  142. }
  143. }
  144. render() {
  145. return (
  146. <View>
  147. <Input
  148. style={{
  149. height: 28,
  150. width: width - 50,
  151. marginTop: 20,
  152. borderRadius: width / 2,
  153. alignSelf: 'center',
  154. paddingLeft: 14,
  155. }}
  156. textStyle={{
  157. paddingLeft: 10,
  158. height: 28,
  159. fontSize: 11,
  160. padding: 0,
  161. }}
  162. iconSize={14}
  163. //blurOnSubmit={true}
  164. multiline={false}
  165. textInputBacg={'#F5F5F5'}
  166. iconColor={'#CCC'}
  167. placeholderTextColor={'#CCC'}
  168. placeholderSize={8}
  169. placeholder = {'请输入颜色编码'}
  170. onchangeFn={async e => {
  171. this.getGoodsByKW(e)
  172. }}
  173. />
  174. <Text
  175. style={{
  176. color: '#999',
  177. fontSize: 14,
  178. marginTop: 15,
  179. lineHeight: 20,
  180. letterSpacing: 0.17,
  181. }}
  182. >
  183. 商品列表
  184. </Text>
  185. <FlatList
  186. keyExtractor={(item, index) => index}
  187. style={{height:280}}
  188. data={this.state.goodsList}
  189. renderItem={({ item, key}) => this._goodsList(item, key,this.state.goodsList)}
  190. numColumns= {1}
  191. />
  192. </View>
  193. )
  194. }
  195. }
  196. const styles = StyleSheet.create({
  197. titleText: {
  198. fontSize: 14,
  199. lineHeight: 20,
  200. color: '#999',
  201. },
  202. contentText: {
  203. flex: 1,
  204. fontSize: 13,
  205. lineHeight: 18,
  206. color: '#333',
  207. },
  208. })
  209. export default GoodsFlatList