<template>
  <div class="emr-history-container">
    <div class="search-box">
      <el-input placeholder="病历名称搜索..." v-model="queryParams.searchKey">
        <template #append>
          <el-button @click="queryList">查询</el-button>
        </template>
      </el-input>
    </div>
    <el-scrollbar class="emr-history-scrollbar-container" style="width: 100%">
      <div v-for="item in historyData" :key="item.id" class="scrollbar-item">
        <el-tooltip
          effect="dark"
          :content="`${item.name}(${item.recordTime})`"
          placement="bottom"
        >
          <el-text class="w-150px mb-2" truncated @click="handleNodeClick(item)">
            {{ item.name }}({{ item.recordTime }})
          </el-text>
        </el-tooltip>
      </div>
    </el-scrollbar>
  </div>
</template>

<script setup>
import { ref, reactive, defineEmits, unref } from 'vue';
import { getRecordByEncounterIdList } from '../api';
import { ElTree } from 'element-plus';
import { ElMessageBox, ElMessage, ElLoading } from 'element-plus';
import { patientInfo } from '../../store/patient.js';
const emits = defineEmits(['historyClick']);
const props = defineProps({
  definitionId: {
    type: String,
    default: '',
  },
});
const definitionId = defineModel('definitionId', {
  type: String,
  default: '',
});
const defaultProps = {
  children: 'children',
  label: 'name',
};
const queryParams = ref({
  searchKey: '',
  isPage: 0,
});
const historyData = ref([]);
const queryList = async () => {
  try {
    if (patientInfo.value.encounterId && unref(definitionId)&&unref(definitionId) !== '') {
      const res = await getRecordByEncounterIdList({
        ...queryParams.value,
        encounterId: patientInfo.value.encounterId,
        patientId: patientInfo.value.patientId,
        definitionId: unref(definitionId),
      });
      historyData.value = res.data || [];
    }else{
      historyData.value = [];
    }

  } catch (error) {
    ElMessage.error('获取模板树失败');
    historyData.value = [];
  }
};
const handleNodeClick = (data) => {
  emits('historyClick', data);
};
const currentSelectTemplate = ref({});
defineExpose({ queryList });
</script>

<style lang="scss" scoped>
.emr-history-container {
    height: 100%;
//   padding: 8px;
 .search-box {
        height: 40px;
        line-height: 40px;

        
 }
.emr-history-scrollbar-container{
    padding: 8px;
    height: calc(100% - 40px);
  .scrollbar-item {
    height: 40px;
    line-height: 40px;
    border-radius: 4px;
    cursor: pointer;
    background: var(--el-color-primary-light-9);
    & + .scrollbar-item {
      margin-top: 8px;
    }
  }
}

}
</style>
