...
|
...
|
@@ -3,6 +3,7 @@ |
|
|
* @author: jiangmin
|
|
|
* @date: 2016/07/05
|
|
|
*/
|
|
|
// todo uid为假值;编辑时设置默认;省市区重置;手机号码逆向显示
|
|
|
|
|
|
var cascadingAddress = require('../plugins/cascading-address');
|
|
|
var dialog = require('../plugins/dialog');
|
...
|
...
|
@@ -13,55 +14,26 @@ var $consignee = $('#consignee'); |
|
|
var $address = $('#addressDetail');
|
|
|
var $mobile = $('#mobile');
|
|
|
var $phone = $('#phone');
|
|
|
// var $default = 'N';
|
|
|
var currentLength = $('.a-table').find('tr').length - 1;// 当前地址条数
|
|
|
var leftLength = 20 - currentLength;// 还剩地址条数
|
|
|
var reg = new RegExp(/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/);// 手机号码校验
|
|
|
|
|
|
require('./me');
|
|
|
require('../plugins/check');
|
|
|
|
|
|
// 设置收货地址
|
|
|
$('.default-address').click(function() {
|
|
|
if ($(this).hasClass('checked')) {
|
|
|
$(this).removeClass('checked');
|
|
|
$(this).html('');
|
|
|
} else {
|
|
|
$(this).addClass('checked');
|
|
|
$(this).html('');
|
|
|
}
|
|
|
$('.input-radio').check({
|
|
|
type: 'radio'
|
|
|
// onChange: function(ele, checked) {
|
|
|
// if (checked) {
|
|
|
// $default = 'Y';
|
|
|
// } else {
|
|
|
// $default = 'N';
|
|
|
// }
|
|
|
// }
|
|
|
});
|
|
|
|
|
|
// 校验
|
|
|
$consignee.focus(function() {
|
|
|
$(this).next().hide();
|
|
|
});
|
|
|
$consignee.blur(function() {
|
|
|
if ($(this).val().trim() === '') {
|
|
|
$(this).next().show();
|
|
|
}
|
|
|
});
|
|
|
$address.focus(function() {
|
|
|
$(this).next().hide();
|
|
|
});
|
|
|
$address.blur(function() {
|
|
|
if ($(this).val().trim() === '') {
|
|
|
$(this).next().show();
|
|
|
}
|
|
|
});
|
|
|
$mobile.focus(function() {
|
|
|
$(this).next().hide();
|
|
|
});
|
|
|
$mobile.blur(function() {
|
|
|
if ($(this).val().trim() === '') {
|
|
|
$(this).next().show();
|
|
|
} else {
|
|
|
if (!reg.test(($(this).val().trim()))) {
|
|
|
$(this).next().show();
|
|
|
$(this).next().html('手机号码格式不正确');
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
|
|
|
$(function() {
|
|
|
// 运行此demo
|
|
|
// 1. 安装 npm i -g json-server
|
...
|
...
|
@@ -72,10 +44,12 @@ $(function() { |
|
|
resource: 'areas'
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 公共方法
|
|
|
*/
|
|
|
var Bll = {
|
|
|
// 获取输入框输入的值
|
|
|
getInfo() {
|
|
|
// todo uid
|
|
|
var uid = '123456';
|
|
|
|
|
|
return {
|
...
|
...
|
@@ -85,36 +59,32 @@ $(function() { |
|
|
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('');
|
|
|
address.reset();
|
|
|
},
|
|
|
|
|
|
// 校验
|
|
|
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 = '所在区域请选择到:区';
|
|
|
let addressForm = $('.form-group1');
|
|
|
|
|
|
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.find('.error-tips').show() :
|
|
|
addressForm.find('.error-tips').hide();
|
|
|
if (info.consignee === '' || info.address === '' || info.mobile === '' || !reg.test(info.mobile) ||
|
|
|
typeof (info.area_code) === 'undefined') {
|
|
|
flag = false;
|
|
|
}
|
|
|
return flag;
|
|
|
},
|
...
|
...
|
@@ -141,8 +111,6 @@ $(function() { |
|
|
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());
|
...
|
...
|
@@ -185,8 +153,6 @@ $(function() { |
|
|
$('tbody').append(html);
|
|
|
Bll.setTableTile();
|
|
|
Bll.clearInput();
|
|
|
|
|
|
// location.href="/me/address";
|
|
|
} else {
|
|
|
new _alert('新增接口出错了').show();
|
|
|
}
|
...
|
...
|
@@ -204,19 +170,14 @@ $(function() { |
|
|
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();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
// 修改收货地址
|
...
|
...
|
@@ -224,8 +185,15 @@ $(function() { |
|
|
let id = $(this).data('id');
|
|
|
let tr = $(this).parents('.table-body');
|
|
|
let td = tr.find('td');
|
|
|
let areaCode = tr.find('input').eq(1).val();
|
|
|
|
|
|
address.setAddress({
|
|
|
province: areaCode.substring(0, 2), // 省
|
|
|
city: areaCode.substring(0, 4), // 市
|
|
|
dist: areaCode // 区县
|
|
|
});
|
|
|
$('.error-tips').hide();
|
|
|
$('.tip').html('修改地址 电话为选填项,其他均为必填项');
|
|
|
Bll.setInfo(id, td);
|
|
|
});
|
|
|
|
...
|
...
|
@@ -242,7 +210,6 @@ $(function() { |
|
|
url: '/me/address/del',
|
|
|
dataType: 'json',
|
|
|
data: {
|
|
|
// todo uid
|
|
|
uid: '123456',
|
|
|
id: id
|
|
|
},
|
...
|
...
|
@@ -272,7 +239,6 @@ $(function() { |
|
|
url: '/me/address/default',
|
|
|
dataType: 'json',
|
|
|
data: {
|
|
|
// todo uid
|
|
|
uid: '123456',
|
|
|
id: id
|
|
|
},
|
...
|
...
|
|