<template>
  <view>
    <uv-upload 
      :fileList="fileList" 
      :multiple="multiple"
      :maxCount="maxCount" 
      :width="width"
      :height="height"
      @afterRead="afterRead" 
      @delete="deleteFile"
    >
      <slot :value="value"></slot>
    </uv-upload>
  </view>
</template>


<script>
	export default {
    props: {
			value: {
				default: null
			},
      multiple: {
        type: Boolean,
        default: false,
      },
      maxCount: {
        type: Number,
        default: 1,
      },
      width: {
        type: Number | String,
        default: null,
      },
      height: {
        type: Number | String,
        default: null,
      },
    },
		data() {
      return {
        fileList: [],
      }
    },
    methods: {
			deleteFile(){
				this.fileList = []
        this.$emit('input', null)
			},
			afterRead(e){
				let self = this

				e.file.forEach(file => {
					self.$Oss.ossUpload(file.url).then(url => {
						self.fileList = [url]
            self.$emit('input', url)
					})
				})
			},
    },
  }
</script>

<style scoped lang="scss">
</style>