<template>
  <el-table :data="props.data.data"
            :height="windowSize.h / 1.4"
            highlight-current-row
            @row-click="dianJiaJianChaXiangQing">
    <el-table-column label="项目名称" prop="orderName" show-overflow-tooltip></el-table-column>
    <el-table-column label="接受" prop="receiveFlagName" show-overflow-tooltip></el-table-column>
    <el-table-column label="时间" prop="startTime">
      <template #default="{row}">
        {{ getFormatDatetime(row.startTime, 'YY-MM-DD HH:mm') }}
      </template>
    </el-table-column>
    <el-table-column label="操作" width="120">
      <template #default="scope">
        <el-button v-if="props.data.delFlag?false:true" icon="Delete" type="danger"
                   @click.stop="dianJiShanChu(scope.row, scope.$index)"> 删除
        </el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination
      :current-page="props.data.currentPage"
      :page-size="props.data.pageSize"
      :pager-count="7"
      :total="props.data.total"
      layout="total, prev, pager, next"
      @current-change="handleCurrentChange"/>
</template>

<script setup name='CheckApplicationHistory'>
import {computed} from "vue";
import store from "@/store";
import {shanChuJianChaJianYan} from "@/api/zhu-yuan-yi-sheng/jian-yan-jian-cha-shen-qing";
import {ElMessageBox} from "element-plus";
import {getFormatDatetime} from '@/utils/date'

const props = defineProps({
  data: Object,
  returnData: Function,
  currentChange: Function
})

const windowSize = computed(() => {
  return store.state.app.windowSize
})


const dianJiaJianChaXiangQing = (row) => {
  props.returnData(row)
}

const dianJiShanChu = (row, index) => {
  ElMessageBox.confirm(`您确定要删除【${row.orderName}】吗？`, '提示')
      .then(() => {
        shanChuJianChaJianYan(row.reqNo, row.inpatientNo, row.admissTimes).then((res) => {
          props.data.data.splice(index, 1)
        })
      })
      .catch(() => {
      })
}

const handleCurrentChange = (val) => {
  props.currentChange(val)
}

</script>

<style scoped lang="scss">

</style>
