<template>
    <el-card class="tjm_card_style_custom">
        <div class="tjm_card_table">
            <el-table v-loading="loading" row-key="id" header-cell-class-name="tjm_card_table_header" height="400" :data="tableData" border @row-click="table_detail">
                <el-table-column type="index" label="序号" width="55"></el-table-column>
                <el-table-column label="回复人" prop="createName" min-width="120" show-overflow-tooltip></el-table-column>
                <el-table-column label="回复内容" prop="messageContent" min-width="180" show-overflow-tooltip></el-table-column>
                <el-table-column label="回复日期" min-width="120" show-overflow-tooltip>
                    <template #default="scope">{{ scope.row.createTime.split(" ")[0] }}</template>
                </el-table-column>
                <el-table-column label="状态" width="120">
                    <template #default="scope">
                        <el-tag v-if="scope.row.isRead == 1" type="success">已读</el-tag>
                        <el-tag v-if="scope.row.isRead == 0" type="warning">未读</el-tag>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <div class="tjm_card_pagination">
            <yh-pagination v-model:pageNo="params.page" v-model:pageSize="params.size" :total="total" @paginationChange="reloadTable"></yh-pagination>
        </div>
    </el-card>
</template>

<script>
import mittBus from "@/utils/mittBus";
import { useUserStore } from "@/store/user";
import API from "@/api/policy/toDo";
import Msg from "@/api/policy/message";
import yhPagination from "@/components/Pagination/index.vue";

export default {
    components: {
        yhPagination
    },

    data() {
        return {
            loading: false,
            params: {
                page: 1,
                size: 10,
                createId: useUserStore().userInfo.id
            },

            total: 0,
            tableData: []
        }
    },

    mounted() {
        this.reloadTable();
    },

    methods: {
        reloadTable() {
            this.loading = true;
            API.msg(this.params).then(res => {
                this.loading = false;
                if (res.code === 200) {
                    this.tableData = res.data.records;
                    this.total = res.data.total;
                } else ElMessage.error(res.msg);
            }).catch(() => this.loading = false);
        },

        table_detail({ id, isRead, refId, policyName, policyDocNo }) {
            if (isRead == 0) Msg.edit({ id, isRead: 1 }).then(() => mittBus.emit("getMessage"));
            this.$emit("replyAll", { id: refId, name: policyName, docNo: policyDocNo });
        }
    }
}
</script>

<style lang="scss" scoped>
.tjm_card_style_custom {
  border: none;
  box-shadow: 0 0;

  :deep(.el-card__body) {
    padding-top: 10px;

    .tjm_card_table {
      margin-top: 0;
    }
  }
}
</style>