Authored by Rock Zhang

Merge branch 'develop' of git.dev.yoho.cn:web/yohobuy into develop

/**
* 地址管理
* @author: bikai<kai.bi@yoho.cn>
* @date: 2015/11/17
*/
var $ = require('jquery'),
tip = require('../plugin/tip');
var $action = $('.action'),
$addressForm = $('.edit-address'),
$submit = $('.submit'),
$addAddress = $('.add-address'),
$editAddressPage = $('.my-edit-address-page'),
$addressListPage = $('.my-address-list-page'),
$area = $('.area'),
$footer = $('#yoho-footer'),
isSubmiting,
newArea = [];
function editAddress(data) {
data = data || {};
$addressForm.find('[name="id"]').val(data.id || '');
$addressForm.find('[name="consignee"]').val(data.consignee || '');
$addressForm.find('[name="mobile"]').val(data.mobile || '');
$addressForm.find('[name="area_code"]').val(data.areaCode || '');
$addressForm.find('[name="area"]').val(data.area || '');
$addressForm.find('[name="address"]').val(data.address || '');
$editAddressPage.show();
$addressForm.find('[name="consignee"]').focus();
}
function deleteAddress(data) {
}
// 添加地址
$addAddress.on('touchend', function() {
editAddress();
});
// 编辑或删除
$action.on('touchend', '.edit', function() {
editAddress($(this).data());
}).on('touchend', '.del', function() {
deleteAddress();
});
$submit.on('touchend', function() {
$addressForm.submit();
return false;
});
$addressForm.on('submit', function() {
if (isSubmiting) {
return false;
}
isSubmiting = true;
$.ajax({
method: 'POST',
url: '/home/saveaddress',
data: $(this).serialize()
}).then(function(res) {
if ($.type(res) !== 'object') {
res = {};
}
if (res.code !== 200) {
tip.show(res.message || '网络出了点问题~');
} else {
window.location.reload();
}
}).fail(function() {
tip.show('网络出了点问题~');
}).always(function() {
isSubmiting = false;
});
return false;
});
// 省市区
$area.on('touchend', function() {
$footer.hide();
$addressListPage.show();
});
$addressListPage.on('touchend', '.address', function() {
newArea.push($(this).children('.caption').text());
$(this).siblings().hide();
$(this).children('ul').show();
return false;
}).on('touchend', '.address-last', function() {
// 填结果到 html
newArea.push($(this).children('.caption').text());
$('[name="area"]').val(newArea.join(' '));
$('[name="area_code"]').val($(this).data('id'));
// 恢复默认的三级选择
$addressListPage.hide();
$addressListPage.find('ul').hide();
$addressListPage.children('ul').show().children('li').show();
$footer.show();
newArea = [];
return false;
});
... ...
... ... @@ -102,7 +102,7 @@
.my-edit-address-page {
position: absolute;
bottom: 0;
top: pxToRem(90px);
top: 0;
width: 100%;
color: #d0d0d0;
background: #f0f0f0;
... ... @@ -157,7 +157,7 @@
textarea {
height: pxToRem(58px) * 2;
padding: pxToRem(20px) pxToRem(10px);
padding: pxToRem(20px) 0;
}
}
... ... @@ -171,4 +171,32 @@
font-size: pxToRem(32px);
line-height: pxToRem(88px);
}
}
\ No newline at end of file
}
.my-address-list-page {
position: absolute;
bottom: 0;
top: 0;
width: 100%;
color: #444;
background: #fff;
li {
padding: 0 pxToRem(30px);
font-size: pxToRem(32px);
line-height: pxToRem(88px);
border-bottom: 1px solid #e0e0e0;
.iconfont {
float: right;
color: #d0d0d0;
}
ul {
display: none;
position: absolute;
top: 0;
left: 0;
background: #fff;
width: 100%;
}
}
}
... ...
... ... @@ -6,7 +6,7 @@
<span class="tel">{{mobile}}</span>
<p class="address-info">{{area}} {{address}}</p>
<div class="action iconfont">
<a href="/home/address/edit?id={{address_id}}" class="edit">&#xe61e;</a>
<span class="edit" data-id="{{address_id}}" data-consignee="{{consignee}}" data-mobile="{{mobile}}" data-area-code="{{area_code}}" data-area="{{area}}" data-address="{{address}}">&#xe61e;</span>
<span class="del" data-id="{{address_id}}">&#xe621;</span>
</div>
</div>
... ... @@ -30,5 +30,7 @@
</div>
</div>
</div>
{{> me/address/edit-address}}
{{> me/address/address-list}}
</div>
{{> layout/footer}}
\ No newline at end of file
... ...
... ... @@ -237,4 +237,9 @@
<script>
seajs.use('js/me/online-service');
</script>
{{/if}}
{{#if addressPage}}
<script>
seajs.use('js/me/address');
</script>
{{/if}}
\ No newline at end of file
... ...
<div class="my-address-list-page 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
... ...
{{> layout/header}}
<div class="my-edit-address-page yoho-page">
<div class="my-edit-address-page hide">
<form class="edit-address">
<input type="hidden" name="id" value="">
<label class="username">
用户名
<input type="text" name="name" value="张三">
收件人
<input type="text" name="consignee" value="">
</label>
<label class="mobile">
手机号码
<input type="text" name="mobile" value="18911110110">
<input type="text" name="mobile" value="">
</label>
<label class="area">
省市区
<input type="text" name="area" value="江苏省南京市栖霞区">
<input type="hidden" name="area_code" value="">
<input type="text" name="area" value="" readonly>
<span class="iconfont">&#xe604;</span>
</label>
<label class="address">
详细地址
<textarea name="address">东大街西大66号茶馆东大街西大66号茶馆东大街西大66号茶馆</textarea>
<textarea name="address"></textarea>
</label>
</form>
... ... @@ -24,5 +25,4 @@
<div class="submit">
确认
</div>
</div>
{{> layout/footer}}
\ No newline at end of file
</div>
\ No newline at end of file
... ...
... ... @@ -245,7 +245,7 @@ class HomeController extends AbstractAction
$address = \Index\UserModel::getAddressData($uid);
$addressList = \Index\UserModel::getAddressListData($uid);
// print_r($address);
// print_r($addressList);
$this->_view->display('address', array(
'addressPage' => true,
... ... @@ -311,7 +311,7 @@ class HomeController extends AbstractAction
$service = home\OnlineModel::getOnlineServiceInfo();
$this->_view->display('online_service', array(
$this->_view->display('online-service', array(
'onlineServicePage' => true,
// 'pageFooter' => true,
'service' => $service
... ... @@ -328,7 +328,7 @@ class HomeController extends AbstractAction
}
$this->setTitle('在线客服');
$this->setNavHeader($cateName, true, '');
$this->_view->display('online_service_detail', $service);
$this->_view->display('online-service-detail', $service);
}
/**
... ...