MyGarageNoCar.js
5.6 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
import {
request
} from '../../request/index.js'
const a = getApp()
Page({
data: {
imagesUrl: a.globalData.baseUrl,
_num: 1,
way: 1,
MyGarageNoCar: [],
list: [{
id: 0,
title: '标题1',
create_time: '2019-09-06'
}, {
id: 1,
title: '标题2',
create_time: '2019-09-06'
}, {
id: 2,
title: '标题3',
create_time: '2019-09-06'
}],
startX: 0, //开始坐标
startY: 0,
page: 1,
is_cloose: false,
},
touchE: function (e) {
// // console.log(e);
var that = this
if (e.changedTouches.length == 1) {
//手指移动结束后触摸点位置的X坐标
var endX = e.changedTouches[0].clientX;
//触摸开始与结束,手指移动的距离
var disX = that.data.startX - endX;
var delBtnWidth = that.data.delBtnWidth;
//如果距离小于删除按钮的1/2,不显示删除按钮
var txtStyle = disX > delBtnWidth / 2 ? "left:-" + delBtnWidth + "rpx" : "left:0rpx";
//获取手指触摸的是哪一项
var index = e.currentTarget.dataset.index;
var MyGarageNoCar = that.data.MyGarageNoCar;
MyGarageNoCar[index].txtStyle = txtStyle;
//更新列表的状态
that.setData({
MyGarageNoCar: MyGarageNoCar
});
}
},
//手指触摸动作开始 记录起点X坐标
touchstart: function (e) {
//开始触摸时 重置所有删除
this.data.MyGarageNoCar.forEach(function (v, i) {
if (v.isTouchMove) //只操作为true的
v.isTouchMove = false;
})
this.setData({
startX: e.changedTouches[0].clientX,
startY: e.changedTouches[0].clientY,
MyGarageNoCar: this.data.MyGarageNoCar
})
},
//滑动事件处理
touchmove: function (e) {
var that = this,
index = e.currentTarget.dataset.index, //当前索引
startX = that.data.startX, //开始X坐标
startY = that.data.startY, //开始Y坐标
touchMoveX = e.changedTouches[0].clientX, //滑动变化坐标
touchMoveY = e.changedTouches[0].clientY, //滑动变化坐标
//获取滑动角度
angle = that.angle({
X: startX,
Y: startY
}, {
X: touchMoveX,
Y: touchMoveY
});
that.data.MyGarageNoCar.forEach(function (v, i) {
v.isTouchMove = false
//滑动超过30度角 return
if (Math.abs(angle) > 30) return;
if (i == index) {
if (touchMoveX > startX) //右滑
v.isTouchMove = false
else //左滑
v.isTouchMove = true
}
})
//更新数据
that.setData({
MyGarageNoCar: that.data.MyGarageNoCar
})
},
/**
* 计算滑动角度
* @param {Object} start 起点坐标
* @param {Object} end 终点坐标
*/
angle: function (start, end) {
var _X = end.X - start.X,
_Y = end.Y - start.Y
//返回角度 /Math.atan()返回数字的反正切值
return 360 * Math.atan(_Y / _X) / (2 * Math.PI);
},
changeTitle(e) { // 切换
let um = e.currentTarget.dataset.num
this.setData({
_num: um
})
if (um == 2) {
this.getMyGarageNoCar()
} else {
this.onShow()
}
// console.log(this.data._num);
},
onLoad: function (options) {
},
onShow: function () {
this.getMyGarageNoCar()
},
getMyGarageNoCar() { //获取待
let that = this
let cat = that.data._num
if (cat == 1) {
that.setData({
way: 1,
is_cloose: false
})
that.getadd()
} else {
that.setData({
way: 2,
is_cloose: false
})
that.getadd()
}
},
async getadd() {
let that = this
that.setData({
MyGarageNoCar: []
})
try {
const {
data: {
data
}
} = await request({
url: 'api/my/zanGood',
data: {
way: that.data.way
}
})
that.setData({
MyGarageNoCar: data
})
if (data.length != 0) {
that.setData({
is_cloose: false
})
} else {
that.setData({
is_cloose: true
})
}
// console.log(that.data.MyGarageNoCar, "有赞");
} catch (err) {
// console.log(err);
that.setData({
msg: err.msg
})
that.popTest()
}
},
delOrder(e) { // 删除
let that = this
wx.showModal({
title: '提示',
content: '确定要删除该商品吗?',
success: async function (res) {
if (res.confirm) {
try {
const {
data
} = await request({
url: 'api/new2/zanShareDel',
data: {
id: e.currentTarget.dataset.id
}
})
// console.log(data, "删除");
if (data.code == 1) {
let msg = data.msg
a.popSuccessTest(msg)
setTimeout(() => {
that.getMyGarageNoCar()
}, 1000);
} else {
let msg = data.msg
a.popTest(msg)
}
} catch (err) {
let msg = err.msg
a.popTest(msg)
}
} else {
}
}
})
},
storeDetail(e) {
// console.log(e);
let id = e.currentTarget.dataset.id
wx.navigateTo({
url: '/pages/detail/detail?id=' + id
})
},
popSuccessTest() {
wx.showToast({
title: this.data.msg,
icon: '',
duration: 1300,
mask: true
})
},
popTest() {
wx.showToast({
title: this.data.msg,
icon: 'none',
duration: 1300,
mask: true
})
},
})