Authored by 姜敏

收货地址--样式调整。出错提示修改。

@@ -11,12 +11,16 @@ const addressModel = require('../models/address'); @@ -11,12 +11,16 @@ const addressModel = require('../models/address');
11 /** 11 /**
12 * 收货地址页面加载 12 * 收货地址页面加载
13 */ 13 */
14 -const index = (req, res) => { 14 +const index = (req, res, next) => {
15 addressModel.getAddressDataAsync('123456', 20).then(result => { 15 addressModel.getAddressDataAsync('123456', 20).then(result => {
16 - for (let i = 0; i < result.data.length; i++) {  
17 - result.data[i].default = result.data[i].is_default === 'Y'; 16 + let length = result.length ? result.length : 0;
  17 +
  18 + for (let i = 0; i < length; i++) {
  19 + result[i].default = result[i].is_default === 'Y';
  20 + result[i].mobile = result[i].mobile.substring(0, 3) + '****' + result[i].mobile.substring(7, 11);
18 } 21 }
19 - result.data.leftLength = 20 - result.data.length; 22 + result.leftLength = 20 - length;
  23 + result.length = length;
20 res.render('index', { 24 res.render('index', {
21 module: 'me', 25 module: 'me',
22 page: 'address', 26 page: 'address',
@@ -27,10 +31,10 @@ const index = (req, res) => { @@ -27,10 +31,10 @@ const index = (req, res) => {
27 banner: 'http://placehold.it/150x120', 31 banner: 'http://placehold.it/150x120',
28 address: true, 32 address: true,
29 title: '收货地址', 33 title: '收货地址',
30 - data: result.data 34 + data: result
31 } 35 }
32 }); 36 });
33 - }); 37 + }).catch(next);
34 }; 38 };
35 39
36 /** 40 /**
@@ -45,6 +49,7 @@ const addAddressData = (req, res) => { @@ -45,6 +49,7 @@ const addAddressData = (req, res) => {
45 let phone = req.body.phone; 49 let phone = req.body.phone;
46 50
47 addressModel.addAddressData(uid, address, areaCode, consignee, mobile, phone).then(result => { 51 addressModel.addAddressData(uid, address, areaCode, consignee, mobile, phone).then(result => {
  52 + // console.log("添加result", result);
48 res.send(result); 53 res.send(result);
49 }); 54 });
50 }; 55 };
@@ -62,6 +67,7 @@ const updateAddressData = (req, res) => { @@ -62,6 +67,7 @@ const updateAddressData = (req, res) => {
62 let phone = req.body.phone; 67 let phone = req.body.phone;
63 68
64 addressModel.updateAddressData(id, uid, address, areaCode, consignee, mobile, phone).then(result => { 69 addressModel.updateAddressData(id, uid, address, areaCode, consignee, mobile, phone).then(result => {
  70 + // console.log("修改result", result);
65 res.send(result); 71 res.send(result);
66 }); 72 });
67 }; 73 };
  1 +/**
  2 + * [个人中心]yoho币
  3 + * @author: jiangmin
  4 + * @date: 2016/07/11
  5 + */
  6 +
  7 +'use strict';
  8 +const mcHandler = require('../models/menu-crumb-handler');
  9 +
  10 +// const currencyModel = require('../models/currency');
  11 +
  12 +/**
  13 + * yoho币页面加载
  14 + */
  15 +const index = (req, res) => {
  16 + res.render('index', {
  17 + module: 'me',
  18 + page: 'currency',
  19 + isMe: true,
  20 + content: {
  21 + nav: mcHandler.getMeCrumb(),
  22 + navigation: mcHandler.getSideMenu('YOHO币'),
  23 + banner: 'http://placehold.it/150x120',
  24 + currency: true,
  25 + tabs: [
  26 + {
  27 + text: '全部明细',
  28 + isActive: true,
  29 + type: 'all'
  30 + },
  31 + {
  32 + text: '全部收入',
  33 + type: 'paying'
  34 + },
  35 + {
  36 + text: '全部支出',
  37 + type: 'delivering'
  38 + }
  39 + ],
  40 + title: 'YOHO币'
  41 + }
  42 + });
  43 +};
  44 +
  45 +module.exports = {
  46 + index
  47 +};
