header.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <div style="background-color:#fff;overflow: hidden;" :style="{'border-bottom': borbtm?'1px solid':'none'}">
  3. <u-navbar title="" @rightClick="rightClick" :autoBack="!isSwitch" placeholder @leftClick="leftClick" :leftIcon="isSwitch? '' : 'arrow-left' ">
  4. <div slot="center" style="width:80%;">
  5. <uni-data-select :clear="false" style="flex:1" v-model="hotelIds" :localdata="range" @change="change"></uni-data-select>
  6. </div>
  7. </u-navbar>
  8. <!-- <u--input placeholder="房间号/姓名/手机号/身份证号" border="surround" shape="circle" prefixIcon="search" prefixIconStyle="font-size: 22px;color: #909399" fontSize="12px" :customStyle="{border:'1px solid #e2e2e2',padding:'0 10px',margin:'0 10px',borderRadius:'20px'}">
  9. </u--input> -->
  10. <slot name="search"></slot>
  11. <div style="margin:10px 0 6px 0;">
  12. <!-- <u-subsection :list="list" mode="subsection" :current="current" @change="sectionChange"></u-subsection> -->
  13. <slot name="section"></slot>
  14. </div>
  15. </div>
  16. </template>
  17. <script>
  18. import {
  19. mapState
  20. } from 'vuex'
  21. import {
  22. getHotelList
  23. } from '../utils/api'
  24. export default {
  25. props: {
  26. borbtm: {
  27. type: Boolean,
  28. default: true
  29. },
  30. isSwitch: {
  31. type: Boolean,
  32. default: false
  33. }
  34. },
  35. data() {
  36. return {
  37. hotelIds: 0,
  38. value: 0,
  39. range: [{
  40. value: 0,
  41. text: "全部"
  42. },
  43. {
  44. value: 1,
  45. text: "沙县大酒店"
  46. },
  47. {
  48. value: 2,
  49. text: "游泳"
  50. },
  51. ],
  52. }
  53. },
  54. computed: {
  55. // ...mapState(['hotelIdList','hotelId'])
  56. ...mapState({
  57. hotelIdList: state => state.hotelIdList,
  58. hotelId: state => state.hotelId
  59. })
  60. },
  61. watch: {
  62. hotelIdList(newVal) {
  63. console.log('header', newVal);
  64. this.range = newVal.map(item => {
  65. return {
  66. value: item.id,
  67. text: item.name
  68. }
  69. })
  70. }
  71. },
  72. async mounted() {
  73. },
  74. methods: {
  75. async getHotels(cb) {
  76. let data = await getHotelList()
  77. if (data.code == 200) {
  78. this.$nextTick(() => {
  79. this.$store.commit('setHotelIdList', data.result.records)
  80. let cacheStore = uni.getStorageSync("hotelInfo")
  81. if(cacheStore) {
  82. this.hotelIds = cacheStore.id
  83. this.$store.commit('setHotelId', cacheStore.id)
  84. } else {
  85. this.hotelIds = data.result.records[0].id
  86. uni.setStorageSync("hotelInfo",data.result.records[0])
  87. this.$store.commit('setHotelId', data.result.records[0].id)
  88. }
  89. if(cb) {
  90. cb()
  91. }
  92. this.$emit('change',this.hotelIds)
  93. })
  94. }
  95. },
  96. change(e) {
  97. console.log(e)
  98. this.$store.commit('setHotelId', e)
  99. let hotels = this.hotelIdList
  100. let index = hotels.findIndex(s=>s.id == e)
  101. if(index > -1) {
  102. uni.setStorageSync("hotelInfo",hotels[index])
  103. }
  104. console.log(this.hotelId);
  105. this.$emit('change', e)
  106. },
  107. leftClick() {
  108. if (this.isSwitch) {
  109. return
  110. }
  111. console.log('leftClick');
  112. },
  113. rightClick(){}
  114. }
  115. }
  116. </script>
  117. <style lang="scss">
  118. /deep/.uni-select {
  119. border: none !important;
  120. text-align: center;
  121. }
  122. </style>