<template>
  <div class="mainCss">
    <div class="pageRight_none">
      <div class="content">
        <a-form layout="inline" style="padding-left: 10px;">
          <a-form-item label="问题编号：" >
            <a-input v-model:value="searchParam.fileNoNumber"/>
          </a-form-item>
          <a-form-item label="记录生成时间：" >
            <a-month-picker v-model="searchParam.intmA" @change="handleChange" format="YYYY-MM" placeholder="选择年月" />
          </a-form-item>
          <a-form-item>
            <a-button type="primary" @click="search" style="margin-left: 10px">查询</a-button>
            <a-button type="primary" @click="exportExcel" style="margin-left: 10px">导出</a-button>
          </a-form-item>
        </a-form>
        <a-table
          :columns="columns"
          :data-source="tableData"
          :pagination="false"
          rowKey="index"
          :loading="isLoading"
          :style="{ height: tableHeight + 'px' }"
          :scroll="{ x: '100%', y: tableHeight - 100 }"
          bordered>
          <template #bodyCell="{ column, text }">
            <template v-if="column.slots?.customRender === 'tooltipCell'">
              <a-tooltip placement="topLeft" :title="text">
                <span>{{ text }}</span>
              </a-tooltip>
            </template>
            <template v-else>
              {{ text }}
            </template>
          </template>
        </a-table>
        <a-pagination
            show-size-changer
            v-model="pageNum"
            v-model:pageSize="pageSize"
            :total="total"
            :page-size-options="['5', '10', '20', '30', '40']"
            :show-total="total => `共${total}条`"
            @showSizeChange="handleSizeChange"
            @change="handleCurrentChange"/>
      </div>
    </div>
  </div>
</template>

<script>
import moment from 'moment/moment';
import { getCqzgjlList } from '@/api/slzj/slzj';
import { exportModel } from '@/utils/gw_exportModel';
import { hostUrl } from '../../utils/global_variable.js';
import { dateFormat, formatD } from '../../utils/gw_date';
export default {
  components: {},
  data() {
    return {
      searchParam: {
        fileNoNumber: '',
        intmA: '',
      },
      tableData: [],
      pageNum: 1,
      pageSize: 10,
      total: 0,
      isLoading: false,
      tableHeight: window.innerHeight - 260,
      columns: [
        {
          title: '问题编号',
          dataIndex: 'fileNoNumber',
          width: 100,
          align: 'center',
          slots: { customRender: 'tooltipCell' },
          customCell: () => {
            return {
              style: {
                maxWidth: '100px',
                overflow: 'hidden',
                whiteSpace: 'nowrap',
                textOverflow: 'ellipsis',
              },
            };
          },
        },
        {
          title: '工程名称',
          dataIndex: 'nm',
          width: 200,
          align: 'center',
          slots: { customRender: 'tooltipCell' },
          customCell: () => {
            return {
              style: {
                maxWidth: '200px',
                overflow: 'hidden',
                whiteSpace: 'nowrap',
                textOverflow: 'ellipsis',
              },
            };
          },
        },
        {
          title: '问题',
          dataIndex: 'inspPblmDesc',
          width: 200,
          align: 'center',
          slots: { customRender: 'tooltipCell' },
          customCell: () => {
            return {
              style: {
                maxWidth: '200px',
                overflow: 'hidden',
                whiteSpace: 'nowrap',
                textOverflow: 'ellipsis',
              },
            };
          },
        },
        {
          title: '地市',
          dataIndex: 'upAdName',
          width: 100,
          align: 'center',
          slots: { customRender: 'tooltipCell' },
          customCell: () => {
            return {
              style: {
                maxWidth: '100px',
                overflow: 'hidden',
                whiteSpace: 'nowrap',
                textOverflow: 'ellipsis',
              },
            };
          },
        },
        {
          title: '区县',
          dataIndex: 'adName',
          width: 100,
          align: 'center',
          slots: { customRender: 'tooltipCell' },
          customCell: () => {
            return {
              style: {
                maxWidth: '100px',
                overflow: 'hidden',
                whiteSpace: 'nowrap',
                textOverflow: 'ellipsis',
              },
            };
          },
        },
        {
          title: '记录生成时间',
          dataIndex: 'intm',
          width: 150,
          align: 'center',
          slots: { customRender: 'tooltipCell' },
          customCell: () => {
            return {
              style: {
                maxWidth: '150px',
                overflow: 'hidden',
                whiteSpace: 'nowrap',
                textOverflow: 'ellipsis',
              },
            };
          },
        },
        {
          title: '超期记录',
          dataIndex: 'zgNotes',
          width: 200,
          align: 'center',
          slots: { customRender: 'tooltipCell' },
          customCell: () => {
            return {
              style: {
                maxWidth: '200px',
                overflow: 'hidden',
                whiteSpace: 'nowrap',
                textOverflow: 'ellipsis',
              },
            };
          },
        },
      ],
    };
  },
  computed: {
    userId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '';
    },
    hostUrl() {
      return hostUrl;
    },
    formatD() {
      return formatD;
    },
  },
  created() {},
  mounted() {
    this.search();
  },
  methods: {
    async exportExcel() {
      const datas = JSON.stringify(this.searchParam);
      const url =
        '/modular-source/6ace62b8e2bb467d98286d260aebcef2/pdcApi/bis/insp/zg/pblm/getPblmRecordExport';
      const type = 'post';
      const exportName = '超期整改记录.xls';
      const result = await exportModel(type, url, exportName, datas);
    },
    search() {
      this.getList();
    },
    handleChange(e) {
      this.searchParam.intmA = e.format('YYYY-MM');
    },
    handleSizeChange(size, val) {
      this.pageSize = val;
      this.search();
    },
    handleCurrentChange(val) {
      this.pageNum = val;
      this.getList();
    },
    getList() {
      this.searchParam.pageNum = this.pageNum;
      this.searchParam.pageSize = this.pageSize;
      this.isLoading = true;
      getCqzgjlList(this.searchParam).then((res) => {
        this.isLoading = false;
        this.tableData = res.data.list;
        this.total = res.data.total;
        this.tableData.forEach((element, index) => {
          element['index'] = this.pageSize * (this.pageNum - 1) + index + 1;
          element['intm'] = element['intm']
            ? element['intm'].substring(0, 10)
            : '';
        });
      });
    },
    timestampToTime(val) {
      return dateFormat(val, 'yyyy-MM-dd');
    },
  },
};
</script>

<style lang='less' scoped>
:deep(.ant-table-pagination) {
  float: left;
}

:deep(.ant-layout-sider),
:deep(.ant-layout-content) {
  background: #fff;
}

:deep(.ant-table-thead>tr>th),
:deep(.ant-table-tbody>tr>td) {
  padding: 0;
  height: 60px;
  line-height: 60px;
}

:deep(.ant-table-scroll) {
  position: relative;
  z-index: 1;
}

:deep(.ant-table-fixed-left),
:deep(.ant-table-fixed-right) {
  z-index: 2;
}
.pageRight_none {
  width: calc(100% - 20px);
  margin-left: 10px;
}
.content {
  width: 100%;
}

:deep(.success-delete) {
  background: #ffa3a8 !important;
}

.mainCss {
  width: 100%;
  height: calc(100% - 20px);
  display: flex;
}
.pageLeft_none {
  display: none;
}

.pageRight {
  width: calc(100% - 330px);
  margin-left: 10px;
}

.custom_dialog .scroll300 {
  max-height: 60vh !important;
}
</style>
