search.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. <template>
  2. <view class="hotelList">
  3. <view class="fixed-box">
  4. <view class="search-box">
  5. <view class="city-box">
  6. <image class="icon" src="../static/blue-position.png" mode=""></image>
  7. {{query.cityName}}
  8. </view>
  9. <view class="input-box">
  10. <view class="time-box" @click="show = true">
  11. <view class="time">
  12. <view class="label">
  13. </view>
  14. <view class="value">
  15. {{query.checkInDate | filterDate('time')}}
  16. </view>
  17. </view>
  18. <view class="time">
  19. <view class="label">
  20. </view>
  21. <view class="value">
  22. {{query.checkOutDate | filterDate('time')}}
  23. </view>
  24. </view>
  25. </view>
  26. <input class="input" type="text" v-model="query.keyword" placeholder="搜索酒店名/地名/关键词" />
  27. </view>
  28. </view>
  29. <view class="tab-box">
  30. <view class="tab-item" :class="[query.sortKey?'active':'']" @click="handleTab(0)">
  31. 推荐排序
  32. <image class="icon" src="@/static/shop-desc.png" mode=""></image>
  33. </view>
  34. <view class="tab-item" :class="[query.filter.star.length||query.filter.price.length?'active':'']" @click="handleTab(1)">
  35. 档次价格
  36. <image class="icon" src="@/static/shop-desc.png" mode=""></image>
  37. </view>
  38. <view class="tab-item" :class="[query.filter.poiCode?'active':'']" @click="handleTab(2)">
  39. 区域位置
  40. <image class="icon" src="@/static/shop-desc.png" mode=""></image>
  41. </view>
  42. <!-- <view class="tab-item" @click="handleTab(3)">
  43. 综合筛选
  44. <image class="icon" src="@/static/shop-desc.png" mode=""></image>
  45. </view> -->
  46. </view>
  47. </view>
  48. <!-- 列表 -->
  49. <zs-list class="store-box" mt="150rpx" @load="loadMore" :status="status">
  50. <view class="hotel-item" v-for="(item,index) in list" :key="index" @click="goDetail(item.hotelId)">
  51. <zs-img :src="item.picture" width="190rpx" height="296rpx" radius="full" mode="widthFix" ></zs-img>
  52. <view class="info">
  53. <view class="title">
  54. {{item.chineseName}}
  55. </view>
  56. <view class="district">
  57. <!-- 观山湖区 -->
  58. </view>
  59. <view class="distance-box">
  60. <view class="distance">
  61. 距你{{item|filterDistance}}公里
  62. </view>
  63. <view class="price-box">
  64. <view class="price">
  65. ¥{{item.price}}
  66. </view>
  67. <view class="label">
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </zs-list>
  74. <u-popup :show="show1" :round="16" mode="top" @close="show1 = false">
  75. <view class="content">
  76. <view class="search-box">
  77. <view class="city-box">
  78. <image class="icon" src="../static/blue-position.png" mode=""></image>
  79. {{query.cityName}}
  80. </view>
  81. <view class="input-box">
  82. <view class="time-box" @click="show = true">
  83. <view class="time">
  84. <view class="label">
  85. </view>
  86. <view class="value">
  87. {{query.checkInDate | filterDate('time')}}
  88. </view>
  89. </view>
  90. <view class="time">
  91. <view class="label">
  92. </view>
  93. <view class="value">
  94. {{query.checkOutDate | filterDate('time')}}
  95. </view>
  96. </view>
  97. </view>
  98. <input class="input" type="text" v-model="query.keyword" placeholder="搜索酒店名/地名/关键词" />
  99. </view>
  100. </view>
  101. <view class="tab-box">
  102. <view class="tab-item" @click="handleTab(0)">
  103. 推荐排序
  104. <image class="icon" src="@/static/shop-desc.png" mode=""></image>
  105. </view>
  106. <view class="tab-item" @click="handleTab(1)">
  107. 档次价格
  108. <image class="icon" src="@/static/shop-desc.png" mode=""></image>
  109. </view>
  110. <view class="tab-item" @click="handleTab(2)">
  111. 区域位置
  112. <image class="icon" src="@/static/shop-desc.png" mode=""></image>
  113. </view>
  114. <!-- <view class="tab-item" @click="handleTab(3)">
  115. 综合筛选
  116. <image class="icon" src="@/static/shop-desc.png" mode=""></image>
  117. </view> -->
  118. </view>
  119. <view class="choose-box">
  120. <view class="radio-box" v-if="active == 0">
  121. <view class="radio" v-for="item in sortList" :key="item.value" @click="chooseTab(item.value,0)">
  122. <view class="label">
  123. {{item.label}}
  124. </view>
  125. <view class="value" v-if="query.sortKey == item.value">
  126. </view>
  127. </view>
  128. </view>
  129. <template v-else-if="active == 1">
  130. <view class="sub-title mb100">
  131. 价格区间
  132. </view>
  133. <zs-slider class="zs-slider" ref="slider" v-model="priceValue" :min="0" :max="5000" :step="10" :blockWidth="40" @end="moveEnd" />
  134. <view class="sub-title mt60">
  135. 星级(可多选)
  136. </view>
  137. <view class="tab-box">
  138. <view class="tab" :class="[query.filter.star.indexOf(item.id) != -1?'active':'']" v-for="item in starList" :key="item.id" @click="chooseTab(item.id,1)">
  139. {{item.label}}
  140. </view>
  141. <view class="tab" style="border: none;" v-if="starList.length%3 == 2"></view>
  142. </view>
  143. </template>
  144. <view class="radio-box" v-if="active == 2">
  145. <view class="radio" v-for="item in districtList" :key="item.id" @click="chooseTab(item,2)">
  146. <view class="label">
  147. {{item.label}}
  148. </view>
  149. <view class="value" v-if="query.filter.poiCode == item.id">
  150. </view>
  151. </view>
  152. </view>
  153. </view>
  154. </view>
  155. <view class="btn-box">
  156. <view class="btn" type="default" @click="reset">重置</view>
  157. <view class="btn" type="default" @click="show1 = false">完成</view>
  158. </view>
  159. </u-popup>
  160. <u-calendar
  161. startText="住店"
  162. endText="离店"
  163. :monthNum="5"
  164. confirmDisabledText="请选择离店日期"
  165. :show="show"
  166. mode="range"
  167. @confirm="confirm"
  168. @close="show = false"
  169. ref="calendar"
  170. :rowHeight="100"
  171. closeOnClickOverlay
  172. color="#EE4320"
  173. >
  174. </u-calendar>
  175. </view>
  176. </template>
  177. <script>
  178. import {getHotelList} from '@/api/hotel.js';
  179. import {debounce} from '@/utils/tool.js'
  180. export default {
  181. data() {
  182. return {
  183. active:0,
  184. show:false,
  185. show1:false,
  186. list: [],
  187. status:'more',
  188. query:{
  189. "checkInDate":uni.$u.timeFormat(new Date().getTime(), 'yyyy-mm-dd') ,
  190. "checkOutDate":uni.$u.timeFormat(new Date().getTime()+1000*60*60*24, 'yyyy-mm-dd'),
  191. "cityCode": 0,
  192. "cityName": uni.getStorageSync('city').replace('市',''),
  193. "filter": {
  194. "star":[],
  195. "price":[],
  196. "poiKey": "DISTRICT",
  197. "poiCode": "",
  198. "latitude": JSON.parse(uni.getStorageSync('location')).latitude,
  199. "longitude": JSON.parse(uni.getStorageSync('location')).longitude,
  200. },
  201. "keyword": "",
  202. "limit": 10,
  203. "returnFilter": 0,
  204. "sortKey": "recommend",
  205. "start": 0
  206. },
  207. districtList:JSON.parse(uni.getStorageSync('districtList')),
  208. sortList:[
  209. {
  210. value:'recommend',
  211. label:'推荐排序'
  212. },
  213. {
  214. value:'satisfaction',
  215. label:'口碑'
  216. },
  217. {
  218. value:'price-asc',
  219. label:'起价升序'
  220. },
  221. {
  222. value:'price-desc',
  223. label:'起价降序'
  224. }
  225. ],
  226. priceValue: [10, 2000], // 可以指定默认值
  227. starList:[
  228. {
  229. id:1,
  230. label:'一星级'
  231. },
  232. {
  233. id:2,
  234. label:'二星级'
  235. },
  236. {
  237. id:3,
  238. label:'三星级'
  239. },
  240. {
  241. id:4,
  242. label:'四星级'
  243. },
  244. {
  245. id:5,
  246. label:'五星级'
  247. },
  248. {
  249. id:6,
  250. label:'经济型'
  251. },
  252. {
  253. id:7,
  254. label:'舒适型'
  255. },
  256. {
  257. id:8,
  258. label:'高档型'
  259. },
  260. {
  261. id:9,
  262. label:'豪华型'
  263. },
  264. {
  265. id:0,
  266. label:'普通型'
  267. }
  268. ]
  269. }
  270. },
  271. filters: {
  272. filterDate: function(value,type) {
  273. let timestamp = new Date(value).getTime()
  274. if(type == 'time'){
  275. return uni.$u.timeFormat(timestamp, 'mm-dd');
  276. }else if(type == 'day'){
  277. let arr = ['日','一','二','三','四','五','六']
  278. let num = new Date(timestamp).getDay()
  279. return `周${arr[num]}`
  280. }
  281. },
  282. filterDistance: function(item) {
  283. let location = JSON.parse(uni.getStorageSync('location'))
  284. /*参数:两地的经纬度数值*/
  285. var radLat1 = location.latitude * Math.PI / 180.0;
  286. var radLat2 = item.latitude* Math.PI / 180.0;
  287. var a = radLat1 - radLat2;
  288. var b = location.longitude* Math.PI / 180.0 - item.longitude* Math.PI / 180.0;
  289. var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
  290. Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
  291. s = s * 6378137.0;//地球半径 单位米;
  292. s = Math.round(s * 10000) / 10000 /1000 //输出为千米
  293. s = s.toFixed(2)
  294. return s
  295. }
  296. },
  297. watch: {
  298. 'query.keyword':debounce(function(val) {
  299. this.search()
  300. })
  301. },
  302. methods: {
  303. moveEnd(){
  304. console.log('结束');
  305. this.query.filter.price = [this.priceValue[0]+'-'+this.priceValue[1]]
  306. this.search()
  307. },
  308. reset(){
  309. this.query.sortKey = "recommend"
  310. this.query.filter.star = []
  311. this.query.filter.price = []
  312. this.$refs.slider.updateValue(10, 2000)
  313. this.query.filter.poiCode = ''
  314. this.query.filter.latitude = JSON.parse(uni.getStorageSync('location')).latitude
  315. this.query.filter.longitude = JSON.parse(uni.getStorageSync('location')).longitude
  316. this.search()
  317. },
  318. chooseTab(val,type){
  319. if(type == 0){
  320. this.query.sortKey = val
  321. }else if(type == 1){
  322. if(this.query.filter.star.indexOf(val) != -1){
  323. console.log(11111111,this.query.filter.star.indexOf(val));
  324. let index = this.query.filter.star.indexOf(val)
  325. this.query.filter.star.splice(index,1)
  326. }else{
  327. console.log(22222222222,this.query.filter.star.indexOf(val));
  328. this.query.filter.star.push(val)
  329. }
  330. }else if(type == 2){
  331. this.query.filter.poiCode = val.id
  332. this.query.filter.latitude = val.location.lat
  333. this.query.filter.longitude = val.location.lng
  334. }
  335. this.search()
  336. },
  337. close(){},
  338. search(){
  339. this.query.start = 0
  340. this.list = []
  341. this.getHotelList()
  342. },
  343. confirm(e) {
  344. console.log(e);
  345. this.show = false
  346. if(e){
  347. console.log(this);
  348. this.day = e.length - 1
  349. this.query.checkInDate = e[0]
  350. this.query.checkOutDate = e[this.day]
  351. this.search()
  352. }
  353. },
  354. loadMore() {
  355. this.getHotelList()
  356. },
  357. jump(url){
  358. uni.navigateTo({
  359. url
  360. })
  361. },
  362. handleTab(val){
  363. this.show1 = true
  364. this.active = val
  365. },
  366. goDetail(id) {
  367. uni.navigateTo({
  368. url:`/hotel/hotelDetail?id=${id}&checkInDate=${this.query.checkInDate}&checkOutDate=${this.query.checkOutDate}`
  369. })
  370. },
  371. getHotelList(){
  372. this.status = 'loading'
  373. getHotelList(this.query).then(res=>{
  374. if(res.state == 'Success'){
  375. this.list = this.list.concat(res.content.data.hotelList)
  376. if((this.list.length) >= res.content.data.count){
  377. this.status = 'noMore'
  378. }else{
  379. this.status = 'more'
  380. this.query.start++
  381. }
  382. }
  383. })
  384. }
  385. },
  386. onLoad(options) {
  387. this.query.keyword = options.key
  388. this.query.checkInDate = options.checkInDate
  389. this.query.checkOutDate = options.checkOutDate
  390. this.getHotelList()
  391. }
  392. }
  393. </script>
  394. <style lang="scss" >
  395. .hotelList{
  396. padding: 0 24rpx;
  397. .fixed-box{
  398. position: fixed;
  399. top: 0%;
  400. left: 0%;
  401. z-index: 2;
  402. width: 100%;
  403. background: #fff;
  404. padding: 0 24rpx;
  405. }
  406. .search-box{
  407. display: flex;
  408. align-items: center;
  409. .city-box{
  410. display: flex;
  411. align-items: center;
  412. font-weight: 600;
  413. font-size: 28rpx;
  414. color: #222222;
  415. .icon{
  416. width: 30rpx;
  417. height: 30rpx;
  418. }
  419. }
  420. .input-box{
  421. width: 590rpx;
  422. height: 72rpx;
  423. background: #F6F6F6;
  424. border-radius: 32rpx;
  425. margin-left: 20rpx;
  426. padding: 0 20rpx;
  427. box-sizing: border-box;
  428. display: flex;
  429. align-items: center;
  430. .time-box{
  431. display: flex;
  432. flex-direction: column;
  433. justify-content: space-around;
  434. .time{
  435. display: flex;
  436. align-items: center;
  437. .label{
  438. font-size: 22rpx;
  439. color: #AAAAAA;
  440. }
  441. .value{
  442. font-size: 22rpx;
  443. color: #222222;
  444. padding-left: 10rpx;
  445. }
  446. }
  447. }
  448. .input{
  449. flex: 1;
  450. margin-left: 20rpx;
  451. font-size: 24rpx;
  452. color: #AAAAAA;
  453. }
  454. }
  455. }
  456. .tab-box{
  457. display: flex;
  458. align-items: center;
  459. padding: 20rpx 0;
  460. max-height: 800rpx;
  461. overflow: auto;
  462. .tab-item{
  463. flex: 1;
  464. display: flex;
  465. align-items: center;
  466. justify-content: center;
  467. font-size: 26rpx;
  468. .icon{
  469. width: 32rpx;
  470. height: 32rpx;
  471. }
  472. }
  473. .tab-item.active{
  474. color: #FF4D3A;
  475. }
  476. }
  477. .radio-box{
  478. max-height: 800rpx;
  479. overflow: auto;
  480. .radio{
  481. padding: 20rpx 0;
  482. display: flex;
  483. align-items: center;
  484. justify-content: space-between;
  485. .label{
  486. font-size: 26rpx;
  487. color: #222222;
  488. }
  489. .value{
  490. color: #FF4D3A;
  491. }
  492. }
  493. }
  494. .zs-list {
  495. margin-top: 20rpx;
  496. .hotel-item {
  497. display: flex;
  498. align-items: center;
  499. background: #fff;
  500. border-bottom: 1rpx solid #F0F0F0;
  501. padding: 14rpx 0;
  502. .info{
  503. padding-left: 20rpx;
  504. flex: 1;
  505. .title{
  506. font-weight: 600;
  507. font-size: 32rpx;
  508. color: #222222;
  509. line-height: 50rpx;
  510. // width: 300rpx;
  511. // white-space: nowrap;
  512. // overflow: hidden;
  513. // text-overflow: ellipsis;
  514. // margin-top: 20rpx;
  515. }
  516. .district{
  517. display: flex;
  518. align-items: center;
  519. font-size: 24rpx;
  520. color: #AAAAAA;
  521. margin-top: 20rpx;
  522. }
  523. .distance-box{
  524. display: flex;
  525. align-items: center;
  526. justify-content: space-between;
  527. .distance{
  528. font-size: 24rpx;
  529. color: #AAAAAA;
  530. margin-top: 20rpx;
  531. }
  532. .price-box{
  533. display: flex;
  534. align-items: center;
  535. .price{
  536. font-weight: 600;
  537. font-size: 36rpx;
  538. color: #FF4D3A;
  539. }
  540. .label{
  541. font-size: 24rpx;
  542. color: #AAAAAA;
  543. }
  544. }
  545. }
  546. }
  547. }
  548. }
  549. .content{
  550. padding: 20rpx 24rpx;
  551. .choose-box{
  552. .tab-box{
  553. display: flex;
  554. justify-content: space-between;
  555. flex-wrap: wrap;
  556. .tab{
  557. flex-shrink: 0;
  558. width: 204rpx;
  559. height: 60rpx;
  560. line-height: 60rpx;
  561. text-align: center;
  562. border-radius: 8rpx 8rpx 8rpx 8rpx;
  563. margin-bottom: 20rpx;
  564. box-sizing: border-box;
  565. border: 1rpx solid #EE4320;
  566. color: rgba(238, 67, 32, .5);
  567. }
  568. .tab.active{
  569. background: #EE4320;
  570. color: #fff;
  571. }
  572. }
  573. }
  574. .sub-title{
  575. font-size: 28rpx;
  576. font-weight: bold;
  577. margin: 20rpx 0;
  578. }
  579. .mb100{
  580. margin-bottom: 100rpx!important;
  581. }
  582. .mt60{
  583. margin-top: 60rpx!important;
  584. }
  585. .zs-slider{
  586. // margin-bottom: 60rpx;
  587. }
  588. }
  589. .btn-box{
  590. display: flex;
  591. align-items: center;
  592. justify-content: center;
  593. padding: 20rpx 0;
  594. .btn{
  595. width: 200rpx;
  596. height: 70rpx;
  597. line-height: 70rpx;
  598. text-align: center;
  599. border-radius: 35rpx;
  600. border: 2rpx solid #EE4320;
  601. font-weight: 600;
  602. font-size: 28rpx;
  603. color: #EE4320;
  604. }
  605. .btn+.btn{
  606. background: #EE4320;
  607. color: #fff;
  608. margin-left: 20rpx;
  609. }
  610. }
  611. .u-safe-bottom{
  612. display: none!important;
  613. }
  614. }
  615. </style>