<template>
  <view>
    <u-action-sheet :list="list" @tap="uploadImge" v-model="show"></u-action-sheet>
  </view>
</template>

<script>
  import {
    album,
    camera
  } from '@/utils/author.js'
  import uploadImage from '@/utils/ossutil/uploadFile.js';
  export default {
    name: "upload",
    props: {
      value: {
        type: Boolean,
        default: false,
      },
    },
    data() {
      return {
        list: [{
            text: '拍摄',
            fontSize: 28,
            color: '#383838'
          },
          {
            text: '从相册选择',
            fontSize: 28,
            color: '#383838'
          }
        ],
      };
    },
    computed: {
      show: {
        get() {
          return this.value;
        },
        set(e) {
          this.$emit('input', e);
        },
      }
    },
    methods: {
      async uploadImge(index) {
        //相机
        if (index == 0) {
          // #ifdef APP-PLUS
          // let result = await camera()
          // if (!result) return
          // #endif
          this.openImage('camera')
        } else {
          //相册
          // #ifdef APP-PLUS
          // let result = await album()
          // if (!result) return
          // #endif
          this.openImage('album')
        }
      },
      //拍照
      openImage(val) {
        uni.chooseImage({
          count: 1,
          sourceType: [val],
          crop:{
          		width:'80',
          		height:'80',
          },
          success: (res) => {
            this.$emit('result',res.tempFilePaths[0])
          },
          fail: (err) => {
            console.log(err)
          }
        })
      },
    }
  }
</script>

<style lang="scss">

</style>
