Authored by 毕凯

地址修改 省市区列表异步加载

@@ -13,11 +13,11 @@ var $addressForm = $('.edit-address'), @@ -13,11 +13,11 @@ var $addressForm = $('.edit-address'),
13 $submit = $('.submit'), 13 $submit = $('.submit'),
14 $editAddressPage = $('.my-edit-address-page'), 14 $editAddressPage = $('.my-edit-address-page'),
15 $addressListPage = $('.my-address-list-page'), 15 $addressListPage = $('.my-address-list-page'),
16 - $area = $('.area'),  
17 $footer = $('#yoho-footer'), 16 $footer = $('#yoho-footer'),
18 $backBtn = $('.nav-back'), 17 $backBtn = $('.nav-back'),
19 $navTitle = $('.nav-title'), 18 $navTitle = $('.nav-title'),
20 navTitle = $navTitle.html(), 19 navTitle = $navTitle.html(),
  20 + $area = $('.area'),
21 isSubmiting, 21 isSubmiting,
22 currentPage = 'edit', 22 currentPage = 'edit',
23 newArea = []; 23 newArea = [];
@@ -109,6 +109,12 @@ $submit.on('touchend', function() { @@ -109,6 +109,12 @@ $submit.on('touchend', function() {
109 $(this).removeClass('highlight'); 109 $(this).removeClass('highlight');
110 }); 110 });
111 111
  112 +$('input, textarea').on('focus', function() {
  113 + $footer.hide();
  114 +}).on('blur', function() {
  115 + $footer.show();
  116 +});
  117 +
