Authored by biao

Merge branch 'feature/my-order' into develop

... ... @@ -110,6 +110,19 @@ const getCancelOrderReason = (req, res) => {
});
};
const editOrder = (req, res) => {
const uid = global.yoho.uid || '10931021';
const query = req.query;
query.uid = uid;
console.log(query);
orderModel.editOrder(query).then(result => {
res.json(result);
});
};
module.exports = {
index: index,
detail: detail,
... ... @@ -117,6 +130,7 @@ module.exports = {
getOrderTotal: getOrderTotal,
cancelOrder: cancelOrder,
deleteOrder: deleteOrder,
editOrder: editOrder,
getExpressInfo: getExpressInfo,
getCancelOrderReason: getCancelOrderReason
};
... ...
... ... @@ -100,8 +100,47 @@ const isMobileOrder = {
6: true
};
// 转换时间戳
const _convertUnixTime = src => {
return moment.unix(src).format('YYYY-MM-DD hh:mm:ss');
};
const _convertAddress = (addressList, createTime) => {
let addrList = [];
addressList.forEach(addr => {
let address = {
time: '',
city: '',
action: ''
};
address.time = addr.acceptTime;
addr = addr.acceptAddress.split(' ');
if (addr.length > 1 && /市/.test(addr[0])) {
address.city = addr[0].replace('市', '');
addr.splice(0, 1);
address.action = addr.join('');
} else {
address.action = addr.join('');
}
addrList.push(address);
});
// 增加一个默认初始状态
addrList.push({
time: createTime,
action: '您的订单已提交,等待付款'
});
return _.reverse(addrList);
};
// 根据订单状态获取当前步骤
const _getStepByOrderStatus = (st) => {
const _getStepByOrderStatus = st => {
let steps = [
{
stepStr: '1.提交订单'
... ... @@ -128,50 +167,6 @@ const _getStepByOrderStatus = (st) => {
return steps;
};
// 转换时间戳
const _convertUnixTime = (src) => {
return moment.unix(src).format('YYYY-MM-DD hh:mm:ss');
};
const deleteOrder = (uid, code) => {
return api.get('', {
method: 'app.SpaceOrders.delOrderByCode',
uid: uid,
order_code: code
}, {
cache: true
});
};
const cancelOrder = (uid, code) => {
return api.get('', {
method: 'app.SpaceOrders.close',
uid: uid,
order_code: code
}, {
cache: true
});
};
const getCancelOrderReason = () => {
return api.get('', {
method: 'app.SpaceOrders.closeReasons'
}, {
cache: true
});
};
const getExpressInfo = (uid, code) => {
return api.get('', {
method: 'app.express.get',
uid: uid,
order_code: code
}, {
cache: true
});
};
const _getDetail = (uid, code) => {
return api.get('', {
method: 'app.SpaceOrders.detail',
... ... @@ -244,38 +239,43 @@ const _getUserOrder = (uid, type, page) => {
});
};
const _convertAddress = (addressList, createTime) => {
let addrList = [];
addressList.forEach(addr => {
let address = {
time: '',
city: '',
action: ''
};
address.time = addr.acceptTime;
addr = addr.acceptAddress.split(' ');
if (addr.length > 1 && /市/.test(addr[0])) {
address.city = addr[0].replace('市', '');
addr.splice(0, 1);
address.action = addr.join('');
} else {
address.action = addr.join('');
}
const deleteOrder = (uid, code) => {
return api.get('', {
method: 'app.SpaceOrders.delOrderByCode',
uid: uid,
order_code: code
}, {
cache: true
});
};
addrList.push(address);
const cancelOrder = (uid, code) => {
return api.get('', {
method: 'app.SpaceOrders.close',
uid: uid,
order_code: code
}, {
cache: true
});
};
// 增加一个默认初始状态
addrList.push({
time: createTime,
action: '您的订单已提交,等待付款'
const getCancelOrderReason = () => {
return api.get('', {
method: 'app.SpaceOrders.closeReasons'
}, {
cache: true
});
};
return _.reverse(addrList);
const getExpressInfo = (uid, code) => {
return api.get('', {
method: 'app.express.get',
uid: uid,
order_code: code
}, {
cache: true
});
};
const getOrderData = (uid, type, page) => {
... ... @@ -362,11 +362,27 @@ const getOrderDetail = (uid, code) => {
});
};
const editOrder = data => {
return api.get('', {
method: 'app.SpaceOrders.updateDeliveryAddress',
uid: data.uid,
order_code: data.orderCode,
user_name: data.userName,
area_code: data.areaCode,
address: data.address,
mobile: data.mobile,
phone: data.phone
}, {
cache: true
});
};
module.exports = {
getOrderData: getOrderData,
getOrderDetail: getOrderDetail,
cancelOrder: cancelOrder,
getCancelOrderReason: getCancelOrderReason,
deleteOrder: deleteOrder,
editOrder: editOrder,
getExpressInfo: getExpressInfo
};
... ...
... ... @@ -23,6 +23,7 @@ router.get('/deleteOrder', order.deleteOrder);
router.get('/cancelOrder', order.cancelOrder);
router.get('/getCancelOrderReason', order.getCancelOrderReason);
router.get('/getExpressInfo', order.getExpressInfo);
router.get('/editOrder', order.editOrder);
// 个人中心首页/收货地址
router.get('/address', address.index);
... ...
... ... @@ -10,11 +10,6 @@ var nameReg = /^[\u4e00-\u9fa5]{2,5}$/;
var addressReg = /^[\s\S]{2,100}$/;
var phoneReg = /^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
// var codeReg = /^[0-9]{6}$/;
// var emailReg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
// var telCodeReg = /^[0-9]{3,5}$/;
// var telReg = /^[0-9]{5,10}$/;
var validateMap = {
name: {
sl: '#user-name',
... ... @@ -36,6 +31,14 @@ var validateMap = {
reg: phoneReg,
errMsg: '您输入的联系电话格式不正确'
}
},
phone: {
sl: '#user-phone',
v: {
isNumber: true,
minLength: 8,
errMsg: '您输入的电话号码给是不正确'
}
}
};
... ... @@ -45,12 +48,14 @@ function getTpl(data) {
return editOrderTpl(data);
}
function initAddr() {
function initAddr(areaCode) {
addr = addrSelector({
el: '#user-city',
url: 'http://localhost:3000/areas/0',
resource: 'areas'
el: '#user-city'
});
if (areaCode) {
addr.setAddress(areaCode.toString());
}
}
function getValidateKey(id) {
... ... @@ -71,9 +76,37 @@ function validateData() {
}
});
validate.addr(addr.getAreaIds(), {
el: '#user-city',
errMsg: '请填写完整的省市区信息'
});
return pass;
}
function editOrder() {
var code = $('.edit-dialog .form').data('code');
var areaCode = addr.getAreaIds().split(',')[2];
var userName = $('#user-name').val();
var address = $('#user-address').val();
var mobile = $('#user-mobile').val();
var phone = $('#user-phone').val();
$.ajax({
url: '/me/editOrder',
data: {
orderCode: code,
areaCode: areaCode,
userName: userName,
address: address,
mobile: mobile,
phone: phone
}
}).done(function(result) {
console.log(result);
});
}
function showDiaglog(tpl, code, onEdit) {
var areaCode;
var tip = new _dialog({
... ... @@ -86,6 +119,7 @@ function showDiaglog(tpl, code, onEdit) {
name: '确定',
cb: function() {
if (validateData()) {
editOrder();
tip.close(onEdit);
} else {
console.log('err');
... ... @@ -103,17 +137,18 @@ function showDiaglog(tpl, code, onEdit) {
]
}).show();
initAddr();
areaCode = $('.input-row.selector').data('area');
initAddr(areaCode);
if (areaCode) {
// Since there's some bug when addr is set the real area code,
// use the fake data instead for develop phase
// addr.setAddress(areaCode);
addr.setAddress('320102');
}
// 绑定取消焦点的校验事件
$('.edit-dialog .input-row .validate').on('blur', function() {
var $this = $(this);
var v = validateMap[getValidateKey($this.get(0).id)];
validate.do(v.sl, v.v);
});
}
function start(tplData) {
... ...
... ... @@ -7,12 +7,15 @@ var makeValidate = {
},
isNumber: function(val, bl) {
return bl && !isNaN(parseInt(val, 10));
},
addr: function(val) {
return val.split(',').length === 3;
}
};
function showMsg(obj) {
var text = obj.msg || '数据格式有问题,请检查';
var m = '<span class="error-msg validate-msg"><span class="iconfont">-</span>' + text + '</span>';
var m = '<span class="error-msg validate-msg"><span class="iconfont">&#xe60c;</span>' + text + '</span>';
var curMsg = $(obj.el).next('.validate-msg');
... ... @@ -23,7 +26,7 @@ function showMsg(obj) {
if (obj.err) {
$(obj.el).after(m);
} else {
m = '<span class="correct-msg validate-msg"><span class="iconfont">+</span>';
m = '<span class="correct-msg validate-msg"><span class="iconfont">&#xe610;</span>';
$(obj.el).after(m);
}
}
... ... @@ -52,7 +55,27 @@ function validate(selector, conditions) {
return pass;
}
function validateAddr(val, conditions) {
var pass = true;
if (makeValidate.addr(val)) {
showMsg({
el: conditions.el
});
} else {
pass = false;
showMsg({
el: conditions.el,
err: true,
msg: conditions.errMsg
});
}
return pass;
}
module.exports = {
do: validate
do: validate,
addr: validateAddr
};
... ...
... ... @@ -5,6 +5,7 @@
$normalSize: 14px;
$borderColor: #f1f1f1;
$skyBlue: #379ed6;
.cancel-btn {
background-color: #fff;
... ... @@ -12,6 +13,11 @@
border: 1px solid #1b1b1b;
}
.btns,
.btn {
text-align: center !important;
}
.asterisk {
position: relative;
top: 2px;
... ... @@ -169,5 +175,24 @@
}
}
}
.error-msg {
color: #c71814;
}
.correct-msg {
color: $skyBlue;
}
.error-msg,
.correct-msg {
font-size: $normalSize;
padding-left: 5px;
.iconfont {
font-size: $normalSize;
margin-right: 5px;
}
}
}
}
... ...
<h1 class="dialog-title">订单修改</h1>
{{# data}}
<div class="form" data-code={{orderCode}}>
{{# data}}
<div class="input-row necessary">
<span class="asterisk">*</span>
<label for="user-name"><span></span><span></span>人:</label>
... ... @@ -25,7 +25,7 @@
<div class="input-row">
<span class="asterisk vhide">*</span>
<label for="user-phone">电话号码:</label>
<input class="input" type="text" id="user-phone" placeholder="请输入电话号码(选填)" value="{{phone}}">
<input class="input validate" type="text" id="user-phone" placeholder="请输入电话号码(选填)">
</div>
{{/ data}}
</div>
{{/ data}}
... ...