<template>
  <cms-form-magnifier
    ref="commonMagnifierRef"
    width="50%"
    @searchMethod="search"
    @zoom="zoomModal"
    v-on="listeners"
    v-bind="$attrs"
    :destroy-on-close="true"
    :columns="columns"
    :query-params="queryParams"
    :disabled="disabled"
    :modal-title="magnifierTitle || $t('common-user.title')"
    :transfer="true" styles="width: 100%"
    :value="inputValue"
    :form-model="formModel"
    :multiple="multiple"
    :match-key="matchKey"
    :form-items="formItemConfig"
    :modal-width="modalWidth"
    :modal-height="modalHeight"
    :placeholder="placeholder"
    :height="height"
    :show-search-form="showSearchForm"
    :request-call="requestCall">
    <template v-for="(item, index) in formItemConfig" :slot="item.prop">
      <slot :name="item.prop"></slot>
    </template>
  </cms-form-magnifier>
</template>

<script>
import {
  dictionaryMix,
  formConfigMix,
  mixTableConfig,
  mixTableConstants,
  pageInitMix
} from "@/comps/mixin/common-mixins";

export default {
  name: "CmsCommonMagnifier",
  mixins: [ dictionaryMix, pageInitMix, formConfigMix, mixTableConfig, mixTableConstants ],
  data() {
    let { ...listeners } = this.$listeners;
    return {
      listeners: listeners,
    }
  },
  created() {

  },
  methods: {
    search: function () {
      this.$refs['commonMagnifierRef'].reload();
    },
    zoomModal({$modal, $event, type}) {
    },
  },
  props: {
    placeholder: String,
    dictionaryConfig: {
      type: Array,
      default: () => {
        return []
      }
    },
    formItemConfig: {
      type: Array,
      default: () => {
        return []
      }
    },
    /* 表格列 */
    columns: {
      type: Array,
      default: () => {
        return []
      }
    },
    magnifierTitle: {
      type: String,
      default: undefined
    },
    value: {
      type: [ Array, String, Number, Boolean ],
      default: () => {
        return "";
      },
    },
    matchKey: Object,
    multiple: {
      type: Boolean,
    },
    formModel: {
      type: Object,
      default: () => {
        return {}
      }
    },
    disabled: Boolean,
    /** 查询参数 */
    queryParams: {
      type: Object,
      default: () => {
        return {};
      },
    },
    modalWidth: { // modal 宽度
      type: [ String, Number ],
      default: () => {
        return '50%'
      }
    },
    modalHeight: { // modal 高度
      type: [ String, Number ],
      default: '50%'
    },
  },
  computed: {
    inputValue: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit("input", val);
      }
    },
  },
}
</script>

<style scoped>

</style>
