childlist.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. const app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. keyword:'',
  8. status:[{statu:'已入库',type:'00'},{statu:'已出库',type:'10'},{statu:'已结束',type:'20'}],
  9. text:'已入库',
  10. type:'00',
  11. isStatus:false,
  12. startX: 0, // 开始X坐标
  13. startY: 0, // 开始Y坐标
  14. },
  15. allStatus(){
  16. if(this.data.isStatus){
  17. this.setData({
  18. isStatus:false
  19. })
  20. }else{
  21. this.setData({
  22. isStatus:true
  23. })
  24. }
  25. },
  26. setKeyword(e) {
  27. this.setData({
  28. keyword: e.detail.value
  29. })
  30. },
  31. /**
  32. * 生命周期函数--监听页面加载
  33. */
  34. onShow(){
  35. this.getChildList(this.data.chainId)
  36. },
  37. onLoad: function (options) {
  38. this.setData({chainId:options.chainId})
  39. },
  40. searchList(){
  41. this.getChildList(this.data.chainId);
  42. },
  43. getChildList(chainId){
  44. var that = this;
  45. app.requestP({
  46. url: "/chain/pageChain",
  47. method: "post",
  48. contentType: ' application/json',
  49. data: {
  50. pageNum: 1,
  51. pageSize: 1000,
  52. parentId:chainId,
  53. transportStatus:that.data.type || '',
  54. keyword:that.data.keyword || ''
  55. }
  56. }).then(res => {
  57. var data = res.data.data.rows;
  58. that.setData({list:data});
  59. }).catch(err=>{
  60. app.showToptip(that,'error',err.data.msg)
  61. })
  62. },
  63. setStatus(e){
  64. var type = e.currentTarget.dataset.type;
  65. for(var i in this.data.status){
  66. if(this.data.status[i].type == type){
  67. this.setData({
  68. text:this.data.status[i].statu,
  69. type,
  70. isStatus:false
  71. })
  72. this.getChildList(this.data.chainId);
  73. break;
  74. }
  75. }
  76. },
  77. addLabel(){
  78. var chainId = this.data.chainId;
  79. wx.navigateTo({
  80. url: '/pages/workbench/tempList/addChain/addChain?pid='+chainId,
  81. })
  82. },
  83. editList(e){
  84. var item = e.currentTarget.dataset.item;
  85. wx.navigateTo({
  86. url: '/pages/workbench/tempList/addChain/addChain?item='+JSON.stringify(item),
  87. })
  88. },
  89. delList(e){
  90. var that = this;
  91. var id = e.currentTarget.dataset.id;
  92. app.requestP({
  93. url:'/chain/del',
  94. method:'post',
  95. data:{
  96. chainId:id
  97. }
  98. }).then(res=>{
  99. app.showToptip(that,'success',res.data.msg);
  100. that.getChildList(that.data.chainId)
  101. }).catch(err=>{
  102. app.showToptip(that,'error',err.data.msg);
  103. })
  104. },
  105. /**
  106. * 生命周期函数--监听页面初次渲染完成
  107. */
  108. onReady: function () {
  109. },
  110. /**
  111. * 生命周期函数--监听页面隐藏
  112. */
  113. onHide: function () {
  114. },
  115. /**
  116. * 生命周期函数--监听页面卸载
  117. */
  118. onUnload: function () {
  119. },
  120. /**
  121. * 页面相关事件处理函数--监听用户下拉动作
  122. */
  123. onPullDownRefresh: function () {
  124. },
  125. /**
  126. * 页面上拉触底事件的处理函数
  127. */
  128. onReachBottom: function () {
  129. },
  130. /**
  131. * 用户点击右上角分享
  132. */
  133. onShareAppMessage: function () {
  134. },
  135. // 手指触摸动作开始
  136. touchStart: function (e) {
  137. let that = this;
  138. //开始触摸时 重置所有删除
  139. that.data.list.forEach(function (v, i) {
  140. if (v.isTouchMove) v.isTouchMove = false; // 只操作为true的
  141. })
  142. // 记录手指触摸开始坐标
  143. that.setData({
  144. startX: e.changedTouches[0].clientX, // 开始X坐标
  145. startY: e.changedTouches[0].clientY, // 开始Y坐标
  146. list: that.data.list
  147. })
  148. },
  149. // 手指触摸后移动
  150. touchMove: function (e) {
  151. let that = this,
  152. index = e.currentTarget.dataset.index, // 当前下标
  153. startX = that.data.startX, // 开始X坐标
  154. startY = that.data.startY, // 开始Y坐标
  155. touchMoveX = e.changedTouches[0].clientX, // 滑动变化坐标
  156. touchMoveY = e.changedTouches[0].clientY, // 滑动变化坐标
  157. // 获取滑动角度
  158. angle = that.angle({
  159. X: startX,
  160. Y: startY
  161. }, {
  162. X: touchMoveX,
  163. Y: touchMoveY
  164. });
  165. // 判断滑动角度
  166. that.data.list.forEach(function (v, i) {
  167. v.isTouchMove = false
  168. // 滑动超过30度角 return
  169. if (Math.abs(angle) > 30) return;
  170. if (i == index) {
  171. // 右滑
  172. if (touchMoveX > startX)
  173. v.isTouchMove = false
  174. // 左滑
  175. else
  176. v.isTouchMove = true
  177. }
  178. })
  179. // 更新数据
  180. that.setData({
  181. list: that.data.list
  182. })
  183. },
  184. // 计算滑动角度
  185. angle: function (start, end) {
  186. let that = this,
  187. _X = end.X - start.X,
  188. _Y = end.Y - start.Y;
  189. // 返回角度 /Math.atan()返回数字的反正切值
  190. return 360 * Math.atan(_Y / _X) / (2 * Math.PI);
  191. },
  192. })