index.js
2.8 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
let App = getApp();
Page({
data: {
adresslist:[],
},
onLoad: function (options) {
},
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
let that = this;
App._get('adress/lists', {}, function (result) {
that.setData({
adresslist: result.data.list
});
//获得dialog组件
that.SwipeCellList = that.selectAllComponents(".vscell");
//这里对所有的 vscell 默认选取
that.SwipeCellList.forEach(function (value, index, array) {
//console.log(value.dataset.defult);
if (value.dataset.defult == '1') {
that.SwipeCellList[index].open("left");
}
});
if (that.SwipeCellList[1]) {
that.SwipeCellList[1].open("right");
}
});
//时间段
setTimeout(function (){
that.SwipeCellList.forEach(function (value, index, array) {
if (value.dataset.defult == '1') {
that.SwipeCellList[index].close();
}
});
if (that.SwipeCellList[1]) {
that.SwipeCellList[1].close();
}
}, 800)
},
onclickItem: function (e) {
console.log(e);
let that = this;
if (e.detail =="left"){
var idx = e.target.dataset.id;
this.data.adresslist.forEach(function (value, index, array) {
if (index == idx){
value.isdefault = "1";
//设置默认项
App._post('adress/setdefault', { id: value.address_id}, function (result) {
App.showSuccess(result.msg);
});
}else{
value.isdefault = "0";
}
});
this.setData({
adresslist: this.data.adresslist
});
return;
}
if (e.detail == "right"){
var idx = e.target.dataset.id;
if (this.data.adresslist.length <= 1){
App.showError('至少保留一个收货地址。');
return;
}
this.data.adresslist.every(function (value, index) {
if (index == idx) {
//如果删除的为默认项
if (value.isdefault == "1"){
App.showError('无法删除默认项。');
} else {
that.data.adresslist.splice(index, 1);
//这里提交删除
App._post('adress/del', { id: value.address_id }, function (result) {
App.showSuccess(result.msg);
});
}
return false;
}
return true;
});
this.setData({
adresslist: this.data.adresslist
});
return;
}
if (e.detail == "cell") {
//跳转到 编辑页面
var idx = e.target.dataset.adressid;
wx.navigateTo({
url: './edit?id=' + idx
})
}
},
createAddress:function(){
wx.navigateTo({
url: './create'
});
},
})