<template>
  <div class="d-page d-flex flex-column">
    <title-bar title="个人业务汇总" @clickLeft="onClick">
      <van-icon slot="left" name="cross" size="24" />
    </title-bar>
    <van-button @click="test(0)">拍照</van-button>
    <van-button @click="test(1)">录像</van-button>
    <van-button @click="test(2)">录音</van-button>
    <van-button @click="test(3)">定位</van-button>
    <van-button @click="test(4)">扫码</van-button>
  </div>
</template>
<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import TitleBar from "@/components/general/TitleBar.vue";
import { MediaFile } from "@/model/entity/MediaFile";
import mediaService from "@/services/media.service";

@Component({
  name: "PersonalStatsView",
  components: { TitleBar },
})
export default class PersonalStatsView extends Vue {
  pageTitle = ""; // 页面标题

  onClick() {
    this.$router.go(-1);
  }
  mounted() {
    this.pageTitle = this.$route.meta?.name;
  }
  test(index: number) {
    const data = new MediaFile();
    data.objId = "1111";
    data.userId = "000000";
    data.address = "定位信息";
    data.userName = "拍摄人";
    if (index == 0) {
      this.$native.capturePhoto(data).then((data) => {
        console.log(JSON.stringify(data));
      });
    } else if (index == 2) {
      this.$native.captureRecord(data).then(() => {
        mediaService.selectByObjId("1111").then((data: any) => {
          alert(JSON.stringify(data));
        });
      });
    } else if (index == 1) {
      this.$native.captureVideo(data).then(() => {
        mediaService.selectByObjId("1111").then((data: any) => {
          alert(JSON.stringify(data));
        });
      });
    } else if (index == 3) {
      this.$native
        .getCurrentPosition()
        .then((res) => {
          alert(JSON.stringify(res));
        })
        .catch((e) => {
          alert(e);
        });
    } else {
      this.$native.qrScan().then((res) => {
        alert(res);
      });
    }
  }
}
</script>

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