<template>
  <div class="emr-template-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-template-scrollbar-container" style="width: 100%">
      <div v-for="item in templateData" :key="item.id" class="scrollbar-item">
        <el-tooltip
          effect="dark"
          :content="`${item.name}`"
          placement="bottom"
        >
          <el-text class="2" truncated @click="handleNodeClick(item)">
            <div class="template-item">{{ item.name }}
               <el-space>
             <el-icon><Edit @click="handleEdit(item)" /></el-icon>
            </el-space></div>
            
          </el-text>
        </el-tooltip>
      </div>
    </el-scrollbar>
  </div>
</template>

<script setup>
import { ref, reactive, defineEmits, unref } from 'vue';
import { getListByDefinitionId } from '../api';
import { ElTree } from 'element-plus';
import { ElMessageBox, ElMessage, ElLoading } from 'element-plus';
import { patientInfo } from '../../store/patient.js';
const emits = defineEmits(['templateClick','edit']);
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 templateData = ref([]);
const queryList = async () => {
  try {
    if ( unref(definitionId)&&unref(definitionId) !== '') {
      const res = await getListByDefinitionId(unref(definitionId));
      templateData.value = res.data || [];
    }else{
      templateData.value = [];
    }

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

<style lang="scss" scoped>
.emr-template-container {
    height: 100%;
//   padding: 8px;
 
.emr-template-scrollbar-container{
    padding: 8px;
    height: 100%;
  .scrollbar-item {
    height: 40px;
    line-height: 40px;
    border-radius: 4px;
    cursor: pointer;
    background: var(--el-color-primary-light-9);
    & + .scrollbar-item {
      margin-top: 8px;
    }
    .el-text{
      width: calc(100% - 0px);
    display: flex;
    justify-content: space-between;
    padding: 0 8px;
    }
    .template-item{
      width: 100%;
    display: flex;
    justify-content: space-between;
    }
  }
}

}
</style>
