<template>
  <view class="upload">
    <u-icon name="plus" size="24px" class="flex justify-center w-12 h-12 bg-blue-100 rounded-full shadow-md" @tap="handleUpload"></u-icon>
  </view>
</template>

<script>
import { mapGetters } from 'vuex';

export default {
  computed: mapGetters('user', ['userId']),
  methods: {
    // 导入wbs
    async handleUpload() {
      try {
        const data = await this.$u.api.import();
        console.log('data: ', data);
        // 导入WBS成功后
        // 直接打开导入的项目
        this.$emit('success');
        setTimeout(() => {
          this.$u.route('/pages/project/project', {
            u: this.userId,
            p: data.id,
            pname: data.pname,
            url: data.url,
          });
        }, 2000);
      } catch (error) {
        this.$emit('error', error);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.upload {
  position: absolute;
  right: 10px;
  bottom: 0;
  transform: translate3d(0, 50%, 0);
}

/deep/ .uicon-plus {
  color: theme('colors.blue.500') !important;
}
</style>
