<!-- 业务看板 -->
<script lang="ts" setup name="BoardList">
import { reactive, ref } from 'vue'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import { exportListApi, getListPage } from '@/api/eqpt/measurementPlan/board'
import { exportFile } from '@/utils/exportUtils'
const { proxy } = getCurrentInstance() as any
const listQuery = reactive({
  deptName: '',
  offset: 1,
  limit: 20,
})
const columns = ref([
  {
    text: '部门',
    value: 'deptName',
    align: 'center',
  },
  {
    text: '设备总数',
    value: 'total',
    align: 'center',
  },
  {
    text: '本月到期设备',
    value: 'monthToExpire',
    align: 'center',
  },
  {
    text: '已超期设备',
    value: 'expired',
    align: 'center',
  },
  {
    text: '在检设备',
    value: 'inCheck',
    align: 'center',
  },
  {
    text: '年度应检数量',
    value: 'yearToCheck',
    align: 'center',
  },
  {
    text: '年度已检数量',
    value: 'yearChecked',
    align: 'center',
  },
  {
    text: '计量计划完成率',
    value: 'planFinishRate',
    align: 'center',
  },
])
const list = ref([])
const total = ref(0)
const listLoading = ref(true)

// 获取数据
const fetchData = (isNowPage = true) => {
  listLoading.value = true
  if (!isNowPage) {
    // 是否显示当前页，否则跳转第一页
    listQuery.offset = 1
  }
  // getListPage(listQuery).then((response) => {
  //   list.value = response.data
  listLoading.value = false
  // })
}
fetchData()
// 查询数据
const search = () => {
  fetchData(false)
}
// 重置
const reset = () => {
  listQuery.deptName = ''
  listQuery.offset = 1
  listQuery.limit = 20
  search()
}
// 导出列表
const exportList = () => {
  if (list.value.length) {
    const loading = ElLoading.service({
      lock: true,
      text: 'Loading',
      background: 'rgba(255, 255, 255, 0.8)',
    })
    exportListApi(listQuery).then((res) => {
      exportFile(res.data, '业务看板')
      loading.close()
    })
      .catch((_) => {
        loading.close()
      })
  }
  else {
    ElMessage.warning('无可导出内容')
  }
}
</script>

<template>
  <app-container>
    <!-- 筛选条件 -->
    <search-area :need-clear="true" @search="search" @clear="reset">
      <search-item>
        <el-input v-model.trim="listQuery.deptName" placeholder="部门" clearable />
      </search-item>
    </search-area>
    <table-container>
      <template #btns-right>
        <icon-button icon="icon-export" title="导出" @click="exportList" />
      </template>
      <!-- 普通表格 -->
      <normal-table
        :data="list" :total="total" :columns="columns" :query="listQuery" :list-loading="listLoading"
        :is-showmulti-select="false" :pagination=" false " :options="
          {
            needIndex: true, // 是否需要序号列
            border: true, // 是否需要上方边框
          }
        "
      >
        <template #preColumns>
          <el-table-column label="#" align="center" width="40">
            <template #default="props">
              {{ props.$index + 1 }}
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
  </app-container>
</template>

