index.vue 13 KB

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