<template>
  <section class="pumList">
    <ai-list>
      <ai-title slot="title" title="经营主体" isShowBottomBorder isShowArea v-model="search.areaId" :instance="instance"
                @change="page.current=1,getTableData()"/>
      <template #content>
        <ai-search-bar>
          <template #left>
            <ai-select v-model="select.enterpriseType" @change="typeChange" placeholder="企业类型" :selectList="$dict.getDict('enterpriseType')"></ai-select>
            <ai-select v-model="select.enterpriseStatus" @change="statusChange" placeholder="认证状态" :selectList="$dict.getDict('userEnterpriseStatus')"></ai-select>
          </template>
          <template #right>
            <el-input size="small" placeholder="搜索企业名称、法人姓名、登录账号" v-model="search.enterpriseName" clearable
                      @change="page.current=1,getTableData()"/>
          </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="操作" fixed="right" align="center">
            <template slot-scope="{row}">
              <el-button type="text" @click="showDetail(row.id)">详情</el-button>
            </template>
          </el-table-column>
        </ai-table>
      </template>
    </ai-list>
  </section>
</template>

<script>
import {mapState} from "vuex";

export default {
  name: "pumList",
  props: {
    instance: Function,
    dict: Object,
    permissions: Function
  },
  computed: {
    ...mapState(['user'])
  },
  data() {
    return {
      search: {name: ""},
      page: {current: 1, size: 10, total: 0},
      select: {enterpriseType: '', enterpriseStatus: ''},
      tableData: [],
      colConfigs: [
        {label: "企业名称", prop: "enterpriseName"},
        {label: "企业类型", prop: "enterpriseType", dict: "enterpriseType"},
        {label: "所属区划", prop: "areaName"},
        {label: "法人姓名", prop: "legalPersonName"},
        {label: "联系方式", prop: "phone"},
        {label: "创建时间", prop: "createTime"},
        {label: "登录账号", prop: "loginAccount"},
        {slot: "options"},
      ]
    }
  },
  methods: {
    getTableData() {
      this.instance.post("/appportaluserenterprise/list", null, {
        params: {...this.page, ...this.search, status: 1,...this.select}
      }).then(res => {
        if (res?.data) {
          this.tableData = res.data?.records
          this.page.total = res.data.total
        }
      })
    },
    showDetail(id) {
      this.$router.push({query: {id}})
    },
    typeChange(v) {
      this.select.enterpriseType = v
      this.getTableData()
    },
    statusChange(v) {
      this.select.enterpriseStatus = v
      this.getTableData()
    }
  },
  created() {
    this.dict.load('userEnterpriseStatus')
    this.getTableData()
    this.search.areaId = this.user.info.areaId
  }
}
</script>

<style lang="scss" scoped>
.pumList {
}
</style>
