<template>
  <!-- 独立拍摄页：由 vehicleAdd 跳转进入（query.type = front/back/car），
       确认/取消/降级后 $router.back() 返回 vehicleAdd -->
  <camera-guide
    :visible="show"
    :type="type"
    @confirm="onConfirm"
    @cancel="goBack"
    @fallback="onFallback"
  />
</template>

<script>
import CameraGuide from "@/components/CameraGuide.vue";

export default {
  name: 'cameraGuidePage',
  components: { CameraGuide },
  data() {
    return {
      show: false // 挂载后置 true，触发组件 visible 侦听器启动相机
    }
  },
  computed: {
    type() {
      const t = this.$route.query.type
      return ['front', 'back', 'car'].includes(t) ? t : 'front'
    }
  },
  mounted() {
    this.show = true
  },
  methods: {
    onConfirm({ blob, dataURL }) {   // 拍照确认：结果存入 store，返回 vehicleAdd 消费
      this.$store.commit('camera/setResult', { type: this.type, blob, dataURL })
      this.$router.back()
    },
    onFallback(e) {   // 相机不可用：降级信息存入 store，返回 vehicleAdd 走系统选择器
      this.$store.commit('camera/setFallback', { type: this.type, error: e })
      this.$router.back()
    },
    goBack() {
      this.$router.back()
    }
  }
}
</script>
