const app = getApp(); Page({ /** * 页面的初始数据 */ data: { keyword: '', pageNum: 1, pageSize: 999, productTypeId: '', productList: [], scrollHeight: 0, // scroll-view高度 startX: 0, // 开始X坐标 startY: 0, // 开始Y坐标 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // this.getProductList(); // 动态获取屏幕高度 this.setData({ scrollHeight: wx.getSystemInfoSync().screenHeight }) }, setKeyword(e) { this.setData({ keyword: e.detail.value }) }, searchList(){ this.getProductList(this.data.keyword); }, getProductList(keyword) { var that = this; const { pageNum, pageSize, productTypeId } = that.data; app.requestP({ url: '/productType/productTypeState', method: 'post', data: { keyword : keyword || '', pageNum, pageSize, productTypeId } }).then(res => { that.setData({ productList: res.data.data }) }).catch(err=>{ app.showToptip(that,'error',err.data.msg) }) }, toProductInfo(e) { const id = e.currentTarget.dataset.id; const name = e.currentTarget.dataset.name; var that = this; wx.navigateTo({ url: '/pages/workbench/product/productInfo/productInfo?id=' + id + '&name=' + name, }) }, addProductType() { var that = this; wx.navigateTo({ url: '/pages/workbench/product/addProdutType/addProdutType', }) }, // 手指触摸动作开始 touchStart: function (e) { let that = this; //开始触摸时 重置所有删除 that.data.productList.forEach(function (v, i) { if (v.isTouchMove) v.isTouchMove = false; // 只操作为true的 }) // 记录手指触摸开始坐标 that.setData({ startX: e.changedTouches[0].clientX, // 开始X坐标 startY: e.changedTouches[0].clientY, // 开始Y坐标 productList: that.data.productList }) }, // 手指触摸后移动 touchMove: function (e) { let 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.productList.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({ productList: that.data.productList }) }, // 计算滑动角度 angle: function (start, end) { let that = this, _X = end.X - start.X, _Y = end.Y - start.Y; // 返回角度 /Math.atan()返回数字的反正切值 return 360 * Math.atan(_Y / _X) / (2 * Math.PI); }, // 删除 delList: function (e) { let that = this, index = e.currentTarget.dataset.index, id = that.data.productList[index].id; // 当前下标 app.requestP({ url: '/productType/remove', method: 'post', data: { productTypeId:id } }).then(res => { //切割当前下标元素,更新数据 that.data.productList.splice(index, 1); that.setData({ productList: that.data.productList }) app.showToptip(that, "success",res.data.msg); }).catch(error => { app.showToptip(that, "error",error.data.msg); }) }, editList(e){ var id = e.currentTarget.dataset.id; var name = e.currentTarget.dataset.name; wx.navigateTo({ url: '/pages/workbench/product/addProdutType/addProdutType?id=' + id + '&name=' + name, }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.getProductList(); // 动态获取屏幕高度 this.setData({ scrollHeight: wx.getSystemInfoSync().screenHeight }) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })