<template>
  <section class="List">
    <ai-list>
      <ai-title slot="title" title="公共事业欠费信息" isShowBottomBorder/>
      <template #content>
        <ai-search-bar>
          <template #left>
            <el-button type="primary" icon="iconfont iconAdd" @click="toAdd('')">添加</el-button>
          </template>
          <template #right>
            <el-input size="small" placeholder="欠费主体/统一信用社会代码" v-model="search.organizationName" clearable @clear="page.current = 1, search.organizationName = '',getTableData()" 
            suffix-icon="iconfont iconSearch" v-throttle="() => {(page.current = 1), getTableData();}"/>
            <ai-import :instance="instance" :dict="dict" importUrl="/appcreditpublicutilitiesarrears/import" url="/appcreditpublicutilitiesarrears/downloadTemplate" name="公共事业欠费信息" @success="getTableData(), $message.success('导入成功!')">
              <el-button size="small">导入</el-button>
            </ai-import>
            <ai-download :instance="instance" url="/appcreditpublicutilitiesarrears/export" :params="search" fileName="公共事业欠费信息"
                         :disabled="tableData.length == 0">
              <el-button size="small">导出</el-button>
            </ai-download>
          </template>
        </ai-search-bar>
        <ai-table :tableData="tableData" :total="page.total" :current.sync="page.current" :size.sync="page.size"
                  @getList="getTableData" :col-configs="colConfigs" :dict="dict">
          <el-table-column slot="options" label="操作"  align="center">
            <template slot-scope="{ row }">
              <el-button type="text" @click="toAdd(row.id)">详情</el-button>
              <el-button type="text" @click="handleDelete(row.id)">删除</el-button>
            </template>
          </el-table-column>
        </ai-table>
      </template>
    </ai-list>
  </section>
</template>

<script>
export default {
  name: "List",
  props: {
    instance: Function,
    dict: Object,
    permissions: Function
  },
  data() {
    return {
      search: {organizationName: ""},
      page: {current: 1, size: 10, total: 0},
      tableData: [],
    }
  },
  computed: {
    colConfigs() {
      return [
        { prop: "arrearsSubject", label: '欠费主体', align: "center", width: "180px", },
        { prop: "unifiedCode", label: '统一信用代码', align: "center", width: "180px", },
        { prop: "arrearsType", label: '欠费类型名称', align: "center", width: "180px", dict: 'arrearsType'},
        { prop: "arrearsAmount", label: '欠费金额（万元）', align: "center", width: "180px", },
        { prop: "dishonestySeverity", label: '失信严重程度', align: "center", width: "180px", dict:"dishonestySeverity"},
        { prop: "cognizanceDate", label: '认定日期', align: "center", width: "180px", },
        { prop: "createTime", label: '更新时间', align: "center", width: "180px", },
        { prop: "createUserName", label: '操作人', align: "center", width: "180px", },
        { slot: "options" ,},
      ]
    }
  },
  created() {
    this.$dict.load('arrearsType','dishonestySeverity')
    this.getTableData()
  },
  methods: {
    getTableData() {
      this.instance.post("/appcreditpublicutilitiesarrears/list", null, {
        params: {...this.page, ...this.search,...this.select}
      }).then(res => {
        if (res?.data) {
          this.tableData = res.data?.records
          this.page.total = res.data.total
        }
      })
    },
    toAdd(id) {
      this.$emit('change', {
        type: 'Add',
        params: {
          id: id || ''
        }
      })
    },
    handleDelete(id) {
      this.$confirm("是否要删除？").then(() => {
        this.instance.post(`/appcreditpublicutilitiesarrears/delete?ids=${id}`).then(res => {
            if (res.code == 0) {
              this.$message.success("删除成功")
              this.getTableData()
            }
          })
      })
    },
  }
}
</script>

<style lang="scss" scoped>
.List {
  height: 100%;
  background: #f3f4f5;
}
</style>