<template>
  <div>
    <a-form-item label="提示文字">
      <a-input
        v-model="localValue.placeholder"
        size="small"
        placeholder="请设置提示语"
      />
    </a-form-item>

    <a-form-item label="数量限制">
      <!-- <a-tooltip title="限制最大上传图片数量（为0则不限制）"><span slot="label">数量限制</span></a-tooltip> -->
      <a-input-number
        v-model="localValue.maxNumber"
        class="max-fill"
        :min="0"
        :precision="0"
        :controls="true"
        size="small"
        placeholder="最多上传几张图片"
        style="width: 100%"
      />
    </a-form-item>

    <a-form-item label="大小限制">
      <!-- <a-tooltip title="限制单个文件最大大小-MB（为0则不限制）"><span slot="label">大小限制</span></a-tooltip> -->
      <a-input-number
        v-model="localValue.maxSize"
        class="max-fill"
        :min="0"
        :precision="1"
        :controls="true"
        size="small"
        placeholder="单个文件最大大小"
        style="width: 100%"
      />
    </a-form-item>

    <a-form-item label="类型限制">
      <!-- <a-tooltip title="限制上传文件的后缀类型"><span slot="label">类型限制</span></a-tooltip> -->
      <a-select
        v-model="localValue.fileTypes"
        mode="tags"
        allowClear
        placeholder="允许上传文件的后缀格式，可设置多种"
        style="width: 100%"
      />
    </a-form-item>

    <a-form-item label="不可下载">
      <a-switch v-model="localValue.onlyRead" />
    </a-form-item>
  </div>
</template>

<script>
export default {
  name: 'FileUploadConfig',
  props: {
    value: {
      type: Object,
      default: () => ({
        placeholder: '',
        maxNumber: null,
        maxSize: null,
        fileTypes: [],
        onlyRead: false
      })
    }
  },
  data() {
    return {
      localValue: { ...this.value }
    };
  },
  watch: {
    localValue: {
      handler(newVal) {
        this.$emit('input', newVal);
      },
      deep: true
    },
    value: {
      handler(newVal) {
        this.localValue = { ...newVal };
      },
      deep: true
    }
  }
};
</script>

<style scoped>
.max-fill {
  width: 100%;
}
</style>
