Authored by 姜敏

个人中心-收货地址调试接口

... ... @@ -13,6 +13,11 @@ const addressModel = require('../models/address');
*/
const index = (req, res) => {
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';
}
// console.log(result.data);
res.render('index', {
module: 'me',
page: 'address',
... ... @@ -22,7 +27,8 @@ const index = (req, res) => {
navigation: mcHandler.getSideMenu('收货地址'),
banner: 'http://placehold.it/150x120',
address: true,
data: result
title: '收货地址',
data: result.data
}
});
});
... ... @@ -58,7 +64,7 @@ const updateAddressData = (req) => {
};
/**
* 添加地址
* 删除地址
*/
const delAddressData = (req) => {
let id = req.body.id;
... ... @@ -68,7 +74,7 @@ const delAddressData = (req) => {
};
/**
* 添加地址
* 设置默认地址
*/
const setDefaultAddress = (req) => {
let id = req.body.id;
... ...
... ... @@ -21,7 +21,7 @@ const getAddressDataAsync = (uid, limit) => {
uid: uid,
limit: limit
}).then(result => {
console.log('接口请求结果result', result);
// console.log('列表结果result', result);
if (result.code === '200') {
return result.data;
}
... ... @@ -34,7 +34,7 @@ const getAddressDataAsync = (uid, limit) => {
*
* @param uid 用户ID
* @param address 地址信息
* @param area_code 城市码
* @param areaCode 城市码
* @param consignee 收货人
* @param mobile 手机号码
* @param phone 电话号码
... ... @@ -50,6 +50,7 @@ const addAddressData = (uid, address, areaCode, consignee, mobile, phone) => {
mobile: mobile,
phone: phone
}).then(result => {
// console.log("添加result",result);
if (result.code === '200') {
return result;
}
... ... @@ -62,7 +63,7 @@ const addAddressData = (uid, address, areaCode, consignee, mobile, phone) => {
* @param id 地址id
* @param uid 用户ID
* @param address 地址信息
* @param area_code 城市码
* @param areaCode 城市码
* @param consignee 收货人
* @param mobile 手机号码
* @param phone 电话号码
... ... @@ -79,6 +80,7 @@ const updateAddressData = (id, uid, address, areaCode, consignee, mobile, phone)
mobile: mobile,
phone: phone
}).then(result => {
// console.log("修改result",result);
if (result.code === '200') {
return result;
}
... ... @@ -98,6 +100,7 @@ const delAddressData = (id, uid) => {
id: id,
uid: uid
}).then(result => {
// console.log("删除result",result);
if (result.code === '200') {
return result;
}
... ... @@ -117,6 +120,7 @@ const setDefaultAddress = (id, uid) => {
id: id,
uid: uid
}).then(result => {
// console.log('设置默认result', result);
if (result.code === '200') {
return result;
}
... ...
<form id="address-form" name="address-form">
<div class="address-page">
<p class="bold title">收货地址</p>
<span class="blue tips">新增地址 电话为选填项,其他均为必填项</span>
<div class="add-address-detail">
<div class="form-group">
<label class="label-name">收货人:</label>
<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">
<label class="label-name">所在区域:</label>
<div id="address"></div>
<span class="blue error-tips">{{> icon/error-round}}所在区域不能为空</span>
</div>
<div class="form-group">
<label class="label-name">详细地址:</label>
<input id="addressDetail" class="input width-275" type="text" placeholder="街道名称或小区名称" maxlength="60">
<span class="blue error-tips">{{> icon/error-round}}详细地址不能为空</span>
</div>
<div class="form-group">
<label class="label-name">手机号码:</label>
<input id="mobile" class="input width-190" type="text" placeholder="请输入手机号码(重要必填)" maxlength="11">
<span class="blue error-tips">{{> icon/error-round}}手机号码不能为空</span>
</div>
<div class="form-group">
<label class="label-name">电话号码:</label>
<input id="phone" class="input width-190" type="text" placeholder="请输入电话号码(选填)">
</div>
<div class="form-group ">
<label class="label-name"></label>
<span class="iconfont radio default-address opreation">&#xe604;</span>
<label class="radio-lable">设置为默认收货地址</label>
</div>
<div class="form-group">
<span class="btn opreation" id="save-address">保存</span>
</div>
</div>
</div>
</form>
<div class="address-table">
<span class="blue table-title">已保存了3条地址,还能保存17条地址</span>
<table class="a-table">
<tr class="table-head">
<th class="width-80">收货人</th>
<th class="width-195">所在区域</th>
<th class="width-280">详细地址</th>
<th class="width-120">手机/电话</th>
<th class="width-260">操作</th>
</tr>
{{#each data}}
<tr class="table-body">
<td class="width-80">{{consignee}}</td>
<td class="width-195">{{address}}</td>
<td class="width-280">{{address}}</td>
<td class="width-120">{{mobile}}</td>
<td class="width-260">
<div>
<span class="blue opreation">修改</span>
|
<span class="blue opreation " id="del-address">删除</span>
{{#if is_default}}
<span class="btn set-default opreation">默认地址</span>
{{else}}
<span class="btn set-default opreation">设为默认</span>
{{/if}}
</div>
</td>
</tr>
{{/each}}
</table>
<div class="user-order">
{{> common/subtitle}}
{{> address/content}}
{{> address/table}}
</div>
... ...
<form id="address-form" name="address-form">
<div class="address-page">
<span class="blue tips">新增地址 电话为选填项,其他均为必填项</span>
<div class="add-address-detail">
<div class="form-group">
<label class="label-name">收货人:</label>
<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">
<label class="label-name">所在区域:</label>
<div id="address"></div>
<span class="blue error-tips">{{> icon/error-round}}所在区域不能为空</span>
</div>
<div class="form-group">
<label class="label-name">详细地址:</label>
<input id="addressDetail" class="input width-275" type="text" placeholder="街道名称或小区名称" maxlength="60">
<span class="blue error-tips">{{> icon/error-round}}详细地址不能为空</span>
</div>
<div class="form-group">
<label class="label-name">手机号码:</label>
<input id="mobile" class="input width-190" type="text" placeholder="请输入手机号码(重要必填)" maxlength="11">
<span class="blue error-tips">{{> icon/error-round}}手机号码不能为空</span>
</div>
<div class="form-group">
<label class="label-name">电话号码:</label>
<input id="phone" class="input width-190" type="text" placeholder="请输入电话号码(选填)">
</div>
<div class="form-group ">
<label class="label-name"></label>
<span class="iconfont radio default-address opreation">&#xe604;</span>
<label class="radio-lable">设置为默认收货地址</label>
</div>
<div class="form-group">
<span class="btn opreation" id="save-address">保存</span>
</div>
</div>
</div>
</form>
... ...
<div class="address-table">
<span class="blue table-title">已保存了3条地址,还能保存17条地址</span>
<table class="a-table">
<tr class="table-head">
<th class="width-80">收货人</th>
<th class="width-195">所在区域</th>
<th class="width-280">详细地址</th>
<th class="width-120">手机/电话</th>
<th class="width-260">操作</th>
</tr>
{{#each data}}
<tr class="table-body">
<td class="width-80">{{consignee}}</td>
<td class="width-195">{{address}}</td>
<td class="width-280">{{address}}</td>
<td class="width-120">{{mobile}}</td>
<td class="width-260">
<div>
<span class="blue opreation">修改</span>
|
<span class="blue opreation del-address" data-id="{{address_id}}">删除</span>
{{#if default}}
<span class="btn set-default opreation">默认地址</span>
{{else}}
<span class="btn set-default opreation" data-id="{{address_id}}">设为默认</span>
{{/if}}
</div>
</td>
</tr>
{{/each}}
</table>
</div>
... ...
... ... @@ -16,7 +16,7 @@ var $phone = $('#phone');
require('./me');
// 设置收货地址
$('.default-address').click(function() {
$('.default-address').click(function () {
if ($(this).hasClass('checked')) {
$(this).removeClass('checked');
$(this).html('&#xe604;');
... ... @@ -27,26 +27,26 @@ $('.default-address').click(function() {
});
// 校验
$consignee.keydown(function() {
$consignee.keydown(function () {
$(this).next().hide();
});
$consignee.blur(function() {
$consignee.blur(function () {
if ($(this).val().trim() === '') {
$(this).next().show();
}
});
$addressDetail.keydown(function() {
$addressDetail.keydown(function () {
$(this).next().hide();
});
$addressDetail.blur(function() {
$addressDetail.blur(function () {
if ($(this).val().trim() === '') {
$(this).next().show();
}
});
$mobile.keydown(function() {
$mobile.keydown(function () {
$(this).next().hide();
});
$mobile.blur(function() {
$mobile.blur(function () {
if ($(this).val().trim() === '') {
$(this).next().show();
} else {
... ... @@ -60,7 +60,7 @@ $mobile.blur(function() {
});
// 保存收货地址
$('#save-address').click(function() {
$('#save-address').click(function () {
if ($consignee.val().trim() === '') {
alert('name不能为空');
} else {
... ... @@ -79,8 +79,8 @@ $('#save-address').click(function() {
mobile: $mobile.val(),
phone: $phone.val()
},
success: function(data) { // 刷新下面列表数据
console.log('保存成功信息', data);
success: function () { // 刷新下面列表数据
}
});
}
... ... @@ -90,16 +90,49 @@ $('#save-address').click(function() {
// 修改收货地址
// 删除收货地址
$('#del-address').click(function() {
$('.del-address').click(function () {
let id = $(this).data('id');
new _confirm({
content: '您确定要删除收货地址吗?',
cb: function() {
alert('您点击了confirm确认');
cb: function () {
$.ajax({
type: 'POST',
url: '/me/address/del',
dataType: 'json',
data: {
// todo uid
uid: '123456',
id: id
},
success: function () { // 刷新下面列表数据
}
});
}
}).show();
});
$(function() {
// 设置默认收货地址
$('.set-default').click(function () {
let id = $(this).data('id');
$.ajax({
type: 'POST',
url: '/me/address/default',
dataType: 'json',
data: {// 保存数据
// todo uid
uid: '123456',
id: id
},
success: function () { // 刷新下面列表数据
}
});
});
$(function () {
// 运行此demo
// 1. 安装 npm i -g json-server
// 2. json-server --watch mock/address.json
... ...