SelectDoctorAndDate.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <window-size>
  3. <van-notice-bar
  4. v-show="data.doctorSources.length > 0"
  5. left-icon="warning-o"
  6. text="挂号后,号源仅就诊当天有效,逾时失效!"
  7. />
  8. <van-grid direction="horizontal" :column-num="7">
  9. <van-grid-item v-for="item in data.oneWeekText" :key="item" :text="'周' + item" />
  10. </van-grid>
  11. <van-grid direction="horizontal" :column-num="7">
  12. <van-grid-item v-for="(item, index) in data.nextSevenDate" :key="index">
  13. <van-badge :content="hasSource(index)" :color="badgeColor(index)">
  14. <van-button
  15. :disabled="disabledBtn(index)"
  16. :type="getType(index)"
  17. size="small"
  18. round
  19. @click="handleClickDate(index, false)"
  20. >{{ item.date }}</van-button
  21. >
  22. </van-badge>
  23. </van-grid-item>
  24. </van-grid>
  25. <div style="height: 5px"></div>
  26. <van-tag type="primary" plain style="margin-left: 5px">{{ selectDate }}</van-tag>
  27. <div style="height: 5px"></div>
  28. <div v-for="(item, index) in data.doctorSources" :key="index">
  29. <van-cell center :title="item.doctorName + ' | ' + item.chargeType" is-link @click="toDoctorArangement(item)">
  30. <template #icon>
  31. <van-image
  32. style="width: 44.11px; height: 60.36px"
  33. round
  34. fit="cover"
  35. :src="'data:image/png;base64,' + item.portrait"
  36. />&nbsp;
  37. </template>
  38. <template #label>
  39. <div :style="labelStyle" v-show="item.introduction">{{ item.introduction }}</div>
  40. </template>
  41. <template #default>
  42. <span v-html="hasLeftNum(item.leftNum)"></span>
  43. </template>
  44. </van-cell>
  45. </div>
  46. <van-empty :image="empty" description="暂未获取到医生数据" v-show="data.doctorSources.length === 0" />
  47. </window-size>
  48. </template>
  49. <script>
  50. import empty from '../../../assets/empty.png'
  51. import { useRouter } from 'vue-router'
  52. import { getOneWeekText, getNextSevenDate } from '../../../utils/date'
  53. import { onMounted, reactive, ref } from 'vue'
  54. import { getSourcesByDate, getDoctorSources } from '../../../api/appointment'
  55. import Cookies from 'js-cookie'
  56. import store from '../../../store'
  57. import { Toast } from 'vant'
  58. export default {
  59. name: 'SelectDoctorAndDate',
  60. setup() {
  61. const windowSize = store.state.windowSize
  62. const labelStyle = {
  63. width: windowSize.w - 100 + 'px',
  64. overflow: 'hidden',
  65. textOverflow: 'ellipsis',
  66. whiteSpace: 'nowrap',
  67. }
  68. const router = useRouter()
  69. const deptCode = router.currentRoute.value.params.deptCode
  70. const selectDate = ref('')
  71. const data = reactive({
  72. currentIndex: 0,
  73. oneWeekText: getOneWeekText(),
  74. nextSevenDate: getNextSevenDate(),
  75. nextSevenDaySources: new Array(7).fill({}),
  76. doctorSources: [],
  77. dateSelected: '',
  78. })
  79. const getType = (index) => {
  80. return index === data.currentIndex ? 'primary' : 'default'
  81. }
  82. const hasSource = (index) => {
  83. return data.nextSevenDaySources[index] === 1 ? '有' : '无'
  84. }
  85. const badgeColor = (index) => {
  86. return data.nextSevenDaySources[index] === 1 ? 'green' : 'red'
  87. }
  88. const disabledBtn = (index) => {
  89. return data.nextSevenDaySources[index] === 0
  90. }
  91. const hasLeftNum = (val) => {
  92. const yes = '<span style="font-size: 12px;color:green">有号</span>'
  93. const no = '<span style="font-size: 12px;color:red">无号</span>'
  94. return val > 0 ? yes : no
  95. }
  96. const handleClickDate = (index, isFromMounted) => {
  97. data.currentIndex = index
  98. data.dateSelected = data.nextSevenDate[index].fullDate
  99. Cookies.set('week', '星期' + data.oneWeekText[index])
  100. localStorage.week = '星期' + data.oneWeekText[index]
  101. const param = {
  102. date: data.dateSelected,
  103. deptCode: deptCode,
  104. }
  105. selectDate.value = param.date
  106. getDoctorSources(param)
  107. .then((res) => {
  108. data.doctorSources = res
  109. })
  110. .catch(() => {
  111. data.doctorSources = []
  112. if (isFromMounted && index < 6) {
  113. handleClickDate(++index, isFromMounted)
  114. }
  115. })
  116. }
  117. const toDoctorArangement = (val) => {
  118. if (val.leftNum === 0) {
  119. Toast.fail(val.doctorName + '医生已无号')
  120. } else {
  121. const to = '/doctorArrangement/' + data.dateSelected + '/' + deptCode + '/' + val.doctorCode
  122. router.push(to)
  123. }
  124. }
  125. onMounted(() => {
  126. const param = {
  127. start: data.nextSevenDate[0].fullDate,
  128. end: data.nextSevenDate[6].fullDate,
  129. dept: deptCode,
  130. }
  131. getSourcesByDate(param).then((res) => {
  132. data.nextSevenDaySources = res
  133. handleClickDate(0, true)
  134. })
  135. })
  136. return {
  137. empty,
  138. selectDate,
  139. deptCode,
  140. getOneWeekText,
  141. handleClickDate,
  142. getType,
  143. data,
  144. hasSource,
  145. disabledBtn,
  146. badgeColor,
  147. hasLeftNum,
  148. labelStyle,
  149. toDoctorArangement,
  150. }
  151. },
  152. }
  153. </script>