index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <view class="pages">
  3. <u-swiper height="200" radius="8" :list="list1" @change="change" @click="click"></u-swiper>
  4. <div class="content-card">
  5. <u-subsection mode="subsection" :list="list" :current="current" @change="sectionChange"></u-subsection>
  6. <u-cell>
  7. <div slot="title" @click="handleToCity">
  8. 长沙市
  9. </div>
  10. <template slot="right-icon">
  11. 搜附近
  12. </template>
  13. </u-cell>
  14. <div class="content-occupation" v-if="current==1">
  15. <div @click="handleCalendar('single')">
  16. <div>入住</div>
  17. <div>{{timeList[0]}}</div>
  18. </div>
  19. <!-- <div>
  20. {{`共${timeList.length-1}晚`}}
  21. </div>
  22. <div>
  23. <div>离店</div>
  24. <div>{{timeList[timeList.length-1]}}</div>
  25. </div> -->
  26. </div>
  27. <div class="content-occupation" v-else>
  28. <div @click="handleCalendar('range')">
  29. <div>入住</div>
  30. <div>{{timeList[0]}}</div>
  31. </div>
  32. <div>
  33. {{`共${timeList.length-1}晚`}}
  34. </div>
  35. <div>
  36. <div>离店</div>
  37. <div>{{timeList[timeList.length-1]}}</div>
  38. </div>
  39. </div>
  40. <u--input placeholder="位置/酒店/关键词" border="surround" shape="circle" clearable></u--input>
  41. <div style="margin-top:20px;">
  42. <u-button type="primary" @click="handleToSearch">搜索</u-button>
  43. </div>
  44. <u-calendar :show="calendarShow" :mode="mode" @confirm="confirm" @close="closeCalendar"></u-calendar>
  45. </div>
  46. </view>
  47. </template>
  48. <script>
  49. import { mapState } from 'vuex'
  50. export default {
  51. data() {
  52. return {
  53. list1: [
  54. 'https://cdn.uviewui.com/uview/swiper/swiper1.png',
  55. 'https://cdn.uviewui.com/uview/swiper/swiper2.png',
  56. 'https://cdn.uviewui.com/uview/swiper/swiper3.png',
  57. ],
  58. list: ['全日房', '钟点房'],
  59. current: 0,
  60. calendarShow:false,
  61. mode: 'range',
  62. // timeList:[],//选择的时间
  63. timeCopy:[]
  64. }
  65. },
  66. computed:{
  67. ...mapState({
  68. timeList:state=>state.timeList
  69. })
  70. },
  71. onLoad() {
  72. },
  73. mounted(){
  74. this.initDate()
  75. },
  76. methods: {
  77. change(e) {
  78. // console.log('change', e)
  79. },
  80. click(e) {
  81. console.log('click', e)
  82. },
  83. sectionChange(e) {
  84. console.log('sectionChange', e)
  85. if (e == 1) {
  86. // this.$state.commit('setTimeList', [this.timeList[0]])
  87. }else{
  88. }
  89. this.current = e
  90. },
  91. handleToCity(){
  92. uni.navigateTo({
  93. url:'/components/city/linzq-citySelect/linzq-citySelect'
  94. })
  95. },
  96. handleCalendar(mode){
  97. // this.calendarShow = true
  98. uni.navigateTo({
  99. url:`/components/calendar/Calendar?mode=${mode}`
  100. })
  101. },
  102. confirm(e){
  103. console.log(e)
  104. this.timeList = e
  105. this.calendarShow = false
  106. },
  107. closeCalendar(){
  108. this.calendarShow = false
  109. },
  110. //初始化时间
  111. initDate(){
  112. let date = new Date();
  113. let year = date.getFullYear();
  114. let month = date.getMonth() + 1;
  115. let day = date.getDate();
  116. let tomorrow = new Date(date.getTime() + 24 * 60 * 60 * 1000);
  117. let tomorrowYear = tomorrow.getFullYear();
  118. let tomorrowMonth = tomorrow.getMonth() + 1;
  119. let tomorrowDay = tomorrow.getDate();
  120. let today = year + '-' + month + '-' + day;
  121. let tomorrowDate = tomorrowYear + '-' + tomorrowMonth + '-' + tomorrowDay;
  122. if (this.timeList.length == 0) {
  123. this.$store.commit('setTimeList', [today, tomorrowDate])
  124. }
  125. // this.timeList = [today, tomorrowDate]
  126. return [today, tomorrowDate];
  127. },
  128. handleToSearch(){
  129. uni.navigateTo({
  130. url:'/components/searchPage/searchPage'
  131. })
  132. }
  133. }
  134. }
  135. </script>
  136. <style lang="scss" scoped>
  137. .content-card {
  138. background-color: #fff;
  139. padding: 20px;
  140. height: 300px;
  141. width: 87vw;
  142. margin: auto;
  143. margin-top: 10px;
  144. }
  145. .pages {
  146. background-color: rgb(243, 243, 243);
  147. height: 100vh;
  148. }
  149. .content-occupation {
  150. display: flex;
  151. justify-content: space-between;
  152. align-items: center;
  153. padding: 10px 15px;
  154. }
  155. </style>