@@ -22,10 +22,11 @@ const getAddressDataAsync = (uid, limit) => { @@ -22,10 +22,11 @@ const getAddressDataAsync = (uid, limit) => {
22 limit: limit 22 limit: limit
23 }).then(result => { 23 }).then(result => {
24 // console.log('列表结果result', result); 24 // console.log('列表结果result', result);
25 - if (result.code === '200') { 25 + if (result.code === 200) {
26 return result.data; 26 return result.data;
  27 + } else {
  28 + return result;
27 } 29 }
28 - return result;  
29 }); 30 });
30 }; 31 };
31 32
  1 +/**
  2 + * [个人中心]YOHO币
  3 + * @author: jiangmin
  4 + * @date: 2016/07/11
  5 + */
  6 +
  7 +'use strict';
  8 +
  9 +// const api = global.yoho.API;
  10 +
@@ -12,6 +12,7 @@ const cRoot = './controllers'; @@ -12,6 +12,7 @@ const cRoot = './controllers';
12 // 订单 12 // 订单
13 const order = require(`${cRoot}/order`); 13 const order = require(`${cRoot}/order`);
14 const address = require(`${cRoot}/address`); 14 const address = require(`${cRoot}/address`);
  15 +const currency = require(`${cRoot}/currency`);
15 16
16 // 个人中心首页/订单 17 // 个人中心首页/订单
17 router.get(['/', '/order'], order.index); 18 router.get(['/', '/order'], order.index);
@@ -24,4 +25,7 @@ router.post('/address/update', address.updateAddressData); @@ -24,4 +25,7 @@ router.post('/address/update', address.updateAddressData);
24 router.post('/address/del', address.delAddressData); 25 router.post('/address/del', address.delAddressData);
25 router.post('/address/default', address.setDefaultAddress); 26 router.post('/address/default', address.setDefaultAddress);
26 27
  28 +// 个人中心首页/YOHO币
  29 +router.get('/currency', currency.index);
  30 +