112 // 省市区 118 // 省市区
113 $area.on('touchend', function() { 119 $area.on('touchend', function() {
114 $editAddressPage.hide(); 120 $editAddressPage.hide();
@@ -119,58 +125,59 @@ $area.on('touchend', function() { @@ -119,58 +125,59 @@ $area.on('touchend', function() {
119 $navTitle.html('地区选择'); 125 $navTitle.html('地区选择');
120 }); 126 });
121 127
122 -// touchend 在下滑的时候会触发  
123 -// 省市区联动  
124 -$addressListPage.find('.address').each(function(i, elem) {  
125 - var addressHammer = new Hammer(elem); 128 +// 省市区列表异步加载
  129 +$.get('/home/locationList').then(function(html) {
  130 + $addressListPage.html(html);
  131 +
  132 + // touchend 在下滑的时候会触发
  133 + // 省市区联动
  134 + $addressListPage.find('.address').each(function(i, elem) {
  135 + var addressHammer = new Hammer(elem);
126 136
127 - addressHammer.on('tap', function(e) {  
128 - var $this = $(e.target); 137 + addressHammer.on('tap', function(e) {
  138 + var $this = $(e.target);
129 139
130 - newArea.push($this.children('.caption').text());  
131 - $this.siblings().hide();  
132 - $this.children('ul').show().children('li').show(); 140 + newArea.push($this.children('.caption').text());
  141 + $this.siblings().hide();
  142 + $this.children('ul').show().children('li').show();
133 143
134 - e.srcEvent.preventDefault();  
135 - e.srcEvent.stopPropagation(); 144 + e.srcEvent.preventDefault();
  145 + e.srcEvent.stopPropagation();
  146 + });
136 }); 147 });
137 -});  
138 148
139 -$addressListPage.find('.address-last').each(function(i, elem) {  
140 - var addressLastHammer = new Hammer(elem); 149 + $addressListPage.find('.address-last').each(function(i, elem) {
  150 + var addressLastHammer = new Hammer(elem);
141 151
142 - addressLastHammer.on('tap', function(e) {  
143 - var $this = $(e.target); 152 + addressLastHammer.on('tap', function(e) {
  153 + var $this = $(e.target);
144 154
145 - // 填结果到 html  
146 - newArea.push($this.children('.caption').text());  
147 - $('[name="area"]').val(newArea.join(' '));  
148 - $('[name="area_code"]').val($this.data('id')); 155 + // 填结果到 html
  156 + newArea.push($this.children('.caption').text());
  157 + $('[name="area"]').val(newArea.join(' '));
  158 + $('[name="area_code"]').val($this.data('id'));
149 159
150 - $editAddressPage.show();  
151 - currentPage = 'edit';  
152 - $navTitle.html(navTitle);  
153 - $footer.show(); 160 + $editAddressPage.show();
  161 + currentPage = 'edit';
  162 + $navTitle.html(navTitle);
  163 + $footer.show();
154 164
155 - // 恢复默认的三级选择  
156 - $addressListPage.hide();  
157 - $addressListPage.find('ul').hide().find('li').removeClass('highlight');  
158 - $addressListPage.children('ul').show().children('li').show();  
159 - newArea = []; 165 + // 恢复默认的三级选择
  166 + $addressListPage.hide();
  167 + $addressListPage.find('ul').hide().find('li').removeClass('highlight');
  168 + $addressListPage.children('ul').show().children('li').show();
  169 + newArea = [];
160 170
161 - e.srcEvent.preventDefault();  
162 - e.srcEvent.stopPropagation(); 171 + e.srcEvent.preventDefault();
  172 + e.srcEvent.stopPropagation();
  173 + });
163 }); 174 });
164 -});  
165 -  
166 -$addressListPage.on('touchstart', 'li', function() {  
167 - $(this).addClass('highlight');  
168 -}).on('touchend touchcancel', 'li', function() {  
169 - $(this).removeClass('highlight');  
170 -});  
171 175
172 -$('input, textarea').on('focus', function() {  
173 - $footer.hide();  
174 -}).on('blur', function() {  
175 - $footer.show(); 176 + $addressListPage.on('touchstart', 'li', function() {
  177 + $(this).addClass('highlight');
  178 + }).on('touchend touchcancel', 'li', function() {
  179 + $(this).removeClass('highlight');
  180 + });
  181 +}).fail(function() {
  182 + tip.show('获取省市区列表失败');
176 }); 183 });
@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
18 <span class="iconfont">&#xe604;</span> 18 <span class="iconfont">&#xe604;</span>
19 </label> 19 </label>
20 <label class="address"> 20 <label class="address">
21 - 详细地址 21 + 详细地址
22 <textarea name="address" maxlength="255">{{address.address}}</textarea> 22 <textarea name="address" maxlength="255">{{address.address}}</textarea>
23 </label> 23 </label>
24 24
@@ -28,5 +28,7 @@ @@ -28,5 +28,7 @@
28 确认 28 确认
29 </div> 29 </div>
30 </div> 30 </div>
  31 + <div class="my-address-list-page page-wrap hide">
  32 + </div>
31 </div> 33 </div>
32 -{{> layout/footer}}  
  34 +{{> layout/footer}}
1 -<div class="my-address-list-page page-wrap hide">  
2 - <ul class="address-list">  
3 - {{# addressList}}  
4 - <li class="address">  
5 - <span class="caption">{{caption}}</span>  
6 - <span class="iconfont">&#xe604;</span>  
7 - <ul>  
8 - {{# sub}}  
9 - <li class="address">  
10 - <span class="caption">{{caption}}</span>  
11 - <span class="iconfont">&#xe604;</span>  
12 - <ul class="address-list">  
13 - {{# sub}}  
14 - <li class="address-last" data-id="{{code}}">  
15 - <span class="caption">{{caption}}</span>  
16 - </li>  
17 - {{/ sub}}  
18 - </ul>  
19 - </li>  
20 - {{/ sub}}  
21 - </ul>  
22 - </li>  
23 - {{/ addressList}}  
24 - </ul>  
25 -</div>  
  1 +<ul class="address-list">
  2 +{{# addressList}}
  3 + <li class="address">
  4 + <span class="caption">{{caption}}</span>
  5 + <span class="iconfont">&#xe604;</span>
  6 + <ul>
  7 + {{# sub}}
  8 + <li class="address">
  9 + <span class="caption">{{caption}}</span>
  10 + <span class="iconfont">&#xe604;</span>
  11 + <ul class="address-list">
  12 + {{# sub}}
  13 + <li class="address-last" data-id="{{code}}">
  14 + <span class="caption">{{caption}}</span>
  15 + </li>
  16 + {{/ sub}}
  17 + </ul>
  18 + </li>
  19 + {{/ sub}}
  20 + </ul>
  21 + </li>
  22 +{{/ addressList}}
  23 +</ul>