home.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  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="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. </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(options) {
  163. console.log(options)
  164. this.keywords = options.keywords
  165. if (!options.level || options.level === '白金') {
  166. this.current = 0
  167. } else if (options.level === '金宿') {
  168. this.current = 1
  169. } else if (options.level === '银宿') {
  170. this.current = 2
  171. }
  172. uni.setNavigationBarTitle({
  173. title: options.town || '靖安县'
  174. })
  175. this.getTownList(options.town)
  176. // this.openPop()
  177. // this.getResidueCount()
  178. },
  179. onReachBottom() {
  180. if (this.hotelList.length < this.total) {
  181. this.page++
  182. this.getHotelList()
  183. } else {
  184. uni.showToast({
  185. title: '没有更多数据了',
  186. icon: 'none'
  187. })
  188. }
  189. },
  190. // 页面下拉刷新回调
  191. onPullDownRefresh() {
  192. setTimeout(() => {
  193. this.hotelList = []
  194. this.page = 1
  195. this.getLocation()
  196. uni.stopPullDownRefresh()
  197. }, 2000)
  198. },
  199. methods: {
  200. // 弹窗点击选择乡镇地址回调
  201. handleChooseTown(name) {
  202. if (!name) {
  203. this.town = '靖安县'
  204. } else {
  205. this.town = name
  206. }
  207. uni.setNavigationBarTitle({
  208. title: this.town
  209. })
  210. this.$refs.popup.close()
  211. uni.showTabBar()
  212. this.getTownList()
  213. this.getLocation()
  214. },
  215. // 打开选择乡镇弹窗回调
  216. openPop() {
  217. this.$refs.popup.open()
  218. uni.hideTabBar()
  219. },
  220. handleGoSetMeal() {
  221. uni.navigateTo({
  222. url: '/pages/setMeal/setMeal'
  223. })
  224. },
  225. // 页面上拉到底部回调
  226. handleRefresh() {
  227. if (this.hotelList.length < this.total) {
  228. this.page++
  229. this.getHotelList()
  230. } else {
  231. uni.showToast({
  232. title: '没有更多数据了',
  233. icon: 'none'
  234. })
  235. }
  236. },
  237. // 滚动条滚动回调
  238. handleScroll(e) {
  239. if (e.detail.scrollTop > 90) {
  240. this.isSticky = true
  241. } else {
  242. this.isSticky = false
  243. }
  244. },
  245. // 获取乡镇剩余房间数
  246. async getResidueCount() {
  247. const res = await this.$myRequest({
  248. url: '/mhotel/ahpgetResidueCount.action'
  249. })
  250. // console.log(res)
  251. if (res.code === 200) {
  252. let residueNumber = 0
  253. res.data.forEach((ele) => {
  254. residueNumber += ele.residueNumber
  255. })
  256. res.data.unshift({
  257. name: '靖安县',
  258. residueNumber
  259. })
  260. this.popList = res.data
  261. }
  262. },
  263. // 获取乡镇集合
  264. async getTownList(town) {
  265. const res = await this.$myRequest({
  266. url: '/mhotel/hotelqueryList.action',
  267. method: 'get',
  268. data: {
  269. code: 10
  270. }
  271. })
  272. // console.log(res)
  273. if (res.code === 200) {
  274. this.placeList = [...this.placeList, ...res.data]
  275. let temindex
  276. this.placeList.forEach((ele, index) => {
  277. if (ele.name === town) {
  278. temindex = index
  279. }
  280. })
  281. this.placeIndex = temindex || 0
  282. this.getLocation()
  283. console.log(this.placeIndex)
  284. }
  285. },
  286. // 获取用户当前位置
  287. getLocation() {
  288. uni.getSetting({
  289. success: (res) => {
  290. if (!res.authSetting['scope.userLocation']) {
  291. uni.authorize({
  292. scope: 'scope.userLocation',
  293. success: (res) => {
  294. // 授权成功
  295. uni.getLocation({
  296. type: 'gcj02',
  297. success: (res) => {
  298. this.myLat = res.latitude
  299. this.myLng = res.longitude
  300. this.showdDistance = true
  301. this.getHotelList()
  302. }
  303. })
  304. },
  305. fail: () => {
  306. uni.showModal({
  307. content: '获取定位权限失败将会影响使用部分功能,是否去设置打开?',
  308. confirmText: '确认',
  309. cancelText: '取消',
  310. success: (res) => {
  311. if (res.confirm) {
  312. uni.openSetting({
  313. success: (res) => {
  314. console.log(res)
  315. this.getLocation()
  316. }
  317. })
  318. } else {
  319. this.showdDistance = false
  320. this.getHotelList()
  321. uni.showToast({
  322. title: '获取定位权限失败',
  323. icon: 'none'
  324. })
  325. }
  326. }
  327. })
  328. }
  329. })
  330. } else {
  331. uni.getLocation({
  332. type: 'gcj02',
  333. success: (res) => {
  334. this.myLat = res.latitude
  335. this.myLng = res.longitude
  336. this.showdDistance = true
  337. this.getHotelList()
  338. }
  339. })
  340. }
  341. }
  342. })
  343. },
  344. // 获取民宿列表
  345. async getHotelList() {
  346. let type
  347. if (this.current === 0) {
  348. type = 3
  349. } else if (this.current === 1) {
  350. type = 2
  351. } else if (this.current === 2) {
  352. type = 1
  353. }
  354. const res = await this.$myRequest({
  355. url: '/mhotel/ahphomePage.action',
  356. data: {
  357. queryValue: this.keywords,
  358. page: this.page,
  359. rows: this.rows,
  360. hotel_township: this.placeList[this.placeIndex].id || '',
  361. userId: uni.getStorageSync('userInfo') ? uni.getStorageSync('userInfo').id : '',
  362. type
  363. }
  364. })
  365. // console.log(res)
  366. if (res.code === 200) {
  367. this.hotelList = [...this.hotelList, ...res.data.pageList]
  368. this.total = res.data.total
  369. // 如果定位成功则获取和民宿之间的距离
  370. if (this.showdDistance && this.hotelList.length) {
  371. this.hotelList.forEach((ele) => {
  372. let lat = ele.hpositionWens.split(',')[0]
  373. let lng = ele.hpositionWens.split(',')[1]
  374. ele.distance = this.calculateDistance(lat, lng)
  375. })
  376. }
  377. }
  378. },
  379. // 点击每一个民宿卡片回调
  380. goPageDetail(item) {
  381. uni.navigateTo({
  382. url: `/pages/detail/detail?id=${item.id}&distance=${item.distance}`
  383. })
  384. },
  385. // 选择地区时的回调
  386. bindPickerChange(e) {
  387. this.placeIndex = e.detail.value
  388. uni.setNavigationBarTitle({
  389. title: this.placeList[this.placeIndex].name
  390. })
  391. this.hotelList = []
  392. this.page = 1
  393. this.getHotelList()
  394. },
  395. // 搜索按钮点击回调
  396. searchHandler() {
  397. this.hotelList = []
  398. this.page = 1
  399. this.getHotelList()
  400. },
  401. onClickItem(e) {
  402. if (this.current !== e.currentIndex) {
  403. this.current = e.currentIndex
  404. this.hotelList = []
  405. this.page = 1
  406. this.getHotelList()
  407. }
  408. },
  409. handleTest() {
  410. uni.showToast({
  411. title: '功能开发中',
  412. icon: 'none',
  413. mask: true
  414. })
  415. },
  416. // 计算两个点之间的距离
  417. calculateDistance(lat, lng) {
  418. let centerLat = lat
  419. let centerLng = lng
  420. let red1 = (this.myLat * Math.PI) / 180.0
  421. let red2 = (centerLat * Math.PI) / 180.0
  422. let a = red1 - red2
  423. let b = (this.myLng * Math.PI) / 180.0 - (centerLng * Math.PI) / 180.0
  424. let R = 6378137
  425. 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)))
  426. let res = (distance / 1000).toFixed(2) * 1
  427. return res
  428. }
  429. }
  430. }
  431. </script>
  432. <style lang="scss" scoped>
  433. .container {
  434. display: flex;
  435. flex-direction: column;
  436. width: 750rpx;
  437. min-height: 100vh;
  438. padding: 0 30rpx;
  439. box-sizing: border-box;
  440. overflow-y: auto;
  441. background-color: #f7f7f7;
  442. .content {
  443. position: sticky;
  444. background-color: #f7f7f7;
  445. .address {
  446. display: flex;
  447. width: 152rpx;
  448. font-size: 28rpx;
  449. .address_text {
  450. width: 104rpx;
  451. text-align: center;
  452. overflow: hidden;
  453. white-space: nowrap;
  454. text-overflow: ellipsis;
  455. }
  456. img {
  457. width: 48rpx;
  458. height: 48rpx;
  459. }
  460. }
  461. .search {
  462. display: flex;
  463. justify-content: space-between;
  464. align-items: center;
  465. width: 538rpx;
  466. height: 80rpx;
  467. opacity: 1;
  468. border-radius: 70px;
  469. background-color: #fff;
  470. .add {
  471. display: flex;
  472. justify-content: center;
  473. align-items: center;
  474. margin-left: 10rpx;
  475. width: 60rpx;
  476. font-size: 50rpx;
  477. height: 60rpx;
  478. line-height: 60rpx;
  479. color: rgba(30, 125, 251, 1);
  480. .img {
  481. width: 30rpx;
  482. height: 30rpx;
  483. }
  484. }
  485. .inp {
  486. height: 60rpx;
  487. line-height: 60rpx;
  488. flex-grow: 1;
  489. font-size: 28rpx;
  490. }
  491. .btnSearch {
  492. width: 100rpx;
  493. text-align: center;
  494. margin-right: 10rpx;
  495. height: 60rpx;
  496. line-height: 60rpx;
  497. opacity: 1;
  498. font-size: 28rpx;
  499. font-weight: 400;
  500. height: 2rem;
  501. color: #096562;
  502. }
  503. }
  504. }
  505. .main {
  506. .icons {
  507. display: flex;
  508. justify-content: space-around;
  509. align-items: center;
  510. height: 158rpx;
  511. border-radius: 12rpx;
  512. background-color: #fff;
  513. .icon_item {
  514. display: flex;
  515. flex-direction: column;
  516. align-items: center;
  517. width: 20%;
  518. .item_top {
  519. display: flex;
  520. align-items: center;
  521. justify-content: center;
  522. width: 60rpx;
  523. height: 60rpx;
  524. border-radius: 50%;
  525. img {
  526. width: 28rpx;
  527. height: 27rpx;
  528. }
  529. .img2 {
  530. width: 40rpx;
  531. height: 25.5rpx;
  532. }
  533. .img3 {
  534. width: 31rpx;
  535. height: 21rpx;
  536. }
  537. }
  538. .color {
  539. background-color: #d8e8e8;
  540. }
  541. .color2 {
  542. background-color: #c2f2d5;
  543. }
  544. .color3 {
  545. background-color: #f7d4ba;
  546. }
  547. .color4 {
  548. background-color: #fae1e2;
  549. }
  550. .color5 {
  551. background-color: #d0e0f2;
  552. }
  553. .item_bottom {
  554. margin-top: 6rpx;
  555. font-size: 28rpx;
  556. }
  557. }
  558. }
  559. .control {
  560. margin: 20rpx 0;
  561. height: 90rpx;
  562. border-radius: 8rpx;
  563. background-color: #fff;
  564. }
  565. .sticky {
  566. position: sticky;
  567. top: 0;
  568. border-radius: 0;
  569. }
  570. .box {
  571. .box_body {
  572. display: flex;
  573. flex-wrap: wrap;
  574. justify-content: space-between;
  575. .box_item {
  576. margin-bottom: 20rpx;
  577. width: 335rpx;
  578. height: 446rpx;
  579. border-radius: 10rpx;
  580. background-color: #fff;
  581. img {
  582. width: 335rpx;
  583. height: 223rpx;
  584. border-radius: 10rpx 10rpx 0 0;
  585. }
  586. .item_name {
  587. margin-left: 22rpx;
  588. margin-top: 10rpx;
  589. line-height: 55rpx;
  590. font-size: 28rpx;
  591. font-weight: bold;
  592. overflow: hidden;
  593. text-overflow: ellipsis;
  594. white-space: nowrap;
  595. }
  596. .item_rate {
  597. display: flex;
  598. align-items: center;
  599. margin-left: 22rpx;
  600. font-size: 24rpx;
  601. .rate_left {
  602. padding: 0 12rpx;
  603. color: #fff;
  604. // border-radius: 32rpx 0 0 32rpx;
  605. border-radius: 32rpx;
  606. background-color: #096562;
  607. }
  608. .rate_right {
  609. padding: 0 16rpx 0 7rpx;
  610. color: #096562;
  611. border-radius: 0 32rpx 32rpx 0;
  612. background-color: #dff2f2;
  613. }
  614. }
  615. .item_distance {
  616. margin-top: 10rpx;
  617. margin-left: 22rpx;
  618. color: #a6a6a6;
  619. font-size: 24rpx;
  620. }
  621. .item_info {
  622. box-sizing: border-box;
  623. padding: 0 30rpx 0 25rpx;
  624. margin-top: 16rpx;
  625. display: flex;
  626. justify-content: space-between;
  627. color: #ff5733;
  628. .info_count {
  629. font-size: 24rpx;
  630. }
  631. .info_price {
  632. margin-top: -5rpx;
  633. font-size: 36rpx;
  634. font-weight: bold;
  635. text {
  636. color: #a6a6a6;
  637. font-size: 24rpx;
  638. font-weight: 400;
  639. }
  640. }
  641. }
  642. }
  643. }
  644. }
  645. .noData {
  646. display: flex;
  647. flex-direction: column;
  648. justify-content: center;
  649. align-items: center;
  650. img {
  651. margin-top: 150rpx;
  652. width: 400rpx;
  653. height: 400rpx;
  654. }
  655. }
  656. }
  657. .popup_body {
  658. width: 618rpx;
  659. height: 687rpx;
  660. border-radius: 21rpx;
  661. background-color: #fff;
  662. .body_header {
  663. display: flex;
  664. justify-content: center;
  665. align-items: center;
  666. position: relative;
  667. height: 113rpx;
  668. border-bottom: 1rpx solid #e6e6e6;
  669. img {
  670. width: 16rpx;
  671. height: 16rpx;
  672. }
  673. .header_title {
  674. margin: 0 10rpx;
  675. font-size: 34rpx;
  676. font-weight: bold;
  677. color: #0f194d;
  678. }
  679. .header_jump {
  680. position: absolute;
  681. top: 38rpx;
  682. right: 30rpx;
  683. font-size: 28rpx;
  684. color: #a6a6a6;
  685. }
  686. }
  687. .body_content {
  688. display: grid;
  689. grid-template-columns: repeat(auto-fill, 160rpx);
  690. gap: 28rpx;
  691. box-sizing: border-box;
  692. padding: 26rpx 40rpx 50rpx;
  693. .content_box {
  694. position: relative;
  695. width: 160rpx;
  696. height: 105rpx;
  697. color: #fff;
  698. border-radius: 10rpx;
  699. img {
  700. width: 160rpx;
  701. height: 105rpx;
  702. border-radius: 10rpx;
  703. }
  704. .box_town {
  705. position: absolute;
  706. top: 17rpx;
  707. left: 0;
  708. right: 0;
  709. text-align: center;
  710. font-size: 28rpx;
  711. font-weight: bold;
  712. }
  713. .box_count {
  714. position: absolute;
  715. top: 57rpx;
  716. left: 0;
  717. right: 0;
  718. text-align: center;
  719. font-size: 18rpx;
  720. }
  721. }
  722. }
  723. }
  724. }
  725. </style>