<template>
  <window-size>
    <van-field v-model="socialNo" label="身份证号" placeholder="请输入要查询的身份证号">
      <template #button>
        <van-button size="small" type="primary" @click="startQuery">查询</van-button>
      </template>
    </van-field>
    <div style="height: 5px"></div>
    <div v-for="(item, index) in list" :key="index">
      <van-cell
        :title="item.aply_CTNT"
        :label="item.ordr_CREATE_DATE"
        :value="filterType(item.patient_TYPE, item.ptnt_ID)"
        is-link
        center
        :to="'/checkExamDetail/' + item.ordr_ID"
      ></van-cell>
    </div>
  </window-size>
</template>

<script>
import { onMounted, ref } from 'vue'
import { checkIndexBySocialNo } from '../../../api/check-exam'
import { Toast } from 'vant'
import { useRouter } from 'vue-router'
import { getPatientInfo } from '../../../api/assessments'

export default {
  setup() {
    const router = useRouter()
    const patientId = router.currentRoute.value.params.patientId
    const socialNo = ref(null)
    const list = ref([])
    const startQuery = () => {
      if (!socialNo.value) {
        Toast({
          message: '请输入正确的身份证号码',
          position: 'top',
        })
      } else {
        checkIndexBySocialNo(socialNo.value).then((res) => {
          list.value = res
        })
      }
    }
    onMounted(() => {
      getPatientInfo(patientId).then((res) => {
        socialNo.value = res.idcard
      })
    })
    return {
      socialNo,
      list,
      startQuery,
      filterType,
    }
  },
}

function filterType(val, no) {
  if (val === '0') {
    return '门诊号：' + no
  } else if (val === '1') {
    return '住院号：' + no
  } else if (val === '3') {
    return '体检号：' + no
  }
  return ''
}
</script>