index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. <template>
  2. <view class="hotel">
  3. <zs-header :background="background"></zs-header>
  4. <zs-img class="banner" width="750rpx" height="556rpx" src="https://hyxhsh.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/LZVwmPjcG6eo4b817697d9ce892c8400c439427fddea.png/1.png"></zs-img>
  5. <view class="search-box">
  6. <view class="address-box">
  7. <view class="address">
  8. {{address}}
  9. </view>
  10. <image class="more" src="@/static/right.png" mode=""></image>
  11. <view class="nearby" @click="handleSearch(1)">
  12. 附近酒店
  13. </view>
  14. <image class="position" src="@/static/rePosition.png" mode=""></image>
  15. </view>
  16. <view class="chooose-box">
  17. <view class="time-box" @click="chooseDate">
  18. <view class="start-time">
  19. {{query.checkInDate | filterDate('time')}}
  20. </view>
  21. <view class="day">
  22. {{query.checkInDate | filterDate('day')}}
  23. </view>
  24. <view class="line">
  25. </view>
  26. <view class="end-time">
  27. {{query.checkOutDate | filterDate('time')}}
  28. </view>
  29. <view class="day">
  30. {{query.checkOutDate | filterDate('day')}}
  31. </view>
  32. </view>
  33. <view class="total">
  34. 共{{day}}晚
  35. <image class="more" src="@/static/right.png" mode=""></image>
  36. </view>
  37. </view>
  38. <view class="input-box">
  39. <input class="input" type="text" v-model="query.keyword" placeholder="搜索酒店名/地名/关键词" />
  40. <image class="more" src="@/static/right.png" mode=""></image>
  41. </view>
  42. <view class="btn-box">
  43. <button class="btn" type="default" @click="handleSearch(0)">查找酒店</button>
  44. </view>
  45. </view>
  46. <!-- 列表 -->
  47. <zs-list class="store-box" mt="0" @load="loadMore" :status="status">
  48. <view class="left">
  49. <view class="hotel-item" v-for="(item,index) in list" :key="index" @click="goDetail(item.hotelId)">
  50. <view >
  51. <zs-img :src="item.picture" width="340rpx" height="322rpx" mode="widthFix"></zs-img>
  52. <view class="info">
  53. <view class="price-box">
  54. <view class="left" v-if="item.price">
  55. <view class="price">
  56. ¥{{item.price}}
  57. </view>
  58. <view class="label">
  59. </view>
  60. </view>
  61. <view class="left" v-else>
  62. <view class="label">
  63. 暂无报价
  64. </view>
  65. </view>
  66. <view class="right">
  67. <image class="star" v-for="i in getTag(item.star).num" src="../static/star.png" mode=""></image>
  68. </view>
  69. </view>
  70. <view class="title">
  71. {{item.chineseName}}
  72. <!-- <view :class="[getTag(item.star).tag]">
  73. {{item.starName}}
  74. </view> -->
  75. </view>
  76. <!-- <view class="desc">
  77. 观山湖区
  78. </view> -->
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. <view class="right">
  84. <view class="hotel-item" v-for="(item,index) in list1" :key="index" @click="goDetail(item.hotelId)">
  85. <view >
  86. <zs-img :src="item.picture" width="340rpx" height="322rpx" mode="widthFix"></zs-img>
  87. <view class="info">
  88. <view class="price-box">
  89. <view class="left" v-if="item.price">
  90. <view class="price">
  91. ¥{{item.price}}
  92. </view>
  93. <view class="label">
  94. </view>
  95. </view>
  96. <view class="left" v-else>
  97. <view class="label">
  98. 暂无报价
  99. </view>
  100. </view>
  101. <view class="right">
  102. <image class="star" v-for="i in getTag(item.star).num" src="../static/star.png" mode=""></image>
  103. </view>
  104. </view>
  105. <view class="title">
  106. {{item.chineseName}}
  107. <!-- <view :class="[getTag(item.star).tag]">
  108. {{item.starName}}
  109. </view> -->
  110. </view>
  111. <!-- <view class="desc">
  112. 观山湖区
  113. </view> -->
  114. </view>
  115. </view>
  116. </view>
  117. </view>
  118. </zs-list>
  119. <u-calendar
  120. startText="住店"
  121. endText="离店"
  122. :monthNum="5"
  123. confirmDisabledText="请选择离店日期"
  124. :show="show"
  125. :mode="mode"
  126. @confirm="confirm"
  127. @close="show = false"
  128. ref="calendar"
  129. :rowHeight="100"
  130. closeOnClickOverlay
  131. color="#EE4320"
  132. >
  133. </u-calendar>
  134. </view>
  135. </template>
  136. <script>
  137. import {getHotelList} from '@/api/hotel.js'
  138. // 腾讯地图
  139. var QQMapWX = require('../libs/qqmap-wx-jssdk.min.js');
  140. var qqmapsdk = new QQMapWX({key:'KX5BZ-B64RC-RO62W-AMWAZ-VVTC3-YAFXF'});
  141. export default {
  142. data() {
  143. return {
  144. address:'',
  145. list:[],
  146. list1:[],
  147. status:'more',
  148. show: false,
  149. background: false,
  150. mode: 'range',
  151. query:{
  152. "checkInDate":uni.$u.timeFormat(new Date().getTime(), 'yyyy-mm-dd') ,
  153. "checkOutDate":uni.$u.timeFormat(new Date().getTime()+1000*60*60*24, 'yyyy-mm-dd'),
  154. "cityCode": 0,
  155. "cityName": uni.getStorageSync('city').replace('市',''),
  156. "filter": {},
  157. "keyword": "",
  158. "limit": 10,
  159. "returnFilter": 0,
  160. "sortKey": "",
  161. "start": 0
  162. },
  163. day:1
  164. }
  165. },
  166. filters: {
  167. filterDate: function(value,type) {
  168. let timestamp = new Date(value).getTime()
  169. if(type == 'time'){
  170. return uni.$u.timeFormat(timestamp, 'mm月dd日');
  171. }else if(type == 'day'){
  172. let arr = ['日','一','二','三','四','五','六']
  173. let num = new Date(timestamp).getDay()
  174. return `周${arr[num]}`
  175. }
  176. }
  177. },
  178. methods: {
  179. getTag(star){
  180. if(star == 0 ||star == 1){
  181. return {tag:'tag1',num:1}
  182. }else if(star == 2 ||star == 6){
  183. return {tag:'tag2',num:2}
  184. }if(star == 3 ||star == 7){
  185. return {tag:'tag2',num:3}
  186. }if(star == 4 ||star == 8){
  187. return {tag:'tag3',num:4}
  188. }if(star == 5 ||star == 9){
  189. return {tag:'tag3',num:5}
  190. }
  191. },
  192. // 获取当前城市
  193. getCity(){
  194. let that = this
  195. that.address = '定位中...'
  196. return new Promise((resolve,reject)=>{
  197. uni.getLocation({
  198. type: 'gcj02',
  199. success: (res) => {
  200. // 解析地址
  201. that.query['location.lat'] = res.latitude
  202. that.query['location.lon'] = res.longitude
  203. // 存储经纬度
  204. uni.setStorageSync('location',JSON.stringify({latitude:res.latitude,longitude:res.longitude}))
  205. qqmapsdk.reverseGeocoder({
  206. location: {
  207. latitude: res.latitude,
  208. longitude: res.longitude
  209. },
  210. success: function(res) {
  211. that.address = res.result.formatted_addresses.recommend
  212. console.log(9999,res);
  213. },
  214. fail: function(res) {
  215. that.city = '定位失败'
  216. },
  217. })
  218. },
  219. fail: () => {
  220. console.log("获取经纬度失败");
  221. },
  222. })
  223. })
  224. },
  225. handleSearch(type){
  226. uni.navigateTo({
  227. url:`./search?key=${this.query.keyword}&checkInDate=${this.query.checkInDate}&checkOutDate=${this.query.checkOutDate}&day=${this.day}&isNear=${type}`
  228. })
  229. },
  230. confirm(e) {
  231. this.show = false
  232. if(e){
  233. this.day = e.length - 1
  234. this.query.checkInDate = e[0]
  235. this.query.checkOutDate = e[this.day]
  236. }
  237. },
  238. loadMore(){
  239. this.getHotelList()
  240. },
  241. goDetail(id) {
  242. uni.navigateTo({
  243. url:`/hotel/hotelDetail?id=${id}&checkInDate=${this.query.checkInDate}&checkOutDate=${this.query.checkOutDate}`
  244. })
  245. },
  246. chooseDate(){
  247. this.show = true
  248. },
  249. getHotelList(){
  250. this.status = 'loading'
  251. let query = JSON.parse(JSON.stringify(this.query))
  252. query.start = query.start*query.limit
  253. getHotelList(query).then(res=>{
  254. if(res.state == 'Success'){
  255. let list = []
  256. let list1 = []
  257. res.content.data.hotelList.map((item,index)=>{
  258. if(index%2){
  259. this.list1.push(item)
  260. }else{
  261. this.list.push(item)
  262. }
  263. })
  264. this.list = this.list.concat(list)
  265. this.list1 = this.list1.concat(list1)
  266. if((this.list.length+this.list1.length) >= res.content.data.count){
  267. this.status = 'noMore'
  268. }else{
  269. this.status = 'more'
  270. this.query.start++
  271. }
  272. }
  273. })
  274. }
  275. },
  276. onPageScroll(e) {
  277. if (e.scrollTop >= 50) {
  278. this.background = true
  279. } else {
  280. this.background = false
  281. }
  282. },
  283. onLoad() {
  284. this.getCity()
  285. }
  286. }
  287. </script>
  288. <style lang="scss" >
  289. .hotel{
  290. background: #F9F9F9;
  291. min-height: 100vh;
  292. .banner{
  293. }
  294. .search-box{
  295. padding: 28rpx 24rpx;
  296. width: 702rpx;
  297. background: #FFFFFF;
  298. border-radius: 16rpx 16rpx 16rpx 16rpx;
  299. margin: -224rpx 24rpx 20rpx;
  300. position: relative;
  301. // top: -224rpx;
  302. box-sizing: border-box;
  303. .address-box{
  304. display: flex;
  305. align-items: center;
  306. padding-bottom: 30rpx;
  307. .address{
  308. flex: 1;
  309. font-weight: 600;
  310. font-size: 32rpx;
  311. color: #222222;
  312. white-space: nowrap;
  313. overflow: hidden;
  314. text-overflow: ellipsis;
  315. }
  316. .more{
  317. width: 48rpx;
  318. height: 48rpx;
  319. margin: 0 16rpx;
  320. }
  321. .nearby{
  322. font-weight: 300;
  323. font-size: 24rpx;
  324. color: #222222;
  325. }
  326. .position{
  327. width: 48rpx;
  328. height: 48rpx;
  329. }
  330. }
  331. .chooose-box{
  332. padding: 78rpx 0 24rpx;
  333. display: flex;
  334. align-items: center;
  335. justify-content: space-between;
  336. border-top:1rpx solid #F0F0F0;
  337. border-bottom: 1rpx solid #F0F0F0;
  338. .time-box{
  339. display: flex;
  340. align-items: flex-end;
  341. .start-time,.end-time{
  342. font-weight: 600;
  343. font-size: 32rpx;
  344. color: #222222;
  345. position: relative;
  346. }
  347. .start-time::before{
  348. content: '入住';
  349. position: absolute;
  350. top:calc(-100% - 20rpx);
  351. left: 0;
  352. font-weight: 300;
  353. font-size: 24rpx;
  354. color: #222222;
  355. }
  356. .end-time::before{
  357. content: '离店';
  358. position: absolute;
  359. top:calc(-100% - 20rpx);
  360. left: 0;
  361. font-weight: 300;
  362. font-size: 24rpx;
  363. color: #222222;
  364. }
  365. .line{
  366. font-weight: 600;
  367. font-size: 32rpx;
  368. color: #222222;
  369. margin: 0 16rpx;
  370. }
  371. .day{
  372. font-weight: 300;
  373. font-size: 28rpx;
  374. color: #222222;
  375. margin-left: 16rpx;
  376. vertical-align: bottom;
  377. }
  378. }
  379. .total{
  380. display: flex;
  381. align-items: center;
  382. font-weight: 300;
  383. font-size: 24rpx;
  384. color: #222222;
  385. .more{
  386. width: 48rpx;
  387. height: 48rpx;
  388. }
  389. }
  390. }
  391. .input-box{
  392. position: relative;
  393. line-height: 84rpx;
  394. border-bottom: 1rpx solid #F0F0F0;
  395. .input{
  396. width: 100%;
  397. height: 84rpx;
  398. line-height: 84rpx;
  399. padding-right: 48rpx;
  400. font-size: 24rpx;
  401. color: #222222;
  402. }
  403. .more{
  404. width: 48rpx;
  405. height: 48rpx;
  406. position: absolute;
  407. top: 50%;
  408. right: 0%;
  409. transform: translateY(-50%);
  410. }
  411. }
  412. .btn-box{
  413. padding-top: 28rpx;
  414. .btn{
  415. height: 80rpx;
  416. background: #EE4320;
  417. border-radius: 40rpx;
  418. font-weight: 600;
  419. font-size: 28rpx;
  420. color: #FFFFFF;
  421. }
  422. }
  423. }
  424. .zs-list {
  425. display: flex;
  426. flex-wrap: wrap;
  427. justify-content: space-between;
  428. padding: 0 24rpx;
  429. .hotel-item.disable{
  430. filter: grayscale(1);
  431. }
  432. .hotel-item {
  433. width: 340rpx;
  434. margin-bottom: 20rpx;
  435. // box-shadow: 0rpx 0rpx 24rpx 2rpx rgba(0, 0, 0, 0.08);
  436. border-radius: 16rpx;
  437. background: #fff;
  438. .icon {
  439. width: 100%;
  440. height: 300rpx;
  441. border-radius: 16rpx 16rpx 0 0;
  442. }
  443. .info{
  444. flex: 1;
  445. padding: 16rpx;
  446. display: flex;
  447. flex-direction: column;
  448. justify-content: space-between;
  449. position: relative;
  450. .title{
  451. font-size: 28rpx;
  452. font-weight: bold;
  453. overflow: hidden;
  454. text-overflow: ellipsis;
  455. /* 弹性伸缩盒子模型显示 */
  456. display: -webkit-box;
  457. /* 限制在一个块元素显示的文本的行数 */
  458. -webkit-line-clamp: 2;
  459. /* 设置或检索伸缩盒对象的子元素的排列方式 */
  460. -webkit-box-orient: vertical;
  461. margin-top: 10rpx;
  462. }
  463. .desc{
  464. font-size: 24rpx;
  465. color: #AAAAAA;
  466. overflow: hidden;
  467. text-overflow: ellipsis;
  468. /* 弹性伸缩盒子模型显示 */
  469. display: -webkit-box;
  470. /* 限制在一个块元素显示的文本的行数 */
  471. -webkit-line-clamp: 2;
  472. /* 设置或检索伸缩盒对象的子元素的排列方式 */
  473. -webkit-box-orient: vertical;
  474. margin-top: 12rpx;
  475. }
  476. .price-box{
  477. display: flex;
  478. justify-content: space-between;
  479. align-items: center;
  480. margin-top: 12rpx;
  481. .left{
  482. display: flex;
  483. align-items: center;
  484. .label{
  485. font-size: 24rpx;
  486. color: #AAAAAA;
  487. margin-left: 6rpx;
  488. }
  489. .price{
  490. font-size: 32rpx;
  491. color: $uni-color-primary;
  492. font-weight: bold;
  493. }
  494. }
  495. .right{
  496. font-size: 24rpx;
  497. color: #AAAAAA;
  498. display: flex;
  499. align-items: center;
  500. .star{
  501. width: 21rpx;
  502. height: 17rpx;
  503. margin-left: 3rpx;
  504. }
  505. .half-star{
  506. width: 10.5rpx;
  507. height: 16.5rpx;
  508. margin-left: 3rpx;
  509. }
  510. }
  511. }
  512. }
  513. }
  514. }
  515. }
  516. </style>