<template>
  <div>
    <!-- 数据表格 -->
    <ele-pro-table
      ref="table"
      :columns="columns"
      :datasource="datasource"
      height="calc(100vh - 265px)"
      full-height="calc(100vh - 116px)"
      tool-class="ele-toolbar-form"
      cache-key="systemOrgUserTable"
    >
      <!-- 表头工具栏 -->
      <template v-slot:toolbar>
        <material-search @search="reload">
        </material-search>
      </template>
      <!-- 角色列 -->
      <template v-slot:roles="{ row }">
        <el-tag
          v-for="item in row.roles"
          :key="item.roleId"
          type="primary"
          size="mini"
          :disable-transitions="true"
        >
          {{ item.roleName }}
        </el-tag>
      </template>
      <!-- 状态列 -->
      <template v-slot:code="{ row }">
        <el-link
          @click="details(row)"
         >{{ row.code }}</el-link>
      </template>
    </ele-pro-table>
  </div>
</template>

<script>
  import MaterialSearch from './material-search.vue';
  import {
    getBoatList
  } from '@/api/ledgerAssets/boat.js';

  export default {
    components: { MaterialSearch },
    props: {
      // 类别id
      rootId: [Number, String],
    },
    data() {
      return {
        // 表格列配置
        columns: [
          {
            columnKey: 'index',
            type: 'index',
            label: '序号',
            width: 55,
            align: 'center',
            showOverflowTooltip: true,
            fixed: 'left'
          },
          {
            prop: 'code',
            label: '类别编码',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'name',
            label: '类别名称',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'brandNum',
            label: '牌号',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'categoryLevelPath',
            label: '分类',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'inUseSum',
            label: '在用',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'inLibrarySum',
            label: '在库',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'consumeSum',
            label: '消耗',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'totalSum',
            label: '总数量',
            showOverflowTooltip: true,
            minWidth: 110
          },
        ]
      };
    },
    methods: {
      /* 表格数据源 */
      datasource({ page, limit, where, order }) {
        return getBoatList({
          ...where,
          ...order,
          pageNum: page,
          size: limit,
          rootCategoryLevelId: this.rootId
        });
      },
      /* 刷新表格 */
      reload(where) {
        this.$refs.table.reload({ pageNum: 1, where: where });
      },

      // 跳转到详情页
      details ({ id }) {
        this.$router.push({
          path: '/ledgerAssets/material/detail',
          query: {
            id
          }
        })
      }
    },
    watch: {
      // 监听类别id变化
      rootId() {
        this.reload();
      }
    }
  };
</script>
