<template>
  <ai-list class="notice">
    <template slot="title">
      <ai-title title="禁言列表" isShowBack isShowBottomBorder @onBackClick="cancel"></ai-title>
    </template>
    <template slot="content">
      <ai-search-bar>
        <template #left>
        </template>
        <template #right>
          <el-input
            v-model="search.userName"
            class="search-input"
            size="small"
            v-throttle="() => {search.current = 1, getList()}"
            placeholder="请输入用户昵称"
            clearable
            @clear="search.current = 1, search.userName = '', getList()"
            suffix-icon="iconfont iconSearch">
          </el-input>
        </template>
      </ai-search-bar>
      <ai-table
        :tableData="tableData"
        :col-configs="colConfigs"
        :total="total"
        style="margin-top: 6px;"
        :current.sync="search.current"
        :size.sync="search.size"
        @getList="getList">
        <el-table-column slot="options" width="100px" fixed="right" label="操作" align="center">
          <template slot-scope="{ row }">
            <div class="table-options">
              <el-button type="text" @click="remove(row.userId)">解除禁言</el-button>
            </div>
          </template>
        </el-table-column>
      </ai-table>
    </template>
  </ai-list>
</template>

<script>
  export default {
    name: 'GagList',

    props: {
      instance: Function,
      dict: Object
    },

    data () {
      return {
        search: {
          current: 1,
          size: 10,
          userName: ''
        },
        total: 0,
        colConfigs: [
          { prop: 'userName',  label: '用户昵称', align: 'left' },
          { prop: 'areaName',  label: '所属地区', align: 'center' },
          { prop: 'createTime',  label: '被禁言时间', align: 'center' }
        ],
        tableData: []
      }
    },

    created() {
      this.getList()
    },

    methods: {
      getList() {
        this.instance.post(`/app/appneighborhoodassistance/blacklist`, null, {
          params: {
            ...this.search
          }
        }).then(res => {
          if (res.code == 0) {
            this.tableData = res.data.records
            this.total = res.data.total
          }
        })
      },

      remove (id) {
        this.$confirm('确定对该用户解除禁言？').then(() => {
          this.instance.post(`/app/appneighborhoodassistance/addBlacklist?userId=${id}`).then(res => {
            if (res.code == 0) {
              this.$message.success('解除成功！')
              this.getList()
            }
          })
        })
      },

      cancel () {
        this.$emit('change', {
          type: 'List',
          isRefresh: true
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
</style>
