<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" size="small" label-width="100px">
      <el-form-item label="内容关键字" prop="noticeContent">
        <el-input v-model="queryParams.noticeContent" clearable style="width: 200px;" placeholder="请输入内容关键字"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleQuery">搜索</el-button>
        <el-button @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <h3 class="toolbar">
      <span class="title">列表</span>
    </h3>
    <el-table v-loading="loading" :data="list" border>
      <el-table-column label="通知类型" prop="noticeType" width="120" align="center" :formatter="noticeTypeFormat"/>
      <el-table-column label="通知标题" prop="noticeTitle" align="center"></el-table-column>
      <el-table-column label="内容" prop="noticeContent" align="left">
        <template slot-scope="scope" >
          <span class="content_msg"> {{scope.row.noticeContent}}</span> <el-button @click="handleView(scope.row)" type="text" size="small">查看详情</el-button>
         </template>
      </el-table-column>
      <el-table-column label="状态" prop="status" align="center" width="120" :formatter="statusFormat"/>
      <el-table-column label="发送时间" align="center" prop="createTime" width="160"></el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"/>
  </div>
</template>

<script>
  import {listMsgApi,noticeByIdApi} from "@/api/admin/msg/msg"
  import {entStateOptions, getLabel, authStateOptions} from '@/utils/dataFormat'
  export default {
    data () {
      return {
        loading: false,
        addTaxVisible: false,
        type: '',
        provinceDataList: [],
        cityDataList: [],
        districtDataList: [],
        msgTypeOptions: [], //通知类型
        statusOptions: [], //通知状态
        entStateOptions: entStateOptions,
        authStateOptions: authStateOptions,
        // 模板状态
        // statusOptions: accessStatus,
        dateRange: [],
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          noticeContent: ''
        },
        list: [],
        total: 0,
        open: false,
        openInfo: false,
      }
    },
    created() {
      this.getList()
      //通知类型
      this.getDicts("sys_notice_type").then(response => {
        this.msgTypeOptions = response.data;
      });
      //通知状态 sys_notice_status
      this.getDicts("msg_type").then(response => {
        this.statusOptions = response.data;
      });

    },
    methods: {
      getList() {
        this.loading = true;
        listMsgApi(this.queryParams).then(response => {
          this.list = response.data.records;
          this.total = response.data.total;
          this.loading = false;
        });
      },
      /** 查看 */
      handleView(row){
       const id = row.noticeId;
         noticeByIdApi(id).then(response => {
           this.$alert(response.data.noticeContent, "消息内容");
         });
         this.getList()
      },
      // 重置
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 搜索
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      noticeTypeFormat(row, col) {
        return this.selectDictLabel(this.msgTypeOptions, row.noticeType);
      },
      statusFormat(row, col) {
        return this.selectDictLabel(this.statusOptions, row.status)
      }
    }
  }
</script>

<style scoped>
  .content_msg{
   white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }
</style>
