home.vue 17 KB

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