<template>
  <div class="AppAdministrativeLicense">
    <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.enterpriseName" clearable
            @clear="page.current = 1, search.enterpriseName = '', getTableData()" suffix-icon="iconfont iconSearch"
            v-throttle="() => {(page.current = 1), getTableData();}"/>
          <ai-import :instance="instance" importUrl="/appcreditadminstrativelicense/import" url="/appcreditadminstrativelicense/downloadTemplate" type="appjob" name="行政许可信息" @success="getTableData(), $message.success('导入成功!')">
            <el-button size="small">导入</el-button>
          </ai-import>
          <ai-download :instance="instance" url="/appcreditadminstrativelicense/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" @selection-change="   (v) => (ids = v.filter((e) => e.sysUserId).map((e) => e.sysUserId)) ">
          <el-table-column slot="options" label="操作" fixed="right" align="center">
            <template slot-scope="{ row }">
              <el-button type="text" @click.native="toAdd(row.id)">详情</el-button>
              <el-button type="text" @click.native="handleDelete(row.id)">删除</el-button>
            </template>
          </el-table-column>
        </ai-table>
      </template>
    </ai-list>
  </div>
</template>

<script>
export default {
  name: "AppAdministrativeLicense",
  props: {
    instance: Function,
    dict: Object,
    permissions: Function
  },
  data() {
    return {
      search: { enterpriseName: "" },
      tableData: [],
      page: { current: 1, size: 10, total: 0 },
      dialog: false,
      form: { name: "" },
      data: {},
    };
  },
  computed: {
    colConfigs() {
      return [
        { label: "许可文书号", prop: "licenseCode", align: "center", width: "260px",},
        { label: "许可有效期至", prop: "endDate", align: "center", width: "200px",},
        { label: "许可机关", prop: "licenseOrganization", align: "center", width: "200px",},
        { label: "经营主体", prop: "enterpriseName", align: "center", width: "200px",},
        { label: "统一信用代码", prop: "unifiedCode", align: "center", width: "200px",},
        { label: "更新时间", prop: "createTime", align: "center", width: "160px",},
        { label: "操作人", prop: "createUserName", align: "center", width: "100px" },
        { slot: "options", },
      ];
    },
  },
  created() {
    this.getTableData()
  },
  methods: {
    // search() {
    //   this.forms.licenseCode = this.search.name
    //   this.getTableData()
    // },
    getTableData() {
      this.instance.post("/appcreditadminstrativelicense/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(`/appcreditadminstrativelicense/delete?ids=${id}`).then(res => {
            if (res.code == 0) {
              this.$message.success("删除成功")
              this.getTableData()
            }
          })
      })
    },
  },
};
</script>

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