<template>
  <div class="component-box-wrapper__half-transparent">
    <div class="component-content-box__dialog-like">
      <div class="component-header-box">
        <div class="component-header__title">{{ injuryMode ? '工伤信息' : '参保信息' }}</div>
        <div class="component-header__close-button">
          <el-button plain icon="Close" circle title="关闭" @click="close"></el-button>
        </div>
      </div>
      <div v-if="injuryMode">
        <el-table :data="injuryinfo" @row-click="handleClickInsuinfo" stripe height="180">
          <el-table-column label="电脑号" prop="indiId"></el-table-column>
          <el-table-column label="工伤个人业务序号" prop="serialPers"></el-table-column>
          <el-table-column label="工伤认定号" prop="identifyCode"></el-table-column>
          <el-table-column label="认定申请时间" prop="identyDate"></el-table-column>
          <el-table-column label="受伤部位" prop="injuryPart"></el-table-column>
          <el-table-column label="报告时间" prop="reportDate"></el-table-column>
          <el-table-column label="事故发生时间" prop="accidentDate"></el-table-column>
          <el-table-column label="事故详细情况" prop="accidentDetail"></el-table-column>
        </el-table>
      </div>
      <div v-else>
        <el-table :data="psnBaseinfo.insuinfo" @row-click="handleClickInsuinfo" stripe height="180">
          <el-table-column label="余额" prop="balc"></el-table-column>
          <el-table-column label="险种类型" prop="insutypeName"></el-table-column>
          <el-table-column label="人员类别" prop="psnTypeName"></el-table-column>
          <el-table-column label="参保状态" prop="psnInsuStasName"></el-table-column>
          <el-table-column label="个人参保日期" prop="psnInsuDate"></el-table-column>
          <el-table-column label="暂停参保日期" prop="pausInsuDate"></el-table-column>
          <el-table-column label="公务员标志" prop="cvlservFlagName"></el-table-column>
          <el-table-column label="参保地医保区划" prop="insuplcAdmdvs"></el-table-column>
          <el-table-column label="参保地名称" prop="insuplcAdmdvsName"></el-table-column>
          <el-table-column label="单位名称" prop="empName"></el-table-column>
        </el-table>
        <div style="height: 16px"></div>
        <el-tag>身份信息</el-tag>
        <el-table :data="psnBaseinfo.idetinfo" stripe height="180">
          <el-table-column label="人员身份类别" prop="psnIdetTypeName"></el-table-column>
          <el-table-column label="人员类别等级" prop="psnTypeLv"></el-table-column>
          <el-table-column label="备注" prop="memo"></el-table-column>
          <el-table-column label="开始时间" prop="begntime"></el-table-column>
          <el-table-column label="结束时间" prop="endtime"></el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import store from '@/store'
import { onMounted, ref, computed } from 'vue'
import { obtainBasicPersonInfo } from '@/api/medical-insurance/si-query'
import { getPersonBaseinfo } from '@/api/medical-insurance/si-injury'
export default {
  props: {
    params: {
      type: Object,
      required: true,
    },
  },
  emits: ['close', 'rowClick'],
  setup(props, ctx) {
    const injuryMode = computed(() => {
      return store.state.ptnt.injuryMode
    })
    const injuryinfo = ref([])
    const psnBaseinfo = ref({
      insuinfo: [],
      idetinfo: [],
    })
    const psnNo = ref(null)

    const handleClickInsuinfo = (row) => {
      row.psnNo = psnNo.value
      ctx.emit('rowClick', row)
    }

    const close = () => {
      ctx.emit('close')
    }

    const fetchInsuinfo = () => {
      if (injuryMode.value) {
        getPersonBaseinfo(props.params)
          .then((res) => {
            injuryinfo.value = res
          })
          .catch(() => {
            ctx.emit('close')
          })
      } else {
        obtainBasicPersonInfo(props.params)
          .then((res) => {
            psnNo.value = res.psnNo
            psnBaseinfo.value = res
          })
          .catch(() => {
            ctx.emit('close')
          })
      }
    }

    onMounted(() => {
      fetchInsuinfo()
    })

    return {
      injuryMode,
      injuryinfo,
      psnBaseinfo,
      handleClickInsuinfo,
      close,
    }
  },
}
</script>
