<template>

  <!-- 列表 -->
  <ContentWrap>
    <div class="tabs">
      <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
        <el-tab-pane 
         v-for="dict in getIntDictOptions(DICT_TYPE.AIR_COLLECTION_TYPE)"
          :key="dict.value"
          :label="dict.label" 
          :name="dict.value"
        >
        
        <el-form
          :model="queryParams"
          ref="queryFormRef"
          :inline="true"
          size="large"
          label-width="68px"
          label-position="right"
        >
        <el-form-item label="站点" prop="siteName">
          <el-input
            v-model="queryParams.siteName"
            placeholder="请输入站点名称"
            clearable
            @keyup.enter="handleQuery"
            class="!w-240px"
          />
        </el-form-item>
      
        <el-form-item label="时间" prop="createTime">
          <el-date-picker
            v-model="queryParams.createTime"
            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 >
          <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>
          <UploadExcel 
            v-model="fileUrls" 
            :file-type="['xlsx', 'xls']" 
            :file-size="1"
            class="mr-5px"
            :type="activeName"

          />
        </el-form-item>
       </el-form>

    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <template #empty>
        <el-empty description="暂无数据" />
      </template>
      <el-table-column label="站点名称" align="center" prop="siteName" />
      <el-table-column
        label="时间"
        align="center"
        prop="createTime"
        :formatter="dateFormatter"
        width="180px"
        :cell-style="{ borderBottom: '1px solid #EBEEF5' }"
        :header-cell-style="{
          borderBottom: '1px solid #EBEEF5',
          backgroundColor: '#F5F7FA'
        }"
      />
      <el-table-column label="数据类型" align="center" prop="type">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.AIR_COLLECTION_TYPE" :value="scope.row.type" />
        </template>
      </el-table-column>
      <el-table-column label="PM2.s(ugim3)" align="center" prop="pm25" />
      <el-table-column label="PMo(ug/m3)" align="center" prop="pm10" />
      <el-table-column label="sOz(ug/m3)" align="center" prop="so2" />
      <el-table-column label="NOz(ug/m3)" align="center" prop="no2" />
      <el-table-column label="NO(Hg/m3)" align="center" prop="no" />
      <el-table-column label="NOx(Hg/m3)" align="center" prop="nOx" />
      <el-table-column label="CO(mg/m3)" align="center" prop="co" />
      <el-table-column label="Oз(ug/m3)" align="center" prop="o3" />
      <!-- <el-table-column label="操作" align="center" min-width="120px">
        <template #default="scope">
          <el-button
            link
            type="primary"
            @click="openForm('update', scope.row.id)"
            v-hasPermi="['system:quality-collection:update']"
          >
            编辑
          </el-button>
          <el-button
            link
            type="danger"
            @click="handleDelete(scope.row.id)"
            v-hasPermi="['system:quality-collection:delete']"
          >
            删除
          </el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
      </el-tab-pane>
      </el-tabs>
    </div>
  </ContentWrap>

  <!-- 表单弹窗：添加/修改 -->
  <QualityCollectionForm ref="formRef" @success="getList" />
</template>

<script setup lang="ts">
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import { QualityCollectionApi, QualityCollectionVO } from '@/api/airqualitycollection'
import QualityCollectionForm from './QualityCollectionForm.vue'
const activeName = ref(1)
import { UploadExcel } from '@/components/UploadFile'


/** 空气质量采集 列表 */
defineOptions({ name: 'QualityCollection' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const loading = ref(true) // 列表的加载中
const list = ref<QualityCollectionVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  siteName: undefined,
  city: undefined,
  type: undefined,
  pm25: undefined,
  pm10: undefined,
  so2: undefined,
  no2: undefined,
  no: undefined,
  nOx: undefined,
  co: undefined,
  o3: undefined,
  remark: undefined,
  remark2: undefined,
  createTime: [],
})
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中

const fileUrls = ref()

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

const handleClick = (tab: TabsPaneContext, event: Event) => {
  console.log(tab.props, event)
}

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

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

/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
  formRef.value.open(type, id)
}

/** 删除按钮操作 */
const handleDelete = async (id: number) => {
  try {
    // 删除的二次确认
    await message.delConfirm()
    // 发起删除
    await QualityCollectionApi.deleteQualityCollection(id)
    message.success(t('common.delSuccess'))
    // 刷新列表
    await getList()
  } catch {}
}

/** 导出按钮操作 */
const handleExport = async () => {
  try {
    // 导出的二次确认
    await message.exportConfirm()
    // 发起导出
    exportLoading.value = true
    const data = await QualityCollectionApi.exportQualityCollection(queryParams)
    download.excel(data, '空气质量采集.xls')
  } catch {
  } finally {
    exportLoading.value = false
  }
}

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>
<style>
  .tabs {
    display: flex;
    flex-direction: column;

    ::v-deep(.el-form-item__label) {
      display: inline-flex;

    }

  }


  .demo-tabs > .el-tabs__content {
    color: #6b778c;
    font-size: 32px;
    font-weight: 600;
  }


</style>