<template>
  <a-table
    ref="table"
    size="middle"
    :scroll="{x:true}"
    bordered
    rowKey="id"
    :columns="columns"
    :dataSource="data"
    :pagination="ipagination"
    :loading="loading"
    class="j-table-force-nowrap"
    @change="handleTableChange">
  </a-table>
</template>
<script>
import { getAction } from '@api/manage'

export default {
  name: 'ReplacementInfo',
  data() {
    return {
      ipagination:{
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30'],
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条"
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      loading: false,
      data: [],
      columns: [
        {
          title: '#',
          dataIndex: '',
          key:'rowIndex',
          width:60,
          align:"center",
          customRender:function (t,r,index) {
            return parseInt(index)+1;
          }
        },
        {
          title:'工单',
          align:"center",
          dataIndex: 'workOrder'
        },
        {
          title:'序号',
          align:"center",
          dataIndex: 'seq'
        },
        {
          title:'物资编码',
          align:"center",
          dataIndex: 'materialCode'
        },
        {
          title:'物资描述',
          align:"center",
          dataIndex: 'materialDescription'
        },
        {
          title:'单位',
          align:"center",
          dataIndex: 'unit_dictText'
        },
        {
          title:'数量',
          align:"center",
          dataIndex: 'quantity'
        },
        {
          title:'时间',
          align:"center",
          dataIndex: 'createTime'
        }
      ],
      url: {
        list: '/workOrder/replacementRecords/list',
      },
    }
  },
  methods: {
    fetchData(deviceId) {
      this.loading = true
      // 加载换件信息数据
      getAction(this.url.list, {deviceId:deviceId}).then((res) => {
        if(res.success) {
          this.data = res.result.records;
        }
      }).finally(()=>{
        this.loading = false;
      });
    },
    handleTableChange(pagination, filters, sorter) {
      //分页、排序、筛选变化时触发
      console.log(pagination)
      // if (Object.keys(sorter).length > 0) {
      //   this.isorter.column = sorter.field;
      //   this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
      // }
      this.ipagination = pagination;
      this.fetchData();
    },
  }
}
</script>
