<template>
  <div>
    <WebRtcCapture ref="webRtcCapture" :multiple="multiple" />
    <div style="height:5px" />
    <button class="btn btn-success" type="button" style="width:100%" @click="imageUpload">
      {{ $t('lang.webRtcImage.uploadImage') }}
    </button>
  </div>
</template>

<script>

import Common from '../common/Common.js';

import ImageService from '../resource/file/ImageService.js';
import FileService from '../resource/file/FileService.js';

import WebRtcCapture from '../widget/WebRtcCapture.vue';
import { Notify, Uuid } from 'pc-component-v3';

export default {

  components: {
    WebRtcCapture,
  },
  props: {
    /**
		 * 可以抓拍多张图片
		 */
    'multiple' : {
      type: Boolean,
      default: null,
    },
  },

  data: function () {
    return {
    };
  },
  methods: {
    /**
		 * 上传图片
		 */
    imageUpload: function () {
      var _self = this;

      var imageSrcs = _self.$refs.webRtcCapture.imageSrcs;
      if (imageSrcs && imageSrcs.length == 0) {
        Notify.error('提示', '没有图片',false);
        return;
      }

      if(_self.multiple == true){
        _self.$emit('uploadImage', imageSrcs);
      }else{
        var imageSrc = imageSrcs[0];
        _self.$emit('uploadImage', imageSrc);
      }
    },
  },
};

</script>

<style scoped>

</style>