address.js
2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* 地址管理
* @author: bikai<kai.bi@yoho.cn>
* @date: 2015/11/17
*/
var $ = require('jquery'),
tip = require('../plugin/tip'),
security = require('../plugin/security'),
loading = require('../plugin/loading');
var $action = $('.action'),
$addressForm = $('.edit-address'),
$submit = $('.submit'),
$addAddress = $('.add-address'),
$footer = $('#yoho-footer'),
$confim = $('.confim-mask'),
$pageWrap = $('.page-wrap'),
$addressItem = $('.address-item'),
deleteId;
$pageWrap.first().css('min-height', function() {
return $(window).height() - $('#yoho-header').height() - $footer.height();
});
window.rePosFooter();
$confim.on('touchend', '.cancel', function() {
deleteId = null;
$confim.hide();
}).on('touchend', '.confim', function() {
loading.showLoadingMask();
$confim.hide();
$.ajax({
method: 'POST',
url: '/home/delAddress',
data: {
id: deleteId
}
}).then(function(res) {
if ($.type(res) !== 'object') {
res = {};
}
if (res.code !== 200) {
tip.show(res.message || '网络出了点问题~');
loading.hideLoadingMask();
} else {
window.location.reload();
}
}).fail(function() {
tip.show('网络出了点问题~');
loading.hideLoadingMask();
}).always(function() {
deleteId = null;
});
});
// 添加地址
if ($addressItem.length < 5) {
$addAddress.attr('href', $addAddress.data('href'));
}
$addAddress.on('touchend', function() {
if ($addressItem.length >= 5) {
tip.show('您最多添加5个收货地址');
return false;
}
});
// 删除
$action.on('touchend', '.del', function() {
deleteId = $(this).data('id');
$confim.show();
});
$submit.on('touchend', function() {
if (security.hasDangerInput(false)) {
return false;
}
$addressForm.submit();
return false;
}).on('touchstart', function() {
$(this).addClass('highlight');
}).on('touchend touchcancel', function() {
$(this).removeClass('highlight');
});