cityList.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <view class="cityList">
  3. <view class="search-box">
  4. <input class="search" v-model="query.name" type="text" placeholder="搜索城市名称" />
  5. </view>
  6. <zs-list class="list" mt="120rpx" @load="loadMore" :status="status">
  7. <view class="item" v-for="item in list" :key="item.code" @click="handleCity(item.name)">
  8. {{item.name}}
  9. </view>
  10. </zs-list>
  11. </view>
  12. </template>
  13. <script>
  14. import {debounce} from '@/utils/tool.js'
  15. import {getCityList} from '@/api/common'
  16. export default {
  17. data() {
  18. return {
  19. query:{
  20. name:'',
  21. page:0,
  22. size:30,
  23. },
  24. list:[],
  25. status:'more',
  26. backUrl:'',
  27. checkInDate:'',
  28. checkOutDate:'',
  29. key:'',
  30. }
  31. },
  32. watch: {
  33. 'query.name':debounce(function(val) {
  34. this.status = 'more'
  35. this.query.page = 0
  36. this.list = []
  37. this.getCityList()
  38. })
  39. },
  40. methods: {
  41. handleCity(name){
  42. let city = name.replace('市','')
  43. if(this.backUrl){
  44. uni.navigateTo({
  45. url:`${this.backUrl}?cityName=${city}&key=${this.key}&checkInDate=${this.checkInDate}&checkOutDate=${this.checkOutDate}`
  46. })
  47. }else{
  48. uni.navigateTo({
  49. url:'/hotel/index?cityName='+city
  50. })
  51. }
  52. },
  53. loadMore(){
  54. this.getCityList()
  55. },
  56. getCityList() {
  57. this.status = 'loading'
  58. getCityList(this.query).then(res=>{
  59. if(res.state == 'Success'){
  60. this.list = this.list.concat(res.content.content)
  61. if(this.list.length == res.content.totalElements){
  62. this.status = 'noMore'
  63. }else{
  64. this.status = 'more'
  65. this.query.page++
  66. }
  67. }
  68. })
  69. }
  70. },
  71. onLoad(options) {
  72. this.backUrl = options.backUrl
  73. this.checkInDate=options.checkInDate,
  74. this.checkOutDate=options.checkOutDate,
  75. this.key=options.key
  76. this.getCityList()
  77. }
  78. }
  79. </script>
  80. <style lang="scss" >
  81. .cityList{
  82. background: #fff;
  83. .search-box{
  84. position: fixed;
  85. top: 0%;
  86. left: 0%;
  87. padding: 0 24rpx ;
  88. background: #fff;
  89. .search{
  90. width: 702rpx;
  91. height: 72rpx;
  92. text-indent: 20rpx;
  93. background: #F6F6F6;
  94. border-radius: 36rpx;
  95. box-sizing: border-box;
  96. padding: 0 40rpx;
  97. }
  98. }
  99. .zs-list{
  100. .item{
  101. padding: 28rpx 0;
  102. font-size: 24rpx;
  103. color: #222222;
  104. border-bottom: 1rpx solid #F0F0F0;
  105. margin: 0 24rpx;
  106. }
  107. }
  108. }
  109. </style>