SelectAdress.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import React, { Component } from 'react'
  2. import {
  3. StyleSheet,
  4. View,
  5. Image,
  6. StatusBar,
  7. Text,
  8. TouchableOpacity,
  9. PixelRatio,
  10. FlatList,
  11. } from 'react-native'
  12. import { connect } from 'react-redux'
  13. import Icon from '../../components/Iconfont/Iconfont'
  14. import { NavigationActions, createAction } from '../../utils'
  15. import { HeaderView } from '../common/HeaderView'
  16. @connect(({ theme, mine }) => ({ ...theme, ...mine }))
  17. class SelectAdress extends Component {
  18. constructor() {
  19. super()
  20. this.state = { adress: [], adressDefault: {} }
  21. }
  22. componentDidMount() {
  23. this.props.dispatch(
  24. createAction('mine/getAdress')({ customer: CUSTOMERINFO.id })
  25. )
  26. // this.setState({ adress: adress });
  27. }
  28. setDefault(item, addressData) {
  29. let adress = addressData
  30. for (val of adress) {
  31. val.isDefault = 0
  32. }
  33. adress[item.index].isDefault = 1
  34. this.setState({ adress: adress, adressDefault: adress[item.index] })
  35. }
  36. touchItem(item) {
  37. this.props.dispatch(NavigationActions.back())
  38. this.props.navigation.state.params(item)
  39. }
  40. _renderItem(item, addressData) {
  41. return (
  42. <TouchableOpacity
  43. style={{
  44. padding: 10,
  45. flexDirection: 'row',
  46. flex: 1,
  47. backgroundColor: '#FFF',
  48. marginBottom: 10,
  49. }}
  50. onPress={() => this.touchItem(item)}
  51. >
  52. {item.item.isDefault == 1 ? (
  53. <Icon
  54. name="icon-icon-duigou"
  55. size={24}
  56. color={'#E14C46'}
  57. style={{ alignSelf: 'center' }}
  58. />
  59. ) : null}
  60. <View style={{ paddingLeft: 10, flex: 1 }}>
  61. <View style={{ flexDirection: 'row' }}>
  62. <Text style={{ fontSize: 15, lineHeight: 21, color: '#333' }}>
  63. {item.item.receiver}
  64. </Text>
  65. <Text
  66. style={{
  67. fontSize: 15,
  68. lineHeight: 21,
  69. color: '#333',
  70. marginLeft: 10,
  71. }}
  72. >
  73. {item.item.receiverPhone}
  74. </Text>
  75. {item.item.isDefault == 1 ? (
  76. <View
  77. style={{
  78. marginLeft: 25,
  79. paddingHorizontal: 5,
  80. backgroundColor: '#E14C46',
  81. borderRadius: 4,
  82. }}
  83. >
  84. <Text
  85. style={{
  86. fontSize: 12,
  87. lineHeight: 17,
  88. color: '#FFF',
  89. }}
  90. >
  91. 默认地址
  92. </Text>
  93. </View>
  94. ) : (
  95. <TouchableOpacity
  96. activeOpacity={1}
  97. style={{ marginLeft: 25 }}
  98. onPress={() => this.setDefault(item, addressData)}
  99. >
  100. <Text
  101. style={{
  102. fontSize: 12,
  103. lineHeight: 17,
  104. color: '#666',
  105. }}
  106. >
  107. 设为默认
  108. </Text>
  109. </TouchableOpacity>
  110. )}
  111. </View>
  112. <Text
  113. style={{
  114. fontSize: 13,
  115. lineHeight: 18,
  116. color: '#333',
  117. marginTop: 3,
  118. }}
  119. >
  120. {/* {item.item.receiverProvince +
  121. item.item.receiverCity +
  122. item.item.receiverDistrict +
  123. item.item.receiverTown +
  124. item.item.receiverAddress} */}
  125. {item.item.country+item.item.receiverAddress}
  126. </Text>
  127. </View>
  128. </TouchableOpacity>
  129. )
  130. }
  131. render() {
  132. const { appTheme, addressData } = this.props
  133. return (
  134. <View
  135. style={[
  136. styles.container,
  137. { backgroundColor: appTheme.backgroundColor },
  138. ]}
  139. >
  140. <StatusBar
  141. animated={true}
  142. barStyle={appTheme.barStyle}
  143. // barStyle={"dark-content"}
  144. backgroundColor={'transparent'}
  145. translucent={true}
  146. />
  147. {/* 头部 */}
  148. {HeaderView(this.props.dispatch, '选择地址')}
  149. {/* 内容 */}
  150. <FlatList
  151. data={addressData}
  152. extraData={this.state}
  153. keyExtractor={(item, index) => index}
  154. renderItem={(item, index) => this._renderItem(item, addressData)}
  155. />
  156. </View>
  157. )
  158. }
  159. }
  160. const styles = StyleSheet.create({
  161. container: {
  162. flex: 1,
  163. },
  164. text333: {
  165. fontSize: 14,
  166. lineHeight: 20,
  167. letterSpacing: 0.17,
  168. color: '#333',
  169. },
  170. text666: {
  171. fontSize: 12,
  172. lineHeight: 17,
  173. color: '#666',
  174. },
  175. text999: {
  176. fontSize: 12,
  177. lineHeight: 17,
  178. color: '#999',
  179. },
  180. })
  181. export default SelectAdress