<template>
  <div class="mainCss">
    <div class="pageRight_none">
      <div class="content">
        <a-form layout="inline" :style="{ display: 'flex', flexWrap: 'wrap', alignItems: 'flex-end', gap: '8px 24px' }">
          <a-form-item label="角色变更人员名称：" style="white-space: nowrap; flex-shrink: 0; margin-bottom: 0;">
            <a-input v-model="searchParam.executorIdsName"/>
          </a-form-item>
          <a-form-item label="现角色类型：" style="white-space: nowrap; flex-shrink: 0; margin-bottom: 0;">
            <a-input v-model="searchParam.newUserType"/>
          </a-form-item>
          <a-form-item label="消息类型：" style="white-space: nowrap; flex-shrink: 0; margin-bottom: 0;">
            <a-select
                style="width: 300px"
                v-model="workflowType"
                placeholder="请选择消息类型"
                allow-clear
                mode="tags">
              <a-select-option v-for="item in msgList" :key="item.value" :value="item.value">{{ item.label }}</a-select-option>
            </a-select>
          </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.dataIndex === 'action'">
              <a-button type="primary" size="small" @click="open(record)">开启</a-button>
            </template>
            <template v-else>
              <a-tooltip placement="topLeft" :title="text">{{ text }}</a-tooltip>
            </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 { getMsgShowList } 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: {
        executorIdsName: '',
        newUserType: '',
      },
      workflowType: [],
      msgList: [
        { label: '撤销', value: '撤销' },
        { label: '补发', value: '补发' },
      ],
      tableData: [],
      pageNum: 1,
      pageSize: 10,
      total: 0,
      isLoading: false,
      tableHeight: window.innerHeight - 260,
      columns: [
        {
          title: '序号',
          dataIndex: 'index',
          width: 50,
          align: 'center',
        },
        {
          title: '角色变更人员名称',
          dataIndex: 'executorIdsName',
          width: 200,
          align: 'center',
          customCell: () => {
            return {
              style: {
                maxWidth: '200px',
                overflow: 'hidden',
                whiteSpace: 'nowrap',
                textOverflow: 'ellipsis',
              },
            };
          },
        },
        {
          title: '原角色类型',
          dataIndex: 'beforUserType',
          width: 200,
          align: 'center',
          customCell: () => {
            return {
              style: {
                maxWidth: '200px',
                overflow: 'hidden',
                whiteSpace: 'nowrap',
                textOverflow: 'ellipsis',
              },
            };
          },
        },
        {
          title: '现角色类型',
          dataIndex: 'newUserType',
          width: 200,
          align: 'center',
          customCell: () => {
            return {
              style: {
                maxWidth: '100px',
                overflow: 'hidden',
                whiteSpace: 'nowrap',
                textOverflow: 'ellipsis',
              },
            };
          },
        },
        {
          title: '变更时间',
          dataIndex: 'changeTime',
          width: 100,
          align: 'center',
          customCell: () => {
            return {
              style: {
                maxWidth: '100px',
                overflow: 'hidden',
                whiteSpace: 'nowrap',
                textOverflow: 'ellipsis',
              },
            };
          },
        },
        {
          title: '业务待办消息标题',
          dataIndex: 'msgTitle',
          width: 200,
          align: 'center',
          customCell: () => {
            return {
              style: {
                maxWidth: '200px',
                overflow: 'hidden',
                whiteSpace: 'nowrap',
                textOverflow: 'ellipsis',
              },
            };
          },
        },
        {
          title: '撤销/补发',
          dataIndex: 'workflowType',
          width: 100,
          align: 'center',
          customCell: () => {
            return {
              style: {
                maxWidth: '80px',
                overflow: 'hidden',
                whiteSpace: 'nowrap',
                textOverflow: 'ellipsis',
              },
            };
          },
        },
        {
          title: '操作',
          dataIndex: 'action',
          width: 80,
          align: 'center',
        },
      ],
    };
  },
  computed: {
    userId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '';
    },
    hostUrl() {
      return hostUrl;
    },
    formatD() {
      return formatD;
    },
  },
  created() {},
  mounted() {
    this.search();
  },
  methods: {
    search() {
      this.pageNum = 1;
      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.searchParam.workflowType = this.workflowType.join(',');
      this.isLoading = true;
      getMsgShowList(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>
