Authored by Rock Zhang

Merge branch 'feature/address' into 'develop'

 地址修改页面  省市区列表加载方式改为异步加载

See merge request !6

Code Review By Rock Zhang
@@ -24,8 +24,8 @@ class Yohobuy @@ -24,8 +24,8 @@ class Yohobuy
24 // const YOHOBUY_URL = 'http://www.yohobuy.com/'; 24 // const YOHOBUY_URL = 'http://www.yohobuy.com/';
25 25
26 /* 测试环境 */ 26 /* 测试环境 */
27 - const API_URL = 'http://devapi.yoho.cn:58078/';  
28 - const SERVICE_URL = 'http://devservice.yoho.cn:58077/'; 27 + const API_URL = 'http://test2.open.yohobuy.com/';
  28 + const SERVICE_URL = 'http://test.service.api.yohobuy.com/';
29 const YOHOBUY_URL = 'http://www.yohobuy.com/'; 29 const YOHOBUY_URL = 'http://www.yohobuy.com/';
30 const YOHOBUY_ORDER = 'http://192.168.102.205:8084/order/'; //我的订单 30 const YOHOBUY_ORDER = 'http://192.168.102.205:8084/order/'; //我的订单
31 const API_URL_MYCENTER = 'http://192.168.102.205:8081/users/'; // 我的个人中心接口URL 31 const API_URL_MYCENTER = 'http://192.168.102.205:8081/users/'; // 我的个人中心接口URL
@@ -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 = [];
@@ -40,7 +40,7 @@ $backBtn.on('touchend', function(e) { @@ -40,7 +40,7 @@ $backBtn.on('touchend', function(e) {
40 40
41 // 恢复默认的三级选择 41 // 恢复默认的三级选择
42 $addressListPage.hide(); 42 $addressListPage.hide();
43 - $addressListPage.find('ul').hide(); 43 + $addressListPage.find('ul').hide().find('li').removeClass('highlight');
44 $addressListPage.children('ul').show().children('li').show(); 44 $addressListPage.children('ul').show().children('li').show();
45 newArea = []; 45 newArea = [];
46 } else { 46 } else {
@@ -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,59 +125,59 @@ $area.on('touchend', function() { @@ -119,59 +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);
126 131
127 - addressHammer.on('tap', function(e) {  
128 - var $this = $(e.target); 132 + // touchend 在下滑的时候会触发
  133 + // 省市区联动
  134 + $addressListPage.find('.address').each(function(i, elem) {
  135 + var addressHammer = new Hammer(elem);
129 136
130 - newArea.push($this.children('.caption').text());  
131 - $this.siblings().hide();  
132 - $this.children('ul').show().children('li').show(); 137 + addressHammer.on('tap', function(e) {
  138 + var $this = $(e.target);
133 139
134 - $(this).removeClass('highlight');  
135 - e.srcEvent.preventDefault();  
136 - e.srcEvent.stopPropagation(); 140 + newArea.push($this.children('.caption').text());
  141 + $this.siblings().hide();
  142 + $this.children('ul').show().children('li').show();
  143 +
  144 + e.srcEvent.preventDefault();
  145 + e.srcEvent.stopPropagation();
  146 + });
137 }); 147 });
138 -});  
139 148
140 -$addressListPage.find('.address-last').each(function(i, elem) {  
141 - var addressLastHammer = new Hammer(elem); 149 + $addressListPage.find('.address-last').each(function(i, elem) {
  150 + var addressLastHammer = new Hammer(elem);
142 151
143 - addressLastHammer.on('tap', function(e) {  
144 - var $this = $(e.target); 152 + addressLastHammer.on('tap', function(e) {
  153 + var $this = $(e.target);
145 154
146 - // 填结果到 html  
147 - newArea.push($this.children('.caption').text());  
148 - $('[name="area"]').val(newArea.join(' '));  
149 - $('[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'));
150 159
151 - $editAddressPage.show();  
152 - currentPage = 'edit';  
153 - $navTitle.html(navTitle);  
154 - $footer.show(); 160 + $editAddressPage.show();
  161 + currentPage = 'edit';
  162 + $navTitle.html(navTitle);
  163 + $footer.show();
155 164
156 - // 恢复默认的三级选择  
157 - $addressListPage.hide();  
158 - $addressListPage.find('ul').hide();  
159 - $addressListPage.children('ul').show().children('li').show();  
160 - newArea = []; 165 + // 恢复默认的三级选择
  166 + $addressListPage.hide();
  167 + $addressListPage.find('ul').hide().find('li').removeClass('highlight');
  168 + $addressListPage.children('ul').show().children('li').show();
  169 + newArea = [];
161 170
162 - e.srcEvent.preventDefault();  
163 - e.srcEvent.stopPropagation(); 171 + e.srcEvent.preventDefault();
  172 + e.srcEvent.stopPropagation();
  173 + });
164 }); 174 });
165 -});  
166 -  
167 -$addressListPage.on('touchstart', 'li', function() {  
168 - $(this).addClass('highlight');  
169 -}).on('touchend touchcancel', 'li', function() {  
170 - $(this).removeClass('highlight');  
171 -});  
172 175
173 -$('input, textarea').on('focus', function() {  
174 - $footer.hide();  
175 -}).on('blur', function() {  
176 - $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('获取省市区列表失败');
177 }); 183 });
@@ -29,6 +29,7 @@ $confim.on('touchend', '.cancel', function() { @@ -29,6 +29,7 @@ $confim.on('touchend', '.cancel', function() {
29 $confim.hide(); 29 $confim.hide();
30 }).on('touchend', '.confim', function() { 30 }).on('touchend', '.confim', function() {
31 loading.showLoadingMask(); 31 loading.showLoadingMask();
  32 + $confim.hide();
32 $.ajax({ 33 $.ajax({
33 method: 'POST', 34 method: 'POST',
34 url: '/home/delAddress', 35 url: '/home/delAddress',
@@ -41,15 +42,15 @@ $confim.on('touchend', '.cancel', function() { @@ -41,15 +42,15 @@ $confim.on('touchend', '.cancel', function() {
41 } 42 }
42 if (res.code !== 200) { 43 if (res.code !== 200) {
43 tip.show(res.message || '网络出了点问题~'); 44 tip.show(res.message || '网络出了点问题~');
  45 + loading.hideLoadingMask();
44 } else { 46 } else {
45 window.location.reload(); 47 window.location.reload();
46 } 48 }
47 }).fail(function() { 49 }).fail(function() {
48 tip.show('网络出了点问题~'); 50 tip.show('网络出了点问题~');
  51 + loading.hideLoadingMask();
49 }).always(function() { 52 }).always(function() {
50 deleteId = null; 53 deleteId = null;
51 - $confim.hide();  
52 - loading.hideLoadingMask();  
53 }); 54 });
54 }); 55 });
55 56
@@ -73,7 +74,7 @@ $action.on('touchend', '.del', function() { @@ -73,7 +74,7 @@ $action.on('touchend', '.del', function() {
73 74
74 $submit.on('touchend', function() { 75 $submit.on('touchend', function() {
75 if (security.hasDangerInput(false)) { 76 if (security.hasDangerInput(false)) {
76 - return false; 77 + return false;
77 } 78 }
78 $addressForm.submit(); 79 $addressForm.submit();
79 return false; 80 return false;
@@ -82,4 +83,3 @@ $submit.on('touchend', function() { @@ -82,4 +83,3 @@ $submit.on('touchend', function() {
82 }).on('touchend touchcancel', function() { 83 }).on('touchend touchcancel', function() {
83 $(this).removeClass('highlight'); 84 $(this).removeClass('highlight');
84 }); 85 });
85 -  
@@ -37,7 +37,7 @@ @@ -37,7 +37,7 @@
37 } 37 }
38 38
39 .action { 39 .action {
40 - font-size: pxToRem(40px); 40 + font-size: pxToRem(32px);
41 line-height: pxToRem(60px); 41 line-height: pxToRem(60px);
42 text-align: right; 42 text-align: right;
43 43
@@ -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,6 +28,7 @@ @@ -28,6 +28,7 @@
28 确认 28 确认
29 </div> 29 </div>
30 </div> 30 </div>
31 - {{> me/address/address-list}} 31 + <div class="my-address-list-page page-wrap hide">
  32 + </div>
32 </div> 33 </div>
33 -{{> 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>
@@ -306,6 +306,23 @@ class HomeController extends AbstractAction @@ -306,6 +306,23 @@ class HomeController extends AbstractAction
306 }*/ 306 }*/
307 307
308 /** 308 /**
  309 + * 异步获取三级地址数据
  310 + */
  311 + public function locationListAction() {
  312 + $result = array();
  313 +
  314 + if ($this->isAjax()) {
  315 + $result['addressList'] = UserModel::getAddressListData($this->_uid);
  316 + }
  317 +
  318 + if (empty($result)) {
  319 + echo ' ';
  320 + } else {
  321 + $this->_view->display('location-list', $result);
  322 + }
  323 + }
  324 +
  325 + /**
309 * 地址管理 326 * 地址管理
310 */ 327 */
311 public function addressAction() { 328 public function addressAction() {
@@ -314,14 +331,12 @@ class HomeController extends AbstractAction @@ -314,14 +331,12 @@ class HomeController extends AbstractAction
314 $this->setNavHeader('地址管理'); 331 $this->setNavHeader('地址管理');
315 332
316 $address = UserModel::getAddressData($this->_uid); 333 $address = UserModel::getAddressData($this->_uid);
317 - $addressList = UserModel::getAddressListData($this->_uid);  
318 334
319 $this->_view->display('address', array( 335 $this->_view->display('address', array(
320 'addressPage' => true, 336 'addressPage' => true,
321 'pageFooter' => true, 337 'pageFooter' => true,
322 'address' => $address, 338 'address' => $address,
323 - 'showAddBtn' => (count($address) <= 5),  
324 - 'addressList' => $addressList 339 + 'showAddBtn' => (count($address) <= 5)
325 )); 340 ));
326 } 341 }
327 342
@@ -172,29 +172,25 @@ class UserModel @@ -172,29 +172,25 @@ class UserModel
172 172
173 // 处理用户收藏的商品数据 173 // 处理用户收藏的商品数据
174 if (isset($favProduct['data']) && !empty($favProduct['data']['product_list'])) { 174 if (isset($favProduct['data']) && !empty($favProduct['data']['product_list'])) {
175 - if ($page > $favProduct['data']['page_total']) {  
176 - $result['end'] = true;  
177 -  
178 - return $result;  
179 - }  
180 -  
181 $datas = array(); 175 $datas = array();
182 $product = array(); 176 $product = array();
183 -  
184 foreach ($favProduct['data']['product_list'] as $val) { 177 foreach ($favProduct['data']['product_list'] as $val) {
185 $product = array(); 178 $product = array();
186 $product['fav_id'] = $val['product_id']; 179 $product['fav_id'] = $val['product_id'];
187 - $product['imgUrl'] = $val['image']; 180 + $product['link'] = isset($val['goodsId']) ? Helpers::url('/product/pro_' . $val['product_skn'] . '_' . $val['goodsId'] . '/' . $val['cnAlphabet'] . '.html') : '';
  181 + $product['imgUrl'] = Helpers::getImageUrl($val['image'], 447, 596);;
188 $product['title'] = $val['product_name']; 182 $product['title'] = $val['product_name'];
189 $product['price'] = !empty($val['market_price']) ? '¥'.$val['market_price'] . '.00' : 0; 183 $product['price'] = !empty($val['market_price']) ? '¥'.$val['market_price'] . '.00' : 0;
190 $product['discountPrice'] = ($val['market_price'] - $val['sales_price'] > 0) ? '¥' . $val['sales_price'] . '.00' : false; 184 $product['discountPrice'] = ($val['market_price'] - $val['sales_price'] > 0) ? '¥' . $val['sales_price'] . '.00' : false;
191 - $product['savePrice'] = ($val['market_price'] - $val['sales_price'] > 0) ? '¥'.($val['market_price'] - $val['sales_price']) . '.00' : false;  
192 - $product['sellOut'] = (bool)($val['price_down']); 185 + $product['savePrice'] = !empty($val['price_down'] > 0) ? '¥'.$val['price_down'] . '.00' : false;
  186 + $product['sellOut'] = ($val['storage'] <= 0);
193 187
194 $datas[] = $product; 188 $datas[] = $product;
195 } 189 }
196 190
197 !empty($datas) && $result['hasFavProduct'] = $datas; 191 !empty($datas) && $result['hasFavProduct'] = $datas;
  192 + } else if ($page > 1 && isset($favProduct['code']) && $favProduct['code'] === 500){
  193 + $result['end'] = true;
198 } 194 }
199 195
200 return $result; 196 return $result;
@@ -230,19 +226,19 @@ class UserModel @@ -230,19 +226,19 @@ class UserModel
230 foreach ($favBrand['data']['brand_list'] as $val) { 226 foreach ($favBrand['data']['brand_list'] as $val) {
231 $brand = array(); 227 $brand = array();
232 $brand['id'] = $val['brand_id']; 228 $brand['id'] = $val['brand_id'];
233 - $brand['brandImg'] = Images::getImageUrl($val['brand_ico'], 235, 314); 229 + $brand['brandImg'] = !empty($val['brand_ico']) ? Images::getImageUrl($val['brand_ico'], 47, 47) : '';
234 $brand['brandName'] = $val['brand_name']; 230 $brand['brandName'] = $val['brand_name'];
235 $brand['update'] = $val['new_product_num']; 231 $brand['update'] = $val['new_product_num'];
236 $brand['discount'] = $val['product_discount_num']; 232 $brand['discount'] = $val['product_discount_num'];
237 - $brand['link'] = '#'; 233 + $brand['link'] = Helpers::url('', array('query' => $val['brand_name']), 'search');
238 234
239 // 处理品牌产品 235 // 处理品牌产品
240 $product = array(); 236 $product = array();
241 foreach ($val['new_product'] as $one) { 237 foreach ($val['new_product'] as $one) {
242 $product = array(); 238 $product = array();
243 $product['imgUrl'] = Images::getImageUrl($one['default_images'], 235, 314); 239 $product['imgUrl'] = Images::getImageUrl($one['default_images'], 235, 314);
244 - $product['price'] = '¥'.$one['market_price'];  
245 - $product['discount'] = '¥'.$one['sales_price']; 240 + $product['price'] = !empty($one['market_price']) ? '¥'.$one['market_price'] . '.00' : 0;
  241 + $product['discount'] = !empty($one['sales_price']) ? '¥'.$one['sales_price'] . '.00' : 0;
246 242
247 $brand['productList'][] = $product; 243 $brand['productList'][] = $product;
248 } 244 }
@@ -277,7 +273,7 @@ class UserModel @@ -277,7 +273,7 @@ class UserModel
277 * @param int $udid 客户端唯一标识 273 * @param int $udid 客户端唯一标识
278 * @param int $page 第几页,默认为1 274 * @param int $page 第几页,默认为1
279 * @param int $limit 限制多少条,默认100 275 * @param int $limit 限制多少条,默认100
280 - * @return array处理之后的数据 276 + * @return array 处理之后的数据
281 */ 277 */
282 public static function browserRecord($uid, $udid, $page, $limit) 278 public static function browserRecord($uid, $udid, $page, $limit)
283 { 279 {
@@ -285,9 +281,30 @@ class UserModel @@ -285,9 +281,30 @@ class UserModel
285 281
286 $records = UserData::browseRecord($uid, $udid, $page, $limit); 282 $records = UserData::browseRecord($uid, $udid, $page, $limit);
287 283
  284 + if (!$records) {
  285 + $result['walkwayUrl'] = '/product/new';
  286 + $result['noRecord'] = true;
  287 +
  288 + return $result;
  289 + }
  290 +
288 // 处理数据 291 // 处理数据
289 - if (isset($records['data']['product_list']) && !empty($records['data']['product_list'])) {  
290 - $result = $records['data']['product_list']; 292 + if (isset($records['data']['product_list'])) {
  293 +
  294 + // 不能再查到结果了
  295 + if ($page == 1 && $records['data']['total'] === 0) {
  296 + $result['walkwayUrl'] = '/product/new';
  297 + $result['noRecord'] = true;
  298 + } else {
  299 + $data = $records['data']['product_list'];
  300 + foreach ($data as &$val) {
  301 + $val['image'] = Helpers::getImageUrl($val['image'], 140, 140);
  302 + $val['sales_price'] = !empty($val['sales_price']) ? $val['sales_price'] . '.00' : 0;
  303 + $val['market_price'] = !empty($val['market_price']) ? $val['market_price'] . '.00' : 0;
  304 + }
  305 +
  306 + !empty($data) && $result['browseRecord'] = $data;
  307 + }
291 } 308 }
292 309
293 return $result; 310 return $result;
@@ -566,7 +583,7 @@ class UserModel @@ -566,7 +583,7 @@ class UserModel
566 foreach ($suggest['data']['list'] as $val) { 583 foreach ($suggest['data']['list'] as $val) {
567 $one = array(); 584 $one = array();
568 $one['suggest_id'] = $val['id']; 585 $one['suggest_id'] = $val['id'];
569 - $one['imgUrl'] = !empty($val['cover_image']) ? Images::getSourceUrl($val['cover_image'], 'suggest') . '?imageMogr2/thumbnail/320x155/extent/240x155/background/d2hpdGU=/position/center/quality/90' : ''; 586 + $one['imgUrl'] = !empty($val['cover_image']) ? Images::getSourceUrl($val['cover_image'], 'suggest') : '';
570 $one['title'] = $val['filter_content']; 587 $one['title'] = $val['filter_content'];
571 $one['content'] = $val['reply_content']; 588 $one['content'] = $val['reply_content'];
572 $one['good'] = ($val['is_reliable'] == 1); 589 $one['good'] = ($val['is_reliable'] == 1);