Преглед изворни кода

检验报告添加日期shortcuts

lighter пре 1 година
родитељ
комит
202c0d3a21
2 измењених фајлова са 110 додато и 120 уклоњено
  1. 8 53
      src/utils/date.js
  2. 102 67
      src/views/hospital-service/check-exam/CheckExamIndex.vue

+ 8 - 53
src/utils/date.js

@@ -13,12 +13,6 @@ export function getDate() {
   return year + '-' + month + '-' + day
 }
 
-export function getTodayAndWeek() {
-  const today = getDate()
-  const week = '星期' + WEEKS[new Date().getDay()]
-  return { today, week }
-}
-
 export function formatDate(date) {
   const year = date.getFullYear()
   let month = date.getMonth() + 1
@@ -32,21 +26,14 @@ export function formatDate(date) {
   return year + '-' + month + '-' + day
 }
 
-export function getOneMonthOffset() {
-  const myDate = new Date()
-  let year = myDate.getFullYear()
-  let month = myDate.getMonth()
-  let date = myDate.getDate()
-  let end = year + '-' + ('0' + (month + 1)).slice(-2) + '-' + ('0' + date).slice(-2)
-  if (month === 0) {
-    year -= 1
-    month = 12
-  } else if (month === 2) {
-    date = date > 28 ? 28 : date
-  } else {
-    date = date > 30 ? 30 : date
-  }
-  let start = year + '-' + ('0' + month).slice(-2) + '-' + ('0' + date).slice(-2)
+export function getDateRangeByOffsetDays(offsetDays) {
+  const now = new Date()
+  let end = now.getFullYear() + '-' + ('0' + (now.getMonth() + 1))
+      .slice(-2) + '-' + ('0' + now.getDate()).slice(-2)
+
+  let begin = new Date(now.getTime() - (3600 * 24 * offsetDays * 1000) )
+  let start = begin.getFullYear() + '-' + ('0' + (begin.getMonth() + 1))
+      .slice(-2) + '-' + ('0' + begin.getDate()).slice(-2)
   return { start, end }
 }
 
@@ -60,23 +47,6 @@ export function getOneWeekOffset(start) {
   return { start, end }
 }
 
-export function getHourMinute() {
-  const date = new Date()
-  const hour = date.getHours()
-  const min = date.getMinutes()
-  return Number(hour + '' + ('0' + min).slice(-2))
-}
-
-export function getTomorrow() {
-  const tomorrow = new Date().getTime() + 24 * 3600 * 1000
-  return new Date(tomorrow)
-}
-
-export function getAWeekFromNow() {
-  const weekAfter = new Date().getTime() + 7 * 24 * 3600 * 1000
-  return new Date(weekAfter)
-}
-
 export function getOneWeekText() {
   const day = new Date().getDay()
   const arr = new Array(7)
@@ -109,21 +79,6 @@ function getDateByOffeset(offset) {
   }
 }
 
-export function formatDatetime(date) {
-  const year = date.getFullYear()
-  let month = date.getMonth() + 1
-  let day = date.getDate()
-  let hour = date.getHours()
-  let minute = date.getMinutes()
-  if (month < 10) {
-    month = '0' + month
-  }
-  if (day < 10) {
-    day = '0' + day
-  }
-  return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':00'
-}
-
 export function getDateTime() {
   const date = new Date()
   const year = date.getFullYear()

+ 102 - 67
src/views/hospital-service/check-exam/CheckExamIndex.vue

@@ -1,7 +1,24 @@
 <template>
   <window-size>
-    <van-cell title="选择日期区间" :value="date" @click="showDateRange = true" />
-    <van-calendar v-model:show="showDateRange" :min-date="minDate" type="range" @confirm="onConfirm" />
+    <van-cell title="选择日期区间" :value="date" @click="showDateShortcuts = true" />
+
+    <van-dialog v-model:show="showDateShortcuts" @confirm="onConfirmShortcuts">
+      <div style="display:flex; justify-content: center; padding: 30px 0 20px 0">
+        <van-radio-group v-model="chosenShortcut">
+          <van-radio name="oneWeek" style="margin-bottom: 12px">近一周</van-radio>
+          <van-radio name="threeMonths" style="margin-bottom: 12px">近三月</van-radio>
+          <van-radio name="halfYear" style="margin-bottom: 12px">近半年</van-radio>
+          <van-radio name="oneYear" style="margin-bottom: 12px">近一年</van-radio>
+          <van-radio name="diy">自定义</van-radio>
+        </van-radio-group>
+      </div>
+    </van-dialog>
+
+    <van-calendar v-model:show="showDateRange"
+                  :min-date="minDate"
+                  :max-date="maxDate"
+                  type="range"
+                  @confirm="onConfirm" />
     <div v-show="examIndex.length > 0">
       <div style="height: 5px"></div>
       <van-tag type="success" size="large" round plain>已发布报告</van-tag>
@@ -24,77 +41,95 @@
   </window-size>
 </template>
 
-<script>
+<script setup>
 import store from '../../../store'
 import empty from '../../../assets/empty.png'
 import { useRouter } from 'vue-router'
 import { computed, onMounted, ref } from 'vue'
 import { checkExamIndex } from '../../../api/check-exam'
-import { formatDate, getOneMonthOffset } from '../../../utils/date'
-export default {
-  name: 'CheckExamIndex',
-  setup() {
-    const router = useRouter()
-    const patientId = router.currentRoute.value.params.patientId
-    const scrollStyle = {
-      height: store.state.screenSize.h - 125 + 'px',
-      overflowY: 'auto',
-    }
-    const date = ref('')
-    const showDateRange = ref(false)
-    const examIndex = computed(() => {
-      return store.state.examIndexArray
-    })
+import {formatDate, getDateRangeByOffsetDays} from '../../../utils/date'
 
-    const onConfirm = (values) => {
-      showDateRange.value = false
-      const start = formatDate(values[0])
-      const end = formatDate(values[1])
-      store.commit('SET_EXAMDATERANGE', [start, end])
-      date.value = `${start} - ${end}`
-      const param = {
-        patientId,
-        start,
-        end,
-        openId: localStorage.getItem('openId')
-      }
-      checkExamIndex(param).then((res) => {
-        store.commit('SET_EXAMINDEXARRAY', res)
-      })
-    }
+const router = useRouter()
+const patientId = router.currentRoute.value.params.patientId
+const scrollStyle = {
+  height: store.state.screenSize.h - 125 + 'px',
+  overflowY: 'auto',
+}
+const date = ref('')
+const minDate = ref(new Date(2012, 0, 1))
+const maxDate = ref(new Date())
+
+const showDateShortcuts = ref(false)
+const chosenShortcut = ref('oneWeek')
+
+const onConfirmShortcuts = () => {
+  switch (chosenShortcut.value) {
+    case 'oneWeek':
+      makeOffset(7)
+      queryInspectionIndex(date.value[0], date.value[1])
+      return
+    case 'threeMonths':
+      makeOffset(90)
+      queryInspectionIndex(date.value[0], date.value[1])
+      return;
+    case 'halfYear':
+      makeOffset(183)
+      queryInspectionIndex(date.value[0], date.value[1])
+      return
+    case 'oneYear':
+      makeOffset(365)
+      queryInspectionIndex(date.value[0], date.value[1])
+      return;
+    default:
+      showDateRange.value = true
+      return;
+  }
+}
 
-    onMounted(() => {
-      const range = store.state.examDateRange
-      if (range.length === 0) {
-        const temp = getOneMonthOffset()
-        range[0] = temp.start
-        range[1] = temp.end
-        store.commit('SET_EXAMDATERANGE', range)
-      }
-      date.value = range[0] + ' - ' + range[1]
-      if (examIndex.value.length === 0) {
-        const param = {
-          patientId,
-          start: range[0],
-          end: range[1],
-          openId: localStorage.getItem('openId')
-        }
-        checkExamIndex(param).then((res) => {
-          store.commit('SET_EXAMINDEXARRAY', res)
-        })
-      }
-      showDateRange.value = false
-    })
-    return {
-      patientId,
-      scrollStyle,
-      empty,
-      minDate: new Date(2010, 0, 1),
-      date,
-      examIndex,
-      onConfirm,
-      showDateRange,
-    }
-  },
+const makeOffset = (offsetDays) => {
+  const range = ['', '']
+  const temp = getDateRangeByOffsetDays(offsetDays)
+  range[0] = temp.start
+  range[1] = temp.end
+  store.commit('SET_EXAMDATERANGE', range)
+  date.value = range[0] + ' - ' + range[1]
 }
+
+const showDateRange = ref(false)
+const examIndex = computed(() => {
+  return store.state.examIndexArray
+})
+
+const onConfirm = (values) => {
+  showDateRange.value = false
+  const start = formatDate(values[0])
+  const end = formatDate(values[1])
+  store.commit('SET_EXAMDATERANGE', [start, end])
+  date.value = `${start} - ${end}`
+  queryInspectionIndex(start, end)
+}
+
+const queryInspectionIndex = (start, end) => {
+  const param = {
+    patientId,
+    start: start,
+    end: end,
+    openId: localStorage.getItem('openId')
+  }
+  checkExamIndex(param).then((res) => {
+    store.commit('SET_EXAMINDEXARRAY', res)
+  })
+}
+
+onMounted(() => {
+  const range = store.state.examDateRange
+  if (range.length === 0) {
+    makeOffset(30)
+  } else {
+    date.value = range[0] + ' - ' + range[1]
+  }
+  if (examIndex.value.length === 0) {
+    queryInspectionIndex(range[0], range[1])
+  }
+})
 </script>