<template>
    <div class="app-container">
        <div class="page-container">
            <el-form :model="queryParams" :inline="true" label-width="80px">
                <el-form-item label="评论内容">
                    <el-input v-model="queryParams.momentContent" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="姓名">
                    <el-input v-model="queryParams.nickName" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item label="账号">
                    <el-input v-model="queryParams.userName" placeholder="请输入"></el-input>
                </el-form-item>
              <el-form-item label="动态编号">
                <el-input v-model="queryParams.momentId" placeholder="请输入"></el-input>
              </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="handleQuery">查询</el-button>
                    <el-button @click="handleReset">重置</el-button>
                </el-form-item>
            </el-form>
          <el-row class="mb10">
            <el-button type="primary" @click="handleExport">导出</el-button>
          </el-row>
            <el-table :data="tableList">
                <el-table-column label="评论内容" prop="content" align="center"></el-table-column>
                <el-table-column label="所属动态编号" align="center" prop="momentId" width="100"></el-table-column>
                <el-table-column label="动态内容" prop="momentContent" align="center" width="300" show-overflow-tooltip></el-table-column>
                <el-table-column label="账号" prop="userName" align="center"></el-table-column>
                <el-table-column label="姓名" prop="nickName" align="center"></el-table-column>
                <el-table-column label="创建时间" prop="createTime" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template #default="{ row }">
                        <el-button type="text" @click="handleDelete(row)">删除</el-button>
                        <el-button type="text" v-if="!row.isTop" @click="handleTop(row, 1)">置顶</el-button>
                        <el-button type="text" v-if="row.isTop == 1" @click="handleTop(row, 0)">取消置顶</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList" />
        </div>


    </div>
</template>

<script>
import { listData, delData, isTopData } from '@/api/comment';

export default {
    name: 'Sensitives',
    data() {
        return {
            queryParams: {
                pageNum: 1,
                pageSize: 10
            },
            tableList: [],
            total: 0
        }
    },
    created() {

    },
    mounted() {
        this.getList()
    },
    methods: {
        // 列表数据
        getList() {
            listData(this.queryParams).then(res => {
                console.log(res)
                this.tableList = res.rows;
                this.total = res.total
            })
        },
        // 删除
        handleDelete(row) {
            this.$modal.confirm('确认要删除评论内容为：' + row.content + '的数据吗？').then(function () {
                return delData(row.id);
            }).then(() => {
                this.$modal.msgSuccess("删除成功");
                this.getList()
            })
        },
        // 查询
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList()
        },
        // 重置
        handleReset() {
            this.queryParams = {
                pageNum: 1,
                pageSize: 10
            }
            this.getList()
        },
        handleExport() {
          this.download('bbs/moment/comment/list/export', {
            ...this.queryParams
          }, `动态评论_${new Date().getTime()}.xlsx`)
        },
        // 置顶/取消置顶
        handleTop(row, isTop) {
            let text = isTop == '0' ? '取消置顶' : '置顶'
            let data = {
                isTop,
                commentId: row.id
            }
            this.$modal.confirm(`确认要${text}评论内容为：${row.content}的数据吗？`).then(function () {
                return isTopData(data);
            }).then(() => {
                this.$modal.msgSuccess(text + "成功");
                this.getList()
            })
        }
    }
}
</script>

<style lang="scss" scoped>
.app-container {
    background-color: rgba(241, 242, 247, 1);
    height: calc(100vh - 50px);

    .page-container {
        background-color: white;
        height: 100%;
        border-radius: 6px;
        padding: 20px 30px;
        box-sizing: border-box;
        overflow: auto;
    }
}
</style>
