<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">定点信息查询</div>
        <div class="component-header__close-button">
          <el-button plain icon="Close" circle title="关闭" @click="close"></el-button>
        </div>
      </div>
      <div>
        <el-select v-model="bizAppyType" placeholder="业务申请类型" style="width: 145px">
          <el-option v-for="item in bizAppyTypes" :key="item.code" :label="item.name" :value="item.code"></el-option>
        </el-select>
        <el-divider direction="vertical"></el-divider>
        <el-button type="primary" icon="Search" @click="requirePsnNo">查询</el-button>
      </div>
      <el-table :data="fixMedins" stripe>
        <el-table-column prop="psnNo" label="人员编号"></el-table-column>
        <el-table-column prop="insutypeName" label="险种类型"></el-table-column>
        <el-table-column prop="fixSrtNo" label="定点排序号"></el-table-column>
        <el-table-column prop="fixmedinsCode" label="定点医药机构编号"></el-table-column>
        <el-table-column prop="fixmedinsName" label="定点医药机构名称"></el-table-column>
        <el-table-column prop="begndate" label="开始日期"></el-table-column>
        <el-table-column prop="enddate" label="结束日期"></el-table-column>
        <el-table-column prop="memo" label="备注"></el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { onMounted, ref } from 'vue'
import { getBizAppyTypes } from '@/api/medical-insurance/si-dict'
import { fetchPsnNo, queryPersonnelAssignmentInfo } from '@/api/medical-insurance/si-query'
import { ElMessage } from 'element-plus'

export default {
  props: {
    socialNo: {
      type: String,
      required: true,
    },
    admdvs: {
      type: String,
      required: true,
    },
  },
  emits: ['close'],
  setup(props, ctx) {
    const bizAppyType = ref(null)
    const bizAppyTypes = ref([])
    const fixMedins = ref([])

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

    const requirePsnNo = () => {
      if (!bizAppyType.value) {
        ElMessage({
          message: '请选择业务申请类型！',
          type: 'warning',
          showClose: true,
        })
        return
      }
      fetchPsnNo(props.socialNo, props.admdvs).then((res) => {
        fetchAssigninfo(res)
      })
    }

    const fetchAssigninfo = (psnNo) => {
      const param = {
        admdvs: props.admdvs,
        psnNo: psnNo,
        bizAppyType: bizAppyType.value,
      }
      queryPersonnelAssignmentInfo(param).then((res) => {
        fixMedins.value = res
      })
    }

    onMounted(() => {
      getBizAppyTypes().then((res) => {
        bizAppyTypes.value = res
      })
    })

    return {
      bizAppyType,
      bizAppyTypes,
      fixMedins,
      requirePsnNo,
      close,
    }
  },
}
</script>
