<template>
  <Dialog :title="dialogTitle" v-model="dialogVisible" style="width: 1050px;">
    <div class="container">
      <div class="top">
        <!-- 列表 -->
        <p style="font-weight: bold">本地列表</p>
        <ContentWrap>
          <el-table
            v-loading="loading"
            :data="list"
            :stripe="true"
            :show-overflow-tooltip="true"
            @row-dblclick="handleRowDblclick"
          >
            <el-table-column label="ID" align="center" prop="id" v-if="false" />
            <el-table-column label="检查项目" align="center" prop="examItemName" />
            <el-table-column label="机构ID" align="center" prop="orgId" v-if="false" />
            <el-table-column label="检查项目代号" align="center" prop="examItemCode" />
            <el-table-column label="检查部位代码" align="center" prop="examPartCode" />
            <el-table-column
              label="第三方检查项目编号"
              align="center"
              prop="thirdPartyExamItemCode"
            />
            <el-table-column
              label="第三方检查项目名称"
              align="center"
              prop="thirdPartyExamItemName"
            />
            <el-table-column
              label="第三方检查项目价格"
              align="center"
              prop="thirdPartyExamItemPrice"
            />
          </el-table>
          <!-- 分页 -->
          <Pagination
            :total="total"
            v-model:page="queryParams.pageNo"
            v-model:limit="queryParams.pageSize"
            @pagination="getList"
          />
        </ContentWrap>
      </div>
      <div class="middle">
        <div>
          <p style="font-weight: bold">本地列表选择：检查项目:{{ bdrow.examItemName }} </p>
          <div>
            <el-button type="success"><Icon icon="ep:refresh" class="mr-5px" /> 对照</el-button>
          </div>
          <div> <p style="font-weight: bold">对照列表选择：第三方检查项目名称：{{}}</p></div>
        </div>
      </div>
      <div class="bottom">
        <p style="font-weight: bold">对照信息列表</p>
        <!-- 列表 -->
        <ContentWrap>
          <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
            <el-table-column label="ID" align="center" prop="id" v-if="false" />
            <el-table-column label="检查项目" align="center" prop="examItemName" v-if="false" />
            <el-table-column label="机构ID" align="center" prop="orgId" v-if="false" />
            <el-table-column label="检查项目代号" align="center" prop="examItemCode" v-if="false" />
            <el-table-column label="检查部位代码" align="center" prop="examPartCode" v-if="false" />
            <el-table-column
              label="第三方检查项目编号"
              align="center"
              prop="thirdPartyExamItemCode"
            />
            <el-table-column
              label="第三方检查项目名称"
              align="center"
              prop="thirdPartyExamItemName"
            />
            <el-table-column
              label="第三方检查项目价格"
              align="center"
              prop="thirdPartyExamItemPrice"
            />
          </el-table>
          <!-- 分页 -->
          <Pagination
            :total="total"
            v-model:page="queryParams.pageNo"
            v-model:limit="queryParams.pageSize"
            @pagination="getList"
          />
        </ContentWrap>
      </div>
    </div>
  </Dialog>
</template>
<script setup lang="ts">
import { examitemsApi, examitemsVO } from '@/api/system/examitems'

/** 检查部位 表单 */
defineOptions({ name: 'ExamitemscompareForm' })

const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗
const loading = ref(true) // 列表的加载中
const list = ref<examitemsVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数

const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('') // 弹窗的标题
const formLoading = ref(false) // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
const formData = ref({
  id: undefined,
  examItemName: undefined,
  createDate: undefined,
  createPerson: undefined,
  isdelete: undefined,
  orgId: undefined,
  deletePerson: undefined,
  deleteDate: undefined,
  examItemCode: undefined,
  examPartCode: undefined,
  thirdPartyExamItemCode: undefined,
  thirdPartyExamItemName: undefined,
  thirdPartyExamItemPrice: undefined
})

const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  examItemName: undefined,
  examItemCode: undefined,
  examPartCode: undefined
})

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await examitemsApi.getexamitemsPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

// 双击本地列表信息
const bdrow = ref({
  id: undefined,
  examItemName: undefined,
  examItemCode: undefined,
  examPartCode: undefined
})
const handleRowDblclick = (row) => {
  bdrow.value = row
  console.log(bdrow.value)
}

const formRef = ref() // 表单 Ref

/** 打开弹窗 */
const open = async () => {
  dialogVisible.value = true
  dialogTitle.value = '字典对照'
  resetForm()
  // 修改时，设置数据

  formLoading.value = true
  try {
    getList()
    //formData.value = await examitemsApi.getexamitems(id)
  } finally {
    formLoading.value = false
  }
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗

/** 提交表单 */
const emit = defineEmits(['success']) // 定义 success 事件，用于操作成功后的回调

/** 重置表单 */
const resetForm = () => {
  formData.value = {
    id: undefined,
    examItemName: undefined,
    createDate: undefined,
    createPerson: undefined,
    isdelete: undefined,
    orgId: undefined,
    deletePerson: undefined,
    deleteDate: undefined,
    examItemCode: undefined,
    examPartCode: undefined,
    thirdPartyExamItemCode: undefined,
    thirdPartyExamItemName: undefined,
    thirdPartyExamItemPrice: undefined
  }
  formRef.value?.resetFields()
  bdrow.value = {
    id: undefined,
    examItemName: undefined,
    examItemCode: undefined,
    examPartCode: undefined
  }
}
</script>

<style>
.container {
  display: flex;
  flex-direction: column;
  height: 800px; /* 使用视口高度确保撑满整个屏幕 */
  width: 1000px;
}

.top,
.bottom {
  flex-grow: 1; /* 使上下部分平分剩余空间 */
  background-color: #f0f0f0; /* 为了视觉效果 */
  padding: 10px;
}

.middle {
  height: 80px; /* 中间部分固定高度 */
  background-color: #fff; /* 为了视觉效果 */
  padding: 20px;
  display: flex;
  justify-content: center; /* 水平居中 */
  align-items: center; /* 垂直居中 */
}
</style>
