<template>
  <ht-demension
    v-model="value"
    :validate="validate"
    :name="name"
    select-label="name"
    :placeholder="placeholder"
    :permission="permission"
    :single="single"
    :config="config"
    :data="data"
    :table-columns="tableColumns"
    :pagination="pagination"
    quick-search-props="name,code"
    @load="handleLoad"
    @valueChange="valueChange"
  />
</template>
<script>
import selector from "@/api/selector.js";

export default {
  name: "my-demension",
  props: {
    validate: [String, Object],
    value: String,
    name: String,
    placeholder: String,
    permission: String,
    single: Boolean,
    config: Object
  },
  data() {
    return {
      data: [],
      tableColumns:[
        {prop:"name",label:"名称",width:"300"},
        {prop:"code",label:"编码"}
      ],
      pagination: {
        page: 1,
        pageSize: 50,
        total: 0
      }
    };
  },
  methods: {
    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();
        });
    },
    valueChange(value) {
      this.$emit("input", value);
    }
  }
};
</script>
