<template>
  <div class="ele-body">
    <el-card shadow="never">
      <!-- 条件区 -->
      <search @search="reload"/>
      <ele-pro-table ref="table" :columns="columns" :datasource="datasource">
        <!-- 操作列 -->
        <template v-slot:action="{ row }">

          <el-link
            type="primary"
            :underline="false"
            icon="el-icon-view"
            @click="handleAddOrEdit('view',row)"
          >
            详情
          </el-link>
        </template>
        <template v-slot:readStatus="{row}">
          <el-tag v-if="row.readStatus" type="success">{{ '已读' }}</el-tag>
          <el-tag v-else type="danger">{{ '未读' }}</el-tag>

        </template>
      </ele-pro-table>
    </el-card>
    <!--新增、修改-->
    <add-or-edit-dialog v-if="addOrEditDialogFlag" :addOrEditDialogFlag.sync="addOrEditDialogFlag"
                        ref="addOrEditDialogRef" @done="reload"></add-or-edit-dialog>
  </div>
</template>
<script>

import search from './index-search.vue';
import addOrEditDialog from "@/views/notifyManage/templateManage/components/addOrEditDialog.vue";
import {notifyMessagePageAPI} from "@/api/notifyRecord";

export default {
  components: {addOrEditDialog, search},
  data() {
    return {
      addOrEditDialogFlag: false,
      columns: [
        {
          columnKey: 'index',
          label: '序号',
          type: 'index',
          width: 55,
          align: 'center',
          showOverflowTooltip: true,
          fixed: 'left'
        },
        {
          prop: 'templateContent',
          label: '消息',
          minWidth: '150',
        },
        {
          prop: 'templateCode',
          label: '模板编码',
          minWidth: '120',
          align: "center",
        },
        {
          prop: 'userName',
          label: '接收人',
          minWidth: '60',
          align: "center",
        },
        {
          prop: 'readStatus',
          label: '状态',
          width: '90',
          slot:'readStatus',
          align: "center",

        },
        {
          prop: 'readTime',
          label: '阅读时间',
          width: '170',
          align: "center",
          showOverflowTooltip: true,
        },
        {
          prop: 'templateNickname',
          label: '发送人',
          width: '100',
          align: "center",
        },
        {
          prop: 'createTime',
          label: '创建时间',
          width: '170',
          align: "center",
          showOverflowTooltip: true,
        },
        // {
        //   columnKey: 'action',
        //   label: '操作',
        //   width: 100,
        //   align: 'center',
        //   slot: 'action',
        //   fixed: 'right'
        // }
      ],
      searchForm: {},
      tableData: [],
      size: 10,
      page: 1,
      total: 0
    };
  },
  methods: {
    //新增或修改模板
    handleAddOrEdit(type, row) {
      this.addOrEditDialogFlag = true
      this.$nextTick(() => {
        this.$refs.addOrEditDialogRef.init(type, row)
      })
    },
    reload(params) {
      this.$refs.table.reload({pageNum: 1, where: params});
    },
    datasource({page, where, limit,...row}) {
      return notifyMessagePageAPI({
        ...where,
        pageNum: page,
        size: limit
      });
    },
    reset() {
    },
  }
};
</script>
<style lang="scss" scoped>
.app-container {
  background: #f0f3f3;
  min-height: calc(100vh - 84px);
}

.zw-page-table {
  background: #ffffff;
  padding-top: 20px;
}

.pagination-wrap {
  display: flex;
  justify-content: flex-end;
  padding: 10px 0;
}

.table {
  width: 100%;
  margin-top: 10px;
}
</style>
