Home.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. import React, { Component } from 'react'
  2. import {
  3. StyleSheet,
  4. ScrollView,
  5. View,
  6. Image,
  7. ActivityIndicator,
  8. ImageBackground,
  9. Text,
  10. Dimensions,
  11. StatusBar,
  12. TouchableOpacity,
  13. RefreshControl,
  14. Alert,
  15. } from 'react-native'
  16. import { connect } from 'react-redux'
  17. import Icon from '../../components/Iconfont/Iconfont'
  18. import { NavigationActions, createAction, Storage, delay } from '../../utils'
  19. import {
  20. CarouselHorizontal,
  21. CarouselVertical,
  22. } from '../../components/carousel/index'
  23. import Input from '../../components/input/index'
  24. import Bubble from '../../components/Bubble'
  25. // import png from "../../static/images/banner.png";
  26. import mask from '../../static/images/home-mask.png'
  27. import announcePng from '../../static/images/home-announce.png'
  28. import inputdef from '../../static/images/home-topInput.png'
  29. import inputred from '../../static/images/home-topred.png'
  30. import homeAllGoods from '../../static/images/home-AllGoods.png'
  31. import homeHotSale from '../../static/images/home-hotSale.png'
  32. import Grid from '../../components/Grid'
  33. import SearchModal from '../commodity/SearchResults'
  34. import { ImageBaseUrl } from '../../utils/fetch/Fetchx'
  35. import { accMul } from '../../utils/utils'
  36. import dataModel from '../common/datamodel/dataModel'
  37. import pendingImg from '../../static/images/home-pending.png'
  38. import temporaryImg from '../../static/images/home-temporary.png'
  39. import dispatchImg from '../../static/images/home-dispatched.png'
  40. import unShipedImg from '../../static/images/home-unshiped.png'
  41. import { isIphoneX } from '../common/theme/config'
  42. import ToastView from '../../components/ToastView'
  43. import moment from 'moment'
  44. const { width, height } = Dimensions.get('window')
  45. @connect(({ theme, home, shoppingcart, announce }) => ({
  46. ...theme,
  47. ...home,
  48. ...shoppingcart,
  49. ...announce,
  50. }))
  51. class Home extends Component {
  52. constructor(props) {
  53. super(props)
  54. this.state = {
  55. header: {
  56. headercol: 'transparent',
  57. inputtx: '#CCC',
  58. inputbacg: '#FFF',
  59. messcol: '#FFF',
  60. inputWidth: width - 20,
  61. // barStyle: "light-content"
  62. barStyle: 'dark-content',
  63. // barStyle: this.props.appTheme.barStyle,
  64. },
  65. headerView: true,
  66. isRefreshing: false,
  67. shopListIds: [],
  68. isRefreshAdd: true,
  69. }
  70. // console.disableYellowBox = true;
  71. }
  72. static navigationOptions = {
  73. tabBarLabel: ({ tintColor }) => (
  74. <Text
  75. style={{
  76. alignSelf: 'center',
  77. marginBottom: 2,
  78. fontSize: 10,
  79. lineHeight: 14,
  80. letterSpacing: 0.12,
  81. color: tintColor,
  82. }}
  83. >
  84. 首页
  85. </Text>
  86. ),
  87. tabBarIcon: ({ focused, tintColor }) =>
  88. tintColor == '#333' ? (
  89. <View style={{ paddingTop: 7 }}>
  90. <Icon name="icon-icon-shouye" size={28} color={tintColor} />
  91. </View>
  92. ) : (
  93. <View style={{ paddingTop: 7 }}>
  94. <Icon name="icon-icon-shouyexuanzhong" size={28} color={tintColor} />
  95. </View>
  96. ),
  97. }
  98. gotoDetail(e) {
  99. this.props.dispatch(
  100. createAction('detail/gotoDetail')({ item: e, comefrom: 'Home' })
  101. )
  102. }
  103. onRefresh() {
  104. //
  105. this.props.dispatch(
  106. createAction('announce/getAnnounce')({ page: 0, pageSize: 10 })
  107. )
  108. //
  109. this.props.dispatch(createAction('announce/getBanner')())
  110. //
  111. this.props.dispatch(createAction('home/getAllPro')())
  112. this.props.dispatch(createAction('home/getHotSale')())
  113. }
  114. touchItemFn = val => {
  115. // this.props.dispatch(
  116. // NavigationActions.reset({
  117. // index: 0, // 注意不要越界
  118. // actions: [NavigationActions.navigate({ routeName: "OrderHome" })]
  119. // })
  120. // );
  121. switch (val) {
  122. case '待审核':
  123. this.props.dispatch(
  124. NavigationActions.navigate({
  125. routeName: 'OrderHome',
  126. action: NavigationActions.navigate({ routeName: 'OrderHome' }),
  127. params: { StateFilter: 'HomeToOrder/shenhe',orderListType:'1' },
  128. })
  129. )
  130. this.props.dispatch(
  131. createAction('orderlist/setRouterParamsReducer')({
  132. routerParams: 'HomeToOrder/shenhe'
  133. })
  134. )
  135. break
  136. case '待发货':
  137. this.props.dispatch(
  138. NavigationActions.navigate({
  139. routeName: 'OrderHome',
  140. action: NavigationActions.navigate({ routeName: 'OrderHome' }),
  141. params: { StateFilter: 'HomeToOrder/fahuo',orderListType:'1' },
  142. })
  143. )
  144. this.props.dispatch(
  145. createAction('orderlist/setRouterParamsReducer')({
  146. routerParams: 'HomeToOrder/fahuo'
  147. })
  148. )
  149. break
  150. case '待签收':
  151. this.props.dispatch(
  152. NavigationActions.navigate({
  153. routeName: 'OrderHome',
  154. action: NavigationActions.navigate({ routeName: 'OrderHome' }),
  155. params: { StateFilter: 'HomeToOrder/shouhuo',orderListType:'1' },
  156. })
  157. )
  158. this.props.dispatch(
  159. createAction('orderlist/setRouterParamsReducer')({
  160. routerParams: 'HomeToOrder/shouhuo'
  161. })
  162. )
  163. break
  164. case '暂存':
  165. this.props.dispatch(
  166. NavigationActions.navigate({
  167. routeName: 'OrderHome',
  168. action: NavigationActions.navigate({ routeName: 'OrderHome' }),
  169. params: { StateFilter: 'HomeToOrder/zancun' },
  170. })
  171. )
  172. this.props.dispatch(
  173. createAction('orderlist/setRouterParamsReducer')({
  174. routerParams: 'HomeToOrder/zancun'
  175. })
  176. )
  177. break
  178. }
  179. }
  180. //待审核、待发货等按钮部分
  181. touchItem(ReqNumData) {
  182. let numDataObj = []
  183. if (ReqNumData && ReqNumData.length > 0) {
  184. ReqNumData.map(data => (numDataObj[data[0]] = data[1]))
  185. }
  186. let _items = [],
  187. right,
  188. itemdatas = [
  189. {
  190. text: '待审核',
  191. fn: this.touchItemFn,
  192. iconName: pendingImg,
  193. // iconName: "icon-daishenhe",
  194. bubbleval: numDataObj['02'] || 0,
  195. },
  196. {
  197. text: '待发货',
  198. fn: this.touchItemFn,
  199. iconName: unShipedImg,
  200. // iconName: "icon-daifahuo",
  201. bubbleval: numDataObj['03'] || 0,
  202. },
  203. {
  204. text: '待签收',
  205. fn: this.touchItemFn,
  206. iconName: dispatchImg,
  207. // iconName: "icon-daishouhuo",
  208. bubbleval: numDataObj['04'] || 0,
  209. },
  210. {
  211. text: '暂存',
  212. fn: this.touchItemFn,
  213. iconName: temporaryImg,
  214. // iconName: "icon-buhuo",
  215. bubbleval: numDataObj['01'] || 0,
  216. },
  217. ]
  218. for (let i = 0; i < itemdatas.length; i++) {
  219. let items = itemdatas[i]
  220. if (items.bubbleval < 10 && items.bubbleval > 0) {
  221. right = 20
  222. } else if (items.bubbleval >= 100) {
  223. right = 5
  224. } else {
  225. right = 7
  226. }
  227. _items.push(
  228. <TouchableOpacity
  229. key={i}
  230. style={[styles.buttonStyle, { width: (width - 20) / 4 }]}
  231. onPress={() => items.fn(items.text)}
  232. >
  233. {/* <Icon name={items.iconName} size={40} color={"#333"} /> */}
  234. <Image
  235. source={items.iconName}
  236. style={
  237. items.text == '待审核'
  238. ? { width: 33, height: 33, marginBottom: 5, marginTop: 3 }
  239. : items.text == '暂存'
  240. ? { width: 40, height: 40, marginTop: 1 }
  241. : { width: 30, height: 30, marginBottom: 6, marginTop: 5 }
  242. }
  243. resizeMode="contain"
  244. />
  245. <Bubble
  246. bubbleColor={'#E14C46'}
  247. size={16}
  248. style={{ position: 'absolute', right: right, top: 0 }}
  249. value={items.bubbleval}
  250. />
  251. <Text style={[styles.buttonText, { lineHeight: 17 }]}>
  252. {items.text}
  253. </Text>
  254. </TouchableOpacity>
  255. )
  256. }
  257. return _items
  258. }
  259. _onScroll(event) {
  260. let offsetY = event.nativeEvent.contentOffset.y
  261. if (offsetY > 35) {
  262. this.setState({
  263. // 下拉样式
  264. header: {
  265. headercol: '#FFF',
  266. inputtx: '#CCC',
  267. inputbacg: '#FFF',
  268. messcol: '#FFF',
  269. inputWidth: width - 50,
  270. barStyle: 'dark-content',
  271. // barStyle: "light-content"
  272. },
  273. })
  274. } else if (offsetY < -20) {
  275. this.setState({ headerView: false })
  276. } else {
  277. this.setState({
  278. // 初始状态样式
  279. header: {
  280. headercol: 'transparent',
  281. inputtx: '#CCC',
  282. inputbacg: '#FFF',
  283. messcol: '#FFF',
  284. inputWidth: width - 20,
  285. barStyle: 'light-content',
  286. },
  287. })
  288. }
  289. }
  290. _addShopCart(item) {
  291. if(item.goodsAttrVals && item.goodsAttrVals.length) {
  292. this.plToast.show('该商品为调色商品,请到商品详情页面下单');
  293. return;
  294. }
  295. if(!item.baseDiscountPrice) {
  296. this.plToast.show('商品暂无价格,无法加入购物车');
  297. return;
  298. }
  299. let postData = dataModel(
  300. item,
  301. CUSTOMERINFO.id,
  302. CUSTOMERINFO.customerRankCode
  303. )
  304. this.props.dispatch(createAction('shoppingcart/addShop')(postData))
  305. this.setState({ isRefreshAdd: this.state.isRefreshAdd })
  306. }
  307. render() {
  308. const {
  309. fetching,
  310. hotSaleDatas,
  311. allProDatas,
  312. shopListIds,
  313. announceDatas,
  314. bannerData,
  315. bannerTime,
  316. ReqNumData,
  317. } = this.props
  318. let bannerImg = [],
  319. announceArr = [],
  320. bannerDate =
  321. bannerTime && bannerTime.length > 0
  322. ? accMul(1000, bannerTime[0].autoPlaySpeed || 0.5)
  323. : 5000
  324. bannerData.map((item, index) => {
  325. bannerImg.push(
  326. <Image
  327. key={index}
  328. source={{ uri: ImageBaseUrl + item.imgUrl }}
  329. resizeMode="stretch"
  330. style={styles.pngstyle}
  331. />
  332. )
  333. })
  334. if (announceDatas && announceDatas.length > 0) {
  335. announceDatas.slice(1, announceDatas.length).map(data => {
  336. announceArr = announceArr.concat(data.noticeInfoMap)
  337. })
  338. }
  339. return (
  340. <View style={[styles.container, { backgroundColor: '#FFF' }]}>
  341. <StatusBar
  342. animated={true}
  343. barStyle={this.state.header.barStyle}
  344. // barStyle={"dark-content"}
  345. backgroundColor={'transparent'}
  346. translucent={true}
  347. />
  348. <ToastView
  349. onDismiss={() => {
  350. //alert('toast消失了');
  351. }}
  352. ref={(element) => {
  353. this.plToast = element;
  354. }}
  355. />
  356. {this.state.headerView ? (
  357. <ImageBackground
  358. source={
  359. this.state.header.headercol == 'transparent' ? inputdef : inputred
  360. }
  361. resizeMode="stretch"
  362. style={{
  363. position: 'absolute',
  364. width: width,
  365. // height: isIphoneX() ? 77 : 60,
  366. height: HEADERSTYLE.height,
  367. // paddingTop: isIphoneX() ? 17 : 10,
  368. paddingTop: isIphoneX() ? HEADERSTYLE.paddingTop : 0,
  369. // backgroundColor: this.state.header.headercol,
  370. backgroundColor: 'transparent',
  371. flexDirection: 'row',
  372. justifyContent: 'center',
  373. alignSelf: 'center',
  374. zIndex: 1,
  375. }}
  376. >
  377. <Input
  378. touchBool={true}
  379. touchInput={() => this.mdl._openModal()}
  380. textInputBacg={this.state.header.inputbacg}
  381. placeholderTextColor={this.state.header.inputtx}
  382. iconColor={this.state.header.inputtx}
  383. iconSize={16}
  384. style={{
  385. height: 28,
  386. width: this.state.header.inputWidth,
  387. marginTop: 18,
  388. borderRadius: width / 2,
  389. alignSelf: 'center',
  390. paddingLeft: 14,
  391. }}
  392. />
  393. {this.state.header.headercol == 'transparent' ? null : (
  394. <View
  395. style={{
  396. alignSelf: 'center',
  397. paddingLeft: 5,
  398. paddingTop: 18,
  399. }}
  400. >
  401. <Icon
  402. name="icon-buhuo"
  403. size={32}
  404. color={this.state.header.messcol}
  405. onPress={() => {
  406. this.props.dispatch(
  407. NavigationActions.navigate({
  408. routeName: 'Replenishment',
  409. })
  410. )
  411. // this.props.dispatch(createAction("home/recentViewClear")());
  412. }}
  413. />
  414. </View>
  415. )}
  416. </ImageBackground>
  417. ) : null}
  418. <ScrollView
  419. style={{ flex: 1 }}
  420. showsHorizontalScrollIndicator={false}
  421. removeClippedSubviews={true}
  422. scrollEventThrottle={200}
  423. style={{ overflow: 'hidden' }}
  424. onScroll={event => {
  425. this._onScroll(event)
  426. }}
  427. refreshControl={
  428. <RefreshControl
  429. refreshing={this.state.isRefreshing}
  430. onRefresh={this.onRefresh.bind(this)} //(()=>this.onRefresh)或者通过bind来绑定this引用来调用方法
  431. tintColor="red"
  432. title={this.state.isRefreshing ? '刷新中....' : '下拉刷新'}
  433. />
  434. }
  435. onMomentumScrollEnd={eve => {
  436. if (eve.nativeEvent.contentOffset.y == 0) {
  437. this.setState({ headerView: true })
  438. }
  439. }}
  440. >
  441. <View style={{ height: 310 }}>
  442. <CarouselHorizontal
  443. width={width}
  444. delayTime={bannerDate}
  445. enableScroll={true}
  446. tintColor={'#FFF'}
  447. touchArrStyle={{
  448. bottom: '6%',
  449. flexDirection: 'row',
  450. }}
  451. imgTouch={a => {
  452. console.log(a)
  453. }}
  454. >
  455. {bannerImg}
  456. </CarouselHorizontal>
  457. <ImageBackground
  458. resizeMode="stretch"
  459. source={mask}
  460. style={{
  461. position: 'absolute',
  462. width: width - 16,
  463. height: 80,
  464. bottom: 0,
  465. marginHorizontal: 8,
  466. }}
  467. >
  468. <View
  469. style={{
  470. paddingTop: 10,
  471. flexDirection: 'row',
  472. }}
  473. >
  474. {this.touchItem(ReqNumData)}
  475. </View>
  476. </ImageBackground>
  477. </View>
  478. <View
  479. style={{
  480. height: 38,
  481. width: width - 20,
  482. marginHorizontal: 10,
  483. borderRadius: 4,
  484. marginTop: 10,
  485. paddingLeft: 10,
  486. paddingRight: 5,
  487. alignSelf: 'center',
  488. justifyContent: 'center',
  489. backgroundColor: '#F5F5F5',
  490. }}
  491. >
  492. <TouchableOpacity
  493. onPress={() => {
  494. this.props.dispatch(
  495. NavigationActions.navigate({ routeName: 'Announcement' })
  496. )
  497. }}
  498. activeOpacity={1}
  499. style={{
  500. flexDirection: 'row',
  501. justifyContent: 'space-between',
  502. }}
  503. >
  504. <Image
  505. resizeMode="stretch"
  506. source={announcePng}
  507. style={{ width: 64, height: 15, alignSelf: 'center' }}
  508. />
  509. <CarouselVertical
  510. enableAnimation={true}
  511. data={announceArr}
  512. // 公告轮播主要内容字段
  513. content={'title'}
  514. // 公告轮播例如'火爆'、'热销'等关键字 字段
  515. title={'totaltitle'}
  516. delay={2500}
  517. duration={1000}
  518. scrollHeight={38}
  519. textStyle={{
  520. fontSize: 13,
  521. lineHeight: 18,
  522. color: '#333',
  523. width: width / 1.6,
  524. marginLeft: 2,
  525. alignSelf: 'center',
  526. }}
  527. titleStyle={{
  528. fontSize: 12,
  529. color: '#E14C46',
  530. fontWeight: 'bold',
  531. marginRight: 5,
  532. }}
  533. />
  534. <View
  535. style={{
  536. alignSelf: 'center',
  537. height: 20,
  538. width: 1,
  539. backgroundColor: '#DDD',
  540. }}
  541. />
  542. <Text
  543. style={{
  544. color: '#333',
  545. alignSelf: 'center',
  546. fontSize: 11,
  547. lineHeight: 16,
  548. }}
  549. >
  550. 更多>
  551. </Text>
  552. </TouchableOpacity>
  553. </View>
  554. <View style={{ flex: 1, backgroundColor: '#FFF' }}>
  555. {hotSaleDatas && hotSaleDatas.length > 0 ? (
  556. <Grid
  557. homeLIstBool={true}
  558. data={
  559. hotSaleDatas && hotSaleDatas.length > 2
  560. ? hotSaleDatas.slice(0, 2)
  561. : hotSaleDatas
  562. }
  563. titleName="热卖促销"
  564. imageSource={homeHotSale}
  565. nameKey="displayName"
  566. pictureKey="mainPictureFileUrl"
  567. priceKey="baseDiscountPrice"
  568. keyext="id"
  569. imageTouch={e => {
  570. this.gotoDetail(e)
  571. }}
  572. shoppingCart={item => {
  573. if (item.isOptional) {
  574. this.gotoDetail(item)
  575. } else {
  576. this._addShopCart(item)
  577. }
  578. }}
  579. titleIcon=""
  580. shopListIds={shopListIds}
  581. />
  582. ) : null}
  583. <Grid
  584. titleName="全部商品"
  585. imageSource={homeAllGoods}
  586. homeLIstBool={true}
  587. data={
  588. allProDatas &&
  589. allProDatas.content &&
  590. allProDatas.content.length > 0
  591. ? allProDatas.content.length > 8
  592. ? allProDatas.content.slice(0, 8)
  593. : allProDatas.content
  594. : []
  595. }
  596. nameKey="displayName"
  597. pictureKey="mainPictureFileUrl"
  598. priceKey="baseDiscountPrice"
  599. keyext="id"
  600. imageTouch={e => {
  601. // this.props.dispatch(
  602. // createAction("home/getRecentView")({ recentView: e })
  603. // );
  604. this.gotoDetail(e)
  605. }}
  606. moreTouch={() =>
  607. // this.props.dispatch(
  608. // createAction("search/searchGoodsAll")({
  609. // comeFrom: "Home",
  610. // searchVal: {
  611. // search_customerId: CUSTOMERINFO.id,
  612. // search_customerRankCode: CUSTOMERINFO.customerRankCode,
  613. // // search_EQ_isOptional: 0,
  614. // // search_EQ_enableStrucManage: 0
  615. // }
  616. // })
  617. // )
  618. this.props.dispatch(
  619. NavigationActions.navigate({
  620. routeName: 'CommodityShowbase',
  621. params: { searchval: '' },
  622. })
  623. )
  624. }
  625. shoppingCart={item => {
  626. if (item.isOptional) {
  627. this.gotoDetail(item)
  628. } else {
  629. this._addShopCart(item)
  630. }
  631. }}
  632. shopListIds={shopListIds}
  633. />
  634. {/* <Grid
  635. homeLIstBool={true}
  636. titleName="最近浏览"
  637. data={recentDatas.slice(0, 2)}
  638. nameKey="displayName"
  639. pictureKey="pictureUrl"
  640. priceKey="salePrice"
  641. keyext="code"
  642. imageTouch={e => {
  643. this.gotoDetail(e);
  644. }}
  645. moreTouch={() =>
  646. this.props.dispatch(
  647. NavigationActions.navigate({ routeName: "RecentViewMore" })
  648. )
  649. }
  650. /> */}
  651. </View>
  652. </ScrollView>
  653. <SearchModal
  654. // cb={data => {
  655. // this._refreshPlist(data);
  656. // }}
  657. ref={mdl => (this.mdl = mdl)}
  658. dispatch={this.props.dispatch}
  659. comFrom={'Home'}
  660. />
  661. {/* {fetching ? (
  662. <View
  663. style={[
  664. styles.container,
  665. {
  666. position: "absolute",
  667. width: width,
  668. height: height,
  669. justifyContent: "center",
  670. backgroundColor: "#000",
  671. opacity: 0.5
  672. }
  673. ]}
  674. >
  675. <ActivityIndicator />
  676. </View>
  677. ) : null} */}
  678. </View>
  679. )
  680. }
  681. }
  682. const styles = StyleSheet.create({
  683. container: {
  684. flex: 1,
  685. },
  686. pngstyle: {
  687. width: width,
  688. height: 240,
  689. },
  690. buttonStyle: {
  691. backgroundColor: 'transparent',
  692. flexDirection: 'column',
  693. alignItems: 'center',
  694. },
  695. buttonText: {
  696. fontSize: 12,
  697. color: '#333',
  698. },
  699. })
  700. export default Home