changeHotel.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <template>
  2. <view>
  3. <u-radio-group v-model="currentSelectedHotelId" placement="column" @change="groupChange">
  4. <u-radio :customStyle="{ marginTop: '20px' , marginLeft: '20px'}" v-for="(item,index) in hotelList"
  5. :key="index" :label="item.name" :name="item.hotelId">
  6. </u-radio>
  7. </u-radio-group>
  8. </view>
  9. </template>
  10. <script>
  11. import {
  12. mapState,
  13. mapMutations
  14. } from 'vuex'
  15. export default {
  16. data() {
  17. return {
  18. hotelList: [],
  19. currentSelectedHotelId: ''
  20. };
  21. },
  22. computed: {
  23. ...mapState('m_business', ['currentHotelId']),
  24. },
  25. methods: {
  26. ...mapMutations('m_business', ['updateCurrentHotelId', 'updateCurrentHotelName']),
  27. async getHotelAndNames() {
  28. let res = await uni.$http.get('/hotelNameAndIds')
  29. this.hotelList = res.data.data
  30. },
  31. groupChange(hotelId) {
  32. console.log(hotelId)
  33. console.log(this.currentSelectedHotelId)
  34. let hotelName
  35. this.hotelList.forEach(hotelInfo => {
  36. if (hotelInfo.hotelId == hotelId) {
  37. hotelName = hotelInfo.name
  38. return
  39. }
  40. })
  41. this.updateCurrentHotelId(hotelId)
  42. this.updateCurrentHotelName(hotelName)
  43. uni.$showMsg('选择酒店成功!')
  44. }
  45. },
  46. onLoad() {
  47. this.getHotelAndNames()
  48. this.currentSelectedHotelId = this.currentHotelId
  49. }
  50. }
  51. </script>
  52. <style lang="scss">
  53. </style>