<template>
  <div>
    <div class="table">
      <el-table border stripe :data="tableList" highlight-current-row>
        <el-table-column type="index" align="center" label="序号" width="50px" />
        <el-table-column prop="title" label="标题" align="center" />
        <el-table-column prop="publishTime" label="发布时间" align="center" />
        <el-table-column prop="publishUserName" label="发布人" align="center" />
        <el-table-column prop="publishOrgName" label="发布人所属单位" align="center" />
        <el-table-column prop="recvDetailsInfo" label="接收人" align="center" />
        <el-table-column prop="operation" label="操作" align="center" width="200px" fixed="right">
          <template slot-scope="scope">
            <el-button size="mini" @click="handleEdit(scope.row)">修改</el-button>
            <el-button size="mini" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination-container">
          <el-pagination
            class="right"
            :current-page.sync="listQuery.page"
            :page-size="listQuery.limit"
            :page-sizes="[10,20,30,40]"
            :total="total"
            @size-change="sizeChange"
            @current-change="pageChange"
            layout="total, sizes, prev, pager, next, jumper"
          ></el-pagination>
        </div>
    </div>
  </div>
</template>
<script>
import { getDraftList,deleteFun,enableWarn,stopWarn,getAllRole,getDepotAll,getDepotById } from '@/api/system/notice'
export default {
  name: "NewNotice",
  data() {
    return {
      // 列表数据
      tableList: [],
      query: {
        title:''
      },
      // 分页
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 10,
      },
      roleList:[],
      depotIdList:[]
    }
  },
  created() {
    this.getRoleList()
    this.getDepotList()
    this.getList()
  },
  methods: {
    getRoleList() {
      getAllRole().then(res => {
        this.roleList = res.data
      })
    },
    getDepotList() {
      let depotId = ''
      getDepotAll(depotId).then(res => {
        this.depotIdList = res.data
      })
    },
    getList() {
      let condition = {
        title: this.query.title,
      }
      let data = {
        pageIndex: this.listQuery.page,
        pageSize: this.listQuery.limit,
        condition: JSON.stringify(condition)
      }
      getDraftList(data).then((res) => {
          if (res.code == 200) {
            this.tableList = res.data.records
            this.listQuery.limit = res.data.size
            this.total = res.data.total
          }
      }).catch((err) => {
          console.log(err)
        })
    },
    search() {
      this.getList()
    },
    clear() {
      this.query = {
        title:''
      }
    },
    sizeChange(v) {
      this.listQuery.limit = v;
      this.getList();
    },
    pageChange(v) {
      this.listQuery.page = v;
      this.getList();
    },
    // 新增按钮
    addBtn(type) {
      this.$router.push({ path: "/notice/addnotice",query: { state: 'add',orgType: type } })
    },
    // 查看
    handleDetail(row) {
      this.$router.push({ path: "/notice/addnotice",query: { state: 'edit',id: row.id }})
    },
    // 编辑
    handleEdit(row) {
      this.$router.push({ path: "/notice/addnotice",query: { state: 'edit',id: row.id }})
    },
    // 删除
    handleDelete(row) {
      this.$confirm('确定删除该项记录?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
          deleteFun(row.id).then((res) => {
            if (res.code == 200) {
              this.getList()
              this.$message({
                type: 'success',
                message: '删除成功!'
              })
            }
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除'
            })
          })
        })
    },
  }
}
</script>
<style scoped>
.header_button {
  margin-bottom: 5px;
}
.pagination-container {
  margin-top:10px;
  margin-right:20px;
  text-align: right;
}
</style>
