Newer
Older
xc-business-system / src / views / equipement / info / book / components / equipmentFlowLog.vue
<!-- 设备台账信息详情 设备流转日志 -->
<script name="StandardBookEquipmentFlowLog" lang="ts" setup>
import type { Ref } from 'vue'
import { onMounted, ref } from 'vue'
import dayjs from 'dayjs'
import { ElLoading, ElMessage } from 'element-plus'
import type { IEquipmentFlowLog } from './book-interface'
import { getDictByCode } from '@/api/system/dict'
import { getEquipmentFlowLog } from '@/api/equipment/info/book'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import useUserStore from '@/store/modules/user'
import type { deptType, dictType } from '@/global'
const props = defineProps({
  equipmentNo: { // 设备编号
    type: String,
    require: true,
  },
})
// 查询条件
const listQuery = ref({
  equipmentNo: '', // 设备编号
  offset: 1,
  limit: 20,
})
const loadingTable = ref(false) // 表格loading
const user = useUserStore() // 用户信息
const list = ref<IEquipmentFlowLog[]>([]) // 表格数据
const columns = ref<TableColumn[]>([ // 表头
  { text: '记录编号', value: 'recordNo', align: 'center', width: '160' },
  { text: '记录名称', value: 'recordName', align: 'center' },
  { text: '记录部门', value: 'recordDept', align: 'center' },
  { text: '记录人', value: 'recordPerson', align: 'center' },
  { text: '记录时间', value: 'recordTime', align: 'center', width: '180' },
])

// -----------------------------------------方法--------------------------------------------------
// 数据查询
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  listQuery.value.equipmentNo = props.equipmentNo // 设备编号
  getEquipmentFlowLog(listQuery.value).then((response) => {
    list.value = response.data.rows.map((item: { estimateSignDate: string; agreementAmount: number; measureValidDate: string }) => {
      return {
        ...item,
        measureValidDate: item.measureValidDate ? dayjs(item.measureValidDate).format('YYYY-MM-DD') : item.measureValidDate,
      }
    })
    total.value = parseInt(response.data.total)
    loadingTable.value = false
  }).catch(() => {
    loadingTable.value = false
  })
}

// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
const changePage = (val: { size?: number; page?: number }) => {
  if (val && val.size) {
    listQuery.value.limit = val.size
  }
  if (val && val.page) {
    listQuery.value.offset = val.page
  }
  fetchData(true)
}
// -------------------------------------------钩子------------------------------------------------
onMounted(async () => {
  fetchData()
})
</script>

<template>
  <detail-block title="设备流转日志">
    <el-table
      v-loading="loadingTable"
      :data="list"
      border
      style="width: 100%;"
    >
      <el-table-column align="center" label="序号" width="80" type="index" />
      <el-table-column
        v-for="item in columns"
        :key="item.value"
        :prop="item.value"
        :label="item.text"
        :width="item.width"
        align="center"
      />
    </el-table>
  </detail-block>
</template>