OptFlatList.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. import React, { Component } from 'react'
  2. import {
  3. StyleSheet,
  4. View,
  5. Image,
  6. StatusBar,
  7. Dimensions,
  8. PixelRatio,
  9. TouchableOpacity,
  10. Text,
  11. FlatList,
  12. ScrollView,
  13. TextInput,
  14. } from 'react-native'
  15. import { connect } from 'react-redux'
  16. import { createAction } from '../../../utils'
  17. import Input from '../../../components/input'
  18. const { width, height } = Dimensions.get('window')
  19. @connect(({ optional }) => ({ ...optional }))
  20. class OptFlatList extends Component {
  21. constructor(props) {
  22. super(props)
  23. this.state = { touchColor: '', refresh: true,findValue:'' }
  24. }
  25. _optionalRow(item, index) {
  26. let valuesname = []
  27. if (item.typeCode !== '04') {
  28. item.colorGroups.content.forEach((data, key) => {
  29. valuesname.push(
  30. <TouchableOpacity
  31. disabled={false}
  32. key={data.id}
  33. activeOpacity={1}
  34. style={{
  35. // height: 30,
  36. paddingHorizontal: 16,
  37. paddingVertical: 6,
  38. borderRadius: 100,
  39. borderColor: data.isChecked ? '#E14C46' : '#DDD',
  40. borderWidth: 1,
  41. justifyContent: 'center',
  42. alignItems: 'center',
  43. marginRight: 15,
  44. }}
  45. onPress={() => {
  46. this.props.dispatch(
  47. createAction('optional/getColorByGroups')({
  48. id : item.goodsId,
  49. groupId : data.id,
  50. colourCode : ""
  51. })
  52. )
  53. item.colorGroups.content.forEach(touchData => {
  54. touchData.isChecked = false
  55. })
  56. item.isChoose = data
  57. data.isChecked = true
  58. this.setState({
  59. touchColor: {
  60. "id" : data.id,
  61. "name" : data.name,
  62. }
  63. })
  64. }}
  65. >
  66. <Text
  67. style={{
  68. color: data.isChecked ? '#E14C46' : '#333',
  69. fontSize: 12,
  70. lineHeight: 17,
  71. }}
  72. numberOfLines={1}
  73. >
  74. {data.name}
  75. </Text>
  76. </TouchableOpacity>
  77. )
  78. })
  79. return (
  80. <View>
  81. <Text
  82. style={{
  83. color: '#999',
  84. fontSize: 14,
  85. marginTop: 15,
  86. lineHeight: 20,
  87. letterSpacing: 0.17,
  88. }}
  89. >
  90. {item.name+"分组"}
  91. </Text>
  92. <ScrollView
  93. scrollEnabled={true}
  94. removeClippedSubviews={true}
  95. showsHorizontalScrollIndicator={false}
  96. automaticallyAdjustContentInsets={false}
  97. pagingEnabled={true}
  98. locked={true}
  99. horizontal={true}
  100. style={{ flexDirection: 'row', marginTop: 8, overflow: 'hidden' }}
  101. >
  102. {valuesname}
  103. </ScrollView>
  104. </View>
  105. )
  106. } else {
  107. valuesname = (
  108. <View
  109. style={{
  110. flex: 1,
  111. borderBottomColor: '#DDD',
  112. marginLeft: 10,
  113. marginBottom: 1,
  114. marginRight: 10,
  115. borderBottomWidth: 1 / PixelRatio.get(),
  116. }}
  117. >
  118. <TextInput
  119. style={{
  120. flex: 1,
  121. padding: 0,
  122. fontSize: 12,
  123. lineHeight: 20,
  124. letterSpacing: 0.38,
  125. color: '#333',
  126. marginTop: 4,
  127. }}
  128. autoCapitalize="none"
  129. autoCorrect={false}
  130. underlineColorAndroid={'transparent'}
  131. clearButtonMode="while-editing"
  132. onChangeText={text => {
  133. item.item[0].attrValCode = text
  134. item.item[0].attrValId = text
  135. item.item[0].attrValName = text
  136. item.isChoose = item.item[0]
  137. }}
  138. defaultValue={item.item[0].attrValName}
  139. onBlur={() => {
  140. this.setState({ refresh: !this.state.refresh })
  141. }}
  142. // value={item.item}
  143. multiline={false}
  144. placeholder={'请输入'}
  145. placeholderTextColor={'#CCC'}
  146. />
  147. </View>
  148. )
  149. return (
  150. <View
  151. style={{
  152. flexDirection: 'row',
  153. paddingVertical: 7,
  154. marginTop: 5,
  155. }}
  156. >
  157. <Text
  158. style={{
  159. color: '#999',
  160. fontSize: 14,
  161. lineHeight: 20,
  162. letterSpacing: 0.17,
  163. alignSelf: 'center',
  164. }}
  165. >
  166. {item.name}
  167. </Text>
  168. {valuesname}
  169. </View>
  170. )
  171. }
  172. }
  173. //颜色卡片列表
  174. _colorList( item, index,colorData) {
  175. return(
  176. <View>
  177. <TouchableOpacity
  178. disabled={false}
  179. key={item.attrValId}
  180. activeOpacity={1}
  181. style={{
  182. paddingHorizontal: 16,
  183. paddingVertical: 6,
  184. borderRadius: 100,
  185. borderColor: item.isChecked ? '#E14C46' : '#DDD',
  186. borderWidth: 1,
  187. justifyContent: 'center',
  188. alignItems: 'center',
  189. marginRight: 15,
  190. width: 160,
  191. marginTop : 5
  192. }}
  193. onPress={() => {
  194. colorData.forEach(touchData => {
  195. touchData.isChecked = false
  196. })
  197. item.isChecked = true
  198. const touchColor = {};
  199. touchColor.children = item;
  200. this.props.dispatch(
  201. createAction('optional/getPriceByColorId')({
  202. organizationId : this.props.optionData[0].saleOrgId,
  203. customerId : CUSTOMERINFO.id,
  204. goodsId : this.props.optionData[0].goodsId,
  205. orderTypeId : '01',
  206. paletteId : item.attrValId,
  207. shopId : ''
  208. })
  209. ).finally(() => {
  210. if(this.props.goodsPriceByColor && this.props.goodsPriceByColor.length) {
  211. touchColor.goodsPriceByColor = this.props.goodsPriceByColor;
  212. this.props.chooseColor(touchColor);
  213. }
  214. })
  215. }}
  216. >
  217. <Text
  218. style={{
  219. color: item.isChecked ? '#E14C46' : '#333',
  220. fontSize: 12,
  221. lineHeight: 17,
  222. }}
  223. numberOfLines={1}
  224. >
  225. {item.attrValName}
  226. </Text>
  227. </TouchableOpacity>
  228. </View>
  229. )
  230. }
  231. //根据色卡号查询调色
  232. getColorByCode(colorCode) {
  233. const { optionData } = this.props
  234. console.log('getColorByCode==========>',colorCode)
  235. this.props.dispatch(
  236. createAction('optional/getColorByGroups')({
  237. id : optionData[0].goodsId,
  238. groupId : "",
  239. colourCode : colorCode?colorCode.toUpperCase():''
  240. })
  241. )
  242. }
  243. render() {
  244. console.log(this.props)
  245. const { optionData, chooseOpt,colorData } = this.props
  246. if (this.props.havaOpt) {
  247. const optChoose = []
  248. optionData.newGoodsAttrVals.sort(
  249. (a, b) => a.isOptionalAttr - b.isOptionalAttr
  250. )
  251. optionData.goodsAttrVals.forEach(data => {
  252. if (data.isOptionalAttr) {
  253. if (data.isChecked) {
  254. optChoose.push(data.attrValName)
  255. } else if (data.productAttrTypeCode == '04')
  256. optChoose.push(data.attrValName)
  257. }
  258. })
  259. return (
  260. <View
  261. style={{
  262. marginBottom: 10,
  263. paddingBottom: 20,
  264. paddingTop: 10,
  265. borderBottomColor: '#EEE',
  266. borderBottomWidth: 1 / PixelRatio.get(),
  267. }}
  268. >
  269. <View style={{ flexDirection: 'row', alignItems: 'center' }}>
  270. <Text style={styles.titleText}>子件:</Text>
  271. <Text style={styles.contentText}>
  272. {optionData.childGoodsName || optionData.goodsDisplayName}
  273. </Text>
  274. </View>
  275. <View
  276. style={{
  277. flexDirection: 'row',
  278. marginTop: 10,
  279. marginBottom: 10,
  280. alignItems: 'center',
  281. }}
  282. >
  283. <Text style={styles.titleText}>已选:</Text>
  284. <Text style={styles.contentText}>{optChoose.join(' | ')}</Text>
  285. </View>
  286. <FlatList
  287. keyExtractor={(item, index) => index}
  288. data={optionData.newGoodsAttrVals}
  289. extraData={{ ...this.props, ...this.state }}
  290. // columnWrapperStyle={{ flexWrap: "wrap" }}
  291. // numColumns={2}
  292. renderItem={({ item, key }) => this._optionalRow(item, key)}
  293. />
  294. </View>
  295. )
  296. } else {
  297. // optionData.sort((a, b) => a.isOptionalAttr - b.isOptionalAttr)
  298. return (
  299. <View>
  300. {/* <FlatList
  301. keyExtractor={(item, index) => index}
  302. data={optionData}
  303. extraData={{ ...this.props, ...this.state }}
  304. // columnWrapperStyle={{ flexWrap: "wrap" }}
  305. // numColumns={2}
  306. renderItem={({ item, key }) => this._optionalRow(item, key)}
  307. /> */}
  308. <Input
  309. // autoFocus={true}
  310. style={{
  311. // // fontSize: 12,
  312. // // lineHeight: 20,
  313. // // letterSpacing: 0.38,
  314. // // color: '#333',
  315. // // marginTop: 4,
  316. // // height: 32,
  317. // // borderRadius: 2,
  318. // // paddingLeft: 5,
  319. // height: 32,
  320. // // width: width - 50,
  321. // borderRadius: width / 2,
  322. // // alignSelf: 'center',
  323. // paddingLeft: 14,
  324. height: 28,
  325. width: width - 50,
  326. marginTop: 20,
  327. borderRadius: width / 2,
  328. alignSelf: 'center',
  329. paddingLeft: 14,
  330. }}
  331. textStyle={{
  332. paddingLeft: 10,
  333. height: 28,
  334. fontSize: 11,
  335. padding: 0,
  336. }}
  337. iconSize={14}
  338. //blurOnSubmit={true}
  339. multiline={false}
  340. textInputBacg={'#F5F5F5'}
  341. iconColor={'#CCC'}
  342. placeholderTextColor={'#CCC'}
  343. placeholderSize={8}
  344. placeholder = {'请输入颜色编码'}
  345. onchangeFn={e => {
  346. // onSubmitEditing={e => {
  347. this.getColorByCode(e)
  348. }}
  349. />
  350. <Text
  351. style={{
  352. color: '#999',
  353. fontSize: 14,
  354. marginTop: 15,
  355. lineHeight: 20,
  356. letterSpacing: 0.17,
  357. }}
  358. >
  359. 调色选项
  360. </Text>
  361. <FlatList
  362. keyExtractor={(item, index) => index}
  363. style={{height:280}}
  364. data={colorData&&colorData.length&&colorData[0].goodsAttrVals}
  365. renderItem={({ item, key}) => this._colorList(item, key,colorData[0].goodsAttrVals)}
  366. numColumns= {2}
  367. />
  368. </View>
  369. )
  370. }
  371. }
  372. }
  373. const styles = StyleSheet.create({
  374. titleText: {
  375. fontSize: 14,
  376. lineHeight: 20,
  377. color: '#999',
  378. },
  379. contentText: {
  380. flex: 1,
  381. fontSize: 13,
  382. lineHeight: 18,
  383. color: '#333',
  384. },
  385. })
  386. export default OptFlatList