highseas.vue 6.6 KB

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