<template>
  <ContentWrap>
<!--      <div v-loading="loading" style="height: 100%">-->
        <el-table :data="deviceStatuses" style="width: 100%">
          <el-table-column prop="deviceName" :label="t('iotDevice.name')"  />
          <el-table-column prop="deviceCode" :label="t('iotDevice.code')"  />
          <el-table-column prop="oldStatus" :label="t('deviceStatus.beforeStatus')" >
            <template #default="scope">
              <dict-tag :type="DICT_TYPE.PMS_DEVICE_STATUS" :value="scope.row.oldStatus" />
            </template>
          </el-table-column>
          <el-table-column prop="newStatus" :label="t('deviceStatus.afterStatus')"  >
            <template #default="scope">
              <dict-tag :type="DICT_TYPE.PMS_DEVICE_STATUS" :value="scope.row.newStatus" />
            </template>
          </el-table-column>
          <el-table-column prop="reason" :label="t('configDevice.reasonForAdjustment')"  />
          <el-table-column prop="creatorName" :label="t('deviceStatus.adjuster')"  />
          <el-table-column
            :label="t('deviceStatus.adjustTime')"
            align="center"
            prop="createTime"

            :formatter="dateFormatter"
          />
        </el-table>
        <!-- 分页 -->
        <Pagination
          :total="total"
          v-model:page="queryParams.pageNo"
          v-model:limit="queryParams.pageSize"
          @pagination="loadDeviceStatuses(props.deviceId)"
        />
<!--      </div>-->
  </ContentWrap>
</template>
<script setup lang="ts">
const { t } = useI18n() // 国际化
import { ref, watch, defineOptions, defineEmits } from 'vue'
import { ElMessage } from 'element-plus'
import * as IotDeviceStatusLogApi from '@/api/pms/iotdevicestatuslog'
import {dateFormatter} from "@/utils/formatTime";
import {DICT_TYPE} from "@/utils/dict";
const drawerVisible = ref<boolean>(false)
const emit = defineEmits(['update:modelValue', 'add', 'delete'])

defineOptions({
  name: 'DeviceStatusLogList'
})

const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  createTime: [],
  deviceId: '',
  name: '',
  code: ''
})

const loading = ref(false)
const total = ref(0) // 列表的总页数
const deviceStatuses = ref([])

const props = defineProps({
  deviceId: Number
})
// 加载设备的状态调整记录
const loadDeviceStatuses = async (deviceId) => {
  queryParams.deviceId = deviceId
  // queryParams.pageNo = 1
  try {
    loading.value = true
    // API调用
    const data = await IotDeviceStatusLogApi.IotDeviceStatusLogApi.getIotDeviceStatusLogPage(queryParams)
    deviceStatuses.value = data.list
    total.value = data.total
  } catch (error) {
    ElMessage.error('数据加载失败')
  } finally {
    loading.value = false
  }
}
onMounted(()=>{
  loadDeviceStatuses(props.deviceId)
})

</script>

<style lang="scss" scoped></style>
