CommodityShowbase.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. import React, { Component } from 'react'
  2. import {
  3. StyleSheet,
  4. View,
  5. Image,
  6. StatusBar,
  7. Dimensions,
  8. TouchableOpacity,
  9. PixelRatio,
  10. Text,
  11. FlatList,
  12. ActivityIndicator,
  13. } from 'react-native'
  14. import { connect } from 'react-redux'
  15. import Icon from '../../components/Iconfont/Iconfont'
  16. import { NavigationActions, createAction, Storage } from '../../utils'
  17. import Input from '../../components/input/index'
  18. import Checkbox from '../../components/checkbox/index'
  19. import Grid from '../../components/Grid'
  20. import Collapsible from 'react-native-collapsible'
  21. import SearchModal from './SearchResults'
  22. import dataModel from '../common/datamodel/dataModel'
  23. import ToastView from '../../components/ToastView'
  24. const { width, height } = Dimensions.get('window')
  25. const AllData = {
  26. saleOrganizationName: '全部供应商',
  27. saleOrganizationId: '',
  28. }
  29. const ProductLineData = {
  30. productLineName: '全部产品线',
  31. productLineId: '',
  32. }
  33. @connect(({ theme, search, shoppingcart, mine }) => ({
  34. ...theme,
  35. ...search,
  36. ...shoppingcart,
  37. ...mine,
  38. }))
  39. class CommodityShowbase extends Component {
  40. constructor(props) {
  41. super(props)
  42. this.state = {
  43. allProDatas: [],
  44. priceCompany: false,
  45. listRowBool: true,
  46. filterIndex1: 0,
  47. filterIndex2: 0,
  48. collapsed: true,
  49. collapsed1: false,
  50. collapsed2: false,
  51. gridStyle: {
  52. viewWid: {
  53. width: width,
  54. height: width * 0.4 + 1,
  55. borderBottomColor: '#F5F5F5',
  56. borderBottomWidth: 1 / PixelRatio.get(),
  57. },
  58. imgWid: {
  59. width: width * 0.4,
  60. height: width * 0.4,
  61. },
  62. },
  63. // searchCondition: {
  64. isNew: false,
  65. productLineId: ProductLineData.productLineId,
  66. productLineName: ProductLineData.productLineName,
  67. keyWord: props.navigation.state.params.searchval,
  68. organizationId: AllData.saleOrganizationId,
  69. organizationName: AllData.saleOrganizationName,
  70. Loading: false,
  71. // }
  72. }
  73. this.page = 0
  74. this.size = 10
  75. }
  76. componentDidMount = () => {
  77. this.props.dispatch(
  78. createAction('mine/getCusSup')({
  79. customerId: CUSTOMERINFO.id,
  80. customerRankCode: CUSTOMERINFO.customerRankCode,
  81. addDefaultData: 'productLine',
  82. })
  83. )
  84. this.props.dispatch(
  85. createAction('search/searchGoodsAll')({
  86. comeFrom: 'Filter',
  87. actionData: [],
  88. pageInfo: { page: 0, size: this.size },
  89. searchInfo: this.SearchVal(),
  90. })
  91. )
  92. this.setState({ keyWord: this.props.navigation.state.params.searchval })
  93. }
  94. onRefresh() {
  95. this._SearchGood()
  96. }
  97. gotoDetail = () => {
  98. this.props.dispatch(NavigationActions.navigate({ routeName: 'Detail' }))
  99. }
  100. toggleExpanded(e) {
  101. if (!this.state.collapsed1 && !this.state.collapsed2) {
  102. e == '1'
  103. ? this.setState({
  104. collapsed: !this.state.collapsed,
  105. collapsed1: !this.state.collapsed1,
  106. })
  107. : this.setState({
  108. collapsed: !this.state.collapsed,
  109. collapsed2: !this.state.collapsed2,
  110. })
  111. } else {
  112. this.state.collapsed1
  113. ? e == '1'
  114. ? this.setState({
  115. collapsed: !this.state.collapsed,
  116. collapsed1: !this.state.collapsed1,
  117. })
  118. : this.setState({
  119. collapsed1: !this.state.collapsed1,
  120. collapsed2: !this.state.collapsed2,
  121. })
  122. : e == '1'
  123. ? this.setState({
  124. collapsed1: !this.state.collapsed1,
  125. collapsed2: !this.state.collapsed2,
  126. })
  127. : this.setState({
  128. collapsed: !this.state.collapsed,
  129. collapsed2: !this.state.collapsed2,
  130. })
  131. }
  132. }
  133. filterIndexfun(item, selnum) {
  134. if (selnum == '1') {
  135. this.state.productLineId = item.item.productLineId
  136. this.setState({
  137. filterIndex1: item.index,
  138. productLineName: item.item.productLineName,
  139. productLineId: item.item.productLineId,
  140. collapsed: !this.state.collapsed,
  141. collapsed1: !this.state.collapsed1,
  142. })
  143. } else {
  144. this.state.organizationId = item.item.saleOrganizationId
  145. this.setState({
  146. filterIndex2: item.index,
  147. organizationName: item.item.saleOrganizationName,
  148. organizationId: item.item.saleOrganizationId,
  149. collapsed: !this.state.collapsed,
  150. collapsed2: !this.state.collapsed2,
  151. })
  152. }
  153. this.onRefresh()
  154. }
  155. filterRender(item) {
  156. if (this.state.collapsed1 && !this.state.collapsed2) {
  157. return (
  158. <TouchableOpacity
  159. key={item.item.id}
  160. style={{
  161. padding: 10,
  162. }}
  163. onPress={() => this.filterIndexfun(item, '1')}
  164. >
  165. {this.state.filterIndex1 == item.index ? (
  166. <View
  167. style={{
  168. flexDirection: 'row',
  169. justifyContent: 'space-between',
  170. }}
  171. >
  172. <Text style={{ color: 'red', alignSelf: 'center' }}>
  173. {item.item.productLineName}
  174. </Text>
  175. <Icon name="icon-icon-duigou" size={20} color={'red'} />
  176. </View>
  177. ) : (
  178. <View
  179. style={{
  180. flexDirection: 'row',
  181. justifyContent: 'space-between',
  182. paddingVertical: 5,
  183. }}
  184. >
  185. <Text style={{ alignSelf: 'center', color: '#333' }}>
  186. {item.item.productLineName}
  187. </Text>
  188. </View>
  189. )}
  190. </TouchableOpacity>
  191. )
  192. } else {
  193. return (
  194. <TouchableOpacity
  195. key={item.item.id}
  196. style={{
  197. padding: 10,
  198. }}
  199. onPress={() => this.filterIndexfun(item, '2')}
  200. >
  201. {this.state.filterIndex2 == item.index ? (
  202. <View
  203. style={{
  204. flexDirection: 'row',
  205. justifyContent: 'space-between',
  206. }}
  207. >
  208. <Text style={{ color: 'red', alignSelf: 'center' }}>
  209. {item.item.saleOrganizationName}
  210. </Text>
  211. <Icon name="icon-icon-duigou" size={20} color={'red'} />
  212. </View>
  213. ) : (
  214. <View
  215. style={{
  216. flexDirection: 'row',
  217. justifyContent: 'space-between',
  218. paddingVertical: 5,
  219. }}
  220. >
  221. <Text style={{ alignSelf: 'center', color: '#333' }}>
  222. {item.item.saleOrganizationName}
  223. </Text>
  224. </View>
  225. )}
  226. </TouchableOpacity>
  227. )
  228. }
  229. }
  230. checkClick(bool, checkname) {
  231. switch (checkname) {
  232. case 'newpro':
  233. this.state.isNew = bool
  234. this.setState({ isNew: bool })
  235. break
  236. case 'inventory':
  237. console.log('inventory>>>>' + bool)
  238. break
  239. case 'hotsale':
  240. console.log('hotsale>>>>>' + bool)
  241. break
  242. }
  243. // this._SearchGood();
  244. this.onRefresh()
  245. }
  246. SearchVal() {
  247. let searchVal = {}
  248. searchVal = {
  249. search_customerId: CUSTOMERINFO.id,
  250. search_customerRankCode: CUSTOMERINFO.customerRankCode,
  251. search_EQ_isEnable: 1,
  252. // search_EQ_isOptional: 0,
  253. // search_EQ_enableStrucManage: 0
  254. }
  255. if (this.state.isNew) {
  256. searchVal.search_EQ_isNew = 1
  257. }
  258. if (this.state.productLineId) {
  259. searchVal.search_EQ_productLineId = this.state.productLineId
  260. }
  261. if (this.state.keyWord) {
  262. searchVal.search_keywords = this.state.keyWord
  263. }
  264. if (this.state.organizationId) {
  265. searchVal.search_organizationId = this.state.organizationId
  266. }
  267. return searchVal
  268. }
  269. _SearchGood() {
  270. this.props.dispatch(
  271. createAction('search/searchGoodsAll')({
  272. comeFrom: 'Filter',
  273. actionData: [],
  274. pageInfo: { page: 0, size: this.size },
  275. searchInfo: this.SearchVal(),
  276. })
  277. )
  278. this.page = 0
  279. }
  280. listRowCol() {
  281. if (this.state.listRowBool) {
  282. this.setState({
  283. listRowBool: !this.state.listRowBool,
  284. gridStyle: {
  285. viewWid: {
  286. borderRightColor: '#F5F5F5',
  287. borderRightWidth: 1 / PixelRatio.get(),
  288. borderBottomColor: '#F5F5F5',
  289. borderBottomWidth: 1 / PixelRatio.get(),
  290. width: width / 2,
  291. height: width / 2 + 110,
  292. },
  293. imgWid: {
  294. width: width / 2 - 1,
  295. height: width / 2,
  296. },
  297. },
  298. })
  299. } else {
  300. this.setState({
  301. listRowBool: !this.state.listRowBool,
  302. gridStyle: {
  303. viewWid: {
  304. width: width,
  305. height: width * 0.4 + 1,
  306. borderBottomColor: '#F5F5F5',
  307. borderBottomWidth: 1 / PixelRatio.get(),
  308. },
  309. imgWid: {
  310. width: width * 0.4,
  311. height: width * 0.4,
  312. },
  313. },
  314. })
  315. }
  316. }
  317. _refreshPlist(data) {
  318. this.state.keyWord = data
  319. this.setState({ keyWord: data })
  320. this.onRefresh()
  321. }
  322. render() {
  323. let selectcolor1, selectcolor2
  324. this.state.collapsed1 && !this.state.collapsed2
  325. ? (selectcolor1 = '#E14C46')
  326. : (selectcolor1 = '#333')
  327. this.state.collapsed2 && !this.state.collapsed1
  328. ? (selectcolor2 = '#E14C46')
  329. : (selectcolor2 = '#333')
  330. const {
  331. appTheme,
  332. listDatas,
  333. totalPages,
  334. shopListIds,
  335. SupplierInfo,
  336. productRefs,
  337. searchRefresh,
  338. } = this.props
  339. let filterData = []
  340. !this.state.collapsed1 && this.state.collapsed2
  341. ? (filterData = SupplierInfo)
  342. : (filterData = productRefs)
  343. return (
  344. <View
  345. style={[
  346. styles.container,
  347. { backgroundColor: appTheme.backgroundColor },
  348. ]}
  349. >
  350. <StatusBar
  351. animated={true}
  352. barStyle={appTheme.barStyle}
  353. backgroundColor={'transparent'}
  354. translucent={true}
  355. />
  356. <View
  357. style={{
  358. width: width,
  359. // height: 60,
  360. height: HEADERSTYLE.height,
  361. backgroundColor: '#FFF',
  362. flexDirection: 'row',
  363. justifyContent: 'space-between',
  364. paddingHorizontal: 10,
  365. // paddingBottom: 5
  366. // borderBottomColor: "#DDD",
  367. // borderBottomWidth: 1 / PixelRatio.get()
  368. }}
  369. >
  370. <TouchableOpacity
  371. style={{ alignSelf: 'flex-end', paddingBottom: 4 }}
  372. onPress={() => this.props.dispatch(NavigationActions.back())}
  373. >
  374. <Icon
  375. name="icon-icon-fanhui"
  376. // style={{ transform: [{ rotate: "90deg" }] }}
  377. size={24}
  378. color={'#666'}
  379. />
  380. </TouchableOpacity>
  381. <View style={{ flexDirection: 'row' }}>
  382. <Input
  383. touchBool={true}
  384. touchInput={() => this.mdl._openModal(this.state.keyWord)}
  385. style={{
  386. height: 28,
  387. width: width / 1.36,
  388. borderRadius: width / 2,
  389. alignSelf: 'flex-end',
  390. paddingLeft: 14,
  391. marginBottom: 4,
  392. }}
  393. placeholder={this.state.keyWord || '请输入商品名称或商品编码'}
  394. textInputBacg={'#EEE'}
  395. iconColor={'#999'}
  396. placeholderTextColor={'#999'}
  397. // onchangeFn={e => {
  398. // console.log(e);
  399. // }}
  400. />
  401. <TouchableOpacity
  402. onPress={() =>
  403. this.props.dispatch(
  404. NavigationActions.navigate({ routeName: 'Replenishment' })
  405. )
  406. }
  407. style={{
  408. alignSelf: 'flex-end',
  409. marginLeft: 8,
  410. }}
  411. >
  412. <Icon name="icon-buhuo" size={32} color={'#666'} />
  413. </TouchableOpacity>
  414. </View>
  415. </View>
  416. <View
  417. style={{
  418. height: 40,
  419. flexDirection: 'row',
  420. backgroundColor: '#FFF',
  421. alignItems: 'center',
  422. }}
  423. >
  424. <TouchableOpacity
  425. style={{
  426. width: width / 2 - 1,
  427. alignItems: 'center',
  428. }}
  429. onPress={() => {
  430. this.toggleExpanded('1')
  431. }}
  432. >
  433. <View
  434. style={{
  435. flexDirection: 'row',
  436. }}
  437. >
  438. <Text style={{ fontSize: 13, color: selectcolor1 }}>
  439. {this.state.productLineName}
  440. </Text>
  441. <Icon
  442. name="icon-icon-xialaxiaosanjiao"
  443. size={13}
  444. style={{ marginLeft: 5 }}
  445. color={selectcolor1}
  446. />
  447. </View>
  448. </TouchableOpacity>
  449. <View style={{ height: 20, width: 1, backgroundColor: '#DDD' }} />
  450. <TouchableOpacity
  451. style={{
  452. width: width / 2,
  453. alignItems: 'center',
  454. }}
  455. onPress={() => {
  456. this.toggleExpanded('2')
  457. }}
  458. >
  459. <View
  460. style={{
  461. flexDirection: 'row',
  462. }}
  463. >
  464. <Text
  465. style={{
  466. fontSize: 13,
  467. color: selectcolor2,
  468. }}
  469. >
  470. {this.state.organizationName}
  471. </Text>
  472. <Icon
  473. name="icon-icon-xialaxiaosanjiao"
  474. size={13}
  475. style={{ marginLeft: 5 }}
  476. color={selectcolor2}
  477. />
  478. </View>
  479. </TouchableOpacity>
  480. </View>
  481. <View
  482. style={{
  483. backgroundColor: '#FFF',
  484. borderBottomColor: '#DDD',
  485. borderBottomWidth: 1 / PixelRatio.get(),
  486. borderTopColor: '#DDD',
  487. borderTopWidth: 1 / PixelRatio.get(),
  488. height: 40,
  489. flexDirection: 'row',
  490. // justifyContent: "space-around"
  491. // 暂时
  492. justifyContent: 'flex-end',
  493. paddingRight: 20,
  494. }}
  495. >
  496. <TouchableOpacity
  497. style={{
  498. flexDirection: 'row',
  499. alignSelf: 'center',
  500. marginLeft: 10,
  501. }}
  502. onPress={() => this.sortPrice()}
  503. >
  504. <Text style={{ fontSize: 12, color: '#333', marginTop: 5 }}>
  505. {/* 价格 */}
  506. </Text>
  507. {/* <Icon name=""/> */}
  508. </TouchableOpacity>
  509. <Checkbox
  510. shape="square"
  511. checked={this.state.isNew}
  512. checkBoxColor={'#E14C46'}
  513. size={14}
  514. labelStyle={{
  515. fontSize: 12,
  516. marginTop: 11,
  517. color: '#333',
  518. }}
  519. label={'新品'}
  520. onChange={a => this.checkClick(a, 'newpro')}
  521. />
  522. {/* <Checkbox
  523. shape="square"
  524. checked={this.state.isNew}
  525. checkBoxColor={"#E14C46"}
  526. size={14}
  527. labelStyle={{
  528. fontSize: 12,
  529. marginTop: 11,
  530. color: "#333"
  531. }}
  532. label={"新品"}
  533. onChange={a => this.checkClick(a, "newpro")}
  534. />
  535. <Checkbox
  536. shape="square"
  537. checked={true}
  538. checkBoxColor={"#E14C46"}
  539. size={14}
  540. labelStyle={{ fontSize: 12, marginTop: 11, color: "#333" }}
  541. label={"促销"}
  542. onChange={a => this.checkClick(a, "hotsale")}
  543. />
  544. <Checkbox
  545. shape="square"
  546. checked={true}
  547. checkBoxColor={"#E14C46"}
  548. size={14}
  549. labelStyle={{
  550. fontSize: 12,
  551. marginTop: 11,
  552. color: "#333"
  553. }}
  554. label={"有库存"}
  555. onChange={a => this.checkClick(a, "inventory")}
  556. /> */}
  557. <TouchableOpacity
  558. onPress={() => this.listRowCol()}
  559. style={{ alignSelf: 'center', marginTop: 5, marginLeft: 20 }}
  560. >
  561. {this.state.listRowBool ? (
  562. // 列表形式
  563. <Icon
  564. name="icon-icon-shangpinqiapianzhanshi"
  565. size={22}
  566. color={'#666'}
  567. />
  568. ) : (
  569. // 宫格形式
  570. <Icon
  571. name="icon-icon-shangpinliebiaozhanshi"
  572. size={22}
  573. color={'#666'}
  574. />
  575. )}
  576. </TouchableOpacity>
  577. </View>
  578. <Grid
  579. ref={gridPull => (this.gridPull = gridPull)}
  580. titleBool={false}
  581. listRowBool={this.state.listRowBool}
  582. // data={this.state.allProDatas}
  583. data={listDatas}
  584. // 名称key
  585. nameKey="displayName"
  586. extraData={this.state}
  587. // 图片key
  588. pictureKey="mainPictureFileUrl"
  589. // 价格key
  590. priceKey="baseDiscountPrice"
  591. // key值 一般输入code
  592. keyext="code"
  593. // 编码
  594. codeKey="code"
  595. // 库存
  596. invenKey="stock"
  597. viewWid={this.state.gridStyle.viewWid}
  598. imgWid={this.state.gridStyle.imgWid}
  599. imageTouch={e => {
  600. this.props.dispatch(createAction('detail/gotoDetail')({ item: e }))
  601. // this.props.dispatch(
  602. // createAction("home/getRecentView")({ recentView: e })
  603. // );
  604. }}
  605. shoppingCart={item => {
  606. if(item.goodsAttrVals && item.goodsAttrVals.length) {
  607. this.plToast.show('该商品为调色商品,请到商品详情页面下单');
  608. return;
  609. }
  610. if(!item.baseDiscountPrice) {
  611. this.plToast.show('商品暂无价格,无法加入购物车');
  612. return;
  613. }
  614. let postData = dataModel(
  615. item,
  616. CUSTOMERINFO.id,
  617. CUSTOMERINFO.customerRankCode
  618. )
  619. this.props.dispatch(createAction('shoppingcart/addShop')(postData))
  620. }}
  621. SearchVal={this.SearchVal()}
  622. onEndReached={() => {
  623. if (this.props.showFoot != 0) {
  624. return
  625. }
  626. if (this.page != 1 && this.page >= totalPages) {
  627. return
  628. } else {
  629. this.page++
  630. }
  631. this.props.dispatch(
  632. createAction('search/searchGoodsAll')({
  633. comeFrom: 'Filter',
  634. actionData: listDatas,
  635. pageInfo: { page: this.page, size: this.size },
  636. searchInfo: this.SearchVal(),
  637. forUse: 'slipOn',
  638. })
  639. )
  640. }}
  641. onRefresh={() => this.onRefresh()}
  642. Parentprops={this.props}
  643. shopListIds={shopListIds}
  644. />
  645. {/* 遮罩 */}
  646. {!this.state.collapsed ? (
  647. <View
  648. style={{
  649. position: 'absolute',
  650. top: 110,
  651. height: 1000,
  652. width: width,
  653. backgroundColor: '#000',
  654. opacity: 0.5,
  655. }}
  656. />
  657. ) : null}
  658. {/* 产品线/供应商-折叠*/}
  659. <View
  660. style={{
  661. position: 'absolute',
  662. top: 101,
  663. left: 0,
  664. backgroundColor: '#FFF',
  665. width: width,
  666. }}
  667. >
  668. <Collapsible collapsed={this.state.collapsed}>
  669. <FlatList
  670. data={filterData}
  671. extraData={this.state}
  672. keyExtractor={(item, index) => index}
  673. renderItem={(item, index) => this.filterRender(item, index)}
  674. />
  675. </Collapsible>
  676. </View>
  677. <SearchModal
  678. cb={data => {
  679. this._refreshPlist(data)
  680. }}
  681. ref={mdl => (this.mdl = mdl)}
  682. dispatch={this.props.dispatch}
  683. comFrom={'CommodityShowbase'}
  684. defaultValue={this.props.defaultValue || '请输入商品名称或商品编码'}
  685. // fuleipro={this.state.footerdata}
  686. />
  687. <ToastView
  688. onDismiss={() => {
  689. //alert('toast消失了');
  690. }}
  691. ref={(element) => {
  692. this.plToast = element;
  693. }}
  694. />
  695. </View>
  696. )
  697. }
  698. }
  699. const styles = StyleSheet.create({
  700. container: {
  701. flex: 1,
  702. },
  703. icon: {
  704. width: 32,
  705. height: 32,
  706. },
  707. })
  708. export default CommodityShowbase