Authored by Rock Zhang

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

  1 +/**
  2 + * 地址管理
  3 + * @author: bikai<kai.bi@yoho.cn>
  4 + * @date: 2015/11/17
  5 + */
  6 +
  7 +var $ = require('jquery'),
  8 + tip = require('../plugin/tip');
  9 +
  10 +var $action = $('.action'),
  11 + $addressForm = $('.edit-address'),
  12 + $submit = $('.submit'),
  13 + $addAddress = $('.add-address'),
  14 + $editAddressPage = $('.my-edit-address-page'),
  15 + $addressListPage = $('.my-address-list-page'),
  16 + $area = $('.area'),
  17 + $footer = $('#yoho-footer'),
  18 + isSubmiting,
  19 + newArea = [];
  20 +
  21 +function editAddress(data) {
  22 + data = data || {};
  23 + $addressForm.find('[name="id"]').val(data.id || '');
  24 + $addressForm.find('[name="consignee"]').val(data.consignee || '');
  25 + $addressForm.find('[name="mobile"]').val(data.mobile || '');
  26 + $addressForm.find('[name="area_code"]').val(data.areaCode || '');
  27 + $addressForm.find('[name="area"]').val(data.area || '');
  28 + $addressForm.find('[name="address"]').val(data.address || '');
  29 + $editAddressPage.show();
  30 + $addressForm.find('[name="consignee"]').focus();
  31 +}
  32 +
  33 +function deleteAddress(data) {
  34 +
  35 +}
  36 +
  37 +// 添加地址
  38 +$addAddress.on('touchend', function() {
  39 + editAddress();
  40 +});
  41 +
  42 +// 编辑或删除
  43 +$action.on('touchend', '.edit', function() {
  44 + editAddress($(this).data());
  45 +}).on('touchend', '.del', function() {
  46 + deleteAddress();
  47 +});
  48 +
  49 +$submit.on('touchend', function() {
  50 + $addressForm.submit();
  51 + return false;
  52 +});
  53 +
  54 +$addressForm.on('submit', function() {
  55 + if (isSubmiting) {
  56 + return false;
  57 + }
  58 + isSubmiting = true;
  59 + $.ajax({
  60 + method: 'POST',
  61 + url: '/home/saveaddress',
  62 + data: $(this).serialize()
  63 + }).then(function(res) {
  64 + if ($.type(res) !== 'object') {
  65 + res = {};
  66 + }
  67 + if (res.code !== 200) {
  68 + tip.show(res.message || '网络出了点问题~');
  69 + } else {
  70 + window.location.reload();
  71 + }
  72 + }).fail(function() {
  73 + tip.show('网络出了点问题~');
  74 + }).always(function() {
  75 + isSubmiting = false;
  76 + });
  77 + return false;
  78 +});
  79 +
  80 +// 省市区
  81 +$area.on('touchend', function() {
  82 + $footer.hide();
  83 + $addressListPage.show();
  84 +});
  85 +
  86 +$addressListPage.on('touchend', '.address', function() {
  87 + newArea.push($(this).children('.caption').text());
  88 + $(this).siblings().hide();
  89 + $(this).children('ul').show();
  90 + return false;
  91 +}).on('touchend', '.address-last', function() {
  92 +
  93 + // 填结果到 html
  94 + newArea.push($(this).children('.caption').text());
  95 + $('[name="area"]').val(newArea.join(' '));
  96 + $('[name="area_code"]').val($(this).data('id'));
  97 +
  98 + // 恢复默认的三级选择
  99 + $addressListPage.hide();
  100 + $addressListPage.find('ul').hide();
  101 + $addressListPage.children('ul').show().children('li').show();
  102 + $footer.show();
  103 + newArea = [];
  104 + return false;
  105 +});
@@ -102,7 +102,7 @@ @@ -102,7 +102,7 @@
102 .my-edit-address-page { 102 .my-edit-address-page {
103 position: absolute; 103 position: absolute;
104 bottom: 0; 104 bottom: 0;
105 - top: pxToRem(90px); 105 + top: 0;
106 width: 100%; 106 width: 100%;
107 color: #d0d0d0; 107 color: #d0d0d0;
108 background: #f0f0f0; 108 background: #f0f0f0;
@@ -157,7 +157,7 @@ @@ -157,7 +157,7 @@
157 157
158 textarea { 158 textarea {
159 height: pxToRem(58px) * 2; 159 height: pxToRem(58px) * 2;
160 - padding: pxToRem(20px) pxToRem(10px); 160 + padding: pxToRem(20px) 0;
161 } 161 }
162 } 162 }
163 163
@@ -171,4 +171,32 @@ @@ -171,4 +171,32 @@
171 font-size: pxToRem(32px); 171 font-size: pxToRem(32px);
172 line-height: pxToRem(88px); 172 line-height: pxToRem(88px);
173 } 173 }
174 -}  
  174 +}
  175 +
  176 +.my-address-list-page {
  177 + position: absolute;
  178 + bottom: 0;
  179 + top: 0;
  180 + width: 100%;
  181 + color: #444;
  182 + background: #fff;
  183 +
  184 + li {
  185 + padding: 0 pxToRem(30px);
  186 + font-size: pxToRem(32px);
  187 + line-height: pxToRem(88px);
  188 + border-bottom: 1px solid #e0e0e0;
  189 + .iconfont {
  190 + float: right;
  191 + color: #d0d0d0;
  192 + }
  193 + ul {
  194 + display: none;
  195 + position: absolute;
  196 + top: 0;
  197 + left: 0;
  198 + background: #fff;
  199 + width: 100%;
  200 + }
  201 + }
  202 +}
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 <span class="tel">{{mobile}}</span> 6 <span class="tel">{{mobile}}</span>
7 <p class="address-info">{{area}} {{address}}</p> 7 <p class="address-info">{{area}} {{address}}</p>
8 <div class="action iconfont"> 8 <div class="action iconfont">
9 - <a href="/home/address/edit?id={{address_id}}" class="edit">&#xe61e;</a> 9 + <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>
10 <span class="del" data-id="{{address_id}}">&#xe621;</span> 10 <span class="del" data-id="{{address_id}}">&#xe621;</span>
11 </div> 11 </div>
12 </div> 12 </div>
@@ -30,5 +30,7 @@ @@ -30,5 +30,7 @@
30 </div> 30 </div>
31 </div> 31 </div>
32 </div> 32 </div>
  33 + {{> me/address/edit-address}}
  34 + {{> me/address/address-list}}
