<template>
  <el-radio-group v-model="chaZhaoLeiXing" @change="dianJiLeiXingChaXun">
    <el-radio-button :label="1">新申请</el-radio-button>
    <el-radio-button :label="2">个人模板</el-radio-button>
    <el-radio-button :label="3">科室模板</el-radio-button>
  </el-radio-group>
  <div style=" overflow: auto" :style="{height: getWindowSize.h / 1.2 + 'px'}">
    <div v-show="chaZhaoLeiXing === 1">
      <JyJcTree yjyc="jc" @node-click="nodeClick"/>
    </div>
    <div v-show="chaZhaoLeiXing !== 1">
      <jy-jc-template-tree :data="templateData"
                           @node-click="rowClick"
                           @del-click="deleteTemplate"/>
    </div>
  </div>
</template>


<script setup name='NewApplication'>
import {ref} from "vue";
import {
  getCheckNewApplication,
  getTemplate, shanShuJianChaMuBan
} from "@/api/zhu-yuan-yi-sheng/jian-yan-jian-cha-shen-qing";
import JyJcTree from "@/components/zhu-yuan-yi-sheng/yi-zhu-lu-ru/jy-jc-tree/JyJcTree.vue";
import {ElMessageBox} from "element-plus";
import store from "@/store";
import {
  addJcCheck,
} from "@/views/hospitalization/zhu-yuan-yi-sheng/public-js/zhu-yuan-yi-sheng";
import JyJcTemplateTree
  from "@/views/hospitalization/zhu-yuan-yi-sheng/jian-cha-jian-yan-shen-qing/JyJcTemplateTree.vue";
import {getWindowSize} from "@/utils/window-size";

const props = defineProps({
  returnItem: Function
})

const config = {value: 'code', label: 'name', children: 'children'}


const chaZhaoLeiXing = ref(1)

const newApplication = ref([])
const templateData = ref([])


const rowClick = (data) => {
  if (data.isTheParentNode === '2') {
    addJcCheck(data)
  }
}

const dianJiLeiXingChaXun = () => {
  if (chaZhaoLeiXing.value !== 1) {
    getTemplate('3', chaZhaoLeiXing.value).then((res) => {
      templateData.value = res
    })
  }
}

const nodeClick = (data) => {
  let temp = {
    execDept: data.execUnit,
    execDeptName: data.execUnitName,
    orderCode: data.code,
    orderName: data.name,
    orderType: data.classes,
    isTheParentNode: '2'
  }
  rowClick(temp)
}

const deleteTemplate = (val) => {
  ElMessageBox.confirm('是否要删除该模板', '提示', {
    type: 'warning',
  }).then(() => {
    shanShuJianChaMuBan(val.code, store.state.user.info.deptCode).then(() => {
      dianJiLeiXingChaXun()
    })
  }).catch(() => {
  })
}

onMounted(() => {
  getCheckNewApplication().then((res) => {
    newApplication.value = res
  })
})

</script>

<style scoped lang="scss">

</style>
