<template>
  <BaseSameLayer
    ref="mideaCameraViewRef"
    :hosSameLayerArgs="hosSameLayerArgs"
    embedType="native/midea-camera-view"
    :defaultWidth="500"
    :defaultHeight="600"
  ></BaseSameLayer>
</template>

<script>
import BaseSameLayer from './baseSameLayer.vue';
const weexModule = weex.requireModule('weexModule');

export default {
  name: 'MideaCameraView',
  data() {
    return {
      width: 0,
      height: 0,
      embedId: '',
    };
  },
  components: {
    BaseSameLayer,
  },
  props: {
    hosUniqueProps: {
      type: Object,
      default() {
        return {};
      },
    },
    data: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  computed: {
    hosSameLayerArgs() {
      return {
        ...this.hosUniqueProps, // 鸿蒙原生组件独有属性
        width: this.width,
        height: this.height,
        data: this.data,
        takePhotoFinish: this.takePhotoFinish,
      };
    },
  },
  mounted() {
    this.width = this.$el.clientWidth;
    this.height = this.$el.clientHeight;
    this.embedId = this.$refs.mideaCameraViewRef.embedId;
    console.log(this.embedId, 'this.embedId');
  },

  methods: {
    takePhotoFinish(res) {
      this.$emit('takePhotoFinish', res);
    },
    takePhoto() {
      weexModule.callNative('cameraHandle', {
        method: 'takePhoto',
        name: this.embedId,
      });
    },
    changeCameraPosition() {
      weexModule.callNative('cameraHandle', {
        method: 'changeCameraPosition',
        name: this.embedId,
      });
    },
    openTorch(params) {
      weexModule.callNative('cameraHandle', {
        method: 'openTorch',
        name: this.embedId,
        params,
      });
    },
    closeTorch(params) {
      weexModule.callNative('cameraHandle', {
        method: 'closeTorch',
        name: this.embedId,
        params,
      });
    },
  },
};
</script>
