index.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. import {Component} from "react"
  2. import React from "react"
  3. import {NavBar, Icon, InputItem, PickerView, TextareaItem} from 'antd-mobile'
  4. import {Button} from 'antd'
  5. import './index.css'
  6. const provinceAll = [
  7. {
  8. label: '江苏省',
  9. value: '江苏省',
  10. },
  11. {
  12. label: '河南省',
  13. value: '河南省',
  14. },
  15. {
  16. label: '安徽省',
  17. value: '安徽省',
  18. children: [
  19. {
  20. label: '合肥市',
  21. value: '合肥市',
  22. children: [
  23. {
  24. label: '蜀山区',
  25. value: '蜀山区',
  26. },
  27. {
  28. label: '瑶海区',
  29. value: '瑶海区',
  30. },
  31. {
  32. label: '包河区',
  33. value: '包河区',
  34. },
  35. {
  36. label: '庐阳区',
  37. value: '庐阳区',
  38. }
  39. ],
  40. },
  41. {
  42. label: '芜湖市',
  43. value: '芜湖市',
  44. children: [
  45. {
  46. label: '镜湖区',
  47. value: '镜湖区',
  48. },
  49. {
  50. label: '弋江区',
  51. value: '弋江区',
  52. },
  53. ],
  54. },
  55. {
  56. label: '六安市',
  57. value: '六安市',
  58. },
  59. {
  60. label: '淮南市',
  61. value: '淮南市',
  62. },
  63. {
  64. label: '马鞍山市',
  65. value: '马鞍山市',
  66. },
  67. {
  68. label: '黄山市',
  69. value: '黄山市',
  70. }
  71. ]
  72. },
  73. {
  74. label: '湖北省',
  75. value: '湖北省',
  76. },
  77. {
  78. label: '江西省',
  79. value: '江西省',
  80. },
  81. ]
  82. class SingleAddress extends Component {
  83. constructor(props) {
  84. super(props)
  85. let state = {
  86. username: '',
  87. telephone: '',
  88. province: '安徽省',
  89. city: '合肥市',
  90. area: '蜀山区',
  91. address: '',
  92. id: ''
  93. }
  94. if (props.addressID === 'add') {
  95. this.state = {...state}
  96. } else {
  97. let {province, city, area, address, telephone, username, id} = props.addressChoosed
  98. this.state = {...state, province, city, area, address, telephone, username, id}
  99. }
  100. }
  101. render() {
  102. let {changePage, history} = this.props
  103. let {username, telephone, province, city, area, address, id} = this.state
  104. return (
  105. <div>
  106. <div className='tools-addressadd-navbar-wrap'>
  107. <NavBar
  108. className='tools-addressadd-navbar'
  109. mode="dark"
  110. icon={<Icon type="left"/>}
  111. onLeftClick={() => {
  112. changePage(false)
  113. }}
  114. >添加新地址</NavBar>
  115. </div>
  116. <div>
  117. <InputItem placeholder="输入姓名" value={username} labelNumber={5} onChange={(username) => {
  118. this.setState({username})
  119. }}>
  120. <div>联系人姓名</div>
  121. </InputItem>
  122. <InputItem placeholder="输入号码" value={telephone} onChange={(telephone) => {
  123. this.setState({telephone})
  124. }}>
  125. <div>手机号码</div>
  126. </InputItem>
  127. <TextareaItem
  128. title="选择地区"
  129. editable={false}
  130. />
  131. <PickerView
  132. data={provinceAll}
  133. value={[province, city ? city : '', area ? area : '']}
  134. onChange={(address) => {
  135. this.setState({province: address[0], city: address[1], area: address[2]})
  136. }}
  137. />
  138. <TextareaItem
  139. title="详细地址"
  140. autoHeight
  141. labelNumber={4}
  142. value={address}
  143. onChange={(address) => {
  144. this.setState({address})
  145. }}
  146. />
  147. </div>
  148. <div className='address-button-group'>
  149. <DefaultAndSaveButton
  150. data={{
  151. username,
  152. telephone,
  153. province,
  154. city,
  155. area,
  156. address,
  157. id
  158. }}
  159. />
  160. <SaveAddressButton
  161. data={{
  162. username,
  163. telephone,
  164. province,
  165. city,
  166. area,
  167. address,
  168. id
  169. }}
  170. history={history}
  171. />
  172. </div>
  173. </div>
  174. )
  175. }
  176. }
  177. export default SingleAddress
  178. class DefaultAndSaveButton extends Component {
  179. constructor(props) {
  180. super(props)
  181. this.state = {}
  182. }
  183. render() {
  184. // let {data} = this.props
  185. return (
  186. <div className='address-button'>
  187. <Button block size='large' style={{outline: 'none'}}>设为默认并保存</Button>
  188. </div>
  189. )
  190. }
  191. }
  192. class SaveAddressButton extends Component {
  193. constructor(props) {
  194. super(props)
  195. this.state = {}
  196. }
  197. render() {
  198. let prePage = this.props.history.location.state.prePage
  199. // let {data} = this.props
  200. return (
  201. <div className='address-button'>
  202. <Button type='primary' block size='large' style={{outline: 'none'}}
  203. onClick={()=>{
  204. if(prePage){
  205. // sessionStorage.setItem('ordersAddress',JSON.stringify(address))
  206. this.props.history.go(-2)
  207. }
  208. }}
  209. >
  210. 保存并使用</Button>
  211. </div>
  212. )
  213. }
  214. }