Authored by 郭成尧

save-use-address

... ... @@ -10,7 +10,7 @@ class orderModel extends global.yoho.BaseModel {
let invoices_title = false;
let invoices_title_personal = false;
let invoices_type = '2';
let addressId = orderInfo.addressId;
let addressId = orderInfo.address_id;
// 用户手机号处理
if (orderInfo.receiverMobile && orderInfo.isModifyTel) {
... ...
... ... @@ -61,6 +61,8 @@ exports.addressJson = (req, res, next) => {
* @param next
*/
exports.addressAct = (req, res, next) => {
let saveAndUse = req.query.refer === 'shopping' || req.query.refer === 'buynow';
req.ctx(addressModel).address({
id: req.query.id ? req.query.id : null,
uid: req.user.uid
... ... @@ -75,7 +77,8 @@ exports.addressAct = (req, res, next) => {
navBtn: false,
backUrl: false
}),
title: result && result.navTitle
title: result && result.navTitle,
saveAndUse: saveAndUse
};
res.render('address/address-act', Object.assign(responseData, result));
... ... @@ -100,8 +103,6 @@ exports.newGetAddress = (req, res, next) => {
* @param next
*/
exports.saveAddress = (req, res, next) => {
/* 没有用户,返回 */
if (!req.user.uid) {
return res.json({
code: 400,
... ... @@ -109,7 +110,6 @@ exports.saveAddress = (req, res, next) => {
});
}
/* 没有地址信息,返回 */
if (!req.body.address) {
return res.json({
code: 401,
... ... @@ -117,7 +117,6 @@ exports.saveAddress = (req, res, next) => {
});
}
/* 没有地区码,返回 */
if (!req.body.area_code) {
return res.json({
code: 402,
... ... @@ -125,7 +124,6 @@ exports.saveAddress = (req, res, next) => {
});
}
/* 没有收件人姓名,返回 */
if (!req.body.consignee) {
return res.json({
code: 403,
... ... @@ -133,14 +131,6 @@ exports.saveAddress = (req, res, next) => {
});
}
/* 邮箱地址校验不通过,返回 */
// if (!req.body.email || !helpers.verifyEmail(req.body.email)) {
// return res.json({
// code: 404,
// message: '输入的邮箱地址格式不正确'
// });
// }
req.ctx(addressModel).saveAddress({
uid: req.user.uid,
address: req.body.address,
... ... @@ -255,4 +245,3 @@ exports.chooseAddress = (req, res, next) => {
res.json(result);
}).catch(next);
};
... ...
... ... @@ -21,11 +21,9 @@
详细地址:
<textarea name="address" maxlength="255">{{address.address}}</textarea>
</label>
</form>
<div class="submit">
确认
保存{{#if saveAndUse}}并使用{{/if}}
</div>
</div>
<div class="my-address-list-page page-wrap hide">
... ...
... ... @@ -207,7 +207,7 @@ function submitOrder(verifyCode) {
isSubmiting = true;
let postData = {
addressId: orderInfo('addressId'),
addressId: orderInfo('address_id'),
cartType: orderInfo('cartType') || 'ordinary',
deliveryId: orderInfo('deliveryId'),
deliveryTimeId: orderInfo('deliveryTimeId'),
... ... @@ -309,8 +309,8 @@ function submitOrder(verifyCode) {
}
// 界面点击,状态存 cookie
if (!orderInfo('addressId')) {
orderInfo('addressId', $addressWrap.data('id'));
if (!orderInfo('address_id')) {
orderInfo('address_id', $addressWrap.data('id'));
}
$('.delivery-id').on('touchend', 'li', function(event) {
... ...
... ... @@ -17,7 +17,7 @@ function init() {
deliveryTimeId: 1,
paymentTypeId: 1,
yohoCoin: 0,
addressId: null,
address_id: null,
coupon_code: null,
invoice: null,
invoices_title: null,
... ...
... ... @@ -228,7 +228,7 @@ function submitOrder(verifyCode) {
let postData = {
activityId: activityId,
sku: productSku,
addressId: orderInfo('addressId'),
addressId: orderInfo('address_id'),
cartType: orderInfo('cartType') || 'ordinary',
deliveryWay: orderInfo('deliveryId'),
deliveryTime: orderInfo('deliveryTimeId'),
... ... @@ -302,8 +302,8 @@ function submitOrder(verifyCode) {
}
// 界面点击,状态存 cookie
if (!orderInfo('addressId')) {
orderInfo('addressId', $addressWrap.data('id'));
if (!orderInfo('address_id')) {
orderInfo('address_id', $addressWrap.data('id'));
}
// 配送方式 发生改变
... ...
... ... @@ -24,7 +24,7 @@ $('.address-item').on('click', function() {
is_support: $this.data('is-support')
};
orderInfo('addressId', addressId);
orderInfo('address_id', addressId);
orderInfo('address', address);
window.location.href = $this.data('href') + (orderInfo('limitUrlSufix') || '');
... ... @@ -36,8 +36,8 @@ $('.address-item').on('click', function() {
});
$confim.on('click', '.confim', function() {
if (orderInfo('addressId') === deleteId) {
orderInfo('addressId', null);
if (orderInfo('address_id') === deleteId) {
orderInfo('address_id', null);
orderInfo('address', null);
}
});
... ...
... ... @@ -8,6 +8,16 @@ const $ = require('yoho-jquery'),
security = require('plugin/security'),
loading = require('plugin/loading');
let orderInfo;
if (window.queryString.refer === 'shopping') {
orderInfo = require('../cart/order-info').orderInfo;
}
if (window.queryString.refer === 'buynow') {
orderInfo = require('../cart/buynow/order-info').orderInfo;
}
const stringHandle = require('common/helpers/stringHandle');
let $addressForm = $('.edit-address'),
... ... @@ -68,10 +78,25 @@ $usernameInput.bind('input propertychange', function() {
}
});
/**
* 添加/编辑保存并设为默认地址
*/
const setDefault = (addressData) => {
let address = {
address_id: addressData.address_id,
consignee: addressData.consignee,
mobile: addressData.mobile,
address_info: `${addressData.area} ${addressData.address}`,
is_support: addressData.is_support
};
orderInfo('address_id', addressData.address_id);
orderInfo('address', address);
};
// 提交表单请求
$addressForm.on('submit', function() {
let username = $usernameInput.val().replace(/(^\s+)|(\s+$)/g, '');
let phone = $(this).find('[name="mobile"]').val();
if (isSubmiting) {
return false;
... ... @@ -97,11 +122,6 @@ $addressForm.on('submit', function() {
return false;
}
if (!(/^[0-9]{11}$/.test(phone))) {
tip.show('请填写正确的手机号');
return false;
}
if (!$(this).find('[name="area_code"]').val() || !$(this).find('[name="area"]').val() ||
$(this).find('[name="area_code"]').val().length < 6) {
tip.show('省市区不能为空');
... ... @@ -130,11 +150,15 @@ $addressForm.on('submit', function() {
loading.hideLoadingMask();
} else if (window.queryString) {
if (window.queryString.refer === 'buynow') {
window.location.href = '/cart/index/buynow/selectAddress?product_sku=' +
setDefault(res.data);
window.location.href = '/cart/index/buynow/orderensure?product_sku=' +
window.queryString.product_sku + '&buy_number=' +
window.queryString.buy_number;
} else if (window.queryString.refer === 'shopping') {
window.location.href = '/cart/index/new/selectAddress';
setDefault(res.data);
window.location.href = '/cart/index/new/orderEnsure?cartType=ordinary';
} else if (window.queryString.refer === 'modify') {
window.location.href = '/home/addressModify';
} else {
... ...