<template>
  <div class="mainCss">
    <div class="pageRight_none">
      <div class="content">
        <a-form layout="inline" style="display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 24px; padding-left: 10px;">
          <a-form-item label="问题编号：" style="white-space: nowrap; flex-shrink: 0; margin-bottom: 0;">
            <a-input v-model="searchParam.fileNoNumber"/>
          </a-form-item>
          <a-form-item label="记录生成时间：" style="white-space: nowrap; flex-shrink: 0; margin-bottom: 0;">
            <a-month-picker v-model="searchParam.intmA" @change="handleChange" format="YYYY-MM" placeholder="选择年月" />
          </a-form-item>
          <a-form-item style="margin-bottom: 0;">
            <a-button type="primary" @click="search" 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, record, text, index }">
              <template v-if="column.slots?.customRender === 'fileNoNumberTooltip'">
                <a-tooltip placement="topLeft" :title="text">{{ text }}</a-tooltip>
              </template>
              <template v-else-if="column.slots?.customRender === 'nmTooltip'">
                <a-tooltip placement="topLeft" :title="text">{{ text }}</a-tooltip>
              </template>
              <template v-else-if="column.slots?.customRender === 'inspPblmDescTooltip'">
                <a-tooltip placement="topLeft" :title="text">{{ text }}</a-tooltip>
              </template>
              <template v-else-if="column.slots?.customRender === 'upAdNameTooltip'">
                <a-tooltip placement="topLeft" :title="text">{{ text }}</a-tooltip>
              </template>
              <template v-else-if="column.slots?.customRender === 'adNameTooltip'">
                <a-tooltip placement="topLeft" :title="text">{{ text }}</a-tooltip>
              </template>
              <template v-else-if="column.slots?.customRender === 'zgNotesTooltip'">
                <a-tooltip placement="topLeft" :title="text">{{ text }}</a-tooltip>
              </template>
              <template v-else-if="column.slots?.customRender === 'auditPersNameTooltip'">
                <a-tooltip placement="topLeft" :title="text">{{ text }}</a-tooltip>
              </template>
              <template v-else-if="column.slots?.customRender === 'adjustRcordTooltip'">
                <a-tooltip placement="topLeft" :title="text">{{ text }}</a-tooltip>
              </template>
              <template v-else-if="column.slots?.customRender === 'action'">
                <a-button type="primary" size="small" @click="open(record)">开启</a-button>
              </template>
              <template v-else>
                {{ text }}
              </template>
            </template>
        </a-table>
        <a-pagination
            show-size-changer
            v-model:current="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 { getHandOpen } from '@/api/slzj/slzj';
import request from '@/utils/gw_ajax_request';
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: 'fileNoNumberTooltip' },
          customCell: () => {
            return {
              style: {
                maxWidth: '100px',
                overflow: 'hidden',
                whiteSpace: 'nowrap',
                textOverflow: 'ellipsis',
              },
            };
          },
        },
        {
          title: '工程名称',
          dataIndex: 'nm',
          width: 200,
          align: 'center',
          slots: { customRender: 'nmTooltip' },
          customCell: () => {
            return {
              style: {
                maxWidth: '200px',
                overflow: 'hidden',
                whiteSpace: 'nowrap',
                textOverflow: 'ellipsis',
              },
            };
          },
        },
        {
          title: '问题',
          dataIndex: 'inspPblmDesc',
          width: 200,
          align: 'center',
          slots: { customRender: 'inspPblmDescTooltip' },
          customCell: () => {
            return {
              style: {
                maxWidth: '200px',
                overflow: 'hidden',
                whiteSpace: 'nowrap',
                textOverflow: 'ellipsis',
              },
            };
          },
        },
        {
          title: '地市',
          dataIndex: 'upAdName',
          width: 100,
          align: 'center',
          slots: { customRender: 'upAdNameTooltip' },
          customCell: () => {
            return {
              style: {
                maxWidth: '100px',
                overflow: 'hidden',
                whiteSpace: 'nowrap',
                textOverflow: 'ellipsis',
              },
            };
          },
        },
        {
          title: '区县',
          dataIndex: 'adName',
          width: 100,
          align: 'center',
          slots: { customRender: 'adNameTooltip' },
          customCell: () => {
            return {
              style: {
                maxWidth: '100px',
                overflow: 'hidden',
                whiteSpace: 'nowrap',
                textOverflow: 'ellipsis',
              },
            };
          },
        },
        {
          title: '超期整改记录',
          dataIndex: 'zgNotes',
          width: 200,
          align: 'center',
          slots: { customRender: 'zgNotesTooltip' },
          customCell: () => {
            return {
              style: {
                maxWidth: '200px',
                overflow: 'hidden',
                whiteSpace: 'nowrap',
                textOverflow: 'ellipsis',
              },
            };
          },
        },
        {
          title: '退回人',
          dataIndex: 'auditPersName',
          width: 80,
          align: 'center',
          slots: { customRender: 'auditPersNameTooltip' },
          customCell: () => {
            return {
              style: {
                maxWidth: '80px',
                overflow: 'hidden',
                whiteSpace: 'nowrap',
                textOverflow: 'ellipsis',
              },
            };
          },
        },
        {
          title: '退回原因',
          dataIndex: 'adjustRcord',
          width: 150,
          align: 'center',
          slots: { customRender: 'adjustRcordTooltip' },
          customCell: () => {
            return {
              style: {
                maxWidth: '150px',
                overflow: 'hidden',
                whiteSpace: 'nowrap',
                textOverflow: 'ellipsis',
              },
            };
          },
        },
        {
          title: '操作',
          width: 100,
          slots: { customRender: 'action' },
          align: 'center',
        },
      ],
    };
  },
  computed: {
    userId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '';
    },
    hostUrl() {
      return hostUrl;
    },
    formatD() {
      return formatD;
    },
  },
  created() {},
  mounted() {
    this.search();
  },
  methods: {
    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();
    },
    open(row) {
      this.$confirm({
        title: '提示',
        content: '确定要关闭吗, 是否继续?',
        okType: 'warning',
        onOk: () => {
          request
            .post(`/bis/insp/BisInspZgPblmRecord/openOrCloseChannel`, {
              id: row.id,
            })
            .then((res) => {
              if (res.success) {
                this.$message.success('修改成功');
                this.getList();
              }
            });
        },
      });
    },
    getList() {
      this.searchParam.pageNum = this.pageNum;
      this.searchParam.pageSize = this.pageSize;
      this.isLoading = true;
      getHandOpen(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;
        });
      });
    },
    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>
