<template>
  <Upload
    :action="info.form.action || ''"
    :name="info.form.name"
    :multiple="info.form.multiple"
    :format="(typeof info.form.fileType === 'string' ?
      info.form.fileType.split(',') : info.form.fileType)"
    :max-size="info.form.max"
    :disabled="info.form.disabled||!info.isNew"
    :on-success="onSuccess"
    :on-error="onError"
    :on-format-error="handleFormatError">
    <Button icon="ios-cloud-upload-outline">{{info.form.placeholder}}</Button>
    <div
      v-if="info.form.tips"
      style="font-size: 10px; color: #666;">
      只能上传不超过 {{info.form.max}}KB 的 {{info.form.format}} 文件!
    </div>
  </Upload>
</template>
<script>
import { baseComponentMixins } from '../mixins'

export default {
  name: 'BaseUpload',
  mixins: [ baseComponentMixins ],
  methods: {
    // 上传成功时的钩子
    onSuccess(rsp, file, fileList) {
      console.log(rsp, file, fileList)
    },
    // 上传失败时的钩子
    onError(err, file, fileList) {
      console.log(err, file, fileList)
    },
    // 上传格式有误
    handleFormatError(file) {
      console.log(file)
    },
  },
}
</script>