租房小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

495 lines
16 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. <template>
  2. <view class="Locations">
  3. <map style="width: 100%;height: 60vh" :layer-style='5' :show-location='true' :latitude="position.latitude"
  4. :longitude="position.longitude" :markers="spotGuideMarkers" :scale="scale" @markertap="markertap" id="mapId"
  5. @callouttap="callouttap">
  6. </map>
  7. <!-- <view class="tabs">
  8. <view class=""
  9. v-for="(item, index) in tabs"
  10. :key="index"
  11. @click="setSpotGuideIndex(index)"
  12. :class="{act : spotGuideIndex == index}">
  13. {{ item }}
  14. </view>
  15. </view> -->
  16. <uv-tabs :list="houseTypeList" :activeStyle="{ color: '#1EC77A', fontWeight: 600 }" lineColor="#1EC77A"
  17. lineHeight="8rpx" lineWidth="50rpx" keyName="title" :current="currentHouseType"
  18. @click="onClickHouseType"></uv-tabs>
  19. <view class="Locations-list">
  20. <!-- 房源列表 -->
  21. <view v-if="list.length > 0">
  22. <view @click="onDetail(item)" class="se-my-10 se-mx-20 se-px-20 se-py-20 se-br-20 se-bgc-white se-flex"
  23. v-for="(item, index) in list" :key="index">
  24. <view class="se-pos se-w-260 se-h-180">
  25. <image v-if="item.iconImage" class="se-a-80 se-pos-lt" :src="item.iconImage" mode=""></image>
  26. <image class="se-w-260 se-h-180 se-br-10" :src="item.images[0]" mode=""></image>
  27. </view>
  28. <view class="se-pl-10 se-w-p-100">
  29. <view class="se-c-black se-fs-28">
  30. {{ item.title }}
  31. </view>
  32. <view class="se-flex se-flex-h-sb se-flex-ai-c se-fs-24 se-mt-10 se-c-66">
  33. <text>{{ item.homeType }}</text>
  34. <text>{{ item.timeGo }}</text>
  35. </view>
  36. <view class="se-flex se-flex-h-sb se-flex-ai-c se-mt-10">
  37. <template v-if="item.iconTitles.length > 0">
  38. <view class="se-flex">
  39. <view
  40. class="se-display-ib se-c-white se-bgc-orange se-fs-22 se-br-8 se-px-10 se-py-5 se-mr-10"
  41. v-for="(items, indexs) in item.iconTitles" :key="indexs">
  42. {{ items }}
  43. </view>
  44. </view>
  45. </template>
  46. <template v-else>
  47. <view></view>
  48. </template>
  49. <view class="se-c-66 se-flex se-flex-ai-c">
  50. <uv-icon name="eye"></uv-icon>
  51. <text class="se-ml-5 se-fs-18">{{ item.num }}</text>
  52. </view>
  53. </view>
  54. <view class="se-flex se-flex-h-sb se-flex-ai-c se-mt-10">
  55. <text class="se-c-red se-fs-24 se-fw-6 se-toe-1">{{ item.price }}/{{ item.unit }}</text>
  56. <text class="se-c-66 se-fs-22 se-toe-1">{{ item.address }}</text>
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. <uv-empty v-else text="没有哦" textSize="30rpx" iconSize="200rpx" icon="list"></uv-empty>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. import { housePageList, houseType } from "@/common/api.js"
  67. import { getInfo } from "@/common/api.js"
  68. export default {
  69. data() {
  70. return {
  71. scale: 12, //缩放级别
  72. show: true,
  73. tabs: [],
  74. spotGuideIndex: 0, // 当前选中的菜单索引
  75. position: {
  76. latitude: 23.106574,
  77. longitude: 113.324587
  78. },
  79. areaId: null, // 当前选中的区域ID
  80. // 房源列表相关数据
  81. list: [],
  82. classId: null,
  83. pageNo: 1,
  84. pageSize: 10,
  85. houseTypeList: [], // 房源类型列表
  86. currentHouseType: 0 ,// 当前选中的房源类型索引
  87. }
  88. },
  89. computed: {
  90. spotGuideMarkers() {
  91. let markers = [];
  92. this.list.forEach((item, index) => {
  93. if (item.latitude && item.longitude) {
  94. markers.push({
  95. id: index,
  96. latitude: item.latitude,
  97. longitude: item.longitude,
  98. iconPath: '/static/image/tourGuide/marker.png',
  99. width: 30,
  100. height: 30,
  101. callout: {
  102. content: item.spotName,
  103. color: '#000000',
  104. fontSize: 14,
  105. borderRadius: 5,
  106. bgColor: '#ffffff',
  107. padding: 5,
  108. display: 'BYCLICK'
  109. }
  110. });
  111. }
  112. });
  113. return markers;
  114. },
  115. },
  116. mounted() {
  117. this.getCurrentLocation()
  118. this.onHouseType() // 获取房源类型
  119. this.onHousePageList() // 加载房源列表
  120. this.getUserInfo() // 加载房源列表
  121. },
  122. onPullDownRefresh() {
  123. if(!uni.getStorageSync('token') || this.userInfo.isPay != 1){
  124. return
  125. }
  126. let that = this
  127. that.pageNo = 1
  128. that.list = []
  129. that.onHousePageList()
  130. },
  131. onReachBottom() {
  132. if(!uni.getStorageSync('token') || this.userInfo.isPay != 1){
  133. return
  134. }
  135. let that = this
  136. that.pageNo = that.pageNo + 1
  137. that.onHousePageList()
  138. },
  139. methods: {
  140. getUserInfo(state){
  141. this.$store.commit('getUserInfo', userInfo => {
  142. if(userInfo.isPay != 1){
  143. uni.showModal({
  144. title: '开通会员可查看租房地图',
  145. success : res => {
  146. if(res.confirm){
  147. this.getUserInfo()
  148. }
  149. }
  150. })
  151. }
  152. })
  153. },
  154. // 获取当前位置
  155. getCurrentLocation() {
  156. const that = this;
  157. uni.getLocation({
  158. type: 'wgs84',
  159. success: function (res) {
  160. console.log('当前位置的经度:' + res.longitude);
  161. console.log('当前位置的纬度:' + res.latitude);
  162. that.position.latitude = res.latitude;
  163. that.position.longitude = res.longitude;
  164. // 更新地图位置
  165. that.onHousePageList();
  166. },
  167. fail: function (err) {
  168. console.error('获取位置失败:', err);
  169. uni.showToast({
  170. title: '获取位置失败',
  171. icon: 'none'
  172. });
  173. }
  174. });
  175. },
  176. //点击tab栏
  177. clickTabs({ index, name }) {
  178. this.currentArea = index
  179. if (this.areaList[index]) {
  180. this.areaId = this.areaList[index].id
  181. }
  182. this.onHousePageList()
  183. this.$nextTick(() => {
  184. this.selectArea()
  185. })
  186. },
  187. setSpotGuideIndex(index) {
  188. this.spotGuideIndex = index
  189. this.onHousePageList()
  190. },
  191. textToSpeech() {
  192. console.log('textToSpeech');
  193. let self = this
  194. // self.context.src = this.$config.baseUrl + '/info/textToAudio?text=' + "你好"
  195. // self.context.play()
  196. // return
  197. plugin.textToSpeech({
  198. lang: "zh_CN",
  199. tts: true,
  200. content: "景德镇市陶阳里御窑景区位于景德镇的城市中心地带,北起瓷都大桥、昌江大道,南至昌江大桥、西至沿江西路,东至莲社路、胜利路。 自宋以来,景德镇先民“沿河建窑,因窑成市”,渐呈“码头—民窑—老街—里弄—御窑”聚落的历史空间和瓷业肌理,形成了世界建筑史上绝无仅有的老城格局,成就了中国“东方瓷国”的盛誉,陶瓷成为了中国走向世界,世界认识中国的文化符号。这里是景德镇历史上制瓷业的中心、原点和高峰,是“一带一路”海上陶瓷之路的零公里起点,是研究皇家御窑制瓷历史文化和景德镇陶瓷技艺,讲好景德镇故事,传播中国声音的“窗口”和“名片”。",
  201. success: function (res) {
  202. self.context.src = res.filename;
  203. self.context.play()
  204. },
  205. fail: function (res) {
  206. console.log("fail tts", res)
  207. }
  208. })
  209. },
  210. //地图点击事件
  211. markertap(e) {
  212. console.log("markertap===你点击了标记点===", e)
  213. let event = this.list[e.markerId]
  214. this.onDetail(event)
  215. // uni.openLocation({
  216. // latitude: spot.latitude,
  217. // longitude: spot.longitude,
  218. // })
  219. // BYCLICK隐藏
  220. // ALWAYS显示
  221. // this.$store.commit('setDisplay',
  222. // this.spotGuideMarkers[e.markerId].id)
  223. // this.$forceUpdate()
  224. // this.spotGuideMarkers.forEach((n, i) => {
  225. // if(i == e.markerId){
  226. // // 显示气泡
  227. // n.callout.display = 'ALWAYS'
  228. // }else{
  229. // // 隐藏气泡
  230. // n.callout.display = 'BYCLICK'
  231. // }
  232. // })
  233. },
  234. openLocation(n) {
  235. uni.openLocation({
  236. latitude: n.spotLatitude,
  237. longitude: n.spotLongitude,
  238. })
  239. },
  240. //地图点击事件
  241. callouttap(e) {
  242. console.log('callouttap地图点击事件', e)
  243. let spot = this.spotGuideMarkers[e.markerId]
  244. uni.openLocation({
  245. latitude: spot.latitude,
  246. longitude: spot.longitude,
  247. })
  248. },
  249. toUrl(item) {
  250. console.log(item);
  251. if (item.categoryId == 0) {
  252. this.$utils.navigateTo(`/pages_order/service/articleDetail?id=${item.id}&type=Inheritance`)
  253. }
  254. },
  255. // 点击按钮将地图中心移动到指定定位点
  256. moveTolocation(latitude, longitude) {
  257. let mapObjs = uni.createMapContext('mapId', this)
  258. mapObjs.moveToLocation(
  259. {
  260. latitude,
  261. longitude
  262. },
  263. {
  264. complete: res => {
  265. console.log('移动完成:', res)
  266. }
  267. })
  268. // this.onRegionChange('',true)
  269. },
  270. // 点击景区,选择最近的一个景点
  271. selectArea() {
  272. let item = this.spotGuide[0]
  273. if (item && item.spotLatitude && item.spotLongitude) {
  274. this.moveTolocation(item.spotLatitude, item.spotLongitude)
  275. }
  276. },
  277. clickAreaDetail(id) {
  278. uni.navigateTo({
  279. url: '/pages_order/service/areaDetail?id=' + id
  280. })
  281. },
  282. // 获取房源类型列表
  283. onHouseType() {
  284. houseType({}).then(response => {
  285. console.info('houseType', response)
  286. this.houseTypeList = response.result
  287. }).catch(error => {
  288. })
  289. },
  290. // 点击房源类型
  291. onClickHouseType(event) {
  292. console.info(event)
  293. let that = this
  294. that.pageNo = 1
  295. that.classId = event.id
  296. that.currentHouseType = event.index
  297. that.list = []
  298. that.onHousePageList()
  299. },
  300. // 获取房源列表
  301. onHousePageList() {
  302. if(!uni.getStorageSync('token') || this.userInfo.isPay != 1){
  303. return
  304. }
  305. let that = this
  306. let params = {
  307. classId: that.classId,
  308. pageNo: that.pageNo,
  309. pageSize: that.pageSize
  310. }
  311. // 如果有位置信息,添加到参数中
  312. if (that.position.latitude && that.position.longitude) {
  313. params.latitude = that.position.latitude
  314. params.longitude = that.position.longitude
  315. }
  316. housePageList(params).then((response) => {
  317. console.info("房源列表数据", response.result.records)
  318. response.result.records.forEach((items, indexs) => {
  319. if (items.image) {
  320. items.images = items.image.split(',')
  321. } else {
  322. items.images = []
  323. }
  324. if (items.homeImage) {
  325. items.homeImages = items.homeImage.split(',')
  326. } else {
  327. items.homeImages = []
  328. }
  329. if (items.iconTitle) {
  330. items.iconTitles = items.iconTitle.split(',')
  331. } else {
  332. items.iconTitles = []
  333. }
  334. })
  335. that.list = that.list.concat(response.result.records)
  336. }).catch((error) => {
  337. })
  338. },
  339. // 点击房源详情
  340. onDetail(event) {
  341. uni.navigateTo({
  342. url: "/pages_subpack/detail/index?id=" + event.id
  343. })
  344. },
  345. }
  346. }
  347. </script>
  348. <style scoped lang="scss">
  349. .Locations {
  350. .tabs {
  351. display: flex;
  352. &>view {
  353. flex: 1;
  354. margin: 20rpx 10rpx;
  355. padding: 20rpx 10rpx;
  356. background-color: #e8f7f0;
  357. color: #1EC77A;
  358. border-radius: 40rpx;
  359. font-size: 24rpx;
  360. text-align: center;
  361. }
  362. .act {
  363. background-color: #1EC77A;
  364. color: #fff;
  365. }
  366. }
  367. .Locations-list {
  368. .main {
  369. display: flex;
  370. margin: 20rpx;
  371. .main-image {
  372. width: 150rpx;
  373. height: 150rpx;
  374. border-radius: 20rpx;
  375. }
  376. .info {
  377. margin-left: 20rpx;
  378. .title {
  379. font-size: 30rpx;
  380. font-weight: 900;
  381. }
  382. .tips {
  383. font-size: 24rpx;
  384. color: #999999;
  385. margin-top: 10rpx;
  386. }
  387. }
  388. .controls {
  389. margin-left: auto;
  390. display: flex;
  391. flex-direction: column;
  392. justify-content: center;
  393. align-items: center;
  394. .f {
  395. image {
  396. width: 50rpx;
  397. height: 50rpx;
  398. }
  399. }
  400. }
  401. .btn {
  402. padding: 10rpx;
  403. font-size: 22rpx;
  404. color: #1EC77A;
  405. border: 1rpx solid #1EC77A;
  406. background-color: #e8f7f0;
  407. display: flex;
  408. justify-content: center;
  409. align-items: center;
  410. margin-top: 10rpx;
  411. border-radius: 15rpx;
  412. image {
  413. width: 25rpx;
  414. height: 25rpx;
  415. }
  416. text {
  417. margin: 0 10rpx;
  418. }
  419. }
  420. }
  421. .list {
  422. padding-left: 40rpx;
  423. .main {
  424. align-items: center;
  425. .main-image {
  426. width: 140rpx;
  427. height: 140rpx;
  428. }
  429. .controls {
  430. flex-direction: row;
  431. .f {
  432. margin: 30rpx;
  433. image {
  434. width: 40rpx;
  435. height: 40rpx;
  436. }
  437. }
  438. }
  439. }
  440. }
  441. }
  442. }
  443. </style>