<template>
  <el-skeleton :loading="loading" animated>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="68px">
      <el-form-item label="标本ID" prop="infoId">
        <el-input
          v-model="queryParams.infoId"
          placeholder="标本ID"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="中文名称" prop="chineseName">
        <el-input
          v-model="queryParams.chineseName"
          placeholder="请输入中文名称"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="标本编号" prop="specimenNumber">
        <el-input
          v-model="queryParams.specimenNumber"
          placeholder="请输入标本编号"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="申请日期" prop="applicationDate">
        <el-date-picker
          v-model="queryParams.applicationDate"
          value-format="YYYY-MM-DD HH:mm:ss"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
          class="!w-220px"
        />
      </el-form-item>
<!--      <el-form-item label="审批状态" prop="status">-->
<!--        <el-select-->
<!--          v-model="queryParams.status"-->
<!--          placeholder="请选择审批状态"-->
<!--          clearable-->
<!--          class="!w-240px"-->
<!--        >-->
<!--          <el-option-->
<!--                     v-for="dict in getIntDictOptions(DICT_TYPE. MUSEUMS_APPROAL_STATUS)"-->
<!--                     :key="dict.value"-->
<!--                     :label="dict.label"-->
<!--                     :value="dict.value" />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-form-item  >
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>

        <el-button
          type="success"
          plain
          @click="handleExport"
          :loading="exportLoading"
          v-hasPermi="['museums:specimen-outbound:export']"
        >
          <Icon icon="ep:download" class="mr-5px" /> 导出
        </el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>

    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="申请人姓名" align="center" width="120px" prop="applicantName" />
      <el-table-column label="申请单位" align="center" width="120px" prop="applicationUsage" />
      <el-table-column label="研究项目名称" align="center" prop="projectName" />
      <el-table-column label="附件" align="center" prop="attachments" >
        <template #default="{ row }">
          <div v-if="row.attachments">
          <el-link
            type="primary"
            download
            :href="row.attachments"
            :underline="false"
            target="_blank"
          >下载</el-link
          >
          </div>
        </template>
      </el-table-column>

      <el-table-column
        label="申请日期"
        align="center"
        prop="createTime"
        :formatter="dateFormatter"
        width="180px"
      />
      <el-table-column
        label="项目开始时间"
        align="center"
        prop="startTime"
        :formatter="dateFormatter"
        width="180px"
      />
      <el-table-column label="审批状态" align="center" prop="sampleStatus" >
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.MUSEUMS_APPROAL_STATUS" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" min-width="150px">
        <template #default="scope" >
          <el-button
            link
            type="primary"
            @click="ApproalDetails(scope.row.id)"
          >
            查看
          </el-button>

        </template>
      </el-table-column>
    </el-table>
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
      />
   </ContentWrap>
<!--  <Approval ref="ApprovalRef" @success="getList" />-->
  </el-skeleton>
</template>


<script setup lang="ts">
// import Approval from "@/views/museums/specimenoutbound/approval.vue"
import download from '@/utils/download'
import { SpecimenOutboundApi, SpecimenOutboundVO } from '@/api/museums/specimenoutbound'
import {dateFormatter} from "@/utils/formatTime";
import {ref} from "vue";
import {DICT_TYPE, getIntDictOptions} from "@/utils/dict";

defineOptions({ name: 'ApproalProcess' })
const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const loading = ref(true) // 列表的加载中
const list = ref<SpecimenOutboundVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  infoId: undefined,
  chineseName: undefined,
  specimenNumber: undefined,
  applicantName: undefined,
  applicationDate: [],
  applicationUsage: undefined,
  attachments: undefined,
  status: [],
  remarks: undefined,
  processInstanceId: undefined,
  operator: undefined,
  outgoingTime: [],
  returner: undefined,
  receiver: undefined,
  returnDate: [],
  specimenCondition: undefined,
  createTime: [],
  sampleStatus: undefined,
  estimatedReturnTime: [],
  startTime:[],
})
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中

// /** 添加/修改操作 */
// const formRef = ref()
// const openForm = (type: string, id?: number) => {
//   formRef.value.open(type, id)
// }
/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await  SpecimenOutboundApi.getSpecimenOutboundPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

// /** 审批按钮操作 */
//
// // 检查用户权限的方法
// const ApprovalRef = ref()
// const handleApproval = ( id?: number) => {
//   ApprovalRef.value.open( id)
//
// }
/** 导出按钮操作 */
const handleExport = async () => {
  try {
    // 导出的二次确认
    await message.exportConfirm()
    // 发起导出
    exportLoading.value = true
    const data = await SpecimenOutboundApi.exportSpecimenOutbound(queryParams)
    download.excel(data, '标本出库回库信息.xls')
  } catch {
  } finally {
    exportLoading.value = false
  }
}

/** 查看出库入库申请审批详情页面 **/
import { useRouter } from 'vue-router';

const router = useRouter();
const ApproalDetails=(dataId: number) => {
  router.push({
    name: 'ApproalDetails',
    query: {
      dataId: dataId,
    }
  })
}


/** 初始化 **/
onMounted(() => {
  getList()
})

</script>
