<template>
  <view class="u-font-14 rounded-md bg-white relative" style="height: 100%" @click="setStorage">
    <u-badge :is-dot="true" :offset="[0, 0]" v-show="pluginInfo.remindNum > 0"></u-badge>

    <!-- <plugin-default /> -->
    <!-- <component :task="task" :is="pluginComponent"></component> -->
    <p-task-title :task="task" v-if="pluginId === '1'" class="p-2" />
    <!-- <p-task-description :task="task" v-if="pluginId === '2'" />
      <p-task-duration-delay :task="task" v-if="pluginId === '3'" />
      <p-task-start-time-delay :task="task" v-if="pluginId === '4'" />
      <p-upload-deliverable :task="task" v-if="pluginId === '5' && isMine" />
      <p-delivery-history :task="task" v-if="pluginId === '5' && !isMine" />
      <p-subtasks :task="task" v-if="pluginId === '6'" />
      <p-subproject :task="task" v-if="pluginId === '7'" />
      <p-task-countdown :task="task" v-if="pluginId === '8'" />
      <p-manage-project :task="task" v-if="pluginId === '9'" />
      <p-manage-role :task="task" v-if="pluginId === '10'" />
      <p-manage-member :task="task" v-if="pluginId === '11'" />
      <p-manage-task :task="task" v-if="pluginId === '12'" />
      <p-wbs-import :task="task" v-if="pluginId === '13' || pluginId === '14'" /> -->

    <!-- 交付物插件 -->
    <p-deliver v-else-if="pluginId === '15'" />
    <p-source-manage v-else-if="pluginId === '16'" class="p-2" />
    <p-finance-audit v-else-if="pluginId === '17'" class="p-2" />
    <p-finance v-else-if="pluginId === '18'" class="p-2" />
    <!-- 个人和终端按钮-->
    <!-- <p-account-management /> -->
    <p-account-management v-else-if="pluginId === '19'" class="p-2" />
    <p-domain-source-manage v-else-if="pluginId === '20'" class="p-2" />
    <p-project-version-management v-else-if="pluginId === '21'" class="p-2" />

    <Render
      v-else
      :task="task"
      :pluginId="pluginId"
      :styleType="styleType"
      :pluginTaskId="pluginTaskId"
      :businessPluginId="businessPluginId"
      :param="param"
    />
  </view>
</template>

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

const props = defineProps({
  task: { default: () => {}, type: Object },
  pluginId: { default: '1', type: String },
  styleType: { default: 0, type: Number },
  pluginTaskId: { default: '', type: String },
  businessPluginId: { default: '', type: String },
  param: { type: String, default: '' },
  pluginInfo: { default: () => {}, type: Object }
});

provide('task', props.task);
provide('pluginInfo', props.pluginInfo);

const store = useStore();
const roleId = computed(() => store.state.role.roleId);
const token = computed(() => store.state.user.token);
const userId = computed(() => store.getters['user/userId']);
const projectId = computed(() => store.getters['project/projectId']);
const isMine = computed(() => store.getters['role/isMine']);
// 插件名称
// const pluginComponent = computed(() => {
//   const target = uni.$pluginConfig.defaults.find(item => item.id === +props.pluginId);
//   if (!target) return '';
//   return target.component;
// });

// if (props.pluginId === '5') {
//   store.dispatch('role/getAllMembers', { projectId: projectId.value });
// }

// 点击时存储 storage
async function setStorage() {
  uni.$storage.setStorageSync('roleId', roleId.value);
}
</script>
