home.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. <template>
  2. <view class="container">
  3. <!-- 搜索框区域 -->
  4. <view class="content">
  5. <uv-row custom-style="margin: 10px 0px" gutter="10">
  6. <picker @change="bindPickerChange" range-key="name" :value="placeIndex" :range="placeList">
  7. <view class="address">
  8. <view class="address_text">{{ placeList[placeIndex].name }}</view>
  9. <img src="../../static/index/bottom.png" />
  10. </view>
  11. </picker>
  12. <view class="search">
  13. <view class="add">
  14. <image class="img" src="../../static/index/search.png" mode="aspectFit"></image>
  15. </view>
  16. <input class="inp" type="text" v-model="keywords" placeholder="请输入关键字搜索" />
  17. <view class="btnSearch" @click="searchHandler">搜索</view>
  18. </view>
  19. </uv-row>
  20. </view>
  21. <scroll-view scroll-y class="main" @scroll="handleScroll" @scrolltolower="handleRefresh">
  22. <!-- 添加一层view解决 css属性 sticky 不生效问题 -->
  23. <view>
  24. <!-- 图标区域 -->
  25. <view class="icons">
  26. <view class="icon_item" @click="handleTest">
  27. <view class="item_top color">
  28. <img src="../../static/index/icon.png" />
  29. </view>
  30. <view class="item_bottom">推文</view>
  31. </view>
  32. <view class="icon_item" @click="handleTest">
  33. <view class="item_top color2">
  34. <img class="img2" src="../../static/index/icon2.png" />
  35. </view>
  36. <view class="item_bottom">周边</view>
  37. </view>
  38. <view class="icon_item" @click="handleGoSetMeal">
  39. <view class="item_top color3">
  40. <img class="img3" src="../../static/index/icon3.png" />
  41. </view>
  42. <view class="item_bottom">套餐</view>
  43. </view>
  44. <view class="icon_item" @click="handleTest">
  45. <view class="item_top color4">
  46. <img src="../../static/index/icon4.png" />
  47. </view>
  48. <view class="item_bottom">招商</view>
  49. </view>
  50. <view class="icon_item" @click="handleTest">
  51. <view class="item_top color5">
  52. <img src="../../static/index/icon5.png" />
  53. </view>
  54. <view class="item_bottom">其他</view>
  55. </view>
  56. </view>
  57. <!-- 分段器区域 -->
  58. <view class="control" :class="{ sticky: isSticky }">
  59. <uni-segmented-control :current="current" :values="items" style-type="text" active-color="#096562" @clickItem="onClickItem" />
  60. </view>
  61. <!-- 民宿列表 -->
  62. <view class="box" v-if="hotelList.length">
  63. <!-- 列表区域 -->
  64. <view class="box_body">
  65. <!-- 每一个民宿区域 -->
  66. <view class="box_item" v-for="item in hotelList" :key="item.id" @click="goPageDetail(item)">
  67. <img mode="aspectFill" :src="item.coverImg" />
  68. <view class="item_name">{{ item.hotel_name }}</view>
  69. <view class="item_rate">
  70. <view class="rate_left">{{ item.scoreHotel || '5.0' }}</view>
  71. <!-- <view class="rate_right">超棒</view> -->
  72. </view>
  73. <view class="item_distance">距您直线{{ item.distance }}公里</view>
  74. <view class="item_info">
  75. <view class="info_count">剩{{ item.roomNumber }}间</view>
  76. <view class="info_price">
  77. ¥{{ item.min_price }}
  78. <text>起</text>
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. </view>
  84. <!-- 没有数据时展示的页面 -->
  85. <view class="noData" v-else>
  86. <img src="../../static/images/noData.png" />
  87. 暂无数据
  88. </view>
  89. </view>
  90. </scroll-view>
  91. <!-- 选择乡镇弹窗区域 -->
  92. <uni-popup ref="popup" :is-mask-click="false" type="center">
  93. <view class="popup_body">
  94. <view class="body_header">
  95. <img src="../../static/my/popup_title.png" />
  96. <view class="header_title">请选择乡镇</view>
  97. <img src="../../static/my/popup_title.png" />
  98. <view class="header_jump" @click="handleChooseTown()">跳过</view>
  99. </view>
  100. <view class="body_content">
  101. <view class="content_box" v-for="(item, index) in popList" :key="index" @click="handleChooseTown(item.name)">
  102. <img v-if="index === 0" src="https://chtech.ncjti.edu.cn/hotelReservation/image/1.png" mode="aspectFill" />
  103. <img v-if="index === 1" src="https://chtech.ncjti.edu.cn/hotelReservation/image/2.png" mode="aspectFill" />
  104. <img v-if="index === 2" src="https://chtech.ncjti.edu.cn/hotelReservation/image/3.png" mode="aspectFill" />
  105. <img v-if="index === 3" src="https://chtech.ncjti.edu.cn/hotelReservation/image/4.png" mode="aspectFill" />
  106. <img v-if="index === 4" src="https://chtech.ncjti.edu.cn/hotelReservation/image/5.png" mode="aspectFill" />
  107. <img v-if="index === 5" src="https://chtech.ncjti.edu.cn/hotelReservation/image/6.png" mode="aspectFill" />
  108. <img v-if="index === 6" src="https://chtech.ncjti.edu.cn/hotelReservation/image/7.png" mode="aspectFill" />
  109. <img v-if="index === 7" src="https://chtech.ncjti.edu.cn/hotelReservation/image/8.png" mode="aspectFill" />
  110. <img v-if="index === 8" src="https://chtech.ncjti.edu.cn/hotelReservation/image/9.png" mode="aspectFill" />
  111. <img v-if="index === 9" src="https://chtech.ncjti.edu.cn/hotelReservation/image/10.png" mode="aspectFill" />
  112. <img v-if="index === 10" src="https://chtech.ncjti.edu.cn/hotelReservation/image/11.png" mode="aspectFill" />
  113. <img v-if="index === 11" src="https://chtech.ncjti.edu.cn/hotelReservation/image/12.png" mode="aspectFill" />
  114. <view class="box_town">{{ item.name }}</view>
  115. <view class="box_count">剩{{ item.residueNumber }}间</view>
  116. </view>
  117. </view>
  118. </view>
  119. </uni-popup>
  120. </view>
  121. </template>
  122. <script>
  123. export default {
  124. data() {
  125. return {
  126. // 分段器数组
  127. items: ['白金级', '金宿级', '银宿级'],
  128. // 当前索引
  129. current: 0,
  130. // 地区数组
  131. placeList: [
  132. {
  133. name: '靖安县'
  134. }
  135. ],
  136. // 当前选择地区索引
  137. placeIndex: 0,
  138. // 搜索框绑定数据
  139. keywords: '',
  140. // 是否显示距离差
  141. showdDistance: false,
  142. // 用户定位经度
  143. myLng: 0,
  144. // 用户定位纬度
  145. myLat: 0,
  146. // 当前页
  147. page: 1,
  148. // 每页多少条
  149. rows: 6,
  150. // 总条数
  151. total: null,
  152. // 民宿列表数组
  153. hotelList: [],
  154. // 当前乡镇
  155. town: '',
  156. // 分段器是否吸顶
  157. isSticky: false,
  158. // 选择乡镇弹窗数据
  159. popList: []
  160. }
  161. },
  162. onLoad() {
  163. this.openPop()
  164. this.getResidueCount()
  165. },
  166. // 页面下拉刷新回调
  167. onPullDownRefresh() {
  168. setTimeout(() => {
  169. this.hotelList = []
  170. this.page = 1
  171. this.getLocation()
  172. uni.stopPullDownRefresh()
  173. }, 2000)
  174. },
  175. methods: {
  176. // 弹窗点击选择乡镇地址回调
  177. handleChooseTown(name) {
  178. if (!name) {
  179. this.town = '靖安县'
  180. } else {
  181. this.town = name
  182. }
  183. uni.setNavigationBarTitle({
  184. title: this.town
  185. })
  186. this.$refs.popup.close()
  187. uni.showTabBar()
  188. this.getTownList()
  189. this.getLocation()
  190. },
  191. // 打开选择乡镇弹窗回调
  192. openPop() {
  193. this.$refs.popup.open()
  194. uni.hideTabBar()
  195. },
  196. handleGoSetMeal() {
  197. uni.navigateTo({
  198. url: '/pages/setMeal/setMeal'
  199. })
  200. },
  201. // 页面上拉到底部回调
  202. handleRefresh() {
  203. if (this.hotelList.length < this.total) {
  204. this.page++
  205. this.getHotelList()
  206. } else {
  207. uni.showToast({
  208. title: '没有更多数据了',
  209. icon: 'none'
  210. })
  211. }
  212. },
  213. // 滚动条滚动回调
  214. handleScroll(e) {
  215. if (e.detail.scrollTop > 90) {
  216. this.isSticky = true
  217. } else {
  218. this.isSticky = false
  219. }
  220. },
  221. // 获取乡镇剩余房间数
  222. async getResidueCount() {
  223. const res = await this.$myRequest({
  224. url: '/mhotel/ahpgetResidueCount.action'
  225. })
  226. // console.log(res)
  227. if (res.code === 200) {
  228. let residueNumber = 0
  229. res.data.forEach((ele) => {
  230. residueNumber += ele.residueNumber
  231. })
  232. res.data.unshift({
  233. name: '靖安县',
  234. residueNumber
  235. })
  236. this.popList = res.data
  237. }
  238. },
  239. // 获取乡镇集合
  240. async getTownList() {
  241. const res = await this.$myRequest({
  242. url: '/mhotel/hotelqueryList.action',
  243. method: 'get',
  244. data: {
  245. code: 10
  246. }
  247. })
  248. // console.log(res)
  249. if (res.code === 200) {
  250. this.placeList = [...this.placeList, ...res.data]
  251. let temindex
  252. this.placeList.forEach((ele, index) => {
  253. if (ele.name === this.town) {
  254. temindex = index
  255. }
  256. })
  257. this.placeIndex = temindex
  258. }
  259. },
  260. // 获取用户当前位置
  261. getLocation() {
  262. uni.getSetting({
  263. success: (res) => {
  264. if (!res.authSetting['scope.userLocation']) {
  265. uni.authorize({
  266. scope: 'scope.userLocation',
  267. success: (res) => {
  268. // 授权成功
  269. uni.getLocation({
  270. type: 'gcj02',
  271. success: (res) => {
  272. this.myLat = res.latitude
  273. this.myLng = res.longitude
  274. this.showdDistance = true
  275. this.getHotelList()
  276. }
  277. })
  278. },
  279. fail: () => {
  280. uni.showModal({
  281. content: '获取定位权限失败将会影响使用部分功能,是否去设置打开?',
  282. confirmText: '确认',
  283. cancelText: '取消',
  284. success: (res) => {
  285. if (res.confirm) {
  286. uni.openSetting({
  287. success: (res) => {
  288. console.log(res)
  289. this.getLocation()
  290. }
  291. })
  292. } else {
  293. this.showdDistance = false
  294. this.getHotelList()
  295. uni.showToast({
  296. title: '获取定位权限失败',
  297. icon: 'none'
  298. })
  299. }
  300. }
  301. })
  302. }
  303. })
  304. } else {
  305. uni.getLocation({
  306. type: 'gcj02',
  307. success: (res) => {
  308. this.myLat = res.latitude
  309. this.myLng = res.longitude
  310. this.showdDistance = true
  311. this.getHotelList()
  312. }
  313. })
  314. }
  315. }
  316. })
  317. },
  318. // 获取民宿列表
  319. async getHotelList() {
  320. let type
  321. if (this.current === 0) {
  322. type = 3
  323. } else if (this.current === 1) {
  324. type = 2
  325. } else if (this.current === 2) {
  326. type = 1
  327. }
  328. const res = await this.$myRequest({
  329. url: '/mhotel/ahphomePage.action',
  330. data: {
  331. queryValue: this.keywords,
  332. page: this.page,
  333. rows: this.rows,
  334. hotel_township: this.placeList[this.placeIndex].id || '',
  335. userId: uni.getStorageSync('userInfo') ? uni.getStorageSync('userInfo').id : '',
  336. type
  337. }
  338. })
  339. // console.log(res)
  340. if (res.code === 200) {
  341. this.hotelList = [...this.hotelList, ...res.data.pageList]
  342. this.total = res.data.total
  343. // 如果定位成功则获取和民宿之间的距离
  344. if (this.showdDistance && this.hotelList.length) {
  345. this.hotelList.forEach((ele) => {
  346. let lat = ele.hpositionWens.split(',')[0]
  347. let lng = ele.hpositionWens.split(',')[1]
  348. ele.distance = this.calculateDistance(lat, lng)
  349. })
  350. }
  351. }
  352. },
  353. // 点击每一个民宿卡片回调
  354. goPageDetail(item) {
  355. uni.navigateTo({
  356. url: `/pages/detail/detail?id=${item.id}&distance=${item.distance}`
  357. })
  358. },
  359. // 选择地区时的回调
  360. bindPickerChange(e) {
  361. this.placeIndex = e.detail.value
  362. uni.setNavigationBarTitle({
  363. title: this.placeList[this.placeIndex].name
  364. })
  365. this.hotelList = []
  366. this.page = 1
  367. this.getHotelList()
  368. },
  369. // 搜索按钮点击回调
  370. searchHandler() {
  371. this.hotelList = []
  372. this.page = 1
  373. this.getHotelList()
  374. },
  375. onClickItem(e) {
  376. if (this.current !== e.currentIndex) {
  377. this.current = e.currentIndex
  378. this.hotelList = []
  379. this.page = 1
  380. this.getHotelList()
  381. }
  382. },
  383. handleTest() {
  384. uni.showToast({
  385. title: '功能开发中',
  386. icon: 'none',
  387. mask: true
  388. })
  389. },
  390. // 计算两个点之间的距离
  391. calculateDistance(lat, lng) {
  392. let centerLat = lat
  393. let centerLng = lng
  394. let red1 = (this.myLat * Math.PI) / 180.0
  395. let red2 = (centerLat * Math.PI) / 180.0
  396. let a = red1 - red2
  397. let b = (this.myLng * Math.PI) / 180.0 - (centerLng * Math.PI) / 180.0
  398. let R = 6378137
  399. let distance = R * 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(red1) * Math.cos(red2) * Math.pow(Math.sin(b / 2), 2)))
  400. let res = (distance / 1000).toFixed(2) * 1
  401. return res
  402. }
  403. }
  404. }
  405. </script>
  406. <style lang="scss" scoped>
  407. .container {
  408. display: flex;
  409. flex-direction: column;
  410. width: 750rpx;
  411. height: 100vh;
  412. padding: 0 30rpx;
  413. box-sizing: border-box;
  414. overflow: hidden;
  415. background-color: #f7f7f7;
  416. .content {
  417. position: sticky;
  418. background-color: #f7f7f7;
  419. .address {
  420. display: flex;
  421. width: 152rpx;
  422. font-size: 28rpx;
  423. .address_text {
  424. width: 104rpx;
  425. text-align: center;
  426. overflow: hidden;
  427. white-space: nowrap;
  428. text-overflow: ellipsis;
  429. }
  430. img {
  431. width: 48rpx;
  432. height: 48rpx;
  433. }
  434. }
  435. .search {
  436. display: flex;
  437. justify-content: space-between;
  438. align-items: center;
  439. width: 538rpx;
  440. height: 80rpx;
  441. opacity: 1;
  442. border-radius: 70px;
  443. background-color: #fff;
  444. .add {
  445. display: flex;
  446. justify-content: center;
  447. align-items: center;
  448. margin-left: 10rpx;
  449. width: 60rpx;
  450. font-size: 50rpx;
  451. height: 60rpx;
  452. line-height: 60rpx;
  453. color: rgba(30, 125, 251, 1);
  454. .img {
  455. width: 30rpx;
  456. height: 30rpx;
  457. }
  458. }
  459. .inp {
  460. height: 60rpx;
  461. line-height: 60rpx;
  462. flex-grow: 1;
  463. font-size: 28rpx;
  464. }
  465. .btnSearch {
  466. width: 100rpx;
  467. text-align: center;
  468. margin-right: 10rpx;
  469. height: 60rpx;
  470. line-height: 60rpx;
  471. opacity: 1;
  472. font-size: 28rpx;
  473. font-weight: 400;
  474. height: 2rem;
  475. color: #096562;
  476. }
  477. }
  478. }
  479. .main {
  480. margin-top: 10rpx;
  481. height: calc(100vh - 120rpx);
  482. .icons {
  483. display: flex;
  484. justify-content: space-around;
  485. align-items: center;
  486. height: 158rpx;
  487. border-radius: 12rpx;
  488. background-color: #fff;
  489. .icon_item {
  490. display: flex;
  491. flex-direction: column;
  492. align-items: center;
  493. width: 20%;
  494. .item_top {
  495. display: flex;
  496. align-items: center;
  497. justify-content: center;
  498. width: 60rpx;
  499. height: 60rpx;
  500. border-radius: 50%;
  501. img {
  502. width: 28rpx;
  503. height: 27rpx;
  504. }
  505. .img2 {
  506. width: 40rpx;
  507. height: 25.5rpx;
  508. }
  509. .img3 {
  510. width: 31rpx;
  511. height: 21rpx;
  512. }
  513. }
  514. .color {
  515. background-color: #d8e8e8;
  516. }
  517. .color2 {
  518. background-color: #c2f2d5;
  519. }
  520. .color3 {
  521. background-color: #f7d4ba;
  522. }
  523. .color4 {
  524. background-color: #fae1e2;
  525. }
  526. .color5 {
  527. background-color: #d0e0f2;
  528. }
  529. .item_bottom {
  530. margin-top: 6rpx;
  531. font-size: 28rpx;
  532. }
  533. }
  534. }
  535. .control {
  536. margin: 20rpx 0;
  537. height: 90rpx;
  538. border-radius: 8rpx;
  539. background-color: #fff;
  540. }
  541. .sticky {
  542. position: sticky;
  543. top: 0;
  544. border-radius: 0;
  545. }
  546. .box {
  547. .box_body {
  548. display: flex;
  549. flex-wrap: wrap;
  550. justify-content: space-between;
  551. .box_item {
  552. margin-bottom: 20rpx;
  553. width: 335rpx;
  554. height: 446rpx;
  555. border-radius: 10rpx;
  556. background-color: #fff;
  557. img {
  558. width: 335rpx;
  559. height: 223rpx;
  560. border-radius: 10rpx 10rpx 0 0;
  561. }
  562. .item_name {
  563. margin-left: 22rpx;
  564. margin-top: 10rpx;
  565. line-height: 55rpx;
  566. font-size: 28rpx;
  567. font-weight: bold;
  568. overflow: hidden;
  569. text-overflow: ellipsis;
  570. white-space: nowrap;
  571. }
  572. .item_rate {
  573. display: flex;
  574. align-items: center;
  575. margin-left: 22rpx;
  576. font-size: 24rpx;
  577. .rate_left {
  578. padding: 0 12rpx;
  579. color: #fff;
  580. // border-radius: 32rpx 0 0 32rpx;
  581. border-radius: 32rpx;
  582. background-color: #096562;
  583. }
  584. .rate_right {
  585. padding: 0 16rpx 0 7rpx;
  586. color: #096562;
  587. border-radius: 0 32rpx 32rpx 0;
  588. background-color: #dff2f2;
  589. }
  590. }
  591. .item_distance {
  592. margin-top: 10rpx;
  593. margin-left: 22rpx;
  594. color: #a6a6a6;
  595. font-size: 24rpx;
  596. }
  597. .item_info {
  598. box-sizing: border-box;
  599. padding: 0 30rpx 0 25rpx;
  600. margin-top: 16rpx;
  601. display: flex;
  602. justify-content: space-between;
  603. color: #ff5733;
  604. .info_count {
  605. font-size: 24rpx;
  606. }
  607. .info_price {
  608. margin-top: -5rpx;
  609. font-size: 36rpx;
  610. font-weight: bold;
  611. text {
  612. color: #a6a6a6;
  613. font-size: 24rpx;
  614. font-weight: 400;
  615. }
  616. }
  617. }
  618. }
  619. }
  620. }
  621. .noData {
  622. display: flex;
  623. flex-direction: column;
  624. justify-content: center;
  625. align-items: center;
  626. img {
  627. margin-top: 150rpx;
  628. width: 400rpx;
  629. height: 400rpx;
  630. }
  631. }
  632. }
  633. .popup_body {
  634. width: 618rpx;
  635. height: 687rpx;
  636. border-radius: 21rpx;
  637. background-color: #fff;
  638. .body_header {
  639. display: flex;
  640. justify-content: center;
  641. align-items: center;
  642. position: relative;
  643. height: 113rpx;
  644. border-bottom: 1rpx solid #e6e6e6;
  645. img {
  646. width: 16rpx;
  647. height: 16rpx;
  648. }
  649. .header_title {
  650. margin: 0 10rpx;
  651. font-size: 34rpx;
  652. font-weight: bold;
  653. color: #0f194d;
  654. }
  655. .header_jump {
  656. position: absolute;
  657. top: 38rpx;
  658. right: 30rpx;
  659. font-size: 28rpx;
  660. color: #a6a6a6;
  661. }
  662. }
  663. .body_content {
  664. display: grid;
  665. grid-template-columns: repeat(auto-fill, 160rpx);
  666. gap: 28rpx;
  667. box-sizing: border-box;
  668. padding: 26rpx 40rpx 50rpx;
  669. .content_box {
  670. position: relative;
  671. width: 160rpx;
  672. height: 105rpx;
  673. color: #fff;
  674. border-radius: 10rpx;
  675. img {
  676. width: 160rpx;
  677. height: 105rpx;
  678. border-radius: 10rpx;
  679. }
  680. .box_town {
  681. position: absolute;
  682. top: 17rpx;
  683. left: 0;
  684. right: 0;
  685. text-align: center;
  686. font-size: 28rpx;
  687. font-weight: bold;
  688. }
  689. .box_count {
  690. position: absolute;
  691. top: 57rpx;
  692. left: 0;
  693. right: 0;
  694. text-align: center;
  695. font-size: 18rpx;
  696. }
  697. }
  698. }
  699. }
  700. }
  701. </style>