<template>
  <ht-dialog
    :single="single"
    :data="data"
    :table-columns="tableColumns"
    :pagination="pagination"
    search-placeholder="名称或别名"
    :dialog-title="title"
    quick-search-props="name,alias"
    :destroy-on-close="destroyOnClose"
    @load="handleLoad"
    @onConfirm="onConfirm"
    ref="htDialog"
    :append-to-body="true"
  />
</template>

<script>
import portal from '@/api/portal.js'
export default {
  name: 'EipPortalDialog',
  props: {
    value: Array,
    name: String,
    single: Boolean,
    destroyOnClose: {
      type: Boolean,
      default: false,
    },
    defaultQuerys: {
      type: Array,
    },
    title: {
      type: String,
      default: '选择门户',
    },
  },
  data() {
    return {
      data: [],
      tableColumns: [
        {prop: 'name', label: '名称'},
        {prop: 'alias', label: '别名'},
      ],
      pagination: {
        page: 1,
        pageSize: 50,
        total: 0,
      },
    }
  },
  methods: {
    showDialog(data) {
      this.$refs.htDialog.showDialog(data)
    },
    handleLoad(param, cb) {
      param.querys = [...(this.defaultQuerys || []), ...(param.querys || [])]
      portal
        .getLayoutManagerPage(param)
        .then((data) => {
          this.data = data.rows
          this.pagination.page = data.page
          this.pagination.pageSize = data.pageSize
          this.pagination.total = data.total
          cb()
        })
        .catch((err) => {
          cb()
        })
    },
    onConfirm(selection) {
      this.$emit('onConfirm', selection, this.name)
      this.$emit('input', selection)
    },
  },
}
</script>

<style scoped></style>
