<template>
  <cms-form-magnifier
    :destroy-on-close="true"
    ref="userMagnifierRef"
    :columns="columnConfig"
    :query-params="queryForm"
    :disabled="disabled"
    :magnifier-title="magnifierTitle || $t('common-user.title')"
    :transfer="true" styles="width: 100%"
    v-model="inputValue"
    :form-model="formModel"
    :multiple="multiple"
    :match-key="matchKey"
    :form-items="formItems"
    v-on="listeners"
    width="50%"
    @searchMethod="search"
    :placeholder="placeholder"
    :request-call="requestCall">
    <template slot="realName">
      <cms-form-input v-model="queryForm.realName" :placeholder="$t('common-user.user.prompt.realName')"/>
    </template>
    <template slot="account">
      <cms-form-input v-model="queryForm.account" :placeholder="$t('common-user.user.prompt.account')"/>
    </template>
    <template slot="userCode">
      <cms-form-input v-model="queryForm.email" :placeholder="$t('common-user.user.prompt.userCode')"/>
    </template>
  </cms-form-magnifier>
</template>

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

export default {
  name: "CmsUserMagnifier",
  mixins: [ dictionaryMix, pageInitMix, formConfigMix, mixTableConfig, mixTableConstants ],
  data() {
    let { ...listeners } = this.$listeners;
    return {
      listeners: listeners,
      queryForm: {
        realName: undefined,
        account: undefined,
        email: undefined,
      },
      // dictionaryConfig: [ {
      //   type: 'custom',
      //   keys:
      //     [ 'cfsAreaService.selectCountyList' ]
      // } ],
    }
  },
  created() {

  },
  methods: {
    search: function () {
      this.$refs['userMagnifierRef'].reload();
    }
  },
  props: {
    placeholder: String,
    dictionaryConfig: {
      type: Array,
      default: []
    },
    magnifierTitle: {
      type: String,
      default: undefined
    },
    value: [ Number, String, Boolean ],
    matchKey: Object,
    multiple: {
      type: Boolean,
      default: false,
    },
    formModel: {
      type: Object,
      default: () => {
        return {}
      }
    },
    disabled: Boolean,
    /** 查询参数 */
    queryParams: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  computed: {
    formItems() {
      return [
        {
          prop: 'userCode',
          label: this.$t('common-user.user.column.userCode'),
        },
        {
          prop: 'realName',
          label: this.$t('common-user.user.column.realName'),
        },
        {
          prop: 'account',
          label: this.$t('common-user.user.column.account'),
        },
      ]
    },
    inputValue: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit("input", val);
      }
    },
    columnConfig() {
      return [
        {
          ...mixTableConfig.seq,
        },
        {
          ...mixTableConfig.default,
          title: this.$t('common-user.user.column.userCode'),
          field: 'userCode',
          width: 200,
        },
        {
          ...mixTableConfig.default,
          title: this.$t('common-user.user.column.realName'),
          field: 'realName',
          minWidth: 160,
        }, {
          ...mixTableConfig.default,
          title: this.$t('common-user.user.column.account'),
          field: 'account',
          width: 160,
        }, {
          ...mixTableConfig.default,
          title: this.$t('common-user.user.column.email'),
          field: 'email',
          width: 160
        },
      ]
    }
  },

}
</script>

<style scoped>

</style>
