<template>
  <div ref="containerRef" class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="危化品名称" prop="hachName">
        <el-input v-model="queryParams.hachName" placeholder="请输入危化品名称" clearable style="width: 200px" @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="所属单位" prop="orgGuid">
        <el-input v-model="queryParams.orgGuid" placeholder="请输入所属单位" clearable style="width: 200px" @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['hazard:objhach:export']">导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :columns="columns" storageKey="hazard-chemsupervise-index"></right-toolbar>
    </el-row>

    <div class="table-wrapper">
    <el-table :height="tableHeight" v-loading="loading" :data="chemList">
      <el-table-column label="危化品名称" align="center" prop="hachName" v-if="columns.hachName.visible" :show-overflow-tooltip="true" />
      <el-table-column label="化学品名称" align="center" prop="chemName" v-if="columns.chemName.visible" :show-overflow-tooltip="true" />
      <el-table-column label="存放地点" align="center" prop="locName" v-if="columns.locName.visible" :show-overflow-tooltip="true" />
      <el-table-column label="储存包装" align="center" prop="storPack" v-if="columns.storPack.visible" />
      <el-table-column label="有毒物质数量" align="center" prop="toxicSubsNum" v-if="columns.toxicSubsNum.visible" />
      <el-table-column label="危险数量" align="center" prop="dangNum" v-if="columns.dangNum.visible" />
      <el-table-column label="当前库存" align="center" prop="currRese" v-if="columns.currRese.visible" />
      <el-table-column label="操作" align="center" width="100">
        <template #default="scope">
          <el-tooltip content="详情" placement="top">
            <el-button link type="primary" icon="View" @click="handleDetail(scope.row)"></el-button>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
    </div>

    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  </div>
</template>

<script setup name="ChemSupervise">
import { listObjHach } from "@/api/slaj/hazard"
import { useTableHeight } from '@/hooks/useTableHeight'

const { tableHeight, containerRef } = useTableHeight()

const { proxy } = getCurrentInstance()

const chemList = ref([])
const loading = ref(true)
const showSearch = ref(true)
const total = ref(0)

const columns = ref({
  hachName: { label: '危化品名称', visible: true },
  chemName: { label: '化学品名称', visible: true },
  locName: { label: '存放地点', visible: true },
  storPack: { label: '储存包装', visible: true },
  toxicSubsNum: { label: '有毒物质数量', visible: true },
  dangNum: { label: '危险数量', visible: true },
  currRese: { label: '当前库存', visible: true }
})

const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    hachName: undefined,
    orgGuid: undefined
  }
})

const { queryParams } = toRefs(data)

function getList() {
  loading.value = true
  listObjHach(queryParams.value).then(res => {
    loading.value = false
    chemList.value = res.rows
    total.value = res.total
  })
}

function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}

function resetQuery() {
  proxy.resetForm("queryRef")
  handleQuery()
}

function handleDetail(row) {
  proxy.$router.push({ path: '/slaj/hazard/chemDetail', query: { guid: row.guid } })
}

function handleExport() {
  proxy.download("hazard/objhach/export", {
    ...queryParams.value
  }, `chemSupervise_${new Date().getTime()}.xlsx`)
}

onMounted(() => {
  getList()
})
</script>
