tempList.js 5.6 KB

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