<template>
  <ContentWrap>
<!--    <div v-loading="loading" style="height: 1000px">-->
      <el-table :data="deviceAllots" style="width: 100%">
        <el-table-column prop="deviceName" label="设备名称" />
        <el-table-column prop="deviceCode" label="设备编码" />
        <el-table-column prop="oldDeptName" label="调整前部门" />
        <el-table-column prop="newDeptName" label="调用后部门" />
        <el-table-column prop="reason" label="调拨原因" />
        <el-table-column prop="creatorName" label="调整人" />
        <el-table-column
          label="调整时间"
          align="center"
          prop="createTime"
          :formatter="dateFormatter"
        />
      </el-table>
      <!-- 分页 -->
      <Pagination
        :total="total"
        v-model:page="queryParams.pageNo"
        v-model:limit="queryParams.pageSize"
        @pagination="loadDeviceAllots(props.deviceId)"
      />
<!--    </div>-->
  </ContentWrap>
</template>
<script setup lang="ts">
import { defineEmits, defineOptions, ref } from 'vue'
import { ElMessage } from 'element-plus'
import { dateFormatter } from '@/utils/formatTime'
import { IotDeviceAllotLogApi } from '@/api/pms/iotdeviceallotlog'

const drawerVisible = ref<boolean>(false)
const emit = defineEmits(['update:modelValue', 'add', 'delete'])

defineOptions({
  name: 'DeviceAllotLogList'
})

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

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

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

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