Commodity.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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. } from 'react-native'
  14. import { connect } from 'react-redux'
  15. import { CarouselHorizontal } from '../../../components/carousel'
  16. import { NavigationActions, createAction } from '../../../utils'
  17. import { ScaleUtil, accMul } from '../../../utils/utils'
  18. import { ImageBaseUrl } from '../../../utils/fetch/Fetchx'
  19. import Icon from '../../../components/Iconfont/Iconfont'
  20. import Specification from './Specification'
  21. import Promotions from './Promotions'
  22. import morePng from '../../../static/images/ic-moredian.png'
  23. import AddShopModel from '../../common/datamodel/dataModel'
  24. import Toast from 'react-native-root-toast'
  25. const { width, height } = Dimensions.get('window')
  26. @connect(({ theme, detail, optional, shoppingcart }) => ({
  27. ...theme,
  28. ...detail,
  29. ...optional,
  30. ...shoppingcart,
  31. }))
  32. class Commodity extends Component {
  33. constructor() {
  34. super()
  35. this.state = {
  36. ScrollLocked: false,
  37. }
  38. }
  39. componentDidMount = () => {
  40. let flagone = false,
  41. flagsec = false
  42. this.props
  43. .dispatch(
  44. createAction('detail/getSpec')({
  45. product: this.props.detailDatas.productId,
  46. id: this.props.detailDatas.id,
  47. customer: CUSTOMERINFO.id,
  48. })
  49. )
  50. .finally(() => {
  51. if (this.props.detailDatas) {
  52. flagone = true
  53. }
  54. })
  55. this.props
  56. .dispatch(
  57. createAction('optional/optionalByGoodIdSaga')({
  58. product: this.props.detailDatas.id,
  59. })
  60. )
  61. .finally(() => {
  62. if (this.props.detailSpec) {
  63. flagsec = true
  64. }
  65. })
  66. this.props
  67. .dispatch(
  68. createAction('optional/getColorByGroups')({
  69. id : this.props.detailDatas.id,
  70. groupId : "",
  71. colourCode : ""
  72. })
  73. )
  74. // if (
  75. // this.props.TabopenSpec &&
  76. // this.props.navigate.state.parame.userFor == "openModel" &&
  77. // flagone &&
  78. // flagsec
  79. // ) {
  80. // this.openSpecification(
  81. // this.props.detailSpec,
  82. // this.props.detailDatas,
  83. // this.props.detailPicts
  84. // );
  85. // }
  86. // console.log(this.props, 422);
  87. }
  88. gotoDetail = () => {
  89. this.props.dispatch(NavigationActions.navigate({ routeName: 'Detail' }))
  90. }
  91. openSpecification(detailSpec, detailDatas, detailPicts,colorGroups) {
  92. let showData = {}
  93. showData.price = detailDatas.baseDiscountPrice || 0
  94. // showData.price = detailDatas.salePrice || detailDatas.basePrice;
  95. // showData.price = detailDatas.salePrice;
  96. showData.picture = detailPicts && detailPicts[0]
  97. this.mdCategory._openModalCate(true, detailSpec, showData, detailDatas,colorGroups)
  98. }
  99. PictureViews(Arr) {
  100. let pictures = []
  101. if (Arr && Arr.length > 0) {
  102. Arr.forEach((item, index) =>
  103. pictures.push(
  104. <Image
  105. key={index}
  106. source={{ uri: ImageBaseUrl + item }}
  107. resizeMode="cover"
  108. style={{ width: width, height: width - 60 }}
  109. />
  110. )
  111. )
  112. }
  113. return pictures
  114. }
  115. ProductInfo(detailDatas) {
  116. const ggdata2 = [
  117. {
  118. id: 1,
  119. key: '重量',
  120. value: detailDatas.grossWeight,
  121. unit: detailDatas.weightUnitName,
  122. precision: detailDatas.weightUnitPrecision,
  123. },
  124. // {
  125. // id: 2,
  126. // key: '体积',
  127. // value: detailDatas.volume,
  128. // unit: detailDatas.volumeUnitName,
  129. // precision: detailDatas.volumeUnitPrecision,
  130. // },
  131. // { id: 3, key: "主数量", value: "-", unit: detailDatas.assistUnitName }
  132. ]
  133. let testdata = []
  134. for (let val of ggdata2) {
  135. testdata.push(
  136. <Text
  137. key={val.id}
  138. style={{
  139. fontSize: 12,
  140. lineHeight: 17,
  141. letterSpacing: 0.14,
  142. color: '#999',
  143. }}
  144. >
  145. {val.key}{' '}
  146. <Text
  147. style={{
  148. fontSize: 12,
  149. lineHeight: 17,
  150. letterSpacing: 0.14,
  151. color: '#333',
  152. }}
  153. >
  154. {ScaleUtil(val.value, val.precision)}
  155. {val.unit}
  156. </Text>
  157. </Text>
  158. )
  159. }
  160. return testdata
  161. }
  162. render() {
  163. const { detailDatas, detailPicts, detailSpec,colorGroups } = this.props
  164. console.log(detailDatas)
  165. let attrVals = []
  166. if (
  167. detailDatas &&
  168. detailDatas.goodsAttrVals &&
  169. detailDatas.goodsAttrVals.length > 0
  170. ) {
  171. detailDatas.goodsAttrVals.map(data => {
  172. if (!data.isOptionalAttr) {
  173. attrVals.push(data.attrValName)
  174. }
  175. })
  176. }
  177. return (
  178. <ScrollView
  179. showsHorizontalScrollIndicator={false}
  180. tabLabel={this.props.tabLabel}
  181. style={{ backgroundColor: '#EEE' }}
  182. scrollEnabled={!this.state.ScrollLocked}
  183. >
  184. <View style={styles.card}>
  185. {/* 轮播图 */}
  186. <View style={styles.image}>
  187. <CarouselHorizontal
  188. panResponBool={true}
  189. width={width}
  190. enableScroll={true}
  191. tintColor={'#E14C46'}
  192. touchArrStyle={{
  193. bottom: '8%',
  194. flexDirection: 'row',
  195. }}
  196. entertouchItemStyle={{
  197. marginRight: 12,
  198. width: 14,
  199. height: 8,
  200. borderRadius: 5,
  201. }}
  202. touchItemStyle={{
  203. backgroundColor: '#D8D8D8',
  204. opacity: 0.5,
  205. marginRight: 12,
  206. width: 8,
  207. height: 8,
  208. borderRadius: 4,
  209. }}
  210. imgTouch={a => {
  211. console.log(a)
  212. }}
  213. >
  214. {this.PictureViews(detailPicts)}
  215. </CarouselHorizontal>
  216. </View>
  217. </View>
  218. {/* 商品信息 */}
  219. <View>
  220. <View
  221. style={{
  222. backgroundColor: '#FFF',
  223. paddingVertical: 12,
  224. paddingLeft: 20,
  225. paddingRight: 10,
  226. borderTopColor: '#DDD',
  227. borderTopWidth: 1 / PixelRatio.get(),
  228. }}
  229. >
  230. <View style={{ flexDirection: 'row' }}>
  231. <Text
  232. style={{
  233. flex: 1,
  234. marginRight: 20,
  235. fontSize: 14,
  236. lineHeight: 20,
  237. color: '#333',
  238. }}
  239. >
  240. {detailDatas.displayName}
  241. </Text>
  242. </View>
  243. <View
  244. style={{
  245. flexDirection: 'row',
  246. marginTop: 10,
  247. marginRight: 10,
  248. }}
  249. >
  250. <Text style={{ fontSize: 20, lineHeight: 28, color: '#E14C46' }}>
  251. {CURRENCY.currencySign}
  252. {detailDatas.baseDiscountPrice || 0}
  253. </Text>
  254. <Text
  255. style={{
  256. marginTop: 10,
  257. marginLeft: 23,
  258. fontSize: 14,
  259. color: '#ccc',
  260. textDecorationLine: 'line-through',
  261. }}
  262. >
  263. {CURRENCY.currencySign}
  264. {detailDatas.basePrice || 0}
  265. </Text>
  266. </View>
  267. <View
  268. style={{
  269. flexDirection: 'column',
  270. justifyContent: 'space-between',
  271. marginTop: 10,
  272. marginRight: 10,
  273. }}
  274. >
  275. <View>
  276. <Text style={{ fontSize: 12, lineHeight: 17, color: '#666' }}>
  277. 编码:{detailDatas.code}
  278. </Text>
  279. </View>
  280. <View>
  281. <Text style={{ fontSize: 12, lineHeight: 17, color: '#666' }}>
  282. {/* 型号:{detailDatas.model?detailDatas.model.substring(0,10):""} */}
  283. 型号:{detailDatas.model?detailDatas.model:""}
  284. </Text>
  285. </View>
  286. <View>
  287. <Text style={{ fontSize: 12, lineHeight: 17, color: '#666' }}>
  288. 规格:{detailDatas.specification?(detailDatas.specification.split('/')[0]+'/'+detailDatas.basicUnitName):""}
  289. </Text>
  290. </View>
  291. {/* <Text
  292. style={{
  293. fontSize: 12,
  294. lineHeight: 17,
  295. color: '#666',
  296. }}
  297. >
  298. 库存:{detailDatas.stock || 9999}
  299. {detailDatas.orderUnitName}
  300. </Text> */}
  301. </View>
  302. </View>
  303. {/* 促销信息 */}
  304. {/* {detailDatas.isPromotion == 1 ? (
  305. <TouchableOpacity
  306. onPress={() => this.mdPromot._openModalCate(true)}
  307. style={{
  308. backgroundColor: '#FFF',
  309. marginTop: 10,
  310. flexDirection: 'row',
  311. paddingHorizontal: 20,
  312. paddingTop: 10,
  313. }}
  314. >
  315. <Text
  316. style={{
  317. fontSize: 12,
  318. lineHeight: 17,
  319. letterSpacing: 0.14,
  320. color: '#999',
  321. }}
  322. >
  323. 促销
  324. </Text>
  325. <View style={{ flex: 1, marginLeft: 5 }}>
  326. <FlatList
  327. keyExtractor={(item, index) => index}
  328. data={[
  329. { title: '满减', data: '满100件20' },
  330. { title: '满额返券', data: '全场满199元包邮' },
  331. { title: '组合', data: '搭配商品A可以立省30元' },
  332. ]}
  333. extraData={this.state}
  334. renderItem={({ item, index }) => (
  335. <View style={{ flexDirection: 'row', marginBottom: 10 }}>
  336. <View
  337. style={{
  338. paddingVertical: 2,
  339. paddingHorizontal: 8,
  340. borderRadius: 100,
  341. borderColor: '#E70013',
  342. borderWidth: 1 / PixelRatio.get(),
  343. }}
  344. >
  345. <Text
  346. style={{
  347. fontSize: 10,
  348. lineHeight: 14,
  349. letterSpacing: 0.14,
  350. color: '#E70013',
  351. }}
  352. >
  353. {item.title}
  354. </Text>
  355. </View>
  356. <Text
  357. style={{
  358. fontSize: 12,
  359. lineHeight: 17,
  360. color: '#333',
  361. marginLeft: 5,
  362. marginTop: 1,
  363. }}
  364. >
  365. {item.data}
  366. </Text>
  367. </View>
  368. )}
  369. />
  370. </View>
  371. <Image
  372. resizeMode="contain"
  373. source={morePng}
  374. style={{ width: 30, height: 18 }}
  375. />
  376. </TouchableOpacity>
  377. ) : null} */}
  378. {/* 规格 */}
  379. {(detailSpec &&
  380. Object.keys(detailSpec).length > 0 &&
  381. detailSpec.polyAttrsDtoList.length > 0) ||
  382. (detailDatas &&
  383. detailDatas.goodsAttrVals &&
  384. detailDatas.goodsAttrVals.length > 0) ||
  385. detailDatas.isOptional ? (
  386. <TouchableOpacity
  387. activeOpacity={1}
  388. onPress={() =>
  389. this.openSpecification(detailSpec, detailDatas, detailPicts,colorGroups)
  390. }
  391. style={{
  392. backgroundColor: '#FFF',
  393. marginTop: 10,
  394. paddingHorizontal: 20,
  395. paddingVertical: 12,
  396. flexDirection: 'row',
  397. justifyContent: 'space-between',
  398. }}
  399. >
  400. <View
  401. style={{
  402. flexDirection: 'row',
  403. width: width * 0.73,
  404. }}
  405. >
  406. <Text
  407. style={{
  408. fontSize: 12,
  409. lineHeight: 17,
  410. color: '#999',
  411. marginRight: 6,
  412. }}
  413. >
  414. 选择调色
  415. </Text>
  416. <Text
  417. style={{
  418. fontSize: 12,
  419. lineHeight: 17,
  420. color: '#333',
  421. marginTop: 1,
  422. }}
  423. >
  424. {attrVals.join(' | ')}
  425. </Text>
  426. </View>
  427. <Image
  428. resizeMode="contain"
  429. source={morePng}
  430. style={{ width: 24, height: 5, alignSelf: 'center' }}
  431. />
  432. </TouchableOpacity>
  433. ) : null}
  434. {/* 重量 信息等... */}
  435. <View
  436. style={{
  437. backgroundColor: '#FFF',
  438. marginTop: 10,
  439. paddingHorizontal: 20,
  440. paddingVertical: 12,
  441. flexDirection: 'row',
  442. justifyContent: 'space-between',
  443. }}
  444. >
  445. {this.ProductInfo(detailDatas)}
  446. </View>
  447. {/* 规格 */}
  448. <Specification
  449. cb={(cproductid, optionData, touch) => {
  450. touch == 'touchaddd'
  451. ? this.addToShopcartfen(cproductid, optionData)
  452. : this._cbClick(cproductid)
  453. }}
  454. ref={mdCategory => (this.mdCategory = mdCategory)}
  455. colorData= {this.props.colorData}
  456. />
  457. {/* 促销 */}
  458. <Promotions ref={mdPromot => (this.mdPromot = mdPromot)} />
  459. </View>
  460. </ScrollView>
  461. )
  462. }
  463. // 选配请求参数
  464. optionalPostModel(data, optionData) {
  465. let optResult = [],
  466. goodsAttrsObj = {},
  467. goodsOptVals = []
  468. goodsOptVals.push({
  469. attrValCode: optionData.chooseColor.children.attrValCode,
  470. attrValId: optionData.chooseColor.children.attrValId,
  471. attrValName: optionData.chooseColor.children.attrValName,
  472. goodsOptId: "",
  473. prodAttrStrucItemId: optionData.chooseColor.children.prodAttrStrucItemId,
  474. prodAttrStrucItemName: optionData.chooseColor.children.name
  475. })
  476. // optResult = optionData.map(item => {
  477. // goodsAttrsObj[item.isChoose.name] = item.isChoose.attrValName
  478. // goodsOptVals.push({
  479. // attrValCode: item.isChoose.attrValCode,
  480. // attrValId: item.isChoose.attrValId,
  481. // attrValName: item.isChoose.ttrValName,
  482. // goodsOptId: item.isChoose.id,
  483. // prodAttrStrucItemId: item.isChoose.name,
  484. // prodAttrStrucItemName: item.isChoose.prodAttrStrucItemName,
  485. // })
  486. // return `${item.isChoose.name}:${item.isChoose.attrValName}`
  487. // })
  488. const returnData = {
  489. goodsId: data.id,
  490. optResult: optionData[0].name+":"+optionData.chooseColor.children.attrValName,
  491. uniqueKey: data.id,
  492. goodsOptVals: goodsOptVals,
  493. }
  494. return { ...returnData, ...goodsAttrsObj }
  495. }
  496. // 规格添加购物车
  497. addToShopcartfen(orderNum, optionData) {
  498. let newGoodsAttrs = [],
  499. newDetailDatas = JSON.parse(JSON.stringify(this.props.detailDatas))
  500. newGoodsAttrs = newDetailDatas.goodsAttrVals.filter(
  501. item => !item.isOptionalAttr
  502. )
  503. newGoodsAttrs = newGoodsAttrs.concat(optionData)
  504. newDetailDatas.goodsAttrVals = newGoodsAttrs
  505. const saveOpt = this.optionalPostModel(newDetailDatas, optionData),
  506. postData = AddShopModel(
  507. newDetailDatas,
  508. CUSTOMERINFO.id,
  509. CUSTOMERINFO.customerRankCode
  510. )
  511. this.props
  512. .dispatch(
  513. createAction('optional/saveGoodsOpt')([{ goodsOptDtos: [saveOpt] }])
  514. )
  515. .finally(() => {
  516. if (this.props.goodsOpt && this.props.goodsOpt.length > 0) {
  517. const goodsOptIds = []
  518. this.props.goodsOpt.forEach(item => {
  519. item.goodsOptDtos.forEach(itemSec => {
  520. goodsOptIds.push(itemSec.id)
  521. })
  522. })
  523. postData.baseGoodsOptId = goodsOptIds.join()
  524. postData.baseGoodsOptValue = saveOpt.optResult
  525. postData.orderNum = orderNum
  526. postData.mainNum = accMul(postData.orderNum, postData.conversionRate)
  527. postData.ext04 = '1'
  528. postData.ext05 = saveOpt.goodsOptVals[0].attrValId
  529. this.props.dispatch(createAction('shoppingcart/addShop')(postData))
  530. this.getCartNum()
  531. this.mdCategory.closeModalCate()
  532. }
  533. })
  534. // postData.orderNum = orderNum;
  535. // postData.mainNum = accMul(postData.orderNum, postData.conversionRate);
  536. // this.props.dispatch(createAction("shoppingcart/addShop")(postData));
  537. // this.getCartNum();
  538. }
  539. getCartNum() {
  540. // 获取购物车数量
  541. this.props.dispatch(
  542. createAction('shoppingcart/getCartNum')({ customer: CUSTOMERINFO.id })
  543. )
  544. this.toast = Toast.show('加入购物车成功!', {
  545. position: toastHeight,
  546. })
  547. //this.mdCategory.closeModalCate()
  548. }
  549. //自由辅助属性回调函数
  550. async _cbClick(cproductid) {
  551. this.state.prodId = cproductid
  552. this.props.dispatch(
  553. createAction('detail/getDetail')({
  554. inFo: {
  555. id: cproductid,
  556. customer: CUSTOMERINFO.id,
  557. supplier: this.props.detailDatas.saleOrgId,
  558. },
  559. useFor: 'specification',
  560. refresh: this.mdCategory,
  561. })
  562. )
  563. // await this.funProductDetail();
  564. // await this.funPicture();
  565. // await this._queryIsFavourite(cproductid);
  566. //其中this.state.carouselInfos[0]&&this.state.carouselInfos[0].cslPic 先判断carouselInfos[0]是否有值,无值则不传
  567. // this.mdCategory._refreshdata(
  568. // this.state.cateData,
  569. // this.state.basePrice,
  570. // this.state.carouselInfos[0] && this.state.carouselInfos[0].cslPic
  571. // );
  572. }
  573. }
  574. const styles = StyleSheet.create({
  575. card: {
  576. flex: 1,
  577. },
  578. image: {
  579. height: width - 60,
  580. },
  581. })
  582. export default Commodity