index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // pages/search/index.js
  2. import utils from "../../utils/util";
  3. import { queryAllspace } from "../../requests/api";
  4. import Toast from "../../vant-weapp/dist/toast/toast";
  5. import $ from "./../../utils/Tool";
  6. import router from "./../../utils/router";
  7. const app = getApp();
  8. Page({
  9. data: {
  10. alllistContent: [],
  11. projectId: "",
  12. tenantId: "",
  13. userId: null,
  14. currtPage: 0,
  15. allListnum: 0,
  16. seachValue: "",
  17. imgShow: false,
  18. noSpace: false,
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: function (options) {
  24. let projectId = $.store.get("projectId") || $.storage.get("projectId");
  25. let tenantId = $.store.get("tenantId") || $.storage.get("tenantId");
  26. let userId = $.store.get("userId") || $.storage.get("userId");
  27. this.setData({
  28. currtPage: 0,
  29. projectId: projectId,
  30. tenantId: tenantId,
  31. userId: userId,
  32. });
  33. this.getallList();
  34. },
  35. onShow() {
  36. if (this.data.seachValue) { // 搜索条件下
  37. this.spaceSearch();
  38. }
  39. },
  40. getallList(value) {
  41. this.setData({ currtPage: this.data.currtPage + 1 }, async () => {
  42. let data = {
  43. criteria: {
  44. userId: this.data.userId,
  45. projectId: this.data.projectId,
  46. tenantId: this.data.tenantId,
  47. },
  48. page: this.data.currtPage,
  49. size: 15,
  50. orders: [
  51. {
  52. column: "localName",
  53. asc: "true",
  54. },
  55. ],
  56. };
  57. if (this.data.seachValue) {
  58. data.criteria.localName = {
  59. $like: `%${this.data.seachValue}%`,
  60. };
  61. }
  62. wx.showLoading({
  63. title: "加载中",
  64. mask: true,
  65. });
  66. // $.loading();
  67. let res = await queryAllspace(data);
  68. // $.hideLoading();
  69. wx.hideLoading();
  70. this.setData({ allListnum: res.count });
  71. if (res.count && res.content) {
  72. res.content.map((item) => {
  73. item.picInit = utils.picInit(item.roomFuncType);
  74. if (typeof item.isPassengerPass === "undefined") {
  75. item.isPassengerPassShow = false;
  76. } else {
  77. item.isPassengerPassShow = true;
  78. item.isPassengerPass = item.isPassengerPass
  79. ? "有人"
  80. : "无人";
  81. }
  82. });
  83. this.setData({
  84. alllistContent: this.data.alllistContent.concat(
  85. res.content
  86. ),
  87. });
  88. } else {
  89. Toast("暂无更多");
  90. }
  91. });
  92. },
  93. // 搜索
  94. spaceSearch(e) {
  95. let val = e ? e.detail : this.data.seachValue;
  96. this.setData(
  97. { seachValue: val, currtPage: 0, alllistContent: [] },
  98. () => {
  99. this.getallList(val);
  100. }
  101. );
  102. },
  103. listClick(e) {
  104. let data = e.detail.cardDate;
  105. data.outLine && (data.outLine = "");
  106. router.push("adjust", data);
  107. },
  108. /**
  109. * 页面上拉触底事件的处理函数
  110. */
  111. onReachBottom: function () {
  112. if (this.data.allListnum != this.data.alllistContent.length) {
  113. // this.setData({currtPage:this.data.currtPage+1})
  114. this.getallList();
  115. } else {
  116. Toast("暂无更多");
  117. }
  118. },
  119. });