Authored by 姜敏

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

... ... @@ -11,12 +11,16 @@ const addressModel = require('../models/address');
/**
* 收货地址页面加载
*/
const index = (req, res) => {
const index = (req, res, next) => {
addressModel.getAddressDataAsync('123456', 20).then(result => {
for (let i = 0; i < result.data.length; i++) {
result.data[i].default = result.data[i].is_default === 'Y';
let length = result.length ? result.length : 0;
for (let i = 0; i < length; i++) {
result[i].default = result[i].is_default === 'Y';
result[i].mobile = result[i].mobile.substring(0, 3) + '****' + result[i].mobile.substring(7, 11);
}
result.data.leftLength = 20 - result.data.length;
result.leftLength = 20 - length;
result.length = length;
res.render('index', {
module: 'me',
page: 'address',
... ... @@ -27,10 +31,10 @@ const index = (req, res) => {
banner: 'http://placehold.it/150x120',
address: true,
title: '收货地址',
data: result.data
data: result
}
});
});
}).catch(next);
};
/**
... ... @@ -45,6 +49,7 @@ const addAddressData = (req, res) => {
let phone = req.body.phone;
addressModel.addAddressData(uid, address, areaCode, consignee, mobile, phone).then(result => {
// console.log("添加result", result);
res.send(result);
});
};
... ... @@ -62,6 +67,7 @@ const updateAddressData = (req, res) => {
let phone = req.body.phone;
addressModel.updateAddressData(id, uid, address, areaCode, consignee, mobile, phone).then(result => {
// console.log("修改result", result);
res.send(result);
});
};
... ...
/**
* [个人中心]yoho币
* @author: jiangmin
* @date: 2016/07/11
*/
'use strict';
const mcHandler = require('../models/menu-crumb-handler');
// const currencyModel = require('../models/currency');
/**
* yoho币页面加载
*/
const index = (req, res) => {
res.render('index', {
module: 'me',
page: 'currency',
isMe: true,
content: {
nav: mcHandler.getMeCrumb(),
navigation: mcHandler.getSideMenu('YOHO币'),
banner: 'http://placehold.it/150x120',
currency: true,
tabs: [
{
text: '全部明细',
isActive: true,
type: 'all'
},
{
text: '全部收入',
type: 'paying'
},
{
text: '全部支出',
type: 'delivering'
}
],
title: 'YOHO币'
}
});
};
module.exports = {
index
};
... ...
... ... @@ -22,10 +22,11 @@ const getAddressDataAsync = (uid, limit) => {
limit: limit
}).then(result => {
// console.log('列表结果result', result);
if (result.code === '200') {
if (result.code === 200) {
return result.data;
} else {
return result;
}
return result;
});
};
... ...
/**
* [个人中心]YOHO币
* @author: jiangmin
* @date: 2016/07/11
*/
'use strict';
// const api = global.yoho.API;
... ...
... ... @@ -12,6 +12,7 @@ const cRoot = './controllers';
// 订单
const order = require(`${cRoot}/order`);
const address = require(`${cRoot}/address`);
const currency = require(`${cRoot}/currency`);
// 个人中心首页/订单
router.get(['/', '/order'], order.index);
... ... @@ -24,4 +25,7 @@ router.post('/address/update', address.updateAddressData);
router.post('/address/del', address.delAddressData);
router.post('/address/default', address.setDefaultAddress);
// 个人中心首页/YOHO币
router.get('/currency', currency.index);
module.exports = router;
... ...
... ... @@ -43,7 +43,7 @@
{{!-- 我的YOHO币 --}}
{{#if currency}}
{{> curency}}
{{> currency}}
{{/if}}
{{!-- 个人设置 --}}
... ...
... ... @@ -8,7 +8,7 @@
<input id="consignee" class="input width-190" type="text" placeholder="请输入您的姓名" maxlength="10">
<span class="blue error-tips">{{> icon/error-round}}收件人不能为空</span>
</div>
<div class="form-group">
<div class="form-group1">
<label class="label-name">所在区域:</label>
<div id="address"></div>
<span class="blue error-tips">{{> icon/error-round}}所在区域不能为空</span>
... ...
... ... @@ -3,16 +3,17 @@
<span class="blue table-title">已保存了{{data.length}}条地址,还能保存{{data.leftLength}}条地址</span>
<table class="a-table">
<tr class="table-head">
<th class="width-80">收货人</th>
<th class="width-70">收货人</th>
<th class="width-195">所在区域</th>
<th class="width-280">详细地址</th>
<th class="width-255">详细地址</th>
<th class="width-120">手机/电话</th>
<th class="width-260">操作</th>
</tr>
{{#each data}}
<tr class="table-body">
<input type="hidden" id="tr_{{address_id}}" value="{{address_id}}">
<td class="width-80">{{consignee}}</td>
<input type="hidden" id="tr_{{area_code}}" value="{{area_code}}">
<td class="width-70">{{consignee}}</td>
<td class="width-195">{{area}}</td>
<td class="width-255">{{address}}</td>
<td class="width-120"><p>{{mobile}}</p><p>{{phone}}</p></td>
... ...
<div class="user-order">
{{> common/subtitle}}
{{> currency/nav}}
</div>
... ...
<div class="order-nav">
<ul class="tabs clearfix">
{{#tabs}}
<li class="{{#if isActive}}active{{/if}}" data-type="{{type}}">{{text}}</li>
{{/tabs}}
</ul>
<div class="search-bar">
<!-- <input class="search-ctrl" type="text" placeholder="商品名称和订单号">
<button class="search-ctrl">搜索订单</button>-->
</div>
</div>
... ...
... ... @@ -4,9 +4,9 @@
* @date: 2016/07/05
*/
var cascadingAddress = require('../plugins/cascading-address');
var dialog = require('../plugins/dialog');
var _alert = dialog.Alert;
var _confirm = dialog.Confirm;
var $addressId = $('#address_id');
var $consignee = $('#consignee');
... ... @@ -15,84 +15,7 @@ var $mobile = $('#mobile');
var $phone = $('#phone');
var currentLength = $('.a-table').find('tr').length - 1;// 当前地址条数
var leftLength = 20 - currentLength;// 还剩地址条数
var Bll = {
// 获取输入框输入的值
getInfo() {
// todo uid
var uid = '123456';
return {
id: $addressId.val(),
uid: uid,
consignee: $consignee.val(),
// todo 地址码
address: $address.val(),
mobile: $mobile.val(),
phone: $phone.val()
// todo 设置默认值
};
},
// 清空输入框
clearInput() {
$consignee.val('');
// todo 省市区清空
$address.val('');
$mobile.val('');
$phone.val('');
},
// 校验
check(info) {
let flag = true;
let reg = new RegExp(/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/);
if (info.consignee === '' || info.address === '' || info.mobile === '') {
flag = '有必填项为空';
} else if (!reg.test(info.mobile)) {
flag = '手机号码格式不对';
}
return flag;
},
// 拼接一条数据的html
getHtml(info) {
var html = '<tr class="table-body">';
html += '<input type="hidden" id="tr_' + info.address_id + '" value="' + info.address_id + '">' +
'<td class=\'width-80\'>' + info.consignee + '</td>' +
'<td class=\'width-195\'>' + info.area + '</td>' +
'<td class=\'width-280\'>' + info.address + '</td>' +
'<td class=\'width-120\'><p>' + info.mobile + '</p><p>' + info.phone + '</p></td>' +
'<td class=\'width-260\'><div><span class=\'blue opreation update-address\'>修改</span>\n|\n' +
'<span class=\'blue opreation del-address\' data-id=\'' + info.address_id + '\'>删除</span>\n' +
'<span class=\'btn set-default opreation \' data-id=\'' + info.address_id + '\'>设为默认</span></div></td>';
html += '</tr>';
return html;
},
// 获取一条数据
setInfo(id, td) {
$addressId.val(id);
$consignee.val(td.eq(0).text());
// todo 省市区逆向展示
// $areaCode.val(td.eq(1).text());
$address.val(td.eq(2).text());
$mobile.val(td.eq(3).children().eq(0).text());
$phone.val(td.eq(3).children().eq(1).text());
},
// 设置表格头部
setTableTile() {
$('.table-title').text('已保存了' + currentLength +
'条地址,还能保存' + leftLength + '条地址');
}
};
var reg = new RegExp(/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/);// 手机号码校验
require('./me');
... ... @@ -108,7 +31,7 @@ $('.default-address').click(function() {
});
// 校验
$consignee.keydown(function() {
$consignee.focus(function() {
$(this).next().hide();
});
$consignee.blur(function() {
... ... @@ -116,7 +39,7 @@ $consignee.blur(function() {
$(this).next().show();
}
});
$address.keydown(function() {
$address.focus(function() {
$(this).next().hide();
});
$address.blur(function() {
... ... @@ -124,15 +47,13 @@ $address.blur(function() {
$(this).next().show();
}
});
$mobile.keydown(function() {
$mobile.focus(function() {
$(this).next().hide();
});
$mobile.blur(function() {
if ($(this).val().trim() === '') {
$(this).next().show();
} else {
let reg = new RegExp(/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/);
if (!reg.test(($(this).val().trim()))) {
$(this).next().show();
$(this).next().html('手机号码格式不正确');
... ... @@ -140,124 +61,227 @@ $mobile.blur(function() {
}
});
// 保存收货地址
$(document).on('click', '#save-address', function() {
var info = Bll.getInfo();
var area = $('#address-form').serialize();
info.area_code = area.substring(area.length - 6);
if (Bll.check(info) === true) {
// 新增
if (info.id === '') {
$.ajax({
type: 'POST',
url: '/me/address/add',
dataType: 'json',
data: info,
success: function(data) {
let html = Bll.getHtml(data.data);
currentLength++;
leftLength--;
$('tbody').append(html);
Bll.setTableTile();
Bll.clearInput();
}
});
} else { // 修改
console.log('上传info', info);
$.ajax({
type: 'POST',
url: '/me/address/update',
dataType: 'json',
data: info,
success: function(data) {
if (data.code === 200) {
$('#tr_' + info.id).parent().before(Bll.getHtml(info)).remove();
Bll.clearInput();
} else {
// alert('修改出错!');
}
}
$(function() {
// 运行此demo
// 1. 安装 npm i -g json-server
// 2. json-server --watch mock/address.json
var address = cascadingAddress({
el: '#address',
url: 'http://localhost:3000/areas/0',
resource: 'areas'
});
var Bll = {
// 获取输入框输入的值
getInfo() {
// todo uid
var uid = '123456';
return {
id: $addressId.val(),
uid: uid,
consignee: $consignee.val(),
address: $address.val(),
mobile: $mobile.val(),
phone: $phone.val()
// todo 设置默认值
};
},
// 清空输入框
clearInput() {
$consignee.val('');
// todo 省市区清空
address.setAddress({
province: '', // 省
city: '', // 市
dist: '' // 区县
});
$address.val('');
$mobile.val('');
$phone.val('');
},
// 校验
check(info) {
let flag = true;
if (info.consignee === '' || info.address === '' || info.mobile === '') {
flag = '有必填项为空';
} else if (!reg.test(info.mobile)) {
flag = '手机号码格式不对';
} else if (typeof (info.area_code) === 'undefined') {
flag = '所在区域请选择到:区';
}
return flag;
},
// 拼接一条数据的html
getHtml(info) {
var html = '<tr class="table-body">';
html += '<input type="hidden" id="tr_' + info.address_id + '" value="' + info.address_id + '">' +
'<input type="hidden" id="tr_' + info.area_code + '" value="' + info.area_code + '">' +
'<td class=\'width-80\'>' + info.consignee + '</td>' +
'<td class=\'width-195\'>' + info.area + '</td>' +
'<td class=\'width-280\'>' + info.address + '</td>' +
'<td class=\'width-120\'><p>' + info.mobile + '</p><p>' + info.phone + '</p></td>' +
'<td class=\'width-260\'><div><span class=\'blue opreation update-address\' data-id=\''+
info.address_id + '\'>修改</span>\n|\n' +
'<span class=\'blue opreation del-address\' data-id=\'' + info.address_id + '\'>删除</span>\n' +
'<span class=\'btn set-default opreation \' data-id=\'' + info.address_id + '\'>设为默认</span></div></td>';
html += '</tr>';
return html;
},
// 获取一条数据
setInfo(id, td) {
$addressId.val(id);
$consignee.val(td.eq(0).text());
// todo 省市区逆向展示
$address.val(td.eq(2).text());
$mobile.val(td.eq(3).children().eq(0).text());
$phone.val(td.eq(3).children().eq(1).text());
},
// 设置表格头部
setTableTile() {
$('.table-title').text('已保存了' + currentLength +
'条地址,还能保存' + leftLength + '条地址');
}
} else {
alert(Bll.check(info));
}
});
};
// 修改收货地址
$('.update-address').click(function() {
let id = $(this).data('id');
let tr = $(this).parents('.table-body');
let td = tr.find('td');
Bll.setInfo(id, td);
});
// 保存收货地址
$(document).on('click', '#save-address', function() {
if (currentLength === 20) {
new _alert('您最多添加20个收货地址,可删除不需要的地址后再添加新地址!').show();
Bll.clearInput();
} else {
let info = Bll.getInfo();
let area = address.getAreaIds();
let areaInfo = address.getAreaLabels();
info.area_code = area.split(',')[2];
info.area = areaInfo.split(',').join(' ');
if (Bll.check(info) === true) {
// 新增
if (info.id === '') {
$.ajax({
type: 'POST',
url: '/me/address/add',
dataType: 'json',
data: info,
success: function(data) {
if (data.code === 200) {
let html = Bll.getHtml(data.data);
// 删除收货地址
$('.del-address').click(function() {
let id = $(this).data('id');
var tr = $(this).parents('.table-body');
var a = new _confirm({
content: '您确定要删除收货地址吗?',
cb: function() {
$.ajax({
type: 'POST',
url: '/me/address/del',
dataType: 'json',
data: {
// todo uid
uid: '123456',
id: id
},
success: function() {
currentLength--;
leftLength++;
tr.remove();
Bll.setTableTile();
a.close();
currentLength++;
leftLength--;
$('tbody').append(html);
Bll.setTableTile();
Bll.clearInput();
// location.href="/me/address";
} else {
new _alert('新增接口出错了').show();
}
}
});
} else { // 修改
$.ajax({
type: 'POST',
url: '/me/address/update',
dataType: 'json',
data: info,
success: function(data) {
if (data.code === 200) {
info.mobile = info.mobile.substring(0, 3) + '****' + info.mobile.substring(7, 11);
info.address_id = info.id;
$('#tr_' + info.id).parent().before(Bll.getHtml(info)).remove();
Bll.clearInput();
// location.href="/me/address";
} else {
new _alert('修改接口出错了').show();
}
}
});
}
});
} else {
new _alert(Bll.check(info)).show();
}
}
}).show();
});
// 设置默认收货地址
$(document).on('click', '.set-default', function() {
var tr = $(this).parents('.table-body');
var tbody = tr.parent();
let id = $(this).data('id');
var self = this;
$.ajax({
type: 'POST',
url: '/me/address/default',
dataType: 'json',
data: {
// todo uid
uid: '123456',
id: id
},
success: function() {
$('.current-default').removeClass('current-default').text('设为默认');
$(self).addClass('current-default').text('默认地址');
tbody.find('.table-body').eq(0).before('<tr class=\'table-body\'>' + tr.html() + '</tr>');
tr.remove();
}
});
});
// 修改收货地址
$(document).on('click', '.update-address', function() {
let id = $(this).data('id');
let tr = $(this).parents('.table-body');
let td = tr.find('td');
$(function() {
// 运行此demo
// 1. 安装 npm i -g json-server
// 2. json-server --watch mock/address.json
cascadingAddress({
el: '#address',
url: 'http://localhost:3000/areas/0',
resource: 'areas'
$('.error-tips').hide();
Bll.setInfo(id, td);
});
// 删除收货地址
$(document).on('click', '.del-address', function() {
let id = $(this).data('id');
var tr = $(this).parents('.table-body');
var a = new _confirm({
content: '您确定要删除收货地址吗?',
cb: function() {
$.ajax({
type: 'POST',
url: '/me/address/del',
dataType: 'json',
data: {
// todo uid
uid: '123456',
id: id
},
success: function() {
currentLength--;
leftLength++;
tr.remove();
Bll.setTableTile();
a.close();
Bll.clearInput();
}
});
}
}).show();
});
// 设置默认收货地址
$(document).on('click', '.set-default', function() {
var tr = $(this).parents('.table-body');
var tbody = tr.parent();
let id = $(this).data('id');
var self = this;
$.ajax({
type: 'POST',
url: '/me/address/default',
dataType: 'json',
data: {
// todo uid
uid: '123456',
id: id
},
success: function() {
$('.current-default').removeClass('current-default').text('设为默认');
$(self).addClass('current-default').text('默认地址');
tbody.find('.table-body').eq(0).before('<tr class=\'table-body\'>' + tr.html() + '</tr>');
tr.remove();
}
});
});
});
... ...
/**
* [个人中心]YOHO币
* @author: jiangmin
* @date: 2016/07/11
*/
... ...
.address-page {
.title {
font-size: 30px;
height: 100px;
line-height: 100px;
text-align: left;
}
.tip {
font-size: 14px;
font-size: 12px;
}
.add-address-detail {
... ... @@ -17,56 +10,61 @@
clear: both;
margin-bottom: 20px;
.default-address,
#address,
.btn {
}
.form-group1 {
clear: both;
margin-bottom: 70px;
}
margin-left: 83px;
}
.default-address,
#address,
.btn {
margin-left: 83px;
}
.label-name {
font-size: 14px;
text-align: left;
float: left;
line-height: 26px;
}
.label-name {
font-size: 14px;
text-align: left;
float: left;
line-height: 26px;
}
.width-190 {
width: 190px;
margin-left: 20px;
}
.width-275 {
width: 275px;
margin-left: 20px;
}
.iconfont {
font-size: 14px;
}
.radio-lable {
font-size: 14px;
}
.error-tips {
font-size: 12px;
height: 26px;
line-height: 26px;
margin-left: 20px;
display: none;
.width-190 {
width: 190px;
margin-left: 20px;
}
.width-275 {
width: 275px;
margin-left: 20px;
}
.iconfont {
font-size: 14px;
}
.radio-lable {
font-size: 14px;
}
.error-tips {
font-size: 12px;
height: 26px;
line-height: 26px;
margin-left: 20px;
.iconfont {
font-size: 12px;
margin-right: 5px;
}
}
.opreation {
cursor: pointer;
margin-right: 5px;
}
}
.opreation {
cursor: pointer;
}
}
}
.address-table {
.table-title {
font-size: 10px;
font-size: 12px;
height: 40px;
line-height: 40px;
}
... ... @@ -96,8 +94,8 @@
padding: 8px 5px;
}
.width-80 {
width: 80px;
.width-70 {
width: 70px;
}
.width-195 {
... ...
... ... @@ -103,3 +103,4 @@
@import "address";
@import "order/index";
@import "currency";
... ...