<template>
  <view>
    <uv-upload 
      :accept="accept"
      :maxCount="1" 
      :width="width"
      :height="height"
      :previewImage="false"
      @afterRead="afterRead" 
      @delete="deleteFile"
    >
      <slot :value="value"></slot>
    </uv-upload>
  </view>
</template>


<script>
	export default {
    props: {
			value: {
				default: null
			},
      accept: {
        type: String,
        default: 'image' // all | media | image | file | video
      },
      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){
        this.$Oss.ossUpload(e.file.url).then(url => {
          this.fileList = [url]
          this.$emit('input', url)
        })
			},
    },
  }
</script>

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