|
|
@@ -1,12 +1,14 @@
|
|
|
import React, { Component } from 'react'
|
|
|
|
|
|
-import { List, InputItem, WhiteSpace ,Picker,PickerView} from 'antd-mobile';
|
|
|
+import { List, InputItem, WhiteSpace ,Picker,PickerView, Button, WingBlank} from 'antd-mobile';
|
|
|
import { createForm } from 'rc-form';
|
|
|
import './FormAddress.css'
|
|
|
|
|
|
+import { district} from 'antd-mobile-demo-data';
|
|
|
|
|
|
-import {province} from './areaData'
|
|
|
+import config from '../../api/url_config'
|
|
|
|
|
|
+const APPID =config.APPID
|
|
|
|
|
|
|
|
|
export default class FormAddress extends Component {
|
|
|
@@ -14,10 +16,100 @@ export default class FormAddress extends Component {
|
|
|
super(props)
|
|
|
|
|
|
this.state={
|
|
|
- areaShow:false
|
|
|
+ areaShow:false,
|
|
|
+ name:'',
|
|
|
+ phone:'',
|
|
|
+ detail:'',
|
|
|
+ code:'',
|
|
|
+ "area": "",
|
|
|
+ "city": "",
|
|
|
+ "province": ""
|
|
|
}
|
|
|
|
|
|
this.trigger=this.trigger.bind(this)
|
|
|
+ this.nameChange=this.nameChange.bind(this)
|
|
|
+ this.phoneChange=this.phoneChange.bind(this)
|
|
|
+ this.detailChange=this.detailChange.bind(this)
|
|
|
+ this.codeChange=this.codeChange.bind(this)
|
|
|
+ this.submit=this.submit.bind(this)
|
|
|
+ }
|
|
|
+ nameChange(e){
|
|
|
+ console.log(e)
|
|
|
+ this.setState({
|
|
|
+ name:e
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ phoneChange(e){
|
|
|
+ console.log(e)
|
|
|
+ this.setState({
|
|
|
+ phone:e
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ detailChange(e){
|
|
|
+ console.log(e)
|
|
|
+ this.setState({
|
|
|
+ detail:e
|
|
|
+ })
|
|
|
+ }
|
|
|
+ codeChange(e){
|
|
|
+ console.log(e)
|
|
|
+ this.setState({
|
|
|
+ code:e
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ areaChange(e){
|
|
|
+ console.log('e',e)
|
|
|
+ console.log(district)
|
|
|
+
|
|
|
+ let provinceCode=e[0],cityCode=e[0],areCode=e[0]
|
|
|
+ let province='',city='',area=''
|
|
|
+
|
|
|
+ district.map((item)=>{
|
|
|
+ if(item.value===provinceCode){
|
|
|
+ console.log('province',item)
|
|
|
+ province=item.label
|
|
|
+ item.children.map((item)=>{
|
|
|
+ if(item.value===cityCode){
|
|
|
+ console.log('city',item)
|
|
|
+ city=item.label
|
|
|
+ item.children((item)=>{
|
|
|
+ if(item.value===areCode){
|
|
|
+ console.log('area',item)
|
|
|
+ area=item.label
|
|
|
+ }
|
|
|
+ return 0
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return 0
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return 0
|
|
|
+ })
|
|
|
+
|
|
|
+ console.log(province+city+area)
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ submit(){
|
|
|
+ let data={
|
|
|
+ "address": this.state.detail,
|
|
|
+ "area": "",
|
|
|
+ "city": "",
|
|
|
+ "default":0,
|
|
|
+ "id": new Date().getTime()+parseInt(Math.random(),10),
|
|
|
+ "postcode": this.state.code,
|
|
|
+ "province": "",
|
|
|
+ "telephone": this.state.phone,
|
|
|
+ "updatedAt": "",
|
|
|
+ "user_id": APPID,
|
|
|
+ "username": this.state.name
|
|
|
+ }
|
|
|
+ //console.log(this.props)
|
|
|
+ this.props.createUserAddress(data)
|
|
|
}
|
|
|
|
|
|
trigger(){
|
|
|
@@ -28,40 +120,53 @@ export default class FormAddress extends Component {
|
|
|
render() {
|
|
|
//const { getFieldProps } = this.props.form;
|
|
|
return (
|
|
|
- <form>
|
|
|
- <List renderHeader={''}>
|
|
|
- <InputItem
|
|
|
- placeholder="姓名"
|
|
|
- type="bankCard"
|
|
|
- >收货人</InputItem>
|
|
|
- <InputItem
|
|
|
- type="phone"
|
|
|
- placeholder="手机号码"
|
|
|
- >手机号码</InputItem>
|
|
|
- <InputItem
|
|
|
- editable={false}
|
|
|
- type="password"
|
|
|
- placeholder="点击选择地区"
|
|
|
- extra={'>'}
|
|
|
- onClick={this.trigger}
|
|
|
- >选择地区</InputItem>
|
|
|
- <InputItem
|
|
|
- type="number"
|
|
|
- placeholder="详细地址"
|
|
|
- >详细地址</InputItem>
|
|
|
- <InputItem
|
|
|
- type="digit"
|
|
|
- placeholder="邮编"
|
|
|
- >邮编</InputItem>
|
|
|
- </List>
|
|
|
- <div className='pickerWrap' style={this.state.areaShow ? {}:{display:"none"}}>
|
|
|
- <PickerView
|
|
|
- data={province}
|
|
|
- value={['02', '02-1', '02-1-1']}
|
|
|
- onChange={(e)=>{console.log(e)}}
|
|
|
- />
|
|
|
- </div>
|
|
|
- </form>
|
|
|
+ <div>
|
|
|
+ <form>
|
|
|
+ <List renderHeader={''} >
|
|
|
+ <InputItem
|
|
|
+ placeholder="姓名"
|
|
|
+ value={this.state.name}
|
|
|
+ onChange={(e)=>{this.nameChange(e)}}
|
|
|
+ >收货人</InputItem>
|
|
|
+ <InputItem
|
|
|
+ type="phone"
|
|
|
+ placeholder="手机号码"
|
|
|
+ value={this.state.phone}
|
|
|
+ onChange={(e)=>{this.phoneChange(e)}}
|
|
|
+ >手机号码</InputItem>
|
|
|
+
|
|
|
+ <div className='pickerWrap' style={this.state.areaShow ? {}:{display:""}}>
|
|
|
+ <List style={{ backgroundColor: 'white' }} className="picker-list">
|
|
|
+ <Picker extra="请选择(可选)"
|
|
|
+ data={district}
|
|
|
+ title="Areas"
|
|
|
+ onOk={e => console.log('ok', e)}
|
|
|
+ onDismiss={e => this.areaChange(e)}
|
|
|
+ onPickerChange={e=> this.areaChange(e)}
|
|
|
+ indicatorStyle={{position:"absolute",bottom:"0",left:"0"}}
|
|
|
+ >
|
|
|
+ <List.Item arrow="horizontal">点击选择地区:{this.state.area}</List.Item>
|
|
|
+ </Picker>
|
|
|
+ </List>
|
|
|
+ </div>
|
|
|
+ <InputItem
|
|
|
+ placeholder="详细地址"
|
|
|
+ value={this.state.detail}
|
|
|
+ onChange={(e)=>{this.detailChange(e)}}
|
|
|
+ >详细地址</InputItem>
|
|
|
+ <InputItem
|
|
|
+ type="number"
|
|
|
+ placeholder="邮编"
|
|
|
+ value={this.state.code}
|
|
|
+ maxLength={6}
|
|
|
+ onChange={(e)=>{this.codeChange(e)}}
|
|
|
+ >邮编</InputItem>
|
|
|
+ </List>
|
|
|
+ <Button type="primary" onClick={this.submit}>提交</Button><WhiteSpace />
|
|
|
+ </form>
|
|
|
+
|
|
|
+
|
|
|
+ </div>
|
|
|
)
|
|
|
}
|
|
|
}
|