<route lang="json">
{
  "style": {
    "navigationBarTitleText": "全部任务",
    "navigationBarBackgroundColor": "#fff"
  }
}
</route>
<script setup lang="ts">
import Card from '@designer-hub/app/src/components/card.vue'
import { getBroker, taskReceive } from '../../../core/libs/requests'
import { useUserStore } from '../../../store'
import { storeToRefs } from 'pinia'
import dayjs from 'dayjs'
import PageHelperEvo from '@/components/page-helper-evo.vue'
import { getTasks } from '../../../core/libs/agent-requests'
import { useTask } from '../../../composables/task'
import { AgentTask } from '@designer-hub/app/src/core/libs/models'
import { ComponentExposed } from 'vue-component-type-helpers'
import TaskCard from '../../agent/components/task-card.vue'

const userStore = useUserStore()
const { userInfo } = storeToRefs(userStore)
const { types } = useTask()
const pageHelperRef = ref<ComponentExposed<typeof PageHelperEvo>>()
const status = ref<any>({
  1: {
    title: '未开始',
    bg: 'bg-[#f04c47]',
    bgClass: 'bg-[#f04c47]',
  },
  2: { title: '进行中', bg: '', bgClass: 'bg-[#2357e9]' },
  3: { title: '已撤回', bg: '', bgClass: 'bg-[#f04c47]' },
  4: { title: '已完成', bg: '', bgClass: 'bg-[#f04c47]' },
  5: { title: '未完成', bg: '', bgClass: 'bg-[#abacaf]' },
  6: { title: '待确认', bg: '', bgClass: 'bg-[#f04c47]' },
})
const query = computed(() => ({ brokerId: userInfo.value.userId, status: '1,2,4,5,6' }))

const { data, run: setData } = useRequest(() =>
  getBroker({ brokerId: String(userInfo.value.userId) }),
)

// 状态（1-未开始，2-进行中，3-已撤回，4-已完成，5-未完成，6-待确认）
const toPoints = async () => {
  await uni.navigateTo({ url: '/pages/agent/points/index' })
}
onMounted(async () => {
  await setData()
})
</script>
<template>
  <div class="py-4 flex-grow flex flex-col">
    <div @click="toPoints">
      <Card custom-class="mx-4">
        <div class="w-full flex items-center">
          <div class="text-black/90 text-base font-normal font-['PingFang_SC'] leading-relaxed">
            任务积分
          </div>
          <div class="flex-1"></div>
          <div class="text-[#ff2e2e] text-[22px] font-medium font-['D-DIN-PRO'] leading-none">
            {{ data?.points ?? 0 }}
          </div>
          <wd-icon name="arrow-right" size="22" color="rgba(0,0,0,.75)"></wd-icon>
        </div>
      </Card>
    </div>

    <PageHelperEvo ref="pageHelperRef" :request="getTasks" :query="query">
      <template #default="{ source }">
        <div class="flex-grow flex flex-col gap-4 p-4">
          <template v-for="item in source?.list" :key="item.id">
            <TaskCard :options="item" @change="pageHelperRef?.refresh()"></TaskCard>
          </template>
        </div>
      </template>
    </PageHelperEvo>
  </div>
</template>
