highseas.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <view class="high-seas-container">
  3. <navbar>
  4. <view class="nav">
  5. <view class="nav-city" @click="$navigateTo('/pages/city/city?activeCity='+JSON.stringify(activeCity))">
  6. <uni-icons class="city-icon" type="location-filled" size="16"></uni-icons>
  7. <text class="city-name">{{activeCity.cityName}}</text>
  8. </view>
  9. <view class="nav-search" @click="$navigateTo('/pages/search/search')"
  10. :style="'height:' + boundingClientRect.height + 'px;border-radius:' + boundingClientRect.height + 'px;line-height:'+(boundingClientRect.height-2)+'px'">
  11. 搜索房源或项目
  12. </view>
  13. <view class="wx-operation"
  14. :style="'width:' + boundingClientRect.width + 'px;height:'+ boundingClientRect.height+'px;'">
  15. </view>
  16. </view>
  17. </navbar>
  18. <mescroll-body :top="getNavBarHeight()" bottom="20" @init="mescrollInit" @down="downCallback" @up="upCallback"
  19. :down="{
  20. auto:false
  21. }">
  22. <view class="house-list">
  23. <house-item v-for="(item,index) in list" :house="item" :key="item.id"></house-item>
  24. </view>
  25. </mescroll-body>
  26. </view>
  27. </template>
  28. <script>
  29. import navbar from "@/components/common/navbar.vue";
  30. import houseItem from "@/components/house/houseItem.vue";
  31. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  32. import {
  33. getOpenHouseListByPage
  34. } from '@/request/api/house.js'
  35. export default {
  36. mixins: [MescrollMixin], // 使用mixin
  37. data() {
  38. return {
  39. boundingClientRect: {},
  40. list: [],
  41. activeCity: {
  42. cityName: '',
  43. cityCode: ''
  44. },
  45. coordinates: ''
  46. }
  47. },
  48. onShow() {
  49. this.boundingClientRect = wx.getMenuButtonBoundingClientRect();
  50. },
  51. onLoad() {
  52. uni.$on('changeCity', data => {
  53. this.activeCity = data;
  54. })
  55. uni.getLocation({
  56. type: 'wgs84',
  57. success: res => {
  58. this.coordinates = res.longitude + ',' + res.latitude;
  59. this.$store.dispatch('app/changeCoordinates', this.coordinates);
  60. uni.setStorageSync('vuex_state', this.$store.state);
  61. this.getLocation();
  62. },
  63. fail: () => {
  64. this.coordinates = this.$store.getters.coordinates;
  65. this.getLocation();
  66. }
  67. });
  68. },
  69. methods: {
  70. getLocation() {
  71. uni.request({
  72. url: 'https://restapi.amap.com/v3/geocode/regeo', // 服务器url
  73. method: 'GET', // 请求方法,默认为GET
  74. data: {
  75. key: '8d6519155e085eb1b83d1de7953b2414',
  76. location: this.coordinates
  77. },
  78. success: (res) => {
  79. if (res.statusCode === 200) {
  80. let data = res.data;
  81. if (data.info == 'OK') {
  82. let regeocode = data.regeocode;
  83. this.activeCity = {
  84. cityName: regeocode.addressComponent.city,
  85. cityCode: regeocode.addressComponent.adcode
  86. }
  87. this.$store.dispatch('app/changeActiveCity', this.activeCity);
  88. uni.setStorageSync('vuex_state', this.$store.state);
  89. this.mescroll.resetUpScroll();
  90. } else {
  91. this.activeCity = this.$store.getters.activeCity;
  92. this.mescroll.resetUpScroll();
  93. }
  94. } else {
  95. this.activeCity = this.$store.getters.activeCity;
  96. this.mescroll.resetUpScroll();
  97. }
  98. },
  99. fail: () => {
  100. this.activeCity = this.$store.getters.activeCity;
  101. this.mescroll.resetUpScroll();
  102. }
  103. });
  104. },
  105. // 获取状态栏高度
  106. geStatusBarHeight() {
  107. return uni.getSystemInfoSync()['statusBarHeight']
  108. },
  109. // 获取导航栏高度
  110. getNavBarHeight() {
  111. // #ifdef MP-WEIXIN
  112. let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  113. // 导航栏高度 = 胶囊高度 + 上间距 + 下间距 + 微调 (menuButtonInfo.top - uni.getSystemInfoSync()['statusBarHeight'] = 上间距)
  114. let navbarHeight = menuButtonInfo.height + (menuButtonInfo.top - uni.getSystemInfoSync()[
  115. 'statusBarHeight']) * 2 + 2
  116. // #endif
  117. // #ifdef APP-PLUS || H5
  118. let navbarHeight = 44
  119. // #endif
  120. return (navbarHeight + this.geStatusBarHeight()) * 2;
  121. },
  122. /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
  123. upCallback(page) {
  124. if (!this.coordinates) return this.mescroll.endErr();
  125. getOpenHouseListByPage({
  126. currPage: page.num,
  127. pageSize: 10,
  128. coordinates: this.coordinates,
  129. code: this.activeCity.cityCode
  130. }).then(res => {
  131. if (res.code === 200) {
  132. this.mescroll.endBySize(res.data.dataList.length, res.data.totalCount);
  133. if (page.num == 1) this.list = []; //如果是第一页需手动制空列表
  134. this.list = this.list.concat(res.data.dataList); //追加新数据
  135. } else {
  136. this.mescroll.endErr();
  137. }
  138. }).catch(() => {
  139. //联网失败, 结束加载
  140. this.mescroll.endErr();
  141. })
  142. }
  143. },
  144. components: {
  145. navbar,
  146. houseItem
  147. }
  148. }
  149. </script>
  150. <style lang="scss">
  151. .high-seas-container {
  152. .nav {
  153. height: 100%;
  154. background: #fff;
  155. width: 100%;
  156. display: flex;
  157. align-items: center;
  158. .nav-city {
  159. height: 50rpx;
  160. max-width: 160rpx;
  161. min-width: 120rpx;
  162. border-radius: 50rpx;
  163. border: 1px solid $uni-primary;
  164. margin-left: 30rpx;
  165. box-sizing: border-box;
  166. display: flex;
  167. align-items: center;
  168. margin-bottom: 4rpx;
  169. .city-icon {
  170. margin-left: 10rpx;
  171. margin-top: 4rpx;
  172. .uni-icons {
  173. color: $uni-primary !important;
  174. }
  175. }
  176. .city-name {
  177. color: $uni-primary;
  178. font-size: 24rpx;
  179. overflow: hidden;
  180. white-space: nowrap;
  181. text-overflow: ellipsis;
  182. padding: 0 20rpx 0 6rpx;
  183. }
  184. }
  185. .nav-search {
  186. flex: 1;
  187. width: 0;
  188. border: 1px solid $uni-border-1;
  189. line-height: 1;
  190. padding-left: 30rpx;
  191. color: $uni-secondary-color;
  192. margin: 0 20rpx;
  193. box-sizing: border-box;
  194. margin-bottom: 4rpx;
  195. font-weight: 200;
  196. height: 64rpx;
  197. border-radius: 64rpx;
  198. line-height: 60rpx;
  199. }
  200. .wx-operation {
  201. margin-right: 8px;
  202. margin-bottom: 4rpx;
  203. }
  204. }
  205. .house-list {
  206. padding: 30rpx;
  207. }
  208. }
  209. </style>