highseas.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <template>
  2. <view class="high-seas-container">
  3. <view class="highseas-container" v-if="!project.id">
  4. <navbar>
  5. <view class="nav">
  6. <view class="nav-city"
  7. @click="$navigateTo('/pages/city/city?activeCity='+JSON.stringify(activeCity))">
  8. <uni-icons class="city-icon" type="location-filled" size="16"></uni-icons>
  9. <text class="city-name">{{activeCity.cityName}}</text>
  10. </view>
  11. <view class="nav-search" @click="$navigateTo('/pages/search/search')"
  12. :style="'height:' + boundingClientRect.height + 'px;border-radius:' + boundingClientRect.height + 'px;line-height:'+(boundingClientRect.height-2)+'px'">
  13. 搜索房源或项目
  14. </view>
  15. <view class="wx-operation"
  16. :style="'width:' + boundingClientRect.width + 'px;height:'+ boundingClientRect.height+'px;'">
  17. </view>
  18. </view>
  19. </navbar>
  20. <mescroll-body :top="getNavBarHeight()" bottom="20" @init="mescrollInit" @down="downCallback"
  21. @up="upCallback" :down="{
  22. auto:false
  23. }">
  24. <view class="house-list">
  25. <house-item v-for="(item,index) in list" :house="item" :key="item.id"></house-item>
  26. </view>
  27. </mescroll-body>
  28. </view>
  29. <view class="project-container" v-else :style="'padding-top: ' + getNavBarHeight() + 'rpx;'">
  30. <view class="project-box">
  31. <view class="project-item">
  32. <view class="project-title">
  33. <view class="title-line"></view>
  34. <view class="title-label">房源分析</view>
  35. </view>
  36. <view class="project-content">
  37. <view class="air-item">
  38. <view class="test-item">
  39. <view class="name">总面积(㎡)</view>
  40. <view class="number">120</view>
  41. </view>
  42. <view class="line"></view>
  43. <view class="test-item">
  44. <view class="name">已租面积(㎡)</view>
  45. <view class="number">120</view>
  46. </view>
  47. <view class="line"></view>
  48. <view class="test-item">
  49. <view class="name">剩余面积(㎡)</view>
  50. <view class="number">120</view>
  51. </view>
  52. </view>
  53. <view class="air-item">
  54. <view class="test-item">
  55. <view class="name">总房源(个)</view>
  56. <view class="number">64</view>
  57. </view>
  58. <view class="line"></view>
  59. <view class="test-item">
  60. <view class="name">已租房源(个)</view>
  61. <view class="number">63</view>
  62. </view>
  63. <view class="line"></view>
  64. <view class="test-item">
  65. <view class="name">剩余房源(个)</view>
  66. <view class="number">1</view>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </template>
  75. <script>
  76. import navbar from "@/components/common/navbar.vue";
  77. import houseItem from "@/components/house/houseItem.vue";
  78. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  79. import {
  80. getOpenHouseListByPage
  81. } from '@/request/api/house.js'
  82. import city from '@/components/city-select/citys.js';
  83. const systemInfo = uni.getSystemInfoSync();
  84. const fontSize = systemInfo.platform === 'ios' ? 26 : 28; // 根据不同平台设置
  85. export default {
  86. mixins: [MescrollMixin], // 使用mixin
  87. data() {
  88. return {
  89. boundingClientRect: {},
  90. list: [],
  91. activeCity: {
  92. cityName: '',
  93. cityCode: ''
  94. },
  95. coordinates: '',
  96. project: {},
  97. fontSize: fontSize
  98. }
  99. },
  100. onShow() {
  101. this.project = this.$store.getters.project;
  102. // #ifdef MP-WEIXIN
  103. this.boundingClientRect = wx.getMenuButtonBoundingClientRect();
  104. // #endif
  105. },
  106. onLoad() {
  107. if (!this.$store.getters.project.id) {
  108. uni.$on('changeCity', data => {
  109. this.activeCity = data;
  110. this.$store.dispatch('app/changeActiveCity', this.activeCity);
  111. uni.setStorageSync('vuex_state', this.$store.state);
  112. this.mescroll.resetUpScroll();
  113. })
  114. uni.getLocation({
  115. type: 'wgs84',
  116. success: res => {
  117. this.coordinates = res.longitude + ',' + res.latitude;
  118. this.$store.dispatch('app/changeCoordinates', this.coordinates);
  119. uni.setStorageSync('vuex_state', this.$store.state);
  120. this.getLocation();
  121. },
  122. fail: () => {
  123. this.coordinates = this.$store.getters.coordinates;
  124. this.getLocation();
  125. }
  126. });
  127. }
  128. },
  129. methods: {
  130. getLocation() {
  131. let coordinates = this.coordinates.split(',');
  132. uni.request({
  133. url: "https://api.tianditu.gov.cn/geocoder?postStr={'lon':" + coordinates[0] + ",'lat':" +
  134. coordinates[1] + ",'ver':1}&type=geocode&tk=72632adad893994a0450b55949c8a8fc", // 服务器url
  135. method: 'GET', // 请求方法,默认为GET
  136. success: (res) => {
  137. if (res.statusCode === 200) {
  138. let data = res.data;
  139. if (data.msg == 'ok') {
  140. if (!data.result || !data.result.addressComponent || !data.result
  141. .addressComponent.city) {
  142. this.activeCity = this.$store.getters.activeCity;
  143. this.mescroll.resetUpScroll();
  144. return;
  145. }
  146. let nowCity = data.result.addressComponent.city.replace('市', '');
  147. let arr = city.filter(node => node.cityName.replace('市', '') == nowCity);
  148. this.activeCity = arr[0]
  149. this.$store.dispatch('app/changeActiveCity', this.activeCity);
  150. uni.setStorageSync('vuex_state', this.$store.state);
  151. this.mescroll.resetUpScroll();
  152. } else {
  153. this.activeCity = this.$store.getters.activeCity;
  154. this.mescroll.resetUpScroll();
  155. }
  156. } else {
  157. this.activeCity = this.$store.getters.activeCity;
  158. this.mescroll.resetUpScroll();
  159. }
  160. },
  161. fail: () => {
  162. this.activeCity = this.$store.getters.activeCity;
  163. this.mescroll.resetUpScroll();
  164. }
  165. });
  166. },
  167. // 获取状态栏高度
  168. geStatusBarHeight() {
  169. return uni.getSystemInfoSync()['statusBarHeight']
  170. },
  171. // 获取导航栏高度
  172. getNavBarHeight() {
  173. // #ifdef MP-WEIXIN
  174. let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  175. // 导航栏高度 = 胶囊高度 + 上间距 + 下间距 + 微调 (menuButtonInfo.top - uni.getSystemInfoSync()['statusBarHeight'] = 上间距)
  176. let navbarHeight = menuButtonInfo.height + (menuButtonInfo.top - uni.getSystemInfoSync()[
  177. 'statusBarHeight']) * 2 + 4
  178. // #endif
  179. // #ifdef APP-PLUS || H5
  180. let navbarHeight = 44
  181. // #endif
  182. return (navbarHeight + this.geStatusBarHeight()) * 2;
  183. },
  184. /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
  185. upCallback(page) {
  186. if (!this.coordinates) return this.mescroll.endErr();
  187. getOpenHouseListByPage({
  188. currPage: page.num,
  189. pageSize: 10,
  190. coordinates: this.coordinates,
  191. addressCode: this.activeCity.cityCode
  192. }).then(res => {
  193. if (res.code === 200) {
  194. this.mescroll.endBySize(res.data.dataList.length, res.data.totalCount);
  195. if (page.num == 1) this.list = []; //如果是第一页需手动制空列表
  196. this.list = this.list.concat(res.data.dataList); //追加新数据
  197. } else {
  198. this.mescroll.endErr();
  199. }
  200. }).catch(() => {
  201. //联网失败, 结束加载
  202. this.mescroll.endErr();
  203. })
  204. }
  205. },
  206. components: {
  207. navbar,
  208. houseItem
  209. }
  210. }
  211. </script>
  212. <style lang="scss">
  213. .project-container {
  214. .project-box {
  215. background: #fff;
  216. }
  217. .project-item {
  218. padding: 30rpx;
  219. .project-title {
  220. display: flex;
  221. align-items: center;
  222. }
  223. .title-line {
  224. width: 18rpx;
  225. height: 64rpx;
  226. background: $uni-primary;
  227. border-radius: 18rpx;
  228. }
  229. .title-label {
  230. font-size: 32rpx;
  231. font-weight: bold;
  232. margin-left: 20rpx;
  233. }
  234. .air-item {
  235. display: flex;
  236. align-items: center;
  237. margin-top: 20rpx;
  238. .test-item {
  239. flex: 1;
  240. width: 0;
  241. overflow: hidden;
  242. text-align: center;
  243. position: relative;
  244. }
  245. .name {
  246. font-size: 24rpx;
  247. margin-bottom: 8rpx;
  248. line-height: 36rpx;
  249. color: $uni-secondary-color;
  250. }
  251. .number {
  252. font-size: 18px;
  253. color: $uni-primary;
  254. }
  255. .line {
  256. height: 32rpx;
  257. width: 2rpx;
  258. background: $uni-border-1;
  259. }
  260. }
  261. }
  262. }
  263. .high-seas-container {
  264. .nav {
  265. height: 100%;
  266. background: #fff;
  267. width: 100%;
  268. display: flex;
  269. align-items: center;
  270. justify-content: center;
  271. .nav-city {
  272. height: 50rpx;
  273. max-width: 160rpx;
  274. min-width: 120rpx;
  275. border-radius: 50rpx;
  276. border: 1px solid $uni-primary;
  277. margin-left: 30rpx;
  278. box-sizing: border-box;
  279. display: flex;
  280. align-items: center;
  281. margin-bottom: 4rpx;
  282. .city-icon {
  283. margin-left: 10rpx;
  284. margin-top: 4rpx;
  285. .uni-icons {
  286. color: $uni-primary !important;
  287. }
  288. }
  289. .city-name {
  290. color: $uni-primary;
  291. font-size: 24rpx;
  292. overflow: hidden;
  293. white-space: nowrap;
  294. text-overflow: ellipsis;
  295. padding: 0 20rpx 0 6rpx;
  296. }
  297. }
  298. .nav-search {
  299. flex: 1;
  300. width: 0;
  301. border: 1px solid $uni-border-1;
  302. line-height: 1;
  303. padding-left: 30rpx;
  304. color: $uni-secondary-color;
  305. margin: 0 20rpx;
  306. box-sizing: border-box;
  307. margin-bottom: 4rpx;
  308. font-weight: 200;
  309. height: 64rpx;
  310. border-radius: 64rpx;
  311. line-height: 60rpx;
  312. }
  313. .wx-operation {
  314. margin-right: 8px;
  315. margin-bottom: 4rpx;
  316. }
  317. }
  318. .house-list {
  319. padding: 30rpx;
  320. }
  321. }
  322. </style>