highseas.vue 6.3 KB

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