27 module.exports = router; 31 module.exports = router;
@@ -43,7 +43,7 @@ @@ -43,7 +43,7 @@
43 43
44 {{!-- 我的YOHO币 --}} 44 {{!-- 我的YOHO币 --}}
45 {{#if currency}} 45 {{#if currency}}
46 - {{> curency}} 46 + {{> currency}}
47 {{/if}} 47 {{/if}}
48 48
49 {{!-- 个人设置 --}} 49 {{!-- 个人设置 --}}
@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 <input id="consignee" class="input width-190" type="text" placeholder="请输入您的姓名" maxlength="10"> 8 <input id="consignee" class="input width-190" type="text" placeholder="请输入您的姓名" maxlength="10">
9 <span class="blue error-tips">{{> icon/error-round}}收件人不能为空</span> 9 <span class="blue error-tips">{{> icon/error-round}}收件人不能为空</span>
10 </div> 10 </div>
11 - <div class="form-group"> 11 + <div class="form-group1">
12 <label class="label-name">所在区域:</label> 12 <label class="label-name">所在区域:</label>
13 <div id="address"></div> 13 <div id="address"></div>
14 <span class="blue error-tips">{{> icon/error-round}}所在区域不能为空</span> 14 <span class="blue error-tips">{{> icon/error-round}}所在区域不能为空</span>
@@ -3,16 +3,17 @@ @@ -3,16 +3,17 @@
3 <span class="blue table-title">已保存了{{data.length}}条地址,还能保存{{data.leftLength}}条地址</span> 3 <span class="blue table-title">已保存了{{data.length}}条地址,还能保存{{data.leftLength}}条地址</span>
4 <table class="a-table"> 4 <table class="a-table">
5 <tr class="table-head"> 5 <tr class="table-head">
6 - <th class="width-80">收货人</th> 6 + <th class="width-70">收货人</th>
7 <th class="width-195">所在区域</th> 7 <th class="width-195">所在区域</th>
8 - <th class="width-280">详细地址</th> 8 + <th class="width-255">详细地址</th>
9 <th class="width-120">手机/电话</th> 9 <th class="width-120">手机/电话</th>
10 <th class="width-260">操作</th> 10 <th class="width-260">操作</th>
11 </tr> 11 </tr>
12 {{#each data}} 12 {{#each data}}
13 <tr class="table-body"> 13 <tr class="table-body">
14 <input type="hidden" id="tr_{{address_id}}" value="{{address_id}}"> 14 <input type="hidden" id="tr_{{address_id}}" value="{{address_id}}">
15 - <td class="width-80">{{consignee}}</td> 15 + <input type="hidden" id="tr_{{area_code}}" value="{{area_code}}">
  16 + <td class="width-70">{{consignee}}</td>
16 <td class="width-195">{{area}}</td> 17 <td class="width-195">{{area}}</td>
17 <td class="width-255">{{address}}</td> 18 <td class="width-255">{{address}}</td>
18 <td class="width-120"><p>{{mobile}}</p><p>{{phone}}</p></td> 19 <td class="width-120"><p>{{mobile}}</p><p>{{phone}}</p></td>
  1 +<div class="user-order">
  2 + {{> common/subtitle}}
  3 + {{> currency/nav}}
  4 +</div>
  1 +<div class="order-nav">
  2 + <ul class="tabs clearfix">
  3 + {{#tabs}}
  4 + <li class="{{#if isActive}}active{{/if}}" data-type="{{type}}">{{text}}</li>
  5 + {{/tabs}}
  6 + </ul>
  7 + <div class="search-bar">
  8 + <!-- <input class="search-ctrl" type="text" placeholder="商品名称和订单号">
  9 + <button class="search-ctrl">搜索订单</button>-->
  10 + </div>
  11 +</div>
@@ -4,9 +4,9 @@ @@ -4,9 +4,9 @@
4 * @date: 2016/07/05 4 * @date: 2016/07/05
5 */ 5 */
6 6
7 -  
8 var cascadingAddress = require('../plugins/cascading-address'); 7 var cascadingAddress = require('../plugins/cascading-address');
9 var dialog = require('../plugins/dialog'); 8 var dialog = require('../plugins/dialog');
  9 +var _alert = dialog.Alert;
10 var _confirm = dialog.Confirm; 10 var _confirm = dialog.Confirm;
11 var $addressId = $('#address_id'); 11 var $addressId = $('#address_id');
12 var $consignee = $('#consignee'); 12 var $consignee = $('#consignee');
@@ -15,84 +15,7 @@ var $mobile = $('#mobile'); @@ -15,84 +15,7 @@ var $mobile = $('#mobile');
15 var $phone = $('#phone'); 15 var $phone = $('#phone');
16 var currentLength = $('.a-table').find('tr').length - 1;// 当前地址条数 16 var currentLength = $('.a-table').find('tr').length - 1;// 当前地址条数
17 var leftLength = 20 - currentLength;// 还剩地址条数 17 var leftLength = 20 - currentLength;// 还剩地址条数
18 -  
19 -var Bll = {  
20 - // 获取输入框输入的值  
21 - getInfo() {  
22 - // todo uid  
23 - var uid = '123456';  
24 -  
25 - return {  
26 - id: $addressId.val(),  
27 - uid: uid,  
28 - consignee: $consignee.val(),  
29 -  
30 - // todo 地址码  
31 - address: $address.val(),  
32 - mobile: $mobile.val(),  
33 - phone: $phone.val()  
34 -  
35 - // todo 设置默认值  
36 - };  
37 - },  
38 -  
39 - // 清空输入框  
40 - clearInput() {  
41 - $consignee.val('');  
42 -  
43 - // todo 省市区清空  
44 - $address.val('');  
45 - $mobile.val('');  
46 - $phone.val('');  
47 - },  
48 -  
49 - // 校验  
50 - check(info) {  
51 - let flag = true;  
52 - let reg = new RegExp(/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/);  
53 -  
54 - if (info.consignee === '' || info.address === '' || info.mobile === '') {  
55 - flag = '有必填项为空';  
56 - } else if (!reg.test(info.mobile)) {  
57 - flag = '手机号码格式不对';  
58 - }  
59 - return flag;  
60 - },  
61 -  
62 - // 拼接一条数据的html  
63 - getHtml(info) {  
64 - var html = '<tr class="table-body">';  
65 -  
66 - html += '<input type="hidden" id="tr_' + info.address_id + '" value="' + info.address_id + '">' +  
67 - '<td class=\'width-80\'>' + info.consignee + '</td>' +  
68 - '<td class=\'width-195\'>' + info.area + '</td>' +  
69 - '<td class=\'width-280\'>' + info.address + '</td>' +  
70 - '<td class=\'width-120\'><p>' + info.mobile + '</p><p>' + info.phone + '</p></td>' +  
71 - '<td class=\'width-260\'><div><span class=\'blue opreation update-address\'>修改</span>\n|\n' +  
72 - '<span class=\'blue opreation del-address\' data-id=\'' + info.address_id + '\'>删除</span>\n' +  
73 - '<span class=\'btn set-default opreation \' data-id=\'' + info.address_id + '\'>设为默认</span></div></td>';  
74 - html += '</tr>';  
75 - return html;  
76 - },  
77 -  
78 - // 获取一条数据  
79 - setInfo(id, td) {  
80 - $addressId.val(id);  
81 - $consignee.val(td.eq(0).text());  
82 -  
83 - // todo 省市区逆向展示  
84 - // $areaCode.val(td.eq(1).text());  
85 - $address.val(td.eq(2).text());  
86 - $mobile.val(td.eq(3).children().eq(0).text());  
87 - $phone.val(td.eq(3).children().eq(1).text());  
88 - },  
89 -  
90 - // 设置表格头部  
91 - setTableTile() {  
92 - $('.table-title').text('已保存了' + currentLength +  
93 - '条地址,还能保存' + leftLength + '条地址');  
94 - }  
95 -}; 18 +var reg = new RegExp(/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/);// 手机号码校验
96 19
97 require('./me'); 20 require('./me');
98 21
@@ -108,7 +31,7 @@ $('.default-address').click(function() { @@ -108,7 +31,7 @@ $('.default-address').click(function() {
108 }); 31 });
109 32
110 // 校验 33 // 校验
111 -$consignee.keydown(function() { 34 +$consignee.focus(function() {
112 $(this).next().hide(); 35 $(this).next().hide();
113 }); 36 });
114 $consignee.blur(function() { 37 $consignee.blur(function() {
@@ -116,7 +39,7 @@ $consignee.blur(function() { @@ -116,7 +39,7 @@ $consignee.blur(function() {
116 $(this).next().show(); 39 $(this).next().show();
117 } 40 }
118 }); 41 });
119 -$address.keydown(function() { 42 +$address.focus(function() {
120 $(this).next().hide(); 43 $(this).next().hide();
121 }); 44 });
122 $address.blur(function() { 45 $address.blur(function() {
@@ -124,15 +47,13 @@ $address.blur(function() { @@ -124,15 +47,13 @@ $address.blur(function() {
124 $(this).next().show(); 47 $(this).next().show();
125 } 48 }
126 }); 49 });
127 -$mobile.keydown(function() { 50 +$mobile.focus(function() {
128 $(this).next().hide(); 51 $(this).next().hide();
129 }); 52 });
130 $mobile.blur(function() { 53 $mobile.blur(function() {
131 if ($(this).val().trim() === '') { 54 if ($(this).val().trim() === '') {
132 $(this).next().show(); 55 $(this).next().show();
133 } else { 56 } else {
134 - let reg = new RegExp(/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/);  
135 -  
136 if (!reg.test(($(this).val().trim()))) { 57 if (!reg.test(($(this).val().trim()))) {
137 $(this).next().show(); 58 $(this).next().show();
138 $(this).next().html('手机号码格式不正确'); 59 $(this).next().html('手机号码格式不正确');
@@ -140,124 +61,227 @@ $mobile.blur(function() { @@ -140,124 +61,227 @@ $mobile.blur(function() {
140 } 61 }
141 }); 62 });
142 63
143 -// 保存收货地址  
144 -$(document).on('click', '#save-address', function() {  
145 - var info = Bll.getInfo();  
146 - var area = $('#address-form').serialize();  
147 -  
148 - info.area_code = area.substring(area.length - 6);  
149 - if (Bll.check(info) === true) {  
150 - // 新增  
151 - if (info.id === '') {  
152 - $.ajax({  
153 - type: 'POST',  
154 - url: '/me/address/add',  
155 - dataType: 'json',  
156 - data: info,  
157 - success: function(data) {  
158 - let html = Bll.getHtml(data.data);  
159 -  
160 - currentLength++;  
161 - leftLength--;  
162 - $('tbody').append(html);  
163 - Bll.setTableTile();  
164 - Bll.clearInput();  
165 - }  
166 - });  
167 - } else { // 修改  
168 - console.log('上传info', info);  
169 - $.ajax({  
170 - type: 'POST',  
171 - url: '/me/address/update',  
172 - dataType: 'json',  
173 - data: info,  
174 - success: function(data) {  
175 - if (data.code === 200) {  
176 - $('#tr_' + info.id).parent().before(Bll.getHtml(info)).remove();  
177 - Bll.clearInput();  
178 - } else {  
179 64
180 - // alert('修改出错!');  
181 - }  
182 - } 65 +$(function() {
  66 + // 运行此demo
  67 + // 1. 安装 npm i -g json-server
  68 + // 2. json-server --watch mock/address.json
  69 + var address = cascadingAddress({
  70 + el: '#address',
  71 + url: 'http://localhost:3000/areas/0',
  72 + resource: 'areas'
  73 + });
  74 +
  75 + var Bll = {
  76 + // 获取输入框输入的值
  77 + getInfo() {
  78 + // todo uid
  79 + var uid = '123456';
  80 +
  81 + return {
  82 + id: $addressId.val(),
  83 + uid: uid,
  84 + consignee: $consignee.val(),
  85 + address: $address.val(),
  86 + mobile: $mobile.val(),
  87 + phone: $phone.val()
  88 +
  89 + // todo 设置默认值
  90 + };
  91 + },
  92 +
  93 + // 清空输入框
  94 + clearInput() {
  95 + $consignee.val('');
  96 +
  97 + // todo 省市区清空
  98 + address.setAddress({
  99 + province: '', // 省
  100 + city: '', // 市
  101 + dist: '' // 区县
183 }); 102 });
  103 + $address.val('');
  104 + $mobile.val('');
  105 + $phone.val('');
  106 + },
  107 +
  108 + // 校验
  109 + check(info) {
  110 + let flag = true;
  111 +
  112 + if (info.consignee === '' || info.address === '' || info.mobile === '') {
  113 + flag = '有必填项为空';
  114 + } else if (!reg.test(info.mobile)) {
  115 + flag = '手机号码格式不对';
  116 + } else if (typeof (info.area_code) === 'undefined') {
  117 + flag = '所在区域请选择到:区';
  118 + }
  119 + return flag;
  120 + },
  121 +
  122 + // 拼接一条数据的html
  123 + getHtml(info) {
  124 + var html = '<tr class="table-body">';
  125 +
  126 + html += '<input type="hidden" id="tr_' + info.address_id + '" value="' + info.address_id + '">' +
  127 + '<input type="hidden" id="tr_' + info.area_code + '" value="' + info.area_code + '">' +
  128 + '<td class=\'width-80\'>' + info.consignee + '</td>' +
  129 + '<td class=\'width-195\'>' + info.area + '</td>' +
  130 + '<td class=\'width-280\'>' + info.address + '</td>' +
  131 + '<td class=\'width-120\'><p>' + info.mobile + '</p><p>' + info.phone + '</p></td>' +
  132 + '<td class=\'width-260\'><div><span class=\'blue opreation update-address\' data-id=\''+
  133 + info.address_id + '\'>修改</span>\n|\n' +
  134 + '<span class=\'blue opreation del-address\' data-id=\'' + info.address_id + '\'>删除</span>\n' +
  135 + '<span class=\'btn set-default opreation \' data-id=\'' + info.address_id + '\'>设为默认</span></div></td>';
  136 + html += '</tr>';
  137 + return html;
  138 + },
  139 +
  140 + // 获取一条数据
  141 + setInfo(id, td) {
  142 + $addressId.val(id);
  143 + $consignee.val(td.eq(0).text());
  144 +
  145 + // todo 省市区逆向展示
  146 + $address.val(td.eq(2).text());
  147 + $mobile.val(td.eq(3).children().eq(0).text());
  148 + $phone.val(td.eq(3).children().eq(1).text());
  149 + },
  150 +
  151 + // 设置表格头部
  152 + setTableTile() {
  153 + $('.table-title').text('已保存了' + currentLength +
  154 + '条地址,还能保存' + leftLength + '条地址');
184 } 155 }
185 - } else {  
186 - alert(Bll.check(info));  
187 - }  
188 -}); 156 + };
189 157
190 -// 修改收货地址  
191 -$('.update-address').click(function() {  
192 - let id = $(this).data('id');  
193 - let tr = $(this).parents('.table-body');  
194 - let td = tr.find('td');  
195 158
196 - Bll.setInfo(id, td);  
197 -}); 159 + // 保存收货地址
  160 + $(document).on('click', '#save-address', function() {
  161 + if (currentLength === 20) {
  162 + new _alert('您最多添加20个收货地址,可删除不需要的地址后再添加新地址!').show();
  163 + Bll.clearInput();
  164 + } else {
  165 + let info = Bll.getInfo();
  166 + let area = address.getAreaIds();
  167 + let areaInfo = address.getAreaLabels();
  168 +
  169 + info.area_code = area.split(',')[2];
  170 + info.area = areaInfo.split(',').join(' ');
  171 + if (Bll.check(info) === true) {
  172 + // 新增
  173 + if (info.id === '') {
  174 + $.ajax({
  175 + type: 'POST',
  176 + url: '/me/address/add',
  177 + dataType: 'json',
  178 + data: info,
  179 + success: function(data) {
  180 + if (data.code === 200) {
  181 + let html = Bll.getHtml(data.data);
198 182
199 -// 删除收货地址  
200 -$('.del-address').click(function() {  
201 - let id = $(this).data('id');  
202 - var tr = $(this).parents('.table-body');  
203 -  
204 - var a = new _confirm({  
205 - content: '您确定要删除收货地址吗?',  
206 - cb: function() {  
207 - $.ajax({  
208 - type: 'POST',  
209 - url: '/me/address/del',  
210 - dataType: 'json',  
211 - data: {  
212 - // todo uid  
213 - uid: '123456',  
214 - id: id  
215 - },  
216 - success: function() {  
217 - currentLength--;  
218 - leftLength++;  
219 - tr.remove();  
220 - Bll.setTableTile();  
221 - a.close(); 183 + currentLength++;
  184 + leftLength--;
  185 + $('tbody').append(html);
  186 + Bll.setTableTile();
  187 + Bll.clearInput();
  188 +
  189 + // location.href="/me/address";
  190 + } else {
  191 + new _alert('新增接口出错了').show();
  192 + }
  193 + }
  194 + });
  195 + } else { // 修改
  196 + $.ajax({
  197 + type: 'POST',
  198 + url: '/me/address/update',
  199 + dataType: 'json',
  200 + data: info,
  201 + success: function(data) {
  202 + if (data.code === 200) {
  203 + info.mobile = info.mobile.substring(0, 3) + '****' + info.mobile.substring(7, 11);
  204 + info.address_id = info.id;
  205 + $('#tr_' + info.id).parent().before(Bll.getHtml(info)).remove();
  206 + Bll.clearInput();
  207 +
  208 + // location.href="/me/address";
  209 + } else {
  210 + new _alert('修改接口出错了').show();
  211 + }
  212 + }
  213 + });
222 } 214 }
223 - }); 215 + } else {
  216 + new _alert(Bll.check(info)).show();
  217 + }
224 } 218 }
225 - }).show();  
226 -});  
227 219
228 -// 设置默认收货地址  
229 -$(document).on('click', '.set-default', function() {  
230 - var tr = $(this).parents('.table-body');  
231 - var tbody = tr.parent();  
232 - let id = $(this).data('id');  
233 - var self = this;  
234 -  
235 - $.ajax({  
236 - type: 'POST',  
237 - url: '/me/address/default',  
238 - dataType: 'json',  
239 - data: {  
240 - // todo uid  
241 - uid: '123456',  
242 - id: id  
243 - },  
244 - success: function() {  
245 - $('.current-default').removeClass('current-default').text('设为默认');  
246 - $(self).addClass('current-default').text('默认地址');  
247 - tbody.find('.table-body').eq(0).before('<tr class=\'table-body\'>' + tr.html() + '</tr>');  
248 - tr.remove();  
249 - }  
250 }); 220 });
251 -});  
252 221
  222 + // 修改收货地址
  223 + $(document).on('click', '.update-address', function() {
  224 + let id = $(this).data('id');
  225 + let tr = $(this).parents('.table-body');
  226 + let td = tr.find('td');
253 227
254 -$(function() {  
255 - // 运行此demo  
256 - // 1. 安装 npm i -g json-server  
257 - // 2. json-server --watch mock/address.json  
258 - cascadingAddress({  
259 - el: '#address',  
260 - url: 'http://localhost:3000/areas/0',  
261 - resource: 'areas' 228 + $('.error-tips').hide();
  229 + Bll.setInfo(id, td);
  230 + });
  231 +
  232 + // 删除收货地址
  233 + $(document).on('click', '.del-address', function() {
  234 + let id = $(this).data('id');
  235 + var tr = $(this).parents('.table-body');
  236 +
  237 + var a = new _confirm({
  238 + content: '您确定要删除收货地址吗?',
  239 + cb: function() {
  240 + $.ajax({
  241 + type: 'POST',
  242 + url: '/me/address/del',
  243 + dataType: 'json',
  244 + data: {
  245 + // todo uid
  246 + uid: '123456',
  247 + id: id
  248 + },
  249 + success: function() {
  250 + currentLength--;
  251 + leftLength++;
  252 + tr.remove();
  253 + Bll.setTableTile();
  254 + a.close();
  255 + Bll.clearInput();
  256 + }
  257 + });
  258 + }
  259 + }).show();
  260 +
  261 + });
  262 +
  263 + // 设置默认收货地址
  264 + $(document).on('click', '.set-default', function() {
  265 + var tr = $(this).parents('.table-body');
  266 + var tbody = tr.parent();
  267 + let id = $(this).data('id');
  268 + var self = this;
  269 +
  270 + $.ajax({
  271 + type: 'POST',
  272 + url: '/me/address/default',
  273 + dataType: 'json',
  274 + data: {
  275 + // todo uid
  276 + uid: '123456',
  277 + id: id
  278 + },
  279 + success: function() {
  280 + $('.current-default').removeClass('current-default').text('设为默认');
  281 + $(self).addClass('current-default').text('默认地址');
  282 + tbody.find('.table-body').eq(0).before('<tr class=\'table-body\'>' + tr.html() + '</tr>');
  283 + tr.remove();
  284 + }
  285 + });
262 }); 286 });
263 }); 287 });
  1 +/**
  2 + * [个人中心]YOHO币
  3 + * @author: jiangmin
  4 + * @date: 2016/07/11
  5 + */
1 .address-page { 1 .address-page {
2 -  
3 - .title {  
4 - font-size: 30px;  
5 - height: 100px;  
6 - line-height: 100px;  
7 - text-align: left;  
8 - }  
9 .tip { 2 .tip {
10 - font-size: 14px; 3 + font-size: 12px;
11 } 4 }
12 5
13 .add-address-detail { 6 .add-address-detail {
@@ -17,56 +10,61 @@ @@ -17,56 +10,61 @@
17 clear: both; 10 clear: both;
18 margin-bottom: 20px; 11 margin-bottom: 20px;
19 12
20 - .default-address,  
21 - #address,  
22 - .btn { 13 + }
  14 + .form-group1 {
  15 + clear: both;
  16 + margin-bottom: 70px;
  17 + }
23 18
24 - margin-left: 83px;  
25 - } 19 + .default-address,
  20 + #address,
  21 + .btn {
  22 + margin-left: 83px;
  23 + }
26 24
27 - .label-name {  
28 - font-size: 14px;  
29 - text-align: left;  
30 - float: left;  
31 - line-height: 26px;  
32 - } 25 + .label-name {
  26 + font-size: 14px;
  27 + text-align: left;
  28 + float: left;
  29 + line-height: 26px;
  30 + }
  31 +
  32 + .width-190 {
  33 + width: 190px;
  34 + margin-left: 20px;
  35 + }
  36 + .width-275 {
  37 + width: 275px;
  38 + margin-left: 20px;
  39 + }
  40 + .iconfont {
  41 + font-size: 14px;
  42 + }
  43 + .radio-lable {
  44 + font-size: 14px;
  45 + }
  46 + .error-tips {
  47 + font-size: 12px;
  48 + height: 26px;
  49 + line-height: 26px;
  50 + margin-left: 20px;
  51 + display: none;
33 52
34 - .width-190 {  
35 - width: 190px;  
36 - margin-left: 20px;  
37 - }  
38 - .width-275 {  
39 - width: 275px;  
40 - margin-left: 20px;  
41 - }  
42 .iconfont { 53 .iconfont {
43 - font-size: 14px;  
44 - }  
45 - .radio-lable {  
46 - font-size: 14px;  
47 - }  
48 - .error-tips {  
49 font-size: 12px; 54 font-size: 12px;
50 - height: 26px;  
51 - line-height: 26px;  
52 - margin-left: 20px;  
53 -  
54 - .iconfont {  
55 - font-size: 12px;  
56 - margin-right: 5px;  
57 - }  
58 - }  
59 - .opreation {  
60 - cursor: pointer; 55 + margin-right: 5px;
61 } 56 }
62 -  
63 } 57 }
  58 + .opreation {
  59 + cursor: pointer;
  60 + }
  61 +
64 } 62 }
65 } 63 }
66 64
67 .address-table { 65 .address-table {
68 .table-title { 66 .table-title {
69 - font-size: 10px; 67 + font-size: 12px;
70 height: 40px; 68 height: 40px;
71 line-height: 40px; 69 line-height: 40px;
72 } 70 }
@@ -96,8 +94,8 @@ @@ -96,8 +94,8 @@
96 padding: 8px 5px; 94 padding: 8px 5px;
97 } 95 }
98 96
99 - .width-80 {  
100 - width: 80px; 97 + .width-70 {
  98 + width: 70px;
101 } 99 }
102 100
103 .width-195 { 101 .width-195 {
@@ -103,3 +103,4 @@ @@ -103,3 +103,4 @@
103 103
104 @import "address"; 104 @import "address";
105 @import "order/index"; 105 @import "order/index";
  106 +@import "currency";