CommodityHome.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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. ImageBackground,
  13. ActivityIndicator,
  14. } from 'react-native'
  15. import { connect } from 'react-redux'
  16. import Icon from '../../components/Iconfont/Iconfont'
  17. import { NavigationActions, createAction } from '../../utils'
  18. import Input from '../../components/input/index'
  19. import SearchModal from './SearchResults'
  20. import png from '../../static/images/defaultimg.jpg'
  21. import Collapsible from 'react-native-collapsible'
  22. import EmptyCommodity from '../../static/images/Empty-commodity.png'
  23. import { ImageBaseUrl } from '../../utils/fetch/Fetchx'
  24. import { ScaleUtil } from '../../utils/utils'
  25. import dataModel from '../common/datamodel/dataModel'
  26. import ToastView from '../../components/ToastView'
  27. const { width, height } = Dimensions.get('window')
  28. @connect(({ theme, search, category, shoppingcart }) => ({
  29. ...theme,
  30. ...search,
  31. ...category,
  32. ...shoppingcart,
  33. }))
  34. class CommodityHome extends Component {
  35. constructor(props) {
  36. super(props)
  37. this.state = {
  38. categorydata2Item:
  39. (props.categorydata &&
  40. props.categorydata[0] &&
  41. props.categorydata[0].items) ||
  42. [],
  43. categorydata3Item:
  44. (props.categorydata &&
  45. props.categorydata[0] &&
  46. props.categorydata[0].items &&
  47. props.categorydata[0].items[0] &&
  48. props.categorydata[0].items[0].items) ||
  49. [],
  50. categoryId: '',
  51. secListIndex: 0,
  52. thirdIndex: 0,
  53. item1Color: 0,
  54. secondIndex: 0,
  55. isRefresh: true,
  56. }
  57. }
  58. static navigationOptions = {
  59. tabBarLabel: ({ tintColor }) => (
  60. <Text
  61. style={{
  62. alignSelf: 'center',
  63. marginBottom: 2,
  64. fontSize: 10,
  65. lineHeight: 14,
  66. letterSpacing: 0.12,
  67. color: tintColor,
  68. }}
  69. >
  70. 商品
  71. </Text>
  72. ),
  73. tabBarIcon: ({ focused, tintColor }) =>
  74. tintColor == '#333' ? (
  75. <View style={{ paddingTop: 7 }}>
  76. <Icon name="icon-icon-shangpin" size={28} color={tintColor} />
  77. </View>
  78. ) : (
  79. <View style={{ paddingTop: 7 }}>
  80. <Icon
  81. name="icon-icon-shangpinxuanzhong"
  82. size={28}
  83. color={tintColor}
  84. />
  85. </View>
  86. ),
  87. }
  88. componentDidMount() {
  89. this.props.dispatch(
  90. createAction('search/searchGoodsByCate')({
  91. searchVal: {
  92. search_customerId: CUSTOMERINFO.id,
  93. search_customerRankCode: CUSTOMERINFO.customerRankCode,
  94. // search_EQ_isOptional: 0,
  95. // search_EQ_enableStrucManage: 0
  96. },
  97. })
  98. )
  99. }
  100. gotoDetail = () => {
  101. this.props.dispatch(NavigationActions.navigate({ routeName: 'Detail' }))
  102. }
  103. searchGoodsFn(item) {
  104. this.props.dispatch(
  105. createAction('search/searchGoodsByCate')({
  106. searchVal: {
  107. search_customerId: CUSTOMERINFO.id,
  108. search_customerRankCode: CUSTOMERINFO.customerRankCode,
  109. search_goodsCategoryIds: item.item.id,
  110. // search_EQ_isOptional: 0,
  111. // search_EQ_enableStrucManage: 0
  112. },
  113. })
  114. )
  115. }
  116. // 一级菜单
  117. leftRender(item, index) {
  118. return (
  119. <View>
  120. <TouchableOpacity
  121. onPress={() => {
  122. this.state.categorydata2Item = []
  123. if (this.state.secListIndex == item.index) {
  124. this.setState({
  125. secListIndex: 'asd',
  126. })
  127. } else {
  128. if (
  129. item.item &&
  130. (Object.keys(item.item).indexOf('items') == -1 ||
  131. (Object.keys(item.item).indexOf('items') !== -1 &&
  132. item.item.items.length == 0))
  133. ) {
  134. this.searchGoodsFn(item)
  135. this.setState({
  136. secListIndex: item.index,
  137. item1Color: item.index,
  138. // categorydata3Item: [],
  139. secondIndex: 0,
  140. })
  141. } else {
  142. this.setState({
  143. categorydata2Item:
  144. item.item && item.item.items && item.item.items.length > 0
  145. ? item.item.items
  146. : [],
  147. secListIndex: item.index,
  148. item1Color: item.index,
  149. // categorydata3Item: [],
  150. secondIndex: 0,
  151. })
  152. }
  153. }
  154. }}
  155. style={{
  156. paddingLeft: 8,
  157. paddingRight: 5,
  158. paddingVertical: 14,
  159. borderBottomColor: '#eee',
  160. borderBottomWidth: 1 / PixelRatio.get(),
  161. flexDirection: 'row',
  162. borderLeftColor:
  163. this.state.item1Color == item.index ? '#E70013' : 'transparent',
  164. borderLeftWidth: 2,
  165. }}
  166. >
  167. <Text
  168. numberOfLines={1}
  169. style={{
  170. flex: 1,
  171. fontSize: 13,
  172. color: '#333',
  173. marginRight: 7,
  174. }}
  175. >
  176. {item.item && item.item.name && item.item.name.length > 4
  177. ? item.item.name.slice(0, 4) + '...'
  178. : item.item.name}
  179. </Text>
  180. {item.item && item.item.items && item.item.items.length > 0 ? (
  181. <Icon
  182. name="icon-icon-xialaxiaosanjiao"
  183. size={14}
  184. style={[
  185. item.item.items && item.item.items.length !== 0
  186. ? this.state.secListIndex == item.index
  187. ? { transform: [{ rotate: '180deg' }] }
  188. : {}
  189. : {},
  190. { alignSelf: 'center' },
  191. ]}
  192. color={'#CCC'}
  193. />
  194. ) : null}
  195. </TouchableOpacity>
  196. <Collapsible collapsed={this.state.secListIndex !== item.index}>
  197. <FlatList
  198. extraData={this.state}
  199. data={this.state.categorydata2Item}
  200. renderItem={item =>
  201. this.secondMenu(item, this.state.categorydata2Item.length)
  202. }
  203. keyExtractor={(item, index) => index}
  204. />
  205. </Collapsible>
  206. </View>
  207. )
  208. }
  209. //二级菜单
  210. secondMenu(item, maxlength) {
  211. return (
  212. <TouchableOpacity
  213. onPress={() => {
  214. this.state.categorydata3Item = []
  215. if (
  216. item.item &&
  217. (Object.keys(item.item).indexOf('items') == -1 ||
  218. (Object.keys(item.item).indexOf('items') !== -1 &&
  219. item.item.items.length == 0))
  220. ) {
  221. this.searchGoodsFn(item)
  222. } else {
  223. this.setState({
  224. categorydata3Item: item.item && item.item.items,
  225. })
  226. }
  227. this.setState({
  228. secondIndex: item.index,
  229. })
  230. }}
  231. style={{ paddingHorizontal: 10, backgroundColor: '#F5F5F5' }}
  232. >
  233. <View
  234. style={{
  235. paddingVertical: 10,
  236. borderBottomColor: '#DDD',
  237. borderBottomWidth: item.index == maxlength - 1 ? 0 : 1,
  238. }}
  239. >
  240. <Text
  241. style={{
  242. fontSize: 13,
  243. lineHeight: 18,
  244. color: this.state.secondIndex == item.index ? '#E70013' : '#333',
  245. alignSelf: 'center',
  246. }}
  247. >
  248. {item.item.name}
  249. </Text>
  250. </View>
  251. </TouchableOpacity>
  252. )
  253. }
  254. // 三级菜单
  255. thirdMenu(item) {
  256. return (
  257. <TouchableOpacity
  258. onPress={() => {
  259. this.setState({ thirdIndex: item.index })
  260. this.searchGoodsFn(item)
  261. }}
  262. style={{
  263. paddingHorizontal: 20,
  264. paddingVertical: 5,
  265. backgroundColor: '#FFF',
  266. borderRadius: 100,
  267. marginTop: 10,
  268. borderWidth: 1 / PixelRatio.get(),
  269. borderColor: this.state.thirdIndex == item.index ? '#E70013' : '#DDD',
  270. marginRight: 10,
  271. }}
  272. >
  273. <Text
  274. style={{
  275. fontSize: 12,
  276. color: this.state.thirdIndex == item.index ? '#E70013' : '#333',
  277. lineHeight: 17,
  278. }}
  279. >
  280. {item.item.name}
  281. </Text>
  282. </TouchableOpacity>
  283. )
  284. }
  285. // 商品信息
  286. commodityInfo(item) {
  287. let gouwucheColor = '#666'
  288. if (this.props.shopListIds.indexOf(item.item.id) !== -1) {
  289. gouwucheColor = '#E70013'
  290. }
  291. return (
  292. <View
  293. style={{
  294. flexDirection: 'row',
  295. paddingRight: 10,
  296. borderBottomColor: '#EEE',
  297. borderBottomWidth: 1 / PixelRatio.get(),
  298. }}
  299. >
  300. <TouchableOpacity
  301. onPress={() =>
  302. this.props.dispatch(
  303. createAction('detail/gotoDetail')({ item: item.item })
  304. )
  305. }
  306. style={{ width: 120, height: 120, padding: 10 }}
  307. >
  308. <Image
  309. resizeMode="contain"
  310. style={{ width: 100, height: 100 }}
  311. source={
  312. item.item.mainPictureFileUrl
  313. ? { uri: ImageBaseUrl + item.item.mainPictureFileUrl }
  314. : png
  315. }
  316. />
  317. </TouchableOpacity>
  318. <View
  319. style={{
  320. flex: 1,
  321. justifyContent: 'space-around',
  322. paddingVertical: 5,
  323. }}
  324. >
  325. <TouchableOpacity
  326. onPress={() =>
  327. this.props.dispatch(
  328. createAction('detail/gotoDetail')({ item: item.item })
  329. )
  330. }
  331. >
  332. <Text
  333. numberOfLines={2}
  334. style={{ fontSize: 12, lineHeight: 17, color: '#333' }}
  335. >
  336. {
  337. item.item.goodsAttrVals&&item.item.goodsAttrVals.length?(<Text style={{backgroundColor: '#f85300',color:'white'}}>调</Text>):""
  338. }
  339. {item.item.displayName}
  340. </Text>
  341. <Text
  342. style={{
  343. fontSize: 12,
  344. lineHeight: 17,
  345. color: '#666',
  346. marginTop: 4,
  347. }}
  348. >
  349. 编码:{item.item.code}
  350. </Text>
  351. <Text
  352. style={{
  353. fontSize: 12,
  354. lineHeight: 17,
  355. color: '#666',
  356. marginTop: 4,
  357. }}
  358. >
  359. {/* 型号:{item.item.model?(item.item.model.length>10?item.item.model.substr(0,10)+'...':item.item.model):""} */}
  360. 型号:{item.item.model?item.item.model:""}
  361. </Text>
  362. <Text
  363. style={{
  364. fontSize: 12,
  365. lineHeight: 17,
  366. color: '#666',
  367. marginTop: 4,
  368. }}
  369. >
  370. 规格:{item.item.specification?(item.item.specification.split("/")[0]+"/"+item.item.basicUnitName):""}
  371. </Text>
  372. </TouchableOpacity>
  373. {/* <Text
  374. style={{
  375. fontSize: 12,
  376. lineHeight: 17,
  377. color: '#666',
  378. }}
  379. >
  380. 库存:{ScaleUtil(item.item.stock)}
  381. </Text> */}
  382. <View
  383. style={{ flexDirection: 'row', justifyContent: 'space-between' }}
  384. >
  385. <Text
  386. style={{
  387. fontSize: 14,
  388. lineHeight: 20,
  389. color: '#E70013',
  390. }}
  391. >
  392. ¥{ScaleUtil(item.item.salePrice || item.item.baseDiscountPrice)}
  393. </Text>
  394. <TouchableOpacity
  395. onPress={() => {
  396. if (item.item.isOptional) {
  397. this.props.dispatch(
  398. createAction('detail/gotoDetail')({
  399. item: item.item,
  400. comefrom: 'Home',
  401. userFor: 'openModel',
  402. })
  403. )
  404. } else {
  405. if(item.item.goodsAttrVals && item.item.goodsAttrVals.length) {
  406. this.plToast.show('该商品为调色商品,请到商品详情页面下单');
  407. return;
  408. }
  409. if(!item.item.baseDiscountPrice) {
  410. this.plToast.show('商品暂无价格,无法加入购物车');
  411. return;
  412. }
  413. let postData = dataModel(
  414. item.item,
  415. CUSTOMERINFO.id,
  416. CUSTOMERINFO.customerRankCode
  417. )
  418. this.props.dispatch(
  419. createAction('shoppingcart/addShop')(postData)
  420. )
  421. }
  422. }}
  423. >
  424. <Icon name="icon-icon-gouwuche" size={22} color={gouwucheColor} />
  425. </TouchableOpacity>
  426. </View>
  427. </View>
  428. </View>
  429. )
  430. }
  431. render() {
  432. const {
  433. appTheme,
  434. categorydata,
  435. GoodsList,
  436. GoodsState,
  437. GoodsFlag,
  438. } = this.props
  439. return (
  440. <View
  441. style={[
  442. styles.container,
  443. { backgroundColor: appTheme.backgroundColor },
  444. ]}
  445. >
  446. <StatusBar
  447. animated={true}
  448. barStyle={appTheme.barStyle}
  449. backgroundColor={'transparent'}
  450. translucent={true}
  451. />
  452. <View
  453. style={{
  454. width: width,
  455. // height: 60,
  456. height: HEADERSTYLE.height,
  457. backgroundColor: '#FFF',
  458. flexDirection: 'row',
  459. justifyContent: 'center',
  460. paddingLeft: 10,
  461. paddingBottom: 7,
  462. borderBottomColor: '#DDD',
  463. borderBottomWidth: 1 / PixelRatio.get(),
  464. }}
  465. >
  466. <View style={{ flexDirection: 'row', justifyContent: 'center' }}>
  467. <Input
  468. touchBool={true}
  469. touchInput={() => this.mdl._openModal()}
  470. iconSize={16}
  471. style={{
  472. height: 28,
  473. width: width - 70,
  474. borderRadius: width / 2,
  475. alignSelf: 'flex-end',
  476. paddingLeft: 14,
  477. }}
  478. placeholder={'商品名称/编码'}
  479. textInputBacg={'#EEE'}
  480. iconColor={'#999'}
  481. placeholderTextColor={'#999'}
  482. />
  483. <TouchableOpacity
  484. onPress={() =>
  485. this.props.dispatch(
  486. NavigationActions.navigate({ routeName: 'Replenishment' })
  487. )
  488. }
  489. style={{
  490. paddingLeft: 6,
  491. alignSelf: 'flex-end',
  492. marginBottom: -6,
  493. }}
  494. >
  495. <Icon name="icon-buhuo" size={34} color={'#999'} />
  496. </TouchableOpacity>
  497. </View>
  498. </View>
  499. {categorydata && categorydata.length > 0 ? (
  500. <View style={{ flex: 1, flexDirection: 'row', marginTop: 4 }}>
  501. <View
  502. style={{
  503. flex: 4,
  504. backgroundColor: '#FFF',
  505. borderRightWidth: 1 / PixelRatio.get(),
  506. borderRightColor: '#EEE',
  507. }}
  508. >
  509. <FlatList
  510. extraData={this.state}
  511. data={categorydata}
  512. renderItem={item => this.leftRender(item)}
  513. keyExtractor={(item, index) => index}
  514. />
  515. </View>
  516. <View style={{ flex: 11, backgroundColor: '#FFF' }}>
  517. {this.state.categorydata3Item &&
  518. this.state.categorydata3Item.length > 0 ? (
  519. <View
  520. style={{
  521. height: 80,
  522. paddingLeft: 15,
  523. marginBottom: 3,
  524. borderBottomWidth: 1 / PixelRatio.get(),
  525. borderBottomColor: '#EEE',
  526. }}
  527. >
  528. <FlatList
  529. data={this.state.categorydata3Item}
  530. extraData={this.state}
  531. keyExtractor={(item, index) => index}
  532. renderItem={(item, index) => this.thirdMenu(item, index)}
  533. columnWrapperStyle={{
  534. flexWrap: 'wrap',
  535. }}
  536. numColumns={3}
  537. />
  538. </View>
  539. ) : null}
  540. {GoodsState ? (
  541. !GoodsFlag ? (
  542. <View style={{ flex: 1 }}>
  543. <FlatList
  544. extraData={this.props}
  545. data={GoodsList}
  546. renderItem={item => this.commodityInfo(item)}
  547. keyExtractor={(item, index) => index}
  548. />
  549. </View>
  550. ) : (
  551. <View
  552. style={{
  553. flex: 1,
  554. alignSelf: 'center',
  555. justifyContent: 'center',
  556. }}
  557. >
  558. <ActivityIndicator />
  559. </View>
  560. )
  561. ) : (
  562. <ImageBackground
  563. resizeMode="contain"
  564. source={EmptyCommodity}
  565. style={{
  566. width: width * 2 / 3,
  567. height: height / 1.7,
  568. alignSelf: 'center',
  569. }}
  570. >
  571. <View
  572. style={{
  573. position: 'absolute',
  574. bottom: '15%',
  575. alignSelf: 'center',
  576. }}
  577. >
  578. <Text
  579. style={{
  580. fontSize: 14,
  581. lineHeight: 20,
  582. letterSpacing: 0.17,
  583. color: '#999',
  584. }}
  585. >
  586. 商品列表出现异常啦~
  587. </Text>
  588. </View>
  589. </ImageBackground>
  590. )}
  591. <View
  592. style={{
  593. marginHorizontal: 15,
  594. borderBottomColor: '#DDD',
  595. borderBottomWidth: 1 / PixelRatio.get(),
  596. }}
  597. />
  598. </View>
  599. </View>
  600. ) : (
  601. <ImageBackground
  602. resizeMode="contain"
  603. source={EmptyCommodity}
  604. style={{
  605. width: width - 80,
  606. height: height / 1.5 - 80,
  607. alignSelf: 'center',
  608. }}
  609. >
  610. <View
  611. style={{
  612. position: 'absolute',
  613. bottom: '15%',
  614. alignSelf: 'center',
  615. }}
  616. >
  617. <Text
  618. style={{
  619. fontSize: 14,
  620. lineHeight: 20,
  621. letterSpacing: 0.17,
  622. color: '#999',
  623. }}
  624. >
  625. 商品分类出现异常啦~
  626. </Text>
  627. </View>
  628. </ImageBackground>
  629. )}
  630. <SearchModal
  631. // cb={data => {
  632. // this._refreshPlist(data);
  633. // }}
  634. ref={mdl => (this.mdl = mdl)}
  635. dispatch={this.props.dispatch}
  636. comFrom={'CommodityHome'}
  637. // fuleipro={this.state.footerdata}
  638. />
  639. <ToastView
  640. onDismiss={() => {
  641. //alert('toast消失了');
  642. }}
  643. ref={(element) => {
  644. this.plToast = element;
  645. }}
  646. />
  647. </View>
  648. )
  649. }
  650. }
  651. const styles = StyleSheet.create({
  652. container: {
  653. flex: 1,
  654. },
  655. icon: {
  656. width: 32,
  657. height: 32,
  658. },
  659. })
  660. export default CommodityHome