<template>
  <ai-list class="notice">
    <template slot="title">
      <ai-title title="审批负责人" isShowBottomBorder :isShowArea="true" v-model="search.areaId" :instance="instance" @change="getList"></ai-title>
    </template>
    <template slot="content">
      <ai-search-bar>
        <template #left>
          <el-button icon="iconfont iconAdd" type="primary" size="small" @click="toAdd('')">添加 </el-button>
        </template>
        <template #right>
          <el-input
            v-model="search.name"
            size="small"
            placeholder="审批负责人"
            clearable
            v-throttle="() => {search.current = 1, getList()}"
            @clear="search.current = 1, search.name = '', getList()"
            suffix-icon="iconfont iconSearch">
          </el-input>
        </template>
      </ai-search-bar>
      <ai-table
        :tableData="tableData"
        :col-configs="colConfigs"
        :total="total"
        style="margin-top: 12px;"
        :current.sync="search.current"
        :size.sync="search.size"
        @selection-change="(v) => (ids = v.map((e) => e.id))"
        @getList="getList">
        <el-table-column slot="options" width="90px" fixed="right" label="操作" align="center">
          <div class="table-options" slot-scope="{ row }">
            <el-button type="text" @click="toAdd(row.id)">编辑</el-button>
            <el-button type="text" @click="remove(row.id)">删除</el-button>
          </div>
        </el-table-column>
      </ai-table>
    </template>
  </ai-list>
</template>

<script>
  import { mapState } from 'vuex'
  export default {
    name: 'List',

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

    data() {
      return {
        search: {
          current: 1,
          size: 10,
          title: '',
          areaId: ''
        },
        ids: [],
        total: 10,
        tableData: []
      }
    },

    computed: {
      ...mapState(['user']),

      colConfigs () {
        return [
          { prop: 'title', label: '审批负责人', align: 'left' },
          { prop: 'createUserName', label: '所属地区', align: 'center' },
          { prop: 'createTime', label: '操作时间', align: 'center' },
          { prop: 'createTime', label: '操作人', align: 'center' },
          { slot: 'options', label: '操作' }
        ]
      }
    },

    created () {
      this.search.areaId = this.user.info.areaId
      this.dict.load('epidemicRecentTestResult').then(() => {
        this.getList()
      })
    },

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

      removeAll () {
        var id = this.ids.join(',')
        this.remove(id)
      },

      remove(id) {
        this.$confirm('确定删除该数据？').then(() => {
          this.instance.post(`/app/appmininotice/delete?ids=${id}`).then(res => {
            if (res.code == 0) {
              this.$message.success('删除成功！')
              this.getList()
            }
          })
        })
      },

      toDetail (id) {
        this.$emit('change', {
          type: 'Detail',
          params: {
            id: id || ''
          }
        })
      },

      toAdd(id) {
        this.$emit('change', {
          type: 'Add',
          params: {
            id: id || ''
          }
        })
      }
    }
  }
</script>

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