index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import $ from './../../utils/Tool'
  2. import router from './../../utils/router'
  3. import {queryAllspace} from '../../requests/api'
  4. let timer = 0;
  5. Page({
  6. data: {
  7. spaceName:'',
  8. spaceId:'',
  9. seachValue:'',
  10. alllistContent:[],
  11. currentList:[],
  12. allListnum:0,
  13. userId:$.store.get('userId'),
  14. tenantId:$.store.get('tenantId'),
  15. projectId:$.store.get('projectId'),
  16. currtPage:0,
  17. },
  18. /**
  19. * 搜索
  20. */
  21. spaceSearch(e){
  22. let value = e.detail
  23. if(timer){
  24. clearTimeout(timer)
  25. }
  26. timer = setTimeout(()=>{
  27. if(value){
  28. this.updateList(value);
  29. // this.setData({seachValue:value,currtPage:0,alllistContent:[]},()=>{
  30. // this.getallList(value);
  31. // });
  32. }else{
  33. this.setData({currentList:alllistContent})
  34. }
  35. },500)
  36. },
  37. updateList(value){
  38. let allList =JSON.parse(JSON.stringify(this.data.alllistContent));
  39. let currentList=[];
  40. allList.forEach(item=>{
  41. if(item.localName.includes(value)){
  42. currentList.push(item)
  43. }
  44. })
  45. this.setData({currentList:currentList})
  46. },
  47. goBack(){
  48. router.pop();
  49. },
  50. async getallList(){
  51. let projectId = $.store.get('projectId') ||$.storage.get('projectId');
  52. let tenantId = $.store.get('tenantId')||$.storage.get('tenantId');
  53. let userId = $.store.get('userId') || $.storage.get('userId');
  54. const data={
  55. "criteria": {
  56. "userId":userId,
  57. "projectId": projectId,
  58. "tenantId": tenantId
  59. },
  60. // page:this.data.currtPage + 1,
  61. // size:20,
  62. orders:[
  63. {
  64. column:"localName",
  65. asc:"true"
  66. }
  67. ]
  68. }
  69. // if(this.data.seachValue){
  70. // data.criteria.localName={$like: `%${this.data.seachValue}%`}
  71. // }
  72. wx.showLoading()
  73. let res =await queryAllspace(data);
  74. wx.hideLoading()
  75. this.setData({allListnum:res.count});
  76. if(res.count&&res.content){
  77. this.setData({alllistContent:this.data.alllistContent.concat(res.content)},()=>{
  78. // res.count>30?this.setData({currentList:this.getPage(1)}):this.setData({currentList:this.data.alllistContent});
  79. this.setData({currentList:this.data.alllistContent})
  80. });
  81. }
  82. },
  83. // 前端分页
  84. getPage(page){
  85. let start = (page-1)*30;
  86. let end = ((page-1)*30 + 30)>this.data.allListnum?this.data.allListnum:((page-1)*30 + 30)
  87. return this.data.alllistContent.slice(start,end)
  88. },
  89. spaceClick(e){
  90. console.log(e.currentTarget.dataset.spaceitem)
  91. let {id,localName} = e.currentTarget.dataset.spaceitem;
  92. let pages = getCurrentPages();
  93. let prevPage = pages[ pages.length - 2 ];
  94. prevPage.setData({ // 将我们想要传递的参数在这里直接setData。上个页面就会执行这里的操作。
  95. spaceId:id,
  96. spaceName:localName,
  97. formSearch:true,
  98. },()=>{
  99. router.pop()
  100. })
  101. },
  102. /**
  103. * 生命周期函数--监听页面加载
  104. */
  105. onLoad: function (options) {
  106. this.getallList();
  107. },
  108. /**
  109. * 页面上拉触底事件的处理函数
  110. */
  111. onReachBottom: function () {
  112. // this.getallList();
  113. },
  114. })