<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="68px"
    >
      <el-form-item :label="t('iotDevice.code')" prop="deviceCode" style="margin-left: 20px">
        <el-input
          v-model="queryParams.deviceCode"
          :placeholder="t('iotDevice.codeHolder')"
          clearable
          @keyup.enter="handleQuery"
          class="!w-200px"
        />
      </el-form-item>
      <el-form-item :label="t('iotDevice.name')" prop="deviceName">
        <el-input
          v-model="queryParams.deviceName"
          :placeholder="t('iotDevice.nameHolder')"
          clearable
          @keyup.enter="handleQuery"
          class="!w-200px"
        />
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" />
          {{ t('operationFill.search') }}</el-button>
        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> {{ t('operationFill.reset') }}</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="主键id" align="center" prop="id" />-->
      <el-table-column :label="t('iotDevice.serial')" width="70" align="center">
        <template #default="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="t('bomList.name')" align="center" prop="orderName" />
      <el-table-column :label="t('iotDevice.code')" align="center" prop="deviceCode" />
      <el-table-column :label="t('monitor.deviceName')" align="center" prop="deviceName" />
      <el-table-column :label="t('operationFill.status')" align="center" prop="ifNormal" />
<!--      <el-table-column :label="t('inspect.createName')" align="center" prop="createName" />-->
      <!--      <el-table-column :label="t('common.sort')" align="center" prop="sort" />-->
      <!--      <el-table-column :label="t('form.remark')" align="center" prop="remark" />-->

      <el-table-column
        :label="t('common.createTime')"
        align="center"
        prop="createTime"
        width="180px"
      />
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>

  <!-- 表单弹窗：添加/修改 -->
</template>

<script setup lang="ts">
import { IotInspectItemApi, IotInspectItemVO } from '@/api/pms/inspect/item'
import {IotInspectOrderApi} from "@/api/pms/inspect/order";

/** 巡检项 列表 */
defineOptions({ name: 'IotInspectOrderDetailStat' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化
const { params } = useRoute()
const loading = ref(true) // 列表的加载中
const list = ref<IotInspectItemVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const deptId= params.deptId;
const createTime = params.createTime;
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  status: undefined,
  deviceCode: undefined,
  deviceName: undefined,
  deptId: undefined,
  createTime: undefined,
})
const productClassifyList = ref<Tree[]>([]) // 树形结构
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await IotInspectOrderApi.getIotInspectDeviceStatusPage(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()
}

/** 初始化 **/
onMounted(async () => {
  debugger
  if (params.status) {
    queryParams.status = params.status
  }
  if(deptId != null){
    queryParams.deptId = deptId;
  }

  if(createTime){
    queryParams.createTime = createTime;
  }
  await getList()
})
</script>
