<template>
  <theme class="m-2" >
    <u-card
      @click="openCard"
      :show-foot="false"
      :show-head="false"
      :style="{ 'max-height': globalsHeight + 'px' }"
      border-radius="25"
      margin="0"
      class="global-container"
    >
      <template v-slot:body>
        <scroll-view :scrollY="true" :style="{ 'max-height': globalsHeight - 30 + 'px' }">
          <skeleton :banner="false" :loading="!globals.length" :row="3" animate class="u-line-2 skeleton"></skeleton>

          <view class="grid gap-2">
            <view v-for="item in globals" :key="item.id">
              <template v-if="item.plugins && item.plugins.length">
                <view v-for="(pluginArr, i) in item.plugins" :key="i">
                  <template class="p-0 u-col-between" v-if="pluginArr.length">
                    <Plugin
                      :class="[`row-span-${plugin.row}`, `col-span-${plugin.col}`]"
                      :task="item"
                      :key="plugin.pluginTaskId"
                      :plugin-task-id="plugin.pluginTaskId"
                      :plugin-id="plugin.pluginId"
                      :param="plugin.param"
                      :style-type="plugin.styleType || 0"
                      v-for="plugin in pluginArr"
                    />
                  </template>
                </view>
              </template>

              <!-- 任务名插件 -->
              <p-task-title :task="item" v-else />
              <!-- 交付物插件 -->
              <p-deliver></p-deliver>
            </view>
          </view>
        </scroll-view>
      </template>
    </u-card>
  </theme>
</template>

<script setup>
import { computed } from 'vue';
import { useStore } from 'vuex';
import Skeleton from '@/components/Skeleton/Skeleton.vue';

const sysHeight = uni.getSystemInfoSync().screenHeight; // 屏幕的高度
const globalsHeight = Math.floor(((sysHeight - 44 - 30 - 10) / 5) * 4); // 全局任务的最大高度
const store = useStore();
const isShrink = computed(() => store.state.task.isShrink); // 全局任务是否收缩
const globals = computed(() => store.getters['task/globals']);
console.log('globals: ', globals.value);

// 手动展开日常任务
function openCard() {
  if (isShrink.value) {
    store.commit('task/setShrink', false);
  }
}
</script>

<style scoped lang="scss">
.u-card-wrap {
  background-color: $u-bg-color;
  padding: 1px;
}

.u-body-item {
  font-size: 32rpx;
  color: #333;
  padding: 20rpx 10rpx;
}

.u-body-item image {
  width: 120rpx;
  flex: 0 0 120rpx;
  height: 120rpx;
  border-radius: 8rpx;
  margin-left: 12rpx;
}
</style>
