﻿﻿﻿﻿﻿﻿﻿﻿<template>
  <a-table
    :row-selection="{
      selectedRowKeys: selectedRowKeys,
      onChange: handleSelectionChange,
    }"
    :columns="columns"
    :data-source="tableData"
    @change="handleCurrentChange"
    :loading="loading"
    rowKey="index"
    :pagination="{
      total,
      defaultPageSize: pageSize,
      showTotal: (total) => `共${total}条`,
    }"
    style="width: 100%;"
    :style="{ height: tableHeight + 'px' }"
    ref="dcryTable"
  >
    <template #bodyCell="{ column, record }">
      <template v-if="column.dataIndex === 'action'">
        <a v-if="ownPriv('manage')" @click="deleteHandler(record)">删除</a>
      </template>
    </template>
  </a-table>
</template>

<script>
import { h } from 'vue';
import request from '../../../../utils/gw_ajax_request';
export default {
  props: ['tableData', 'pageIndex', 'pageSize', 'total', 'loading'],
  data() {
    return {
      tableHeight: window.innerHeight - 280,
      selectedRowKeys: [],
      bisInspAllRlationParams: [],
      columns: [
        {
          title: '序号',
          dataIndex: 'index',
          align: 'center',
          ellipsis: true,
          customCell: () => {
            return {
              style: {
                'min-width': '50px',
              },
            };
          },
          customHeaderCell: () => {
            return {
              style: {
                'min-width': '50px',
              },
            };
          },
        },
        {
          title: '对象名称',
          dataIndex: 'nm',
          align: 'center',
          ellipsis: true,
          customCell: () => {
            return {
              style: {
                'min-width': '100px',
              },
            };
          },
          customHeaderCell: () => {
            return {
              style: {
                'min-width': '100px',
              },
            };
          },
        },
        {
          title: '行政区划',
          dataIndex: 'adName',
          align: 'center',
          ellipsis: true,
          customCell: () => {
            return {
              style: {
                'min-width': '100px',
              },
            };
          },
          customHeaderCell: () => {
            return {
              style: {
                'min-width': '100px',
              },
            };
          },
        },
        {
          title: '督查类别',
          dataIndex: 'type',
          align: 'center',
          ellipsis: true,
          customCell: () => {
            return {
              style: {
                'min-width': '100px',
              },
            };
          },
          customHeaderCell: () => {
            return {
              style: {
                'min-width': '100px',
              },
            };
          },
        },
        {
          title: '位置',
          dataIndex: 'loc',
          align: 'center',
          ellipsis: true,
          customCell: () => {
            return {
              style: {
                'min-width': '100px',
              },
            };
          },
          customHeaderCell: () => {
            return {
              style: {
                'min-width': '100px',
              },
            };
          },
        },
        {
          title: '所在分组',
          dataIndex: 'groupName',
          align: 'center',
          ellipsis: true,
          customCell: () => {
            return {
              style: {
                'min-width': '100px',
              },
            };
          },
          customHeaderCell: () => {
            return {
              style: {
                'min-width': '100px',
              },
            };
          },
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          customCell: () => {
            return {
              style: {
                'min-width': '140px',
              },
            };
          },
          customHeaderCell: () => {
            return {
              style: {
                'min-width': '140px',
              },
            };
          },
        },
      ],
    };
  },
  created() {
    this.getCommonDict();
  },
  methods: {
    getCommonDict() {
      request
        .get('/dict/type/by/gnrl')
        .then((res) => {
          if (res.success) {
            this.commonType = res.data;
            this.columns.forEach((item) => {
              if (item.title == '督查类别') {
                item.customRender = (value, row, index) => {
                  let name = '';
                  this.commonType.forEach((item) => {
                    if (item.dictTypeCd == row.type) {
                      name = item.dictTypeDesc;
                    }
                  });
                  return h('span', null, name);
                };
              }
            });
          } else {
            this.$message.error(res.message);
          }
        })
        .catch((res) => {
          this.$message.error('请求错误' + res.message);
        });
    },
    handleSelectionChange(val, row) {
      this.selectedRowKeys = val;
      this.bisInspAllRlationParams = [];
      row.forEach((item) => {
        this.bisInspAllRlationParams.push(item.objId);
      });
      this.$emit('deleteHandlerobj', this.bisInspAllRlationParams);
    },
    handleCurrentChange(item) {
      this.$emit('handleCurrentChange', item.current);
    },
    deleteHandler(row) {
      this.$emit('deleteHandler', row);
    },
  },
};
</script>

<style lang="less" scoped>
:deep(.ant-table-pagination) {
  float: left;
}
:deep(.ant-table-thead > tr > th),
:deep(.ant-table-tbody > tr > td) {
  padding: 0;
  height: 50px;
}
</style>
