<template>
  <view>
    <!-- 上传提交 v-if="isMine && deliver" -->
    <!-- TODO: 2022年春节为了演示所有人都能看到交付物插件 -->
   <p-deliver-upload
      v-if="deliver"
      @upload-success="getDeliverData"
      class="p-2"
      @edit-success="getDeliverData"
    ></p-deliver-upload>

   <p-deliver-check
      v-if="deliver && deliver.details && deliver.details.length"
      @check-success="getDeliverData"
      class="p-2"
    ></p-deliver-check>
  </view>
</template>

<script setup>
import { useStore } from 'vuex';
import { ref, inject, provide, computed } from 'vue';

const store = useStore();
const task = inject('task');
const deliver = ref(null); // 服务端返回的交付物信息
const isMine = computed(() => store.getters['role/isMine']); // 是不是我的任务

provide('deliver', deliver);

// 根据任务id获取交付物信息
async function getDeliverData() {
  try {
    const { id: taskId } = task;
    if (!taskId) return;
    const param = { taskId };
    const data = await uni.$u.api.getDeliverByTaskId(param);
    deliver.value = data;
  } catch (error) {
    console.log('error: ', error);
  }
}

getDeliverData();
</script>
