forked from Chris-Tsai/zipcode-tw-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
124 lines (118 loc) · 4.01 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import React from 'react';
import ReactDOM from 'react-dom';
import ZipCodeTW from "./es/zipcode/ZipCodeTW";
import RowData from "./_example/js/RawData-hsinchu-no-districts";
class ZipCodeTWTest extends React.Component {
constructor() {
super();
this.state = {
county: '',
district: '',
zipCode: '100',
}
}
// 變更地址資訊
handleZipCodeChange = (e) =>{
const {countyValue, districtValue, zipValue} = e;
this.setState({
county: countyValue,
district: districtValue,
zipCode: zipValue,
});
};
render() {
let countySort = {
"基隆市": 2,
"台北市": 1,
"新北市": 3,
"桃園市": 4,
"新竹市": 5,
"新竹縣": 6,
"苗栗縣": 7,
"台中市": 8,
"彰化縣": 9,
"南投縣": 10,
"雲林縣": 11,
"嘉義市": 12,
"嘉義縣": 13,
"台南市": 14,
"高雄市": 15,
"屏東縣": 16,
"台東縣": 17,
"花蓮縣": 18,
"宜蘭縣": 19,
"澎湖縣": 20,
"金門縣": 21,
"連江縣": 22
};
return (
<div style={{width:'50%', margin: 'auto'}}>
<h1> Example </h1>
<div style={{
display: 'inline-block',
width: 'auto',
verticalAlign: 'middle'
}}>
<ZipCodeTW displayType='text'
countyValue={this.state.county}
districtValue={this.state.district}
zipCodeValue={this.state.zipCode}
countyStyle={{width: '100px', display: 'inline'}}
districtStyle={{
width: '100px',
marginLeft: '5px',
display: 'inline'
}}
zipStyle={{
width: '60px',
marginLeft: '5px',
display: 'inline'
}}
onInited={({countyValue, districtValue, zipValue}) => console.log(countyValue, districtValue, zipValue)}
handleChangeCounty={this.handleZipCodeChange}
handleChangeDistrict={this.handleZipCodeChange}
handleChangeZipCode={this.handleZipCodeChange}
handleBlurZipCode={this.handleZipCodeChange}
handleZipCodeNotExists={this.handleZipCodeChange}
countySort={countySort}
// rowData={RowData}
/>
<br/>
<ZipCodeTW displayType='text'
countyValue={this.state.county}
countyReadonly={true}
districtValue={this.state.district}
zipCodeValue={this.state.zipCode}
zipCodeReadonly={true}
zipCodePositionLast={false}
countyStyle={{width: '100px', display: 'inline'}}
districtStyle={{
width: '100px',
marginLeft: '5px',
display: 'inline'
}}
zipStyle={{
width: '60px',
marginLeft: '5px',
display: 'inline'
}}
onInited={({countyValue, districtValue, zipValue}) => console.log(countyValue, districtValue, zipValue)}
handleChangeCounty={this.handleZipCodeChange}
handleChangeDistrict={this.handleZipCodeChange}
handleChangeZipCode={this.handleZipCodeChange}
handleBlurZipCode={this.handleZipCodeChange}
handleZipCodeNotExists={this.handleZipCodeChange}
countySort={countySort}
/>
</div>
</div>
);
}
}
window.app = {};
app.create = (dom) => {
ReactDOM.render(
<ZipCodeTWTest/>,
dom
)
};