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
// const YOHOBUY_URL = 'http://www.yohobuy.com/';
/* 测试环境 */
const API_URL = 'http://devapi.yoho.cn:58078/';
const SERVICE_URL = 'http://devservice.yoho.cn:58077/';
const API_URL = 'http://test2.open.yohobuy.com/';
const SERVICE_URL = 'http://test.service.api.yohobuy.com/';
const YOHOBUY_URL = 'http://www.yohobuy.com/';
const YOHOBUY_ORDER = 'http://192.168.102.205:8084/order/'; //我的订单
const API_URL_MYCENTER = 'http://192.168.102.205:8081/users/'; // 我的个人中心接口URL
... ...
... ... @@ -13,11 +13,11 @@ var $addressForm = $('.edit-address'),
$submit = $('.submit'),
$editAddressPage = $('.my-edit-address-page'),
$addressListPage = $('.my-address-list-page'),
$area = $('.area'),
$footer = $('#yoho-footer'),
$backBtn = $('.nav-back'),
$navTitle = $('.nav-title'),
navTitle = $navTitle.html(),
$area = $('.area'),
isSubmiting,
currentPage = 'edit',
newArea = [];
... ... @@ -40,7 +40,7 @@ $backBtn.on('touchend', function(e) {
// 恢复默认的三级选择
$addressListPage.hide();
$addressListPage.find('ul').hide();
$addressListPage.find('ul').hide().find('li').removeClass('highlight');
$addressListPage.children('ul').show().children('li').show();
newArea = [];
} else {
... ... @@ -109,6 +109,12 @@ $submit.on('touchend', function() {
$(this).removeClass('highlight');
});
$('input, textarea').on('focus', function() {
$footer.hide();
}).on('blur', function() {
$footer.show();
});
// 省市区
$area.on('touchend', function() {
$editAddressPage.hide();
... ... @@ -119,59 +125,59 @@ $area.on('touchend', function() {
$navTitle.html('地区选择');
});
// touchend 在下滑的时候会触发
// 省市区联动
$addressListPage.find('.address').each(function(i, elem) {
var addressHammer = new Hammer(elem);
// 省市区列表异步加载
$.get('/home/locationList').then(function(html) {
$addressListPage.html(html);
addressHammer.on('tap', function(e) {
var $this = $(e.target);
// touchend 在下滑的时候会触发
// 省市区联动
$addressListPage.find('.address').each(function(i, elem) {
var addressHammer = new Hammer(elem);
newArea.push($this.children('.caption').text());
$this.siblings().hide();
$this.children('ul').show().children('li').show();
addressHammer.on('tap', function(e) {
var $this = $(e.target);
$(this).removeClass('highlight');
e.srcEvent.preventDefault();
e.srcEvent.stopPropagation();
newArea.push($this.children('.caption').text());
$this.siblings().hide();
$this.children('ul').show().children('li').show();
e.srcEvent.preventDefault();
e.srcEvent.stopPropagation();
});
});
});
$addressListPage.find('.address-last').each(function(i, elem) {
var addressLastHammer = new Hammer(elem);
$addressListPage.find('.address-last').each(function(i, elem) {
var addressLastHammer = new Hammer(elem);
addressLastHammer.on('tap', function(e) {
var $this = $(e.target);
addressLastHammer.on('tap', function(e) {
var $this = $(e.target);
// 填结果到 html
newArea.push($this.children('.caption').text());
$('[name="area"]').val(newArea.join(' '));
$('[name="area_code"]').val($this.data('id'));
// 填结果到 html
newArea.push($this.children('.caption').text());
$('[name="area"]').val(newArea.join(' '));
$('[name="area_code"]').val($this.data('id'));
$editAddressPage.show();
currentPage = 'edit';
$navTitle.html(navTitle);
$footer.show();
$editAddressPage.show();
currentPage = 'edit';
$navTitle.html(navTitle);
$footer.show();
// 恢复默认的三级选择
$addressListPage.hide();
$addressListPage.find('ul').hide();
$addressListPage.children('ul').show().children('li').show();
newArea = [];
// 恢复默认的三级选择
$addressListPage.hide();
$addressListPage.find('ul').hide().find('li').removeClass('highlight');
$addressListPage.children('ul').show().children('li').show();
newArea = [];
e.srcEvent.preventDefault();
e.srcEvent.stopPropagation();
e.srcEvent.preventDefault();
e.srcEvent.stopPropagation();
});
});
});
$addressListPage.on('touchstart', 'li', function() {
$(this).addClass('highlight');
}).on('touchend touchcancel', 'li', function() {
$(this).removeClass('highlight');
});
$('input, textarea').on('focus', function() {
$footer.hide();
}).on('blur', function() {
$footer.show();
$addressListPage.on('touchstart', 'li', function() {
$(this).addClass('highlight');
}).on('touchend touchcancel', 'li', function() {
$(this).removeClass('highlight');
});
}).fail(function() {
tip.show('获取省市区列表失败');
});
... ...
... ... @@ -29,6 +29,7 @@ $confim.on('touchend', '.cancel', function() {
$confim.hide();
}).on('touchend', '.confim', function() {
loading.showLoadingMask();
$confim.hide();
$.ajax({
method: 'POST',
url: '/home/delAddress',
... ... @@ -41,15 +42,15 @@ $confim.on('touchend', '.cancel', function() {
}
if (res.code !== 200) {
tip.show(res.message || '网络出了点问题~');
loading.hideLoadingMask();
} else {
window.location.reload();
}
}).fail(function() {
tip.show('网络出了点问题~');
loading.hideLoadingMask();
}).always(function() {
deleteId = null;
$confim.hide();
loading.hideLoadingMask();
});
});
... ... @@ -73,7 +74,7 @@ $action.on('touchend', '.del', function() {
$submit.on('touchend', function() {
if (security.hasDangerInput(false)) {
return false;
return false;
}
$addressForm.submit();
return false;
... ... @@ -82,4 +83,3 @@ $submit.on('touchend', function() {
}).on('touchend touchcancel', function() {
$(this).removeClass('highlight');
});
... ...
... ... @@ -37,7 +37,7 @@
}
.action {
font-size: pxToRem(40px);
font-size: pxToRem(32px);
line-height: pxToRem(60px);
text-align: right;
... ...
... ... @@ -18,7 +18,7 @@
<span class="iconfont">&#xe604;</span>
</label>
<label class="address">
详细地址
详细地址
<textarea name="address" maxlength="255">{{address.address}}</textarea>
</label>
... ... @@ -28,6 +28,7 @@
确认
</div>
</div>
{{> me/address/address-list}}
<div class="my-address-list-page page-wrap hide">
</div>
</div>
{{> layout/footer}}
\ No newline at end of file
{{> layout/footer}}
... ...
{{> me/address/address-list}}
\ No newline at end of file
... ...
<div class="my-address-list-page page-wrap hide">
<ul class="address-list">
{{# addressList}}
<li class="address">
<span class="caption">{{caption}}</span>
<span class="iconfont">&#xe604;</span>
<ul>
{{# sub}}
<li class="address">
<span class="caption">{{caption}}</span>
<span class="iconfont">&#xe604;</span>
<ul class="address-list">
{{# sub}}
<li class="address-last" data-id="{{code}}">
<span class="caption">{{caption}}</span>
</li>
{{/ sub}}
</ul>
</li>
{{/ sub}}
</ul>
</li>
{{/ addressList}}
</ul>
</div>
\ No newline at end of file
<ul class="address-list">
{{# addressList}}
<li class="address">
<span class="caption">{{caption}}</span>
<span class="iconfont">&#xe604;</span>
<ul>
{{# sub}}
<li class="address">
<span class="caption">{{caption}}</span>
<span class="iconfont">&#xe604;</span>
<ul class="address-list">
{{# sub}}
<li class="address-last" data-id="{{code}}">
<span class="caption">{{caption}}</span>
</li>
{{/ sub}}
</ul>
</li>
{{/ sub}}
</ul>
</li>
{{/ addressList}}
</ul>
... ...
... ... @@ -306,6 +306,23 @@ class HomeController extends AbstractAction
}*/
/**
* 异步获取三级地址数据
*/
public function locationListAction() {
$result = array();
if ($this->isAjax()) {
$result['addressList'] = UserModel::getAddressListData($this->_uid);
}
if (empty($result)) {
echo ' ';
} else {
$this->_view->display('location-list', $result);
}
}
/**
* 地址管理
*/
public function addressAction() {
... ... @@ -314,14 +331,12 @@ class HomeController extends AbstractAction
$this->setNavHeader('地址管理');
$address = UserModel::getAddressData($this->_uid);
$addressList = UserModel::getAddressListData($this->_uid);
$this->_view->display('address', array(
'addressPage' => true,
'pageFooter' => true,
'address' => $address,
'showAddBtn' => (count($address) <= 5),
'addressList' => $addressList
'showAddBtn' => (count($address) <= 5)
));
}
... ...
... ... @@ -172,29 +172,25 @@ class UserModel
// 处理用户收藏的商品数据
if (isset($favProduct['data']) && !empty($favProduct['data']['product_list'])) {
if ($page > $favProduct['data']['page_total']) {
$result['end'] = true;
return $result;
}
$datas = array();
$product = array();
foreach ($favProduct['data']['product_list'] as $val) {
$product = array();
$product['fav_id'] = $val['product_id'];
$product['imgUrl'] = $val['image'];
$product['link'] = isset($val['goodsId']) ? Helpers::url('/product/pro_' . $val['product_skn'] . '_' . $val['goodsId'] . '/' . $val['cnAlphabet'] . '.html') : '';
$product['imgUrl'] = Helpers::getImageUrl($val['image'], 447, 596);;
$product['title'] = $val['product_name'];
$product['price'] = !empty($val['market_price']) ? '¥'.$val['market_price'] . '.00' : 0;
$product['discountPrice'] = ($val['market_price'] - $val['sales_price'] > 0) ? '¥' . $val['sales_price'] . '.00' : false;
$product['savePrice'] = ($val['market_price'] - $val['sales_price'] > 0) ? '¥'.($val['market_price'] - $val['sales_price']) . '.00' : false;
$product['sellOut'] = (bool)($val['price_down']);
$product['savePrice'] = !empty($val['price_down'] > 0) ? '¥'.$val['price_down'] . '.00' : false;
$product['sellOut'] = ($val['storage'] <= 0);
$datas[] = $product;
}
!empty($datas) && $result['hasFavProduct'] = $datas;
} else if ($page > 1 && isset($favProduct['code']) && $favProduct['code'] === 500){
$result['end'] = true;
}
return $result;
... ... @@ -230,19 +226,19 @@ class UserModel
foreach ($favBrand['data']['brand_list'] as $val) {
$brand = array();
$brand['id'] = $val['brand_id'];
$brand['brandImg'] = Images::getImageUrl($val['brand_ico'], 235, 314);
$brand['brandImg'] = !empty($val['brand_ico']) ? Images::getImageUrl($val['brand_ico'], 47, 47) : '';
$brand['brandName'] = $val['brand_name'];
$brand['update'] = $val['new_product_num'];
$brand['discount'] = $val['product_discount_num'];
$brand['link'] = '#';
$brand['link'] = Helpers::url('', array('query' => $val['brand_name']), 'search');
// 处理品牌产品
$product = array();
foreach ($val['new_product'] as $one) {
$product = array();
$product['imgUrl'] = Images::getImageUrl($one['default_images'], 235, 314);
$product['price'] = '¥'.$one['market_price'];
$product['discount'] = '¥'.$one['sales_price'];
$product['price'] = !empty($one['market_price']) ? '¥'.$one['market_price'] . '.00' : 0;
$product['discount'] = !empty($one['sales_price']) ? '¥'.$one['sales_price'] . '.00' : 0;
$brand['productList'][] = $product;
}
... ... @@ -277,7 +273,7 @@ class UserModel
* @param int $udid 客户端唯一标识
* @param int $page 第几页,默认为1
* @param int $limit 限制多少条,默认100
* @return array处理之后的数据
* @return array 处理之后的数据
*/
public static function browserRecord($uid, $udid, $page, $limit)
{
... ... @@ -285,9 +281,30 @@ class UserModel
$records = UserData::browseRecord($uid, $udid, $page, $limit);
if (!$records) {
$result['walkwayUrl'] = '/product/new';
$result['noRecord'] = true;
return $result;
}
// 处理数据
if (isset($records['data']['product_list']) && !empty($records['data']['product_list'])) {
$result = $records['data']['product_list'];
if (isset($records['data']['product_list'])) {
// 不能再查到结果了
if ($page == 1 && $records['data']['total'] === 0) {
$result['walkwayUrl'] = '/product/new';
$result['noRecord'] = true;
} else {
$data = $records['data']['product_list'];
foreach ($data as &$val) {
$val['image'] = Helpers::getImageUrl($val['image'], 140, 140);
$val['sales_price'] = !empty($val['sales_price']) ? $val['sales_price'] . '.00' : 0;
$val['market_price'] = !empty($val['market_price']) ? $val['market_price'] . '.00' : 0;
}
!empty($data) && $result['browseRecord'] = $data;
}
}
return $result;
... ... @@ -566,7 +583,7 @@ class UserModel
foreach ($suggest['data']['list'] as $val) {
$one = array();
$one['suggest_id'] = $val['id'];
$one['imgUrl'] = !empty($val['cover_image']) ? Images::getSourceUrl($val['cover_image'], 'suggest') . '?imageMogr2/thumbnail/320x155/extent/240x155/background/d2hpdGU=/position/center/quality/90' : '';
$one['imgUrl'] = !empty($val['cover_image']) ? Images::getSourceUrl($val['cover_image'], 'suggest') : '';
$one['title'] = $val['filter_content'];
$one['content'] = $val['reply_content'];
$one['good'] = ($val['is_reliable'] == 1);
... ...