header.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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: uni.getStorageSync(('hotelId') || ''),
  38. value: 0,
  39. range: [{
  40. value: 0,
  41. text: "全部"
  42. }
  43. ],
  44. }
  45. },
  46. computed: {
  47. // ...mapState(['hotelIdList','hotelId'])
  48. ...mapState({
  49. hotelIdList: state => state.hotelIdList,
  50. hotelId: state => state.hotelId
  51. })
  52. },
  53. onShow(){
  54. // this.hotelIds = uni.getStorageSync('hotelId')
  55. },
  56. watch: {
  57. hotelIdList(newVal) {
  58. console.log('header', newVal);
  59. this.range = newVal.map(item => {
  60. return {
  61. value: item.id,
  62. text: item.name
  63. }
  64. })
  65. // this.hotelIds = newVal[0].id
  66. },
  67. hotelId(newVal, oldVal) {
  68. console.log('header', newVal, oldVal);
  69. if(newVal != oldVal){
  70. this.hotelIds = newVal
  71. }
  72. this.$emit('change', this.hotelIds)
  73. }
  74. },
  75. async mounted() {
  76. let data = await getHotelList()
  77. if (data.code == 200) {
  78. this.$nextTick(() => {
  79. this.$store.commit('setHotelIdList', data.result.records)
  80. // this.hotelIds = data.result.records[0].id
  81. if (uni.getStorageSync('hotelId')) {
  82. this.hotelIds = uni.getStorageSync('hotelId')
  83. this.$store.commit('setHotelId', uni.getStorageSync('hotelId'))
  84. }else{
  85. this.hotelIds = data.result.records[0].id
  86. uni.setStorageSync("hotelId",data.result.records[0].id)
  87. this.$store.commit('setHotelId', data.result.records[0].id)
  88. }
  89. this.$emit('change', this.hotelIds)
  90. })
  91. }
  92. },
  93. methods: {
  94. change(e) {
  95. console.log(e)
  96. this.$store.commit('setHotelId', e)
  97. uni.setStorageSync('hotelId', e)
  98. console.log(this.hotelId);
  99. this.$emit('change', e)
  100. },
  101. leftClick() {
  102. if (this.isSwitch) {
  103. return
  104. }
  105. console.log('leftClick');
  106. },
  107. rightClick(){}
  108. }
  109. }
  110. </script>
  111. <style lang="scss">
  112. /deep/.uni-select {
  113. border: none !important;
  114. text-align: center;
  115. }
  116. </style>