highseas.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. this.$store.dispatch('app/changeActiveCity', this.activeCity);
  55. uni.setStorageSync('vuex_state', this.$store.state);
  56. this.mescroll.resetUpScroll();
  57. })
  58. uni.getLocation({
  59. type: 'wgs84',
  60. success: res => {
  61. this.coordinates = res.longitude + ',' + res.latitude;
  62. this.$store.dispatch('app/changeCoordinates', this.coordinates);
  63. uni.setStorageSync('vuex_state', this.$store.state);
  64. this.getLocation();
  65. },
  66. fail: () => {
  67. this.coordinates = this.$store.getters.coordinates;
  68. this.getLocation();
  69. }
  70. });
  71. },
  72. methods: {
  73. getLocation() {
  74. uni.request({
  75. url: 'https://restapi.amap.com/v3/geocode/regeo', // 服务器url
  76. method: 'GET', // 请求方法,默认为GET
  77. data: {
  78. key: '8d6519155e085eb1b83d1de7953b2414',
  79. location: this.coordinates
  80. },
  81. success: (res) => {
  82. if (res.statusCode === 200) {
  83. let data = res.data;
  84. if (data.info == 'OK') {
  85. let regeocode = data.regeocode;
  86. this.activeCity = {
  87. cityName: regeocode.addressComponent.city,
  88. cityCode: regeocode.addressComponent.adcode
  89. }
  90. this.$store.dispatch('app/changeActiveCity', this.activeCity);
  91. uni.setStorageSync('vuex_state', this.$store.state);
  92. this.mescroll.resetUpScroll();
  93. } else {
  94. this.activeCity = this.$store.getters.activeCity;
  95. this.mescroll.resetUpScroll();
  96. }
  97. } else {
  98. this.activeCity = this.$store.getters.activeCity;
  99. this.mescroll.resetUpScroll();
  100. }
  101. },
  102. fail: () => {
  103. this.activeCity = this.$store.getters.activeCity;
  104. this.mescroll.resetUpScroll();
  105. }
  106. });
  107. },
  108. // 获取状态栏高度
  109. geStatusBarHeight() {
  110. return uni.getSystemInfoSync()['statusBarHeight']
  111. },
  112. // 获取导航栏高度
  113. getNavBarHeight() {
  114. // #ifdef MP-WEIXIN
  115. let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  116. // 导航栏高度 = 胶囊高度 + 上间距 + 下间距 + 微调 (menuButtonInfo.top - uni.getSystemInfoSync()['statusBarHeight'] = 上间距)
  117. let navbarHeight = menuButtonInfo.height + (menuButtonInfo.top - uni.getSystemInfoSync()[
  118. 'statusBarHeight']) * 2 + 2
  119. // #endif
  120. // #ifdef APP-PLUS || H5
  121. let navbarHeight = 44
  122. // #endif
  123. return (navbarHeight + this.geStatusBarHeight()) * 2;
  124. },
  125. /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
  126. upCallback(page) {
  127. if (!this.coordinates) return this.mescroll.endErr();
  128. getOpenHouseListByPage({
  129. currPage: page.num,
  130. pageSize: 10,
  131. coordinates: this.coordinates,
  132. code: this.activeCity.cityCode
  133. }).then(res => {
  134. if (res.code === 200) {
  135. this.mescroll.endBySize(res.data.dataList.length, res.data.totalCount);
  136. if (page.num == 1) this.list = []; //如果是第一页需手动制空列表
  137. this.list = this.list.concat(res.data.dataList); //追加新数据
  138. } else {
  139. this.mescroll.endErr();
  140. }
  141. }).catch(() => {
  142. //联网失败, 结束加载
  143. this.mescroll.endErr();
  144. })
  145. }
  146. },
  147. components: {
  148. navbar,
  149. houseItem
  150. }
  151. }
  152. </script>
  153. <style lang="scss">
  154. .high-seas-container {
  155. .nav {
  156. height: 100%;
  157. background: #fff;
  158. width: 100%;
  159. display: flex;
  160. align-items: center;
  161. .nav-city {
  162. height: 50rpx;
  163. max-width: 160rpx;
  164. min-width: 120rpx;
  165. border-radius: 50rpx;
  166. border: 1px solid $uni-primary;
  167. margin-left: 30rpx;
  168. box-sizing: border-box;
  169. display: flex;
  170. align-items: center;
  171. margin-bottom: 4rpx;
  172. .city-icon {
  173. margin-left: 10rpx;
  174. margin-top: 4rpx;
  175. .uni-icons {
  176. color: $uni-primary !important;
  177. }
  178. }
  179. .city-name {
  180. color: $uni-primary;
  181. font-size: 24rpx;
  182. overflow: hidden;
  183. white-space: nowrap;
  184. text-overflow: ellipsis;
  185. padding: 0 20rpx 0 6rpx;
  186. }
  187. }
  188. .nav-search {
  189. flex: 1;
  190. width: 0;
  191. border: 1px solid $uni-border-1;
  192. line-height: 1;
  193. padding-left: 30rpx;
  194. color: $uni-secondary-color;
  195. margin: 0 20rpx;
  196. box-sizing: border-box;
  197. margin-bottom: 4rpx;
  198. font-weight: 200;
  199. height: 64rpx;
  200. border-radius: 64rpx;
  201. line-height: 60rpx;
  202. }
  203. .wx-operation {
  204. margin-right: 8px;
  205. margin-bottom: 4rpx;
  206. }
  207. }
  208. .house-list {
  209. padding: 30rpx;
  210. }
  211. }
  212. </style>