ExcuteAppointment.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <window-size>
  3. <van-notice-bar left-icon="volume-o" text="可接种年龄为【18岁-70岁】之间。" />
  4. <van-grid direction="horizontal" :column-num="7">
  5. <van-grid-item v-for="item in oneWeekText" :key="item" :text="'周' + item" />
  6. </van-grid>
  7. <van-grid direction="horizontal" :column-num="7">
  8. <van-grid-item v-for="(item, index) in nextSevenDate" :key="index">
  9. <van-badge :content="hasSource(index)" :color="badgeColor(index)">
  10. <van-button
  11. :disabled="disabledBtn(index)"
  12. :type="getType(index)"
  13. size="small"
  14. round
  15. @click="handleClickDate(index)"
  16. >{{ item.date }}</van-button
  17. >
  18. </van-badge>
  19. </van-grid-item>
  20. </van-grid>
  21. <van-field v-model="vaccinate.vaccinateName" required label="疫苗名称" readonly />
  22. <van-field v-model="vaccinate.vaccinateFactory" required label="疫苗厂家" readonly />
  23. <van-field v-model="vaccinate.name" required type="text" label="姓名" placeholder="请输入姓名" />
  24. <van-field v-model="vaccinate.phone" required type="tel" label="电话" placeholder="请输入手机号" />
  25. <van-field v-model="vaccinate.socialNo" required type="tel" label="身份证" placeholder="请输入身份证号" />
  26. <van-field v-model="vaccinate.corpName" required type="text" label="工作单位" placeholder="请输入工作单位" />
  27. <van-field
  28. v-model="jobCategoryName"
  29. required
  30. label="工作性质"
  31. readonly
  32. @click="showPickJobCategory = true"
  33. placeholder="选择工作性质"
  34. ></van-field>
  35. <van-popup v-model:show="showPickJobCategory" position="bottom" :style="{ height: '50%' }">
  36. <van-picker
  37. title="工作性质"
  38. :columns="jobCategories"
  39. :columns-field-names="customFieldName"
  40. @confirm="confirmPickJobCategory"
  41. />
  42. </van-popup>
  43. <div style="height: 10px"></div>
  44. <van-button block type="primary" @click="submit" :disabled="disabledSubmit">提交预约</van-button>
  45. </window-size>
  46. </template>
  47. <script>
  48. import { computed, onMounted, reactive, ref } from 'vue'
  49. import router from '../../../router'
  50. import { getNextSevenDate, getOneWeekText } from '../../../utils/date'
  51. import {
  52. getNextSevenDaysSources,
  53. getPatientInfoAndJobCategories,
  54. submitVaccinateAppointment,
  55. } from '../../../api/covid-vaccinate'
  56. import { showDialog, showToast } from 'vant'
  57. import { isValidIdcard, isValidPhone } from '../../../utils/validate'
  58. export default {
  59. setup() {
  60. let patientId = router.currentRoute.value.params.patientId
  61. const vaccinateCode = router.currentRoute.value.params.vaccinateCode
  62. const vaccinateName = router.currentRoute.value.params.vaccinateName
  63. const vaccinateFactory = router.currentRoute.value.params.vaccinateFactory
  64. const currentIndex = ref(0)
  65. const oneWeekText = getOneWeekText()
  66. const nextSevenDate = getNextSevenDate()
  67. const nextSevenDaySources = ref([0, 0, 0, 0, 0, 0, 0])
  68. const getType = (index) => {
  69. return index === currentIndex.value ? 'primary' : 'default'
  70. }
  71. const hasSource = (index) => {
  72. return nextSevenDaySources.value[index] > 0 ? nextSevenDaySources.value[index] : '无'
  73. }
  74. const badgeColor = (index) => {
  75. return nextSevenDaySources.value[index] > 0 ? 'green' : 'red'
  76. }
  77. const disabledBtn = (index) => {
  78. return nextSevenDaySources.value[index] < 1
  79. }
  80. const disabledSubmit = computed(() => {
  81. return nextSevenDaySources.value[currentIndex.value] < 1
  82. })
  83. const handleClickDate = (index) => {
  84. currentIndex.value = index
  85. vaccinate.executeDate = nextSevenDate[index].fullDate
  86. }
  87. const vaccinateFactories = ref([])
  88. const showPickJobCategory = ref(false)
  89. const currentDate = ref(new Date())
  90. const formatter = (type, val) => {
  91. if (type === 'year') {
  92. return val + '年'
  93. }
  94. if (type === 'month') {
  95. return val + '月'
  96. }
  97. if (type === 'day') {
  98. return val + '日'
  99. }
  100. return val
  101. }
  102. const jobCategoryName = ref('')
  103. const jobCategories = ref([])
  104. const customFieldName = {
  105. code: 'code',
  106. text: 'name',
  107. }
  108. const confirmPickJobCategory = (val) => {
  109. vaccinate.jobCategory = val.selectedOptions[0].code
  110. jobCategoryName.value = val.selectedOptions[0].name
  111. showPickJobCategory.value = false
  112. }
  113. const vaccinate = reactive({
  114. vaccinateCode: vaccinateCode,
  115. vaccinateName: vaccinateName,
  116. vaccinateFactory: vaccinateFactory,
  117. patientId: '',
  118. name: '',
  119. phone: '',
  120. socialNo: '',
  121. corpName: '',
  122. jobCategory: '',
  123. executeDate: '',
  124. })
  125. const submit = () => {
  126. if (!vaccinate.vaccinateCode || !vaccinate.vaccinateFactory) {
  127. showToast({
  128. message: '请选择疫苗厂家!',
  129. position: 'top',
  130. })
  131. return
  132. }
  133. if (!vaccinate.name) {
  134. showToast({
  135. message: '请输入姓名!',
  136. position: 'top',
  137. })
  138. return
  139. }
  140. if (!isValidPhone(vaccinate.phone)) {
  141. showToast({
  142. message: '请输入正确的手机号码',
  143. position: 'top',
  144. })
  145. return
  146. }
  147. if (!isValidIdcard(vaccinate.socialNo)) {
  148. showToast({
  149. message: '请输入正确的身份证号码',
  150. position: 'top',
  151. })
  152. return
  153. }
  154. if (!vaccinate.corpName) {
  155. showToast({
  156. message: '请输入工作单位,没有工作单位请填‘无’',
  157. position: 'top',
  158. duration: 3000,
  159. })
  160. return
  161. }
  162. if (!vaccinate.jobCategory) {
  163. showToast({
  164. message: '请选择工作性质,如不确定请选‘其他人员’,如无工作请选择‘家务及待业人员’',
  165. position: 'top',
  166. duration: 3000,
  167. })
  168. return
  169. }
  170. if (!vaccinate.executeDate) {
  171. showToast({
  172. message: '请选择接种日期',
  173. position: 'top',
  174. })
  175. return
  176. }
  177. submitVaccinateAppointment(vaccinate).then((res) => {
  178. showDialog({
  179. title: '提示',
  180. message: res,
  181. }).then(() => {
  182. router.push('/hospitalService')
  183. })
  184. })
  185. }
  186. onMounted(() => {
  187. if (!patientId) {
  188. patientId = ''
  189. }
  190. getPatientInfoAndJobCategories(patientId).then((res2) => {
  191. vaccinate.patientId = res2.patientId
  192. vaccinate.name = res2.name
  193. vaccinate.phone = res2.phone
  194. vaccinate.socialNo = res2.socialNo
  195. jobCategories.value = res2.jobCategories
  196. jobCategories.value.forEach(item => {
  197. item.value = item.code
  198. })
  199. getNextSevenDaysSources(vaccinate.vaccinateCode).then((res3) => {
  200. nextSevenDaySources.value = res3
  201. for (let i = 0; i < 7; i++) {
  202. if (res3[i] > 0) {
  203. handleClickDate(i)
  204. break
  205. }
  206. }
  207. })
  208. })
  209. })
  210. return {
  211. oneWeekText,
  212. nextSevenDate,
  213. getType,
  214. hasSource,
  215. badgeColor,
  216. disabledBtn,
  217. handleClickDate,
  218. disabledSubmit,
  219. vaccinate,
  220. vaccinateFactories,
  221. currentDate,
  222. formatter,
  223. showPickJobCategory,
  224. jobCategories,
  225. confirmPickJobCategory,
  226. customFieldName,
  227. jobCategoryName,
  228. submit,
  229. }
  230. },
  231. }
  232. </script>