Authored by 姜敏

修复个人中心地址选中问题,号码不修改问题,日期控件问题

... ... @@ -29,11 +29,11 @@ const index = (req, res, next) => {
let reg = /(\d{3})\d{4}(\d{4})/;
for (let i = 0; i < length; i++) {
resultData[i].default = resultData[i].is_default === 'Y';
resultData[i].mobile = resultData[i].mobile.replace(reg, '$1****$2');
}
resultData.leftLength = 7 - length;
resultData.length = length;
res.display('index', {
module: 'me',
page: 'address',
... ...
... ... @@ -16,6 +16,7 @@ var fs = require('fs');
var path = require('path');
const uuid = require('uuid');
const os = require('os');
const _ = require('lodash');
const regMobile = /(\d{3})\d{4}(\d{4})/;// 正则匹配替换手机号码中间4位
const regEmail = /(\d{3})\d{4}/;// 正则匹配替换邮箱中间4位
... ... @@ -84,6 +85,25 @@ const index = (req, res, next) => {
result.info.head_ico = result.info.head_ico ? helpers.image(result.info.head_ico, 400, 300, 2) : '';
result.info.mobile = result.info.mobile ? result.info.mobile.replace(regMobile, '$1****$2') : '';
result.stepUrl = '/me/setting/step1';
if (result.info.birthday) {
let a = result.info.birthday.split('-');
_.forEach(result.date.selectYear, function(x) {
if (x.value === a[0]) {
x.isSelected = 'selected';
}
});
_.forEach(result.date.selectMonth, function(x) {
if (x.value === a[1]) {
x.isSelected = 'selected';
}
});
_.forEach(result.date.selectDay, function(x) {
if (x.value === a[2]) {
x.isSelected = 'selected';
}
});
}
res.display('index', {
module: 'me',
... ... @@ -305,6 +325,7 @@ const validate1 = (req, res)=> {
} else if (type === 'mobile') {
let a = yield accountModel.checkVerifyMsg(body.code, body.mobile, body.area);
res.send(a);
} else if (type === 'email') {
let a = yield accountModel.sendVerifyEmail(uid, body.email);
... ...
... ... @@ -11,6 +11,43 @@ const crypto = require('crypto');
const fs = require('fs');
/**
* 日期数据
* @returns {{selectYear: Array, selectMonth: Array, selectDay: Array}}
*/
const getSelect = ()=> {
let date = new Date();
let year = date.getFullYear();
let selectYear = [];
let selectMonth = [];
let selectDay = [];
for (let i = 1950; i < year + 1; i++) {
selectYear.push({
id: i,
value: i + ''
});
}
for (let j = 1; j < 13; j++) {
selectMonth.push({
id: j,
value: j + ''
});
}
for (let k = 1; k < 32; k++) {
selectDay.push({
id: k,
value: k + ''
});
}
return {
selectYear,
selectMonth,
selectDay
};
};
/**
* 查询个人详细信息
* @param uid
* @returns {*}
... ... @@ -67,21 +104,17 @@ const _getUserContactInfo = (uid)=> {
const getUserInfo = (uid) => {
let getData = [_getUserInfo(uid), _getUserContactInfo(uid)];
return Promise.all(getData).then(result => {
return {
info: result[0].info,
genders: result[0].genders,
concat: result[1]
concat: result[1],
date: getSelect()
};
});
};
/* const getVerifyInfo = (uid)=> {
return api.get('', {
method: 'web.passport.getUserVerifyInfo',
uid: uid
}).then(result => result);
};*/
/**
* 编辑个人详细信息
... ...
... ... @@ -10,7 +10,7 @@
<th class="width-opearte">操作</th>
</tr>
{{#each data}}
<tr class="table-body">
<tr class="table-body ">
<input type="hidden" id="tr_{{address_id}}" value="{{address_id}}">
<input type="hidden" id="tr_{{area_code}}" value="{{area_code}}">
<td class="width-name">{{consignee}}</td>
... ... @@ -22,11 +22,11 @@
<span class="blue opreation update-address" data-id="{{address_id}}">修改</span>
<em class="op-sep">|</em>
<span class="blue opreation del-address" data-id="{{address_id}}">删除</span>
{{#isY is_default}}
{{#if default}}
<span class="btn set-default opreation current-default ">默认地址</span>
{{^}}
<span class="btn set-default opreation " data-id="{{address_id}}">设为默认</span>
{{/isY}}
{{else}}
<span class="btn set-default opreation " data-id={{address_id}}>设为默认</span>
{{/if}}
</div>
</td>
</tr>
... ...
... ... @@ -53,7 +53,39 @@
</div>
<div class="form-group">
<label class="label-name">出生日期:</label>
<input id="birthday" class="input" type="text" value="{{info.birthday}}">
{{#date}}
<select id="year" >
{{#each selectYear}}
{{#if isSelected}}
<option value="{{id}}" selected={{isSelected}}>{{value}}</option>
{{else}}
<option value="{{id}}" >{{value}}</option>
{{/if}}
{{/each}}
</select>
<select id="month" >
{{#each selectMonth}}
{{#if isSelected}}
<option value="{{id}}" selected={{isSelected}}>{{value}}</option>
{{else}}
<option value="{{id}}" >{{value}}</option>
{{/if}}
{{/each}}
</select>
<select id="day" >
{{#each selectDay}}
{{#if isSelected}}
<option value="{{id}}" selected={{isSelected}}>{{value}}</option>
{{else}}
<option value="{{id}}" >{{value}}</option>
{{/if}}
{{/each}}
</select>
{{/date}}
<span class="blue error-tips">{{> icon/error-round}}出生日期格式不对</span>
</div>
<div class="form-group-address">
... ...
... ... @@ -59,16 +59,28 @@ $(function() {
info.consignee === '' ? $consignee.next().show() : $consignee.next().hide();
info.address === '' ? $address.next().show() : $address.next().hide();
info.mobile === '' ? $mobile.next().show() :
(!reg.test(info.mobile) ? $mobile.next().html('手机号码格式不对').show() : $mobile.next().hide());
typeof (info.area_code) === 'undefined' ?
addressForm.css('margin-bottom', '20px').find('.error-tips').show() :
addressForm.css('margin-bottom', '70px').find('.error-tips').hide();
if (info.consignee === '' || info.address === '' || info.mobile === '' || !reg.test(info.mobile) ||
typeof (info.area_code) === 'undefined') {
flag = false;
if (info.id) {
info.mobile === '' ? $mobile.next().show() : $mobile.next().hide();
if (info.consignee === '' || info.address === '' || info.mobile === '' ||
typeof (info.area_code) === 'undefined') {
flag = false;
}
return flag;
} else {
info.mobile === '' ? $mobile.next().show() :
(!reg.test(info.mobile) ? $mobile.next().html('手机号码格式不对').show() : $mobile.next().hide());
if (info.consignee === '' || info.address === '' || info.mobile === '' || !reg.test(info.mobile) ||
typeof (info.area_code) === 'undefined') {
flag = false;
}
return flag;
}
return flag;
},
// 拼接一条数据的html
... ... @@ -84,7 +96,8 @@ $(function() {
'<td class=\'width-opearte\'><div><span class=\'blue opreation update-address\' data-id=\'' +
info.address_id + '\'>修改</span>\n<em class="op-sep">|</em>\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>';
'<span class=\'btn set-default opreation \' data-id=\'' + info.address_id + '\'>设为默认</span>'+
'</div></td>';
html += '</tr>';
return html;
},
... ... @@ -118,6 +131,7 @@ $(function() {
info.area_code = area.split(',')[2];
info.area = areaInfo.split(',').join(' ');
if (Bll.check(info) === true) {
// 新增
... ... @@ -149,23 +163,46 @@ $(function() {
});
}
} 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();
$('.tip em').html('新增地址');
} else {
new _alert(data.message).show();
if (new RegExp(/^\d{3}[*]{4}\d{4}/).test(info.mobile)) {
$.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();
$('.tip em').html('新增地址');
} else {
new _alert(data.message).show();
}
}
}
});
});
} else if (reg.test(info.mobile)) {
$mobile.next().hide();
$.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();
$('.tip em').html('新增地址');
} else {
new _alert(data.message).show();
}
}
});
} else {
$mobile.next().html('手机号码格式不对').show();
}
}
}
});
... ... @@ -227,12 +264,29 @@ $(function() {
data: {
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();
success: function(data) {
if (data.code === 200) {
$('.current-default').removeClass('current-default').text('设为默认');
$(self).addClass('current-default').text('默认地址');
tbody.find('.table-body').eq(0).before('<tr class=\'table-body select-row\'>' + tr.html()+
'</tr>');
tr.remove();
} else {
new _alert(data.message).show();
}
}
});
});
// 选中某一行
$(document).on('click', '.table-body', function() {
$('.table-body').removeClass('select-row');
$(this).addClass('select-row');
$('.set-default').hide();
$(this).find('.set-default').css('display', 'inline-block');
});
});
... ...
... ... @@ -9,6 +9,14 @@ var _dialog = dialog.Dialog;
var _alert = dialog.Alert;
var modifyHead = require('./setting/modifyHead');// flash操作
var tip;// 头像编辑弹框
var $year = $('#year');
var $month = $('#month');
var $day = $('#day');
var birthday = {
year: $year.val() || '',
month: $month.val() || '',
day: $day.val() || ''
};
var headHtml = modifyHead.swfobject('head', '600px', '400px', '../../img/me/head.swf?code=' + Math.random() +
'&upload_url=' + encodeURIComponent(location.protocol + '//' +
... ... @@ -40,8 +48,8 @@ var Bll = {
typeof (info.area_code) === 'undefined' ?
addressForm.css('margin-bottom', '20px').find('.error-tips').show() :
addressForm.css('margin-bottom', '70px').find('.error-tips').hide();
if (!regBirth.test(info.birthday) || !regName.test(info.nick_name) ||
!regRealName.test(info.username) || typeof (info.area_code) === 'undefined') {
if (!regBirth.test(info.birthday) || !regName.test(info.nick_name) || !regRealName.test(info.username) ||
typeof (info.area_code) === 'undefined') {
flag = false;
}
return flag;
... ... @@ -109,6 +117,18 @@ window.receive_image_bytes = function(obj) {
}
};
// 时间控件切换
$year.on('change', function() {
birthday.year = $(this).val();
});
$month.on('change', function() {
birthday.month = $(this).val();
});
$day.on('change', function() {
birthday.day = $(this).val();
});
$(function() {
var address = cascadingAddress({el: '#address'});
var areaCode = $('#area_code').val();
... ... @@ -139,7 +159,7 @@ $(function() {
nick_name: $('#nick_name').val(),
username: $('#username').val(),
gender: $('#gender').val(),
birthday: $('#birthday').val(),
birthday: birthday.year + '-' + birthday.month + '-' + birthday.day,
area_code: area.split(',')[2],
// todo 手机号码老接口必填
... ...
... ... @@ -11,7 +11,7 @@ var type = types[types.length - 1];// 界面操作类型
var $imgCaptchaInput = $('#captcha');
var second = 60;
var $sms = $('#send-code2');// 发送短信验证码按钮
var area = $('#country-code').text().substring(0)||"86";// 地区码
var area = $('#country-code').text().substring(0) || '86';// 地区码
// 发送短信后倒计时显示
var disableSMSBtn = function() {
second -= 1;
... ...
... ... @@ -8,7 +8,7 @@ var dialog = require('../../plugins/dialog');
var _alert = dialog.Alert;
var types = location.pathname.split('/');
var type = types[types.length - 1];// 界面操作类型
var area = $('#country-code').text()||"86";
var area = $('#country-code').text() || '86';
/**
* 手机号码验证
... ... @@ -35,7 +35,7 @@ $('[placeholder]').placeholder();
// 发送手机验证码
$sms.click(function() {
var mobile = $('#real-mobile').val();
if ($(this).hasClass('disable')) {
return;
... ...
... ... @@ -119,6 +119,10 @@
padding: 8px 0 8px 10px;
}
.select-row {
border: solid 2px black;
}
.width-name {
width: 60px;
word-break: break-all;
... ... @@ -148,8 +152,7 @@
.current-default,
.set-default {
display: inline-block;
display: none;
margin-left: 20px;
}
}
... ...
... ... @@ -6,6 +6,9 @@
clear: both;
margin-bottom: 20px;
}
select {
width: 60px;
}
.form-group-address {
clear: both;
... ...