searchList.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <view>
  3. <!-- <u-navbar :is-back="true" title="房源列表" :border-bottom="false"></u-navbar> -->
  4. <u-sticky offset-top="0">
  5. <view class="sticky">
  6. <filterDropdown :defaultSelected="defaultSelected" :filterData="filterData" :menuTop="0" :updateMenuName="true"
  7. dataFormat="Object" @confirm="confirm"></filterDropdown>
  8. </view>
  9. </u-sticky>
  10. <view class="u-p-l-10 u-p-r-10 waterfall">
  11. <u-waterfall ref="uWaterfall" v-model="flowList">
  12. <template v-slot:left="{leftList}">
  13. <view v-for="(item, index) in leftList" :key="index" class="demo-warter">
  14. <u-lazy-load :image="item.image" :index="index" border-radius="12" threshold="750"
  15. @click="clickImage(item.id)"></u-lazy-load>
  16. <view class="item-title">{{ item.villageName }}
  17. {{ item.type == '整租' ? item.houseNum + item.houseHall + item.toiletNum : item.roomType }}
  18. </view>
  19. <view class="item-price">¥{{ item.price }}</view>
  20. <view class="item-desc">{{ item.type }} | {{ item.type == '整租' ? item.houseArea : item.roomArea }}㎡ |
  21. {{ item.decoration }}
  22. </view>
  23. </view>
  24. </template>
  25. <template v-slot:right="{rightList}">
  26. <view v-for="(item, index) in rightList" :key="index" class="demo-warter">
  27. <u-lazy-load :image="item.image" :index="index" border-radius="10" threshold="750"
  28. @click="clickImage(item.id)"></u-lazy-load>
  29. <view class="item-title">{{ item.villageName }}
  30. {{ item.type == '整租' ? item.houseNum + item.houseHall + item.toiletNum : item.roomType }}
  31. </view>
  32. <view class="item-price">¥{{ item.price }}</view>
  33. <view class="item-desc">{{ item.type }} | {{ item.type == '整租' ? item.houseArea : item.roomArea }}㎡ |
  34. {{ item.decoration }}
  35. </view>
  36. </view>
  37. </template>
  38. </u-waterfall>
  39. <u-loadmore :status="loadStatus" bg-color="rgb(240, 240, 240)" style="height: 80rpx;line-height: 80rpx;"
  40. @loadmore="findHouseList"></u-loadmore>
  41. <u-back-top :scroll-top="scrollTop" top="1000"></u-back-top>
  42. <u-no-network></u-no-network>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import config from "@/common/config.js" // 全局配置文件
  48. import searchData from '@/common/utils/searchData.js';//筛选菜单数据
  49. import filterDropdown from '@/components/zy/filterDropdown.vue';
  50. export default {
  51. components: {
  52. filterDropdown
  53. },
  54. data() {
  55. return {
  56. indexArr: [],
  57. valueArr: [],
  58. defaultSelected: [],
  59. filterData: [],
  60. searchData: {},
  61. pageNum: 1,
  62. pageSize: 20,
  63. scrollTop: 0,
  64. houseList: [],
  65. loadStatus: 'loadmore',
  66. flowList: [],
  67. }
  68. },
  69. onLoad(option) {
  70. let type = option.type
  71. let villageName = option.villageName
  72. this.searchData = {}
  73. if (type) {
  74. this.searchData.type = type
  75. }
  76. if (villageName) {
  77. this.searchData.villageName = villageName
  78. }
  79. // 获取房源数据
  80. this.findHouseList();
  81. // 获取小区数据
  82. this.findVillageList()
  83. },
  84. onPageScroll(e) {
  85. this.scrollTop = e.scrollTop;
  86. },
  87. onReachBottom() {
  88. this.loadStatus = 'loading';
  89. // 获取数据
  90. this.findHouseList()
  91. },
  92. // 下拉刷新
  93. onPullDownRefresh() {
  94. this.pageNum = 1
  95. this.flowList = []
  96. this.$refs.uWaterfall.clear();
  97. // 获取数据
  98. this.findHouseList();
  99. // 关闭刷新
  100. uni.stopPullDownRefresh();
  101. },
  102. methods: {
  103. findHouseList() {
  104. let url = "/api/houseApi/findHouseRoomList";
  105. let defaultData = {
  106. state: 1,
  107. villageCity: uni.getStorageSync('lifeData').vuex_city,
  108. pageNum: this.pageNum,
  109. pageSize: this.pageSize,
  110. orderByColumn: 'update_time,create_time',
  111. isAsc: 'desc'
  112. }
  113. this.$u.get(url, {...defaultData, ...this.searchData}).then(result => {
  114. console.log(this.searchData);
  115. console.log(result);
  116. const data = result.rows;
  117. if (this.pageNum > 1 && data.length < this.pageSize) {
  118. return this.loadStatus = 'nomore';
  119. }
  120. this.houseList = data;
  121. for (let i = 0; i < this.houseList.length; i++) {
  122. // 先转成字符串再转成对象,避免数组对象引用导致数据混乱
  123. let item = this.houseList[i]
  124. if (!item.faceUrl.includes(config.staticUrl)) {
  125. item.image = config.staticUrl + item.faceUrl
  126. } else {
  127. item.image = item.faceUrl
  128. }
  129. if (item.type == 0) {
  130. item.type = '整租'
  131. } else if (item.type == 1) {
  132. item.type = '合租'
  133. }
  134. if (item.roomType == 1) {
  135. item.roomType = '主卧'
  136. } else if (item.roomType == 2) {
  137. item.roomType = '次卧'
  138. } else {
  139. item.roomType = '未知'
  140. }
  141. if (this.$u.test.isEmpty(item.houseNum)) {
  142. item.houseNum = ''
  143. }
  144. if (this.$u.test.isEmpty(item.houseHall)) {
  145. item.houseHall = ''
  146. }
  147. if (this.$u.test.isEmpty(item.toiletNum)) {
  148. item.toiletNum = ''
  149. }
  150. this.flowList.push(item);
  151. }
  152. ++this.pageNum
  153. this.loadStatus = 'loadmore';
  154. });
  155. },
  156. findVillageList() {
  157. let url = "/api/houseApi/findVillageList";
  158. this.$u.get(url, {
  159. city: uni.getStorageSync('lifeData').vuex_city,
  160. orderByColumn: 'name',
  161. isAsc: 'desc'
  162. }).then(result => {
  163. const data = result.rows
  164. for (let i = 0; i < data.length; i++) {
  165. // 先转成字符串再转成对象,避免数组对象引用导致数据混乱
  166. let item = data[i]
  167. searchData[0].submenu.push({
  168. name: item.name,
  169. value: item.name
  170. })
  171. }
  172. this.filterData = searchData;
  173. });
  174. },
  175. clickImage(houseId) {
  176. this.$u.route({
  177. url: '/pages/detail/detail',
  178. params: {
  179. houseId: houseId
  180. }
  181. })
  182. },
  183. //接收菜单结果
  184. confirm(e) {
  185. let type = e.value[1][0]
  186. let villageName = e.value[0][0]
  187. let price = e.value[2][0]
  188. let combo = e.value[3]
  189. let houseNum = combo[0]
  190. let decoration = combo[1]
  191. let feature = combo[2]
  192. this.searchData = {}
  193. if (type) {
  194. this.searchData.type = type
  195. }
  196. if (villageName) {
  197. this.searchData.villageName = villageName
  198. }
  199. if (price) {
  200. this.searchData.price = price
  201. }
  202. if (houseNum && houseNum.length > 0) {
  203. this.searchData.houseNum = houseNum.toString()
  204. }
  205. if (decoration && decoration.length > 0) {
  206. this.searchData.decoration = decoration.toString()
  207. }
  208. if (feature && feature.length > 0) {
  209. this.searchData.feature = feature.toString()
  210. }
  211. this.pageNum = 1
  212. this.houseList = []
  213. this.flowList = []
  214. this.$refs.uWaterfall.clear();
  215. this.findHouseList()
  216. },
  217. code() {
  218. this.$mytip.toast('请咨询技术支持')
  219. }
  220. }
  221. }
  222. </script>
  223. <style lang="scss" scoped>
  224. .waterfall {
  225. // padding-top: 85rpx;
  226. }
  227. .nomore {
  228. background-color: $u-bg-color;
  229. }
  230. .search {
  231. width: 54px;
  232. height: 44px;
  233. &:active {
  234. background-color: $u-bg-color;
  235. }
  236. }
  237. .rowClass {
  238. border-radius: 8px;
  239. background-color: rgb(255, 255, 255);
  240. margin-top: 10 rpx;
  241. }
  242. .hoverClass {
  243. background-color: #E4E7ED;
  244. }
  245. .tabName {
  246. font-size: 28 rpx;
  247. color: $u-main-color;
  248. }
  249. .demo-warter {
  250. border-radius: 8px;
  251. margin-top: 3px;
  252. background-color: #ffffff;
  253. padding: 3px;
  254. position: relative;
  255. }
  256. .u-close {
  257. position: absolute;
  258. top: 20 rpx;
  259. right: 20 rpx;
  260. }
  261. .item-cover {
  262. font-size: 55 rpx;
  263. color: $u-type-warning;
  264. }
  265. .item-title {
  266. font-size: 28 rpx;
  267. color: $u-main-color;
  268. font-weight: bold;
  269. padding-top: 5 rpx;
  270. padding-left: 10 rpx;
  271. }
  272. .item-price {
  273. font-weight: normal;
  274. font-size: 32 rpx;
  275. color: $u-type-warning;
  276. }
  277. .item-desc {
  278. font-weight: normal;
  279. font-size: 26 rpx;
  280. color: $u-tips-color;
  281. padding-bottom: 5 rpx;
  282. padding-left: 10 rpx;
  283. }
  284. .item-tag {
  285. font-size: 24 rpx;
  286. color: $u-tips-color;
  287. margin-top: 3px;
  288. }
  289. </style>