ChooseDepartment.vue 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <window-size>
  3. <van-tree-select
  4. v-model:active-id="data.activeCode"
  5. v-model:main-active-index="data.activeIndex"
  6. :height="treeHeight"
  7. :items="data.depts"
  8. @click-nav="handleSelectNav"
  9. @click-item="handleSelectDept"
  10. />
  11. <van-popup v-model:show="data.showPopup" position="bottom" :style="{ height: '50%' }">
  12. <van-picker title="选择子科室" :columns="data.children" @confirm="onConfirm" @cancel="onCancel" />
  13. </van-popup>
  14. </window-size>
  15. </template>
  16. <script>
  17. import store from '../../../../store'
  18. import { onMounted, reactive } from 'vue'
  19. import { getAllNightDepartments } from '../../../../api/appointment.js'
  20. import router from '../../../../router'
  21. import Cookies from 'js-cookie'
  22. export default {
  23. name: 'ChooseDepartment',
  24. setup() {
  25. const treeHeight = store.state.windowSize.h - 45 + 'px'
  26. const data = reactive({
  27. activeIndex: '',
  28. activeCode: '',
  29. depts: [],
  30. children: [],
  31. showPopup: false,
  32. })
  33. if (Cookies.get('activeNightIndex')) {
  34. data.activeIndex = Cookies.get('activeNightIndex')
  35. }
  36. const onConfirm = (val) => {
  37. let id = val.selectedOptions[0].id
  38. let text = val.selectedOptions[0].text
  39. Cookies.set('appointmentDeptCode', id)
  40. Cookies.set('appointmentDeptName', text)
  41. router.push('/selectDoctorAndDate/' + id + '/' + text + '/yes')
  42. }
  43. const onCancel = () => {
  44. data.showPopup = false
  45. data.activeCode = ''
  46. }
  47. const handleSelectNav = (val) => {
  48. Cookies.set('activeNightIndex', val)
  49. }
  50. const handleSelectDept = (val) => {
  51. if (val.children) {
  52. data.children = val.children
  53. data.showPopup = true
  54. } else {
  55. Cookies.set('appointmentDeptCode', val.id)
  56. Cookies.set('appointmentDeptName', val.text)
  57. router.push('/selectDoctorAndDate/' + val.id + '/' + val.text + '/yes')
  58. }
  59. }
  60. onMounted(() => {
  61. getAllNightDepartments().then((res) => {
  62. data.depts = res
  63. })
  64. })
  65. return {
  66. treeHeight,
  67. handleSelectNav,
  68. handleSelectDept,
  69. data,
  70. onConfirm,
  71. onCancel,
  72. }
  73. },
  74. }
  75. </script>