Tab.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. import React, { Component } from 'react'
  2. import {
  3. StyleSheet,
  4. View,
  5. StatusBar,
  6. PixelRatio,
  7. TouchableOpacity,
  8. Text,
  9. Animated,
  10. Easing,
  11. } from 'react-native'
  12. import { connect } from 'react-redux'
  13. import ScrollableTabView from 'react-native-scrollable-tab-view'
  14. import { NavigationActions, createAction } from '../../../utils'
  15. import DetailTabBar from './TabBar'
  16. import Bubble from '../../../components/Bubble'
  17. import Icon from '../../../components/Iconfont/Iconfont'
  18. import Commodity from './Commodity'
  19. import Detail from './Details'
  20. import dataModel, { AddAttentModal } from '../../common/datamodel/dataModel'
  21. import Toast from 'react-native-root-toast'
  22. @connect(({ theme, detail, shoppingcart, attention }) => ({
  23. ...theme,
  24. ...detail,
  25. ...shoppingcart,
  26. ...attention,
  27. }))
  28. class CommodityDetail extends Component {
  29. constructor() {
  30. super()
  31. this.state = {
  32. isLocked: false,
  33. heightValue: new Animated.Value(0),
  34. widthValue: new Animated.Value(0),
  35. openSpec: false,
  36. }
  37. }
  38. componentDidMount = () => {
  39. this.props.dispatch(
  40. createAction('shoppingcart/getShoppingList')({
  41. params: {
  42. customer: CUSTOMERINFO.id,
  43. },
  44. })
  45. )
  46. this.props.dispatch(createAction('attention/getAttentionList')())
  47. // 获取购物车数量
  48. this.getCartNum()
  49. }
  50. getCartNum() {
  51. // 获取购物车数量
  52. this.props.dispatch(
  53. createAction('shoppingcart/getCartNum')({ customer: CUSTOMERINFO.id })
  54. )
  55. }
  56. render() {
  57. const {
  58. appTheme,
  59. detailDatas,
  60. TotalNum,
  61. attentData,
  62. shopListIds,
  63. } = this.props
  64. const aheight = this.state.heightValue.interpolate({
  65. inputRange: [0, 0.25, 0.5, 0.75, 1],
  66. outputRange: [0, 50, 75, 50, 0],
  67. })
  68. const awidth = this.state.heightValue.interpolate({
  69. inputRange: [0, 0.25, 0.5, 0.75, 1],
  70. outputRange: [100, 140, 160, 180, 200],
  71. })
  72. let attentGoodIds = [],
  73. shopCartShow = false
  74. if (attentData && attentData.length > 0) {
  75. attentData.map(data => {
  76. attentGoodIds.push(data.goodsId)
  77. })
  78. }
  79. if (detailDatas && detailDatas.id && attentGoodIds.length > 0) {
  80. if (attentGoodIds.indexOf(detailDatas.id) !== -1) {
  81. detailDatas.isAttention = true
  82. }
  83. }
  84. if (
  85. shopListIds &&
  86. shopListIds.length > 0 &&
  87. shopListIds.indexOf(detailDatas.id) !== -1
  88. ) {
  89. shopCartShow = true
  90. }
  91. return (
  92. <View
  93. style={{
  94. flex: 1,
  95. backgroundColor: this.state.backgroundColor,
  96. }}
  97. >
  98. <StatusBar
  99. animated={true}
  100. barStyle={appTheme.barStyle}
  101. backgroundColor={'transparent'}
  102. translucent={true}
  103. />
  104. <View style={{ height: 20, backgroundColor: '#FFF' }} />
  105. <View style={{ flex: 1 }}>
  106. <ScrollableTabView
  107. locked={true}
  108. style={{ backgroundColor: '#FFF' }}
  109. initialPage={0}
  110. renderTabBar={() => <DetailTabBar dispatch={this.props.dispatch} />}
  111. scrollEnabled={this.state.isLocked}
  112. // onChangeTab={e => {
  113. // console.log(e);
  114. // }}
  115. >
  116. <Commodity
  117. // userFor={this.props.na}
  118. openSpecification={e => {
  119. console.log(e)
  120. }}
  121. tabLabel="商品"
  122. TabopenSpec={this.state.openSpec}
  123. // style={styles.tabView}
  124. />
  125. {detailDatas.description ? <Detail tabLabel="详情" /> : null}
  126. {/* <DetailComponent tabLabel="子件" /> */}
  127. </ScrollableTabView>
  128. </View>
  129. <Animated.Image
  130. source={require('../../../static/images/MineHome-5.png')}
  131. style={{
  132. width: 20,
  133. height: 20,
  134. position: 'absolute',
  135. bottom: aheight,
  136. right: awidth,
  137. }}
  138. />
  139. <View
  140. style={{
  141. height: 45 + HEADERSTYLE.paddingBottom,
  142. paddingBottom: HEADERSTYLE.paddingBottom,
  143. backgroundColor: '#FFF',
  144. borderTopColor: '#ddd',
  145. borderTopWidth: 1 / PixelRatio.get(),
  146. flexDirection: 'row',
  147. justifyContent: 'space-between',
  148. }}
  149. >
  150. {/* 关注 */}
  151. <TouchableOpacity
  152. onPress={() => {
  153. if (detailDatas.isAttention) {
  154. detailDatas.isAttention = false
  155. this.props
  156. .dispatch(
  157. createAction('attention/delAttentionByGoodsId')({
  158. goodsId: detailDatas.id,
  159. saleOrg: detailDatas.saleOrgId,
  160. })
  161. )
  162. .catch(err => (detailDatas.isAttention = true))
  163. } else {
  164. let returnData = AddAttentModal(
  165. detailDatas,
  166. CUSTOMERINFO.id,
  167. CUSTOMERINFO.customerRankCode
  168. )
  169. this.props.dispatch(
  170. createAction('attention/addAttention')(returnData)
  171. )
  172. }
  173. }}
  174. style={{
  175. flex: 2,
  176. alignSelf: 'center',
  177. alignItems: 'center',
  178. }}
  179. >
  180. {detailDatas.isAttention ? (
  181. <View>
  182. <Icon
  183. name="icon-icon-guanzhuyiguanzhu"
  184. size={24}
  185. color="#E70013"
  186. style={{ alignSelf: 'center' }}
  187. />
  188. <Text
  189. style={{
  190. fontSize: 10,
  191. color: '#666',
  192. lineHeight: 14,
  193. }}
  194. >
  195. 取消关注
  196. </Text>
  197. </View>
  198. ) : (
  199. <View>
  200. <Icon name="icon-icon-qiuguanzhu" size={24} color={'#333'} />
  201. <Text
  202. style={{
  203. fontSize: 10,
  204. color: '#666',
  205. lineHeight: 14,
  206. alignSelf: 'center',
  207. }}
  208. >
  209. 关注
  210. </Text>
  211. </View>
  212. )}
  213. </TouchableOpacity>
  214. {/* 购物车 */}
  215. <View
  216. style={{
  217. flex: 2,
  218. borderLeftColor: '#EEE',
  219. borderLeftWidth: 1 / PixelRatio.get(),
  220. }}
  221. >
  222. <TouchableOpacity
  223. onPress={() => {
  224. this.props.dispatch(
  225. NavigationActions.navigate({
  226. routeName: 'ShoppingCartHome',
  227. params: 'otherToShop',
  228. })
  229. )
  230. }}
  231. style={{
  232. flex: 1,
  233. paddingHorizontal: 8,
  234. alignSelf: 'center',
  235. justifyContent: 'center',
  236. }}
  237. >
  238. <Icon
  239. name="icon-icon-gouwuche"
  240. size={24}
  241. color={'#333'}
  242. style={{ alignSelf: 'center' }}
  243. />
  244. <Bubble
  245. bubbleColor={'#E14C46'}
  246. size={12}
  247. fontSize={9}
  248. style={{ position: 'absolute', right: 0, top: 4 }}
  249. value={TotalNum}
  250. />
  251. <Text style={{ fontSize: 10, lineHeight: 14, color: '#666' }}>
  252. 购物车
  253. </Text>
  254. </TouchableOpacity>
  255. </View>
  256. {/* 加入购物车 */}
  257. <TouchableOpacity
  258. onPress={() => {
  259. // if (!detailDatas.isOptional) {
  260. this.state.heightValue.setValue(0)
  261. this.state.widthValue.setValue(0)
  262. Animated.parallel([
  263. Animated.timing(this.state.heightValue, {
  264. toValue: 1,
  265. duration: 1000,
  266. easing: Easing.linear, // 线性的渐变函数
  267. }),
  268. ]).start(() => {
  269. let postData = dataModel(
  270. detailDatas,
  271. CUSTOMERINFO.id,
  272. CUSTOMERINFO.customerRankCode
  273. )
  274. this.props.dispatch(
  275. createAction('shoppingcart/addShop')(postData)
  276. ).finally(() => {
  277. this.toast = Toast.show('加入购物车成功!', {
  278. position: toastHeight,
  279. })
  280. })
  281. this.getCartNum()
  282. })
  283. // } else {
  284. // if (this.toast) {
  285. // Toast.hide(this.toast)
  286. // }
  287. // this.toast = Toast.show('请求选配界面加入购物车', {
  288. // position: toastHeight,
  289. // })
  290. // }
  291. }}
  292. style={{
  293. flex: 3,
  294. backgroundColor: '#E70013',
  295. }}
  296. >
  297. <View
  298. style={{
  299. flex: 1,
  300. alignSelf: 'center',
  301. justifyContent: 'center',
  302. }}
  303. >
  304. <Text
  305. style={{
  306. fontSize: 14,
  307. color: '#FFF',
  308. lineHeight: 20,
  309. }}
  310. >
  311. 加入购物车
  312. </Text>
  313. </View>
  314. </TouchableOpacity>
  315. </View>
  316. </View>
  317. )
  318. }
  319. }
  320. const styles = StyleSheet.create({
  321. tabView: {
  322. flex: 1,
  323. backgroundColor: 'rgba(0,0,0,0.01)',
  324. },
  325. })
  326. export default CommodityDetail