index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  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" @click="jump('./cityList')">
  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,d) in getTag(item.star).num" :key="d" 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,d) in getTag(item.star).num" :key="d" 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. jump(url){
  180. uni.navigateTo({
  181. url
  182. })
  183. },
  184. getTag(star){
  185. if(star == 0 ||star == 1){
  186. return {tag:'tag1',num:1}
  187. }else if(star == 2 ||star == 6){
  188. return {tag:'tag2',num:2}
  189. }if(star == 3 ||star == 7){
  190. return {tag:'tag2',num:3}
  191. }if(star == 4 ||star == 8){
  192. return {tag:'tag3',num:4}
  193. }if(star == 5 ||star == 9){
  194. return {tag:'tag3',num:5}
  195. }
  196. },
  197. // 获取当前城市
  198. getCity(){
  199. let that = this
  200. that.address = '定位中...'
  201. return new Promise((resolve,reject)=>{
  202. uni.getLocation({
  203. type: 'gcj02',
  204. success: (res) => {
  205. // 解析地址
  206. that.query['location.lat'] = res.latitude
  207. that.query['location.lon'] = res.longitude
  208. // 存储经纬度
  209. uni.setStorageSync('location',JSON.stringify({latitude:res.latitude,longitude:res.longitude}))
  210. qqmapsdk.reverseGeocoder({
  211. location: {
  212. latitude: res.latitude,
  213. longitude: res.longitude
  214. },
  215. success: function(res) {
  216. that.address = res.result.formatted_addresses.recommend
  217. console.log(9999,res);
  218. },
  219. fail: function(res) {
  220. that.city = '定位失败'
  221. },
  222. })
  223. },
  224. fail: () => {
  225. console.log("获取经纬度失败");
  226. },
  227. })
  228. })
  229. },
  230. handleSearch(type){
  231. uni.navigateTo({
  232. url:`./search?key=${this.query.keyword}&checkInDate=${this.query.checkInDate}&checkOutDate=${this.query.checkOutDate}&day=${this.day}&isNear=${type}`
  233. })
  234. },
  235. confirm(e) {
  236. this.show = false
  237. if(e){
  238. this.day = e.length - 1
  239. this.query.checkInDate = e[0]
  240. this.query.checkOutDate = e[this.day]
  241. }
  242. },
  243. loadMore(){
  244. this.getHotelList()
  245. },
  246. goDetail(id) {
  247. uni.navigateTo({
  248. url:`/hotel/hotelDetail?id=${id}&checkInDate=${this.query.checkInDate}&checkOutDate=${this.query.checkOutDate}`
  249. })
  250. },
  251. chooseDate(){
  252. this.show = true
  253. },
  254. getHotelList(){
  255. this.status = 'loading'
  256. let query = JSON.parse(JSON.stringify(this.query))
  257. query.start = query.start*query.limit
  258. getHotelList(query).then(res=>{
  259. if(res.state == 'Success'){
  260. let list = []
  261. let list1 = []
  262. res.content.data.hotelList.map((item,index)=>{
  263. if(index%2){
  264. this.list1.push(item)
  265. }else{
  266. this.list.push(item)
  267. }
  268. })
  269. this.list = this.list.concat(list)
  270. this.list1 = this.list1.concat(list1)
  271. if((this.list.length+this.list1.length) >= res.content.data.count){
  272. this.status = 'noMore'
  273. }else{
  274. this.status = 'more'
  275. this.query.start++
  276. }
  277. }
  278. })
  279. }
  280. },
  281. onPageScroll(e) {
  282. if (e.scrollTop >= 50) {
  283. this.background = true
  284. } else {
  285. this.background = false
  286. }
  287. },
  288. onLoad() {
  289. this.getCity()
  290. }
  291. }
  292. </script>
  293. <style lang="scss" >
  294. .hotel{
  295. background: #F9F9F9;
  296. min-height: 100vh;
  297. .banner{
  298. }
  299. .search-box{
  300. padding: 28rpx 24rpx;
  301. width: 702rpx;
  302. background: #FFFFFF;
  303. border-radius: 16rpx 16rpx 16rpx 16rpx;
  304. margin: -224rpx 24rpx 20rpx;
  305. position: relative;
  306. // top: -224rpx;
  307. box-sizing: border-box;
  308. .address-box{
  309. display: flex;
  310. align-items: center;
  311. padding-bottom: 30rpx;
  312. .address{
  313. flex: 1;
  314. font-weight: 600;
  315. font-size: 32rpx;
  316. color: #222222;
  317. white-space: nowrap;
  318. overflow: hidden;
  319. text-overflow: ellipsis;
  320. }
  321. .more{
  322. width: 48rpx;
  323. height: 48rpx;
  324. margin: 0 16rpx;
  325. }
  326. .nearby{
  327. font-weight: 300;
  328. font-size: 24rpx;
  329. color: #222222;
  330. }
  331. .position{
  332. width: 48rpx;
  333. height: 48rpx;
  334. }
  335. }
  336. .chooose-box{
  337. padding: 78rpx 0 24rpx;
  338. display: flex;
  339. align-items: center;
  340. justify-content: space-between;
  341. border-top:1rpx solid #F0F0F0;
  342. border-bottom: 1rpx solid #F0F0F0;
  343. .time-box{
  344. display: flex;
  345. align-items: flex-end;
  346. .start-time,.end-time{
  347. font-weight: 600;
  348. font-size: 32rpx;
  349. color: #222222;
  350. position: relative;
  351. }
  352. .start-time::before{
  353. content: '入住';
  354. position: absolute;
  355. top:calc(-100% - 20rpx);
  356. left: 0;
  357. font-weight: 300;
  358. font-size: 24rpx;
  359. color: #222222;
  360. }
  361. .end-time::before{
  362. content: '离店';
  363. position: absolute;
  364. top:calc(-100% - 20rpx);
  365. left: 0;
  366. font-weight: 300;
  367. font-size: 24rpx;
  368. color: #222222;
  369. }
  370. .line{
  371. font-weight: 600;
  372. font-size: 32rpx;
  373. color: #222222;
  374. margin: 0 16rpx;
  375. }
  376. .day{
  377. font-weight: 300;
  378. font-size: 28rpx;
  379. color: #222222;
  380. margin-left: 16rpx;
  381. vertical-align: bottom;
  382. }
  383. }
  384. .total{
  385. display: flex;
  386. align-items: center;
  387. font-weight: 300;
  388. font-size: 24rpx;
  389. color: #222222;
  390. .more{
  391. width: 48rpx;
  392. height: 48rpx;
  393. }
  394. }
  395. }
  396. .input-box{
  397. position: relative;
  398. line-height: 84rpx;
  399. border-bottom: 1rpx solid #F0F0F0;
  400. .input{
  401. width: 100%;
  402. height: 84rpx;
  403. line-height: 84rpx;
  404. padding-right: 48rpx;
  405. font-size: 24rpx;
  406. color: #222222;
  407. }
  408. .more{
  409. width: 48rpx;
  410. height: 48rpx;
  411. position: absolute;
  412. top: 50%;
  413. right: 0%;
  414. transform: translateY(-50%);
  415. }
  416. }
  417. .btn-box{
  418. padding-top: 28rpx;
  419. .btn{
  420. height: 80rpx;
  421. background: #EE4320;
  422. border-radius: 40rpx;
  423. font-weight: 600;
  424. font-size: 28rpx;
  425. color: #FFFFFF;
  426. }
  427. }
  428. }
  429. .zs-list {
  430. display: flex;
  431. flex-wrap: wrap;
  432. justify-content: space-between;
  433. padding: 0 24rpx;
  434. .hotel-item.disable{
  435. filter: grayscale(1);
  436. }
  437. .hotel-item {
  438. width: 340rpx;
  439. margin-bottom: 20rpx;
  440. // box-shadow: 0rpx 0rpx 24rpx 2rpx rgba(0, 0, 0, 0.08);
  441. border-radius: 16rpx;
  442. background: #fff;
  443. .icon {
  444. width: 100%;
  445. height: 300rpx;
  446. border-radius: 16rpx 16rpx 0 0;
  447. }
  448. .info{
  449. flex: 1;
  450. padding: 16rpx;
  451. display: flex;
  452. flex-direction: column;
  453. justify-content: space-between;
  454. position: relative;
  455. .title{
  456. font-size: 28rpx;
  457. font-weight: bold;
  458. overflow: hidden;
  459. text-overflow: ellipsis;
  460. /* 弹性伸缩盒子模型显示 */
  461. display: -webkit-box;
  462. /* 限制在一个块元素显示的文本的行数 */
  463. -webkit-line-clamp: 2;
  464. /* 设置或检索伸缩盒对象的子元素的排列方式 */
  465. -webkit-box-orient: vertical;
  466. margin-top: 10rpx;
  467. }
  468. .desc{
  469. font-size: 24rpx;
  470. color: #AAAAAA;
  471. overflow: hidden;
  472. text-overflow: ellipsis;
  473. /* 弹性伸缩盒子模型显示 */
  474. display: -webkit-box;
  475. /* 限制在一个块元素显示的文本的行数 */
  476. -webkit-line-clamp: 2;
  477. /* 设置或检索伸缩盒对象的子元素的排列方式 */
  478. -webkit-box-orient: vertical;
  479. margin-top: 12rpx;
  480. }
  481. .price-box{
  482. display: flex;
  483. justify-content: space-between;
  484. align-items: center;
  485. margin-top: 12rpx;
  486. .left{
  487. display: flex;
  488. align-items: center;
  489. .label{
  490. font-size: 24rpx;
  491. color: #AAAAAA;
  492. margin-left: 6rpx;
  493. }
  494. .price{
  495. font-size: 32rpx;
  496. color: $uni-color-primary;
  497. font-weight: bold;
  498. }
  499. }
  500. .right{
  501. font-size: 24rpx;
  502. color: #AAAAAA;
  503. display: flex;
  504. align-items: center;
  505. .star{
  506. width: 21rpx;
  507. height: 17rpx;
  508. margin-left: 3rpx;
  509. }
  510. .half-star{
  511. width: 10.5rpx;
  512. height: 16.5rpx;
  513. margin-left: 3rpx;
  514. }
  515. }
  516. }
  517. }
  518. }
  519. }
  520. }
  521. </style>