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

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

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

  },
  methods: {
    search: function () {
      this.$refs['cityMagnifierRef'].reload();
    },
    zoomModal({$modal, $event, type}) {
    },
  },
  props: {
    placeholder: String,
    dictionaryConfig: {
      type: Array,
      default: () => {
        return []
      }
    },
    magnifierTitle: {
      type: String,
    },
    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: {
    formItems() {
      return [
        {
          prop: 'provinceCode',
          label: this.$t('common-city.city.column.provinceCode'),
        },
        {
          prop: 'cityCode',
          label: this.$t('common-city.city.column.cityCode'),
        },
        {
          prop: 'areaCode',
          label: this.$t('common-city.city.column.areaCode'),
        },
      ]
    },
    inputValue: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit("input", val);
      }
    },
    columnConfig() {
      return [
        {
          ...mixTableConfig.seq,
          visible: !this.multiple,
        },
        {
          ...mixTableConfig.checkbox,
          visible: this.multiple,
        },
        {
          ...mixTableConfig.default,
          title: this.$t('common-city.city.column.provinceCode'),
          field: 'provinceCode',
          width: 90,
        },
        {
          ...mixTableConfig.default,
          title: this.$t('common-city.city.column.provinceName'),
          field: 'provinceName',
          width: 120,
        },
        {
          ...mixTableConfig.default,
          title: this.$t('common-city.city.column.cityCode'),
          field: 'cityCode',
          width: 90,
        },
        {
          ...mixTableConfig.default,
          title: this.$t('common-city.city.column.cityName'),
          field: 'cityName',
          width: 120,
        },
        {
          ...mixTableConfig.default,
          title: this.$t('common-city.city.column.areaCode'),
          field: 'areaCode',
          width: 90,
        },
        {
          ...mixTableConfig.default,
          title: this.$t('common-city.city.column.areaName'),
          field: 'areaName',
          width: 120,
        },
      ]
    }
  },

}
</script>

<style scoped>

</style>
