<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" @submit.native.prevent :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item  prop="noticeTitle">
                <el-input v-model="queryParams.noticeTitle" placeholder="请输入公告标题" clearable @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

            <Page uri="/system/notice/workbench/list" :request-params="queryParams" ref="pagination">
            <el-table-column label="序号" align="center" prop="noticeId" width="100" />
            <el-table-column label="公告标题" align="center" prop="noticeTitle" :show-overflow-tooltip="true" />
            <el-table-column label="公告类型" align="center" prop="noticeType" width="100">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.sys_notice_type" :value="scope.row.noticeType" />
                </template>
            </el-table-column>
            <el-table-column label="状态" align="center" prop="status" width="100">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.sys_notice_status" :value="scope.row.status" />
                </template>
            </el-table-column>
            <el-table-column label="发布者" align="center" prop="createBy" width="100" />
            <el-table-column label="创建时间" align="center" prop="createTime" width="100">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200px">
                <template slot-scope="scope">
                    <el-button type="text" icon="el-icon-edit" @click="openDetail(scope.row)">详情</el-button>
                </template>
            </el-table-column>
        </Page>

      
        <!-- 添加或修改公告对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                <el-row>
                    <el-col :span="24">
                        <p style="text-align: center; font-size: 25px">{{ form.noticeTitle }}</p>
                    </el-col>
                    <el-col :span="12">
                        <p style="text-align: right; width: 40%">发布者： {{ form.createBy }}</p>
                    </el-col>
                    <el-col :span="12">
                        <p style="text-align: right; width: 90%">发布时间： {{ form.createTime }}</p>
                    </el-col>
                    <el-col :span="24">
                        <div style="text-align: center; margin-left: 30px; margin-right: 30px" v-html="form.noticeContent"></div>
                    </el-col>
                </el-row>
            </el-form>
        </el-dialog>
    </div>
</template>

<script>
import { listWorkbenchNotice } from '@/api/system/notice'

export default {
    name: 'Notice',
    dicts: ['sys_notice_status', 'sys_notice_type'],
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 公告表格数据
            noticeList: [],
            // 弹出层标题
            title: '',
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                noticeTitle: undefined,
                createBy: undefined,
                status: undefined
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {}
        }
    },
    created() {
        this.getList()
    },
    methods: {
        /** 查询公告列表 */
        getList() {
            this.$nextTick(() => {
                this.$refs.pagination.handleSearch(true)
            })
        },
        // 表单重置
        reset() {
            this.form = {
                noticeId: undefined,
                noticeTitle: undefined,
                noticeType: undefined,
                noticeContent: undefined,
                status: '0'
            }
            this.resetForm('form')
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.getList()
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm('queryForm')
            this.handleQuery()
        },
        openDetail(row) {
            this.open = true
            this.form = row
        }
    }
}
</script>
