<template>
  <view class="page-container">
    <vb-list :query-fun="apis.amActivity.activityApi.listApply" :query-params="queryParams" :dataLength="10" :height="listHeight">
      <template #item="{ item }">
        <vb-cell-group>
          <view class="d-fcv">
            <view class="px-15 py-10" @click="onGoAmDetail(item)">
              <!-- <image class="br-round w-50px h-50px r-40px" :src="checkUrl(item.avatar)" mode="aspectFill"></image> -->
              <vb-avatar :src="checkUrl(item.avatar)" :size="50" :name="item.name" />
            </view>
            <view class="flex-column justify-around">
              <view class="my-5">
                {{ item.name }}
                <text
                  v-if="item.auditStatus == '0'"
                  class="px-5 py-2 mx-5 bg-gray-3 border border-1 border-vb text-vb br-10 fs-10"
                >
                  待审核
                </text>
                <text v-else-if="item.auditStatus == '1'" class="px-5 py-2 mx-5 bg-vb text-white br-10 fs-10">
                  已通过
                </text>
                <text v-else-if="item.auditStatus == '2'" class="px-5 py-2 mx-5 bg-danger text-white br-10 fs-10">
                  已拒绝
                </text>
                <template class="ms-20" v-if="activity.needCost">
                  <text v-if="isCost(item)" class="px-5 py-2 mx-5 bg-success text-white br-10 fs-10">
                    已付 {{ Number(item.cost) }}
                  </text>
                  <text v-else class="px-5 py-2 mx-5 bg-gray-3 border border-1 border-vb text-vb br-10 fs-10">
                    未付费
                  </text>
                </template>
              </view>
              <view class="my-5 text-gray-6">{{ item.createTime }}</view>
            </view>
          </view>
        </vb-cell-group>
      </template>
    </vb-list>
  </view>
</template>

<script lang="ts" setup>
import dayjs from "dayjs"
import apis from "@/api"
import route from "@/route"
import configs from "@/core/config"
import { checkUrl } from "@/core/utils"
import appStore from "@/stores"


const wHeight = uni.getWindowInfo().windowHeight
const topHeight = ref(25)
const listHeight = computed(() => {
  return wHeight - topHeight.value - 15
})

const params = route.getRouteParams("activityDetail")
const activityId = params.id
const activity = ref<any>({
  needCost: "0",
})
const queryParams = ref({
  activityId: activityId,
  orderByColumn: "createTime",
  isAsc : "desc"
})

const formatAvatarUrl = (item: any) => {
  return item.avatar ? configs.baseUrl + item.avatar : "/static/images/avatars/empty.png"
}
const isCost = function (item: any) {
  return item.costStatus == 1
}

function onGoAmDetail(item: any) {
  if (!appStore.amProfileStore.notDemo()) {
    return 
  }
  route.navigate("alumnusDetail", { id: item.amId })
}
function loadActivity() {
  if (activity.value) {
    apis.amActivity.activityApi.getActivity(activityId).then((res) => {
      if (res) {
        activity.value = res
      }
    })
  }
}
function init() {
  loadActivity()
}
onMounted(init)
</script>

<style scoped></style>
