index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. const data={
  52. "criteria": {
  53. "userId":$.store.get('userId'),
  54. "projectId": $.store.get('projectId'),
  55. "tenantId": $.store.get('tenantId')
  56. },
  57. // page:this.data.currtPage + 1,
  58. // size:20,
  59. orders:[
  60. {
  61. column:"localName",
  62. asc:"true"
  63. }
  64. ]
  65. }
  66. // if(this.data.seachValue){
  67. // data.criteria.localName={$like: `%${this.data.seachValue}%`}
  68. // }
  69. wx.showLoading()
  70. let res =await queryAllspace(data);
  71. wx.hideLoading()
  72. this.setData({allListnum:res.count});
  73. if(res.count&&res.content){
  74. this.setData({alllistContent:this.data.alllistContent.concat(res.content)},()=>{
  75. // res.count>30?this.setData({currentList:this.getPage(1)}):this.setData({currentList:this.data.alllistContent});
  76. this.setData({currentList:this.data.alllistContent})
  77. });
  78. }
  79. },
  80. // 前端分页
  81. getPage(page){
  82. let start = (page-1)*30;
  83. let end = ((page-1)*30 + 30)>this.data.allListnum?this.data.allListnum:((page-1)*30 + 30)
  84. return this.data.alllistContent.slice(start,end)
  85. },
  86. spaceClick(e){
  87. console.log(e.currentTarget.dataset.spaceitem)
  88. let {id,localName} = e.currentTarget.dataset.spaceitem;
  89. let pages = getCurrentPages();
  90. let prevPage = pages[ pages.length - 2 ];
  91. prevPage.setData({ // 将我们想要传递的参数在这里直接setData。上个页面就会执行这里的操作。
  92. spaceId:id,
  93. spaceName:localName,
  94. formSearch:true,
  95. },()=>{
  96. router.pop()
  97. })
  98. },
  99. /**
  100. * 生命周期函数--监听页面加载
  101. */
  102. onLoad: function (options) {
  103. this.getallList();
  104. },
  105. /**
  106. * 页面上拉触底事件的处理函数
  107. */
  108. onReachBottom: function () {
  109. // this.getallList();
  110. },
  111. })