33 </div> 35 </div>
34 {{> layout/footer}} 36 {{> layout/footer}}
@@ -237,4 +237,9 @@ @@ -237,4 +237,9 @@
237 <script> 237 <script>
238 seajs.use('js/me/online-service'); 238 seajs.use('js/me/online-service');
239 </script> 239 </script>
  240 +{{/if}}
  241 +{{#if addressPage}}
  242 +<script>
  243 + seajs.use('js/me/address');
  244 +</script>
240 {{/if}} 245 {{/if}}
  1 +<div class="my-address-list-page 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 -{{> layout/header}}  
2 -<div class="my-edit-address-page yoho-page"> 1 +<div class="my-edit-address-page hide">
3 <form class="edit-address"> 2 <form class="edit-address">
  3 + <input type="hidden" name="id" value="">
4 <label class="username"> 4 <label class="username">
5 - 用户名  
6 - <input type="text" name="name" value="张三"> 5 + 收件人
  6 + <input type="text" name="consignee" value="">
7 </label> 7 </label>
8 <label class="mobile"> 8 <label class="mobile">
9 手机号码 9 手机号码
10 - <input type="text" name="mobile" value="18911110110"> 10 + <input type="text" name="mobile" value="">
11 </label> 11 </label>
12 <label class="area"> 12 <label class="area">
13 省市区 13 省市区
14 - <input type="text" name="area" value="江苏省南京市栖霞区"> 14 + <input type="hidden" name="area_code" value="">
  15 + <input type="text" name="area" value="" readonly>
15 <span class="iconfont">&#xe604;</span> 16 <span class="iconfont">&#xe604;</span>
16 </label> 17 </label>
17 <label class="address"> 18 <label class="address">
18 详细地址 19 详细地址
19 - <textarea name="address">东大街西大66号茶馆东大街西大66号茶馆东大街西大66号茶馆</textarea> 20 + <textarea name="address"></textarea>
20 </label> 21 </label>
21 22
22 </form> 23 </form>
@@ -24,5 +25,4 @@ @@ -24,5 +25,4 @@
24 <div class="submit"> 25 <div class="submit">
25 确认 26 确认
26 </div> 27 </div>
27 -</div>  
28 -{{> layout/footer}}  
  28 +</div>
@@ -245,7 +245,7 @@ class HomeController extends AbstractAction @@ -245,7 +245,7 @@ class HomeController extends AbstractAction
245 $address = \Index\UserModel::getAddressData($uid); 245 $address = \Index\UserModel::getAddressData($uid);
246 $addressList = \Index\UserModel::getAddressListData($uid); 246 $addressList = \Index\UserModel::getAddressListData($uid);
247 247
248 - // print_r($address); 248 + // print_r($addressList);
249 249
250 $this->_view->display('address', array( 250 $this->_view->display('address', array(
251 'addressPage' => true, 251 'addressPage' => true,
@@ -311,7 +311,7 @@ class HomeController extends AbstractAction @@ -311,7 +311,7 @@ class HomeController extends AbstractAction
311 311
312 $service = home\OnlineModel::getOnlineServiceInfo(); 312 $service = home\OnlineModel::getOnlineServiceInfo();
313 313
314 - $this->_view->display('online_service', array( 314 + $this->_view->display('online-service', array(
315 'onlineServicePage' => true, 315 'onlineServicePage' => true,
316 // 'pageFooter' => true, 316 // 'pageFooter' => true,
317 'service' => $service 317 'service' => $service
@@ -328,7 +328,7 @@ class HomeController extends AbstractAction @@ -328,7 +328,7 @@ class HomeController extends AbstractAction
328 } 328 }
329 $this->setTitle('在线客服'); 329 $this->setTitle('在线客服');
330 $this->setNavHeader($cateName, true, ''); 330 $this->setNavHeader($cateName, true, '');
331 - $this->_view->display('online_service_detail', $service); 331 + $this->_view->display('online-service-detail', $service);
332 } 332 }
333 333
334 /** 334 /**