<template>
  <ht-dialog
    :single="single"
    :data="data"
    :table-columns="tableColumns"
    :pagination="pagination"
    search-placeholder="名称或编码"
    dialog-title="维度对话框"
    quick-search-props="name,code"
    @load="handleLoad"
    @onConfirm="onConfirm"
    ref="htDialog"
  />
</template>
<script>
import selector from "@/api/selector.js";

export default {
  name: "my-demension-dialog",
  props: {
    value: Array,
    name: String,
    single: Boolean
  },
  data() {
    return {
      data: [],
      tableColumns: [
        { prop: "name", label: "名称", width: "300" },
        { prop: "code", label: "编码" }
      ],
      pagination: {
        page: 1,
        pageSize: 50,
        total: 0
      }
    };
  },
  methods: {
    showDialog(selectors) {
      this.$refs.htDialog.showDialog(selectors);
    },
    handleLoad(param, cb) {
      selector
        .getDem(param)
        .then(response => {
          this.data = response.rows;
          this.pagination.page = response.page;
          this.pagination.pageSize = response.pageSize;
          this.pagination.total = response.total;
          cb();
        })
        .catch(err => {
          cb();
        });
    },
    onConfirm(selection) {
      this.$emit("onConfirm", selection);
      this.$emit("input", selection);
    }
  }
};
</script>
