<template>
  <div class="items-center row">
    <img src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Test/Upload/Goods/1713433759000_282.png"
                style="height: 33px" @click="forwardProduct" class="cusor-pointer"/>
    <div class="primary-link-button q-ml-lg cusor-pointer no-select" @click="addVisible=true">创建设计</div>
    <el-dropdown trigger="click">
      <el-avatar
        :size="size"
        :src="userInfo.photo"
        shape="square"
        style="background-color: #e6ddf5; color: #7b35ef"
        class="q-mx-lg cusor-pointer"
        ></el-avatar>
      <template #dropdown>
        <div class="MarketfigurePopover shrink">
          <div class="row items-center">
            <el-avatar
                :size="44"
                shape="square"
                :src="userInfo.photo"
                style="background-color: #e6ddf5; color: #7b35ef"
                class="q-mr-lg cusor-pointer shrink"
                ></el-avatar>
            <div>
              <div class="row items-center">
                <span class="text-weight-bolder" style="font-size: 18px;">{{ userInfo.nickname }}</span>
              </div>
              <div class="text-small text-info" v-if="userInfo.it">团队或企业：{{ userInfo.company }}</div>
              <div class="text-small text-info" v-else>个人用户</div>
            </div>
          </div>
          <div class="vip-box rounded row q-my-lg items-end" :style="{ background: userTheme?.bg }">
            <div class="text-white col">
              <div class="text-weight-bolder">{{ userTheme?.desc }}</div>
              <div class="col text-light q-mt-sm">当前权益：{{ (userInfo.it || userInfo.iv?fr.length:4) }}</div>
              <div class="col text-light q-mt-sm text-small" v-if="userInfo.it || userInfo.iv">有效期至：{{ userInfo.expire }}</div>
            </div>
            <div :style="{'background':vipTheme.color}" @click="openOrderViewHandler(1)" v-if="!userInfo.iv && !userInfo.it" class="text-white pingfangr q-ml-lg rounded cusor-pointer q-py-sm q-px-md no-select">升级专业版</div>
            <div :style="{'background':enTheme.color}"  @click="openOrderViewHandler(0)" v-if="userInfo.iv && !userInfo.it" class="text-white pingfangr q-ml-lg rounded cusor-pointer q-py-sm q-px-md no-select">升级企业</div>
            <div v-if="userInfo.it && (userInfo.ia||userInfo.ic)" @click="openOrderViewHandler(0)" style="background-color: #F1F2F4;" class="text-dark text-bold pingfangr q-ml-lg rounded cusor-pointer q-px-md q-py-sm no-select">立即续费</div>
          </div>
          
          <div class="MarketCapacity">
            <div>
              <el-progress
                :percentage="TravelDesign.storagePercent"
                color="#0A5EF9"
                :stroke-width="8"
                text-inside
                :format="format"
              >
              </el-progress>
            </div>
            <div class="MarketCapacityNum row flex-between">
              <span>{{TravelDesign.CloudUse}}{{TravelDesign.CloudUseUnit}} / {{TravelDesign.CloudTotal}}{{TravelDesign.CloudTotalUnit}}</span>
              <span>容量管理</span>
            </div>
          </div>
          <div class="MarketFootmark row items-center flex-between">
            <div>
              <span>足迹</span>
              <b>{{ sampleData[1] }}</b>
            </div>
            <div>
              <span>收藏</span>
              <b>{{ sampleData[2] }}</b>
            </div>
            <div>
              <span>行程/广告</span>
              <b>{{ sampleData[0] }}</b>
            </div>
          </div>
          <div class="TranLine"></div>
          <div class="MarketSettings row flex-between">
            <!-- <span>账号设置</span> -->
            <el-button link class="pingfangr" style="font-size: 14px" @click="forwardUserCenter">账号设置</el-button>
            <span class="pointer" @click="loginOutHandler">退出登录</span>
          </div>
        </div>
      </template>
    </el-dropdown>
    <el-dropdown trigger="click">
      <el-icon class="pointer" size="21" color="#070707"
        ><MoreFilled
      /></el-icon>
      <template #dropdown>
        <div class="MarketPopoverMore row wrap pointer">
          <div class="column" v-for="(item, index) in moreList" @click="forward(item.Url)">
            <div>
              <img :src="item.icon" width="34" height="34" />
            </div>
            <span>{{ item.Name }}</span>
          </div>
        </div>
      </template>
    </el-dropdown>
  </div>
  <!-- 创建设计 -->
  <temDesign :addTem="addVisible" @close="addVisible=false"/>
  <OrderReview v-if="orderVisible" :show-person="isShowPerson" :default-type="isShowPerson?1:2" @close="()=>orderVisible=false"></OrderReview>
</template>
<script lang="ts" setup>
import { ref } from "vue";
import { useUserStore } from "@/store";
import { storeToRefs } from "pinia";
import { useRouter } from "vue-router";
import { openNewBlank } from "@/utils/common";
import temDesign from "@/components/home/temDesign.vue";
import { EntMemberRight, ENT_USER_THEME, FreeMemberRight, PersonMemberRight, VIP_USER_THEME } from "@/configs/customer";
import OrderReview from '@/views/components/Order/Review.vue'
import UserServices from "@/services/UserService";
import { ApiResult } from "@/configs/axios";

const props = defineProps({
    size: {
      type: Number,
      default: 33,
    },
});
const addVisible = ref(false)
const orderVisible = ref(false)
const forwardProduct = () => router.push('/p/show')
const router = useRouter()
const useUser = useUserStore();
const { userInfo } = storeToRefs(useUser);
const userTheme = useUser.getUserTheme
const vipTheme = VIP_USER_THEME
const enTheme = ENT_USER_THEME
const fr = userInfo.value.it?EntMemberRight:(userInfo.value.iv?PersonMemberRight:FreeMemberRight)
const isShowPerson = ref(true)
const sampleData = ref<any[]>([0,0,0])
const format = (percentage: number) => {
    return percentage == 100 ? '' : ``
}
const moreList = [
  { icon: require("@/assets/img/homeMore0.png"), Name: "添加到桌面" },
  { icon: require("@/assets/img/homeMore1.png"), Name: "关注公众号" },
  { icon: require("@/assets/img/homeMore2.png"), Name: "我的订单", Url:'/u/order' },
  { icon: require("@/assets/img/homeMore3.png"), Name: "意见反馈", Url:'https://work.weixin.qq.com/kfid/kfc378aada578ca8b0e' },
];

const TravelDesign = ref({} as any)

const forwardUserCenter = ()=>{
  router.push('/u')
}
const forward = (url:string|undefined)=>{
  if(url){
    if(url.includes('http://')||url.includes('https://')) openNewBlank(url)
    else router.push(url)
  }
}
const loginOutHandler = ()=>{
    useUser.setUserLoginOut()
}
const openOrderViewHandler = (t:number)=>{
  isShowPerson.value=t==1
  orderVisible.value = true
}
const getSampleHandler = async ()=>{
  const response = await UserServices.GetTripSampleCountAsync()
  if(response.data.resultCode == ApiResult.SUCCESS) sampleData.value = response.data.data
  else sampleData.value = [0,0,0]
}

const getDataStatistics = async () => {
  const response = await UserServices.getPPTUserStatic();
  if(response.data.resultCode == ApiResult.SUCCESS){
    TravelDesign.value = response.data.data
  }
}
getDataStatistics()
getSampleHandler()
</script>
<style scoped>
.vip-box {
  padding: 16px;
  position: relative;
  font-size: 14px;
  color:#FFF;
  z-index: 1;
  width:100%;
  overflow: hidden;
}

.vip-box::after {
  position: absolute;
  top: 0;
  right: -48px;
  bottom: -12px;
  z-index: -1;
  width: 100%;
  background: url('https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Test/Upload/Goods/1713496804000_500.png') no-repeat right center / contain;
  content: "";
  transform: scale(2);
  transform-origin: right center;
}
.MarketfigureMin img {
  margin-top: 18px;
}
.MarketCapacityNum span:last-child {
  font-family: PingFang SC;
  font-weight: 500;
  font-size: 14px;
  color: #5f68e5;
}
.MarketCapacityNum span:first-child {
  font-family: PingFang SC;
  font-weight: bold;
  font-size: 14px;
  color: #4e4e4e;
}
.MarketCapacityNum {
  margin-top: 10px;
}
.MarketfigurePhon span:last-child {
  margin-left: 20px;
}
.MarketfigurePhon {
  font-family: PingFang SC;
  font-weight: 400;
  font-size: 14px;
  color: #b4b4b4;
  margin-top: 5px;
}
.MarketfigureMin {
  background: #e6ddf5;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  text-align: center;
  margin-right: 10px;
  overflow: hidden;
}
.MarketfigurePopover {
  width: 380px;
  padding: 24px 30px 0 30px;
}
.MarketfigurePopover .el-button{
  font-size: 14px !important;
  font-weight: bold;
}
/* .Marketfigure:hover img {
  animation: myfirst 1s;
  -webkit-animation: myfirst 1s;
} */
.Marketfigure img {
  margin-top: 6px;
}
/* @keyframes myfirst {
  from {
    margin-top: 25px;
  }
  to {
    margin-top: 6px;
  }
}

@-webkit-keyframes myfirst {
  from {
    margin-top: 25px;
  }
  to {
    margin-top: 6px;
  }
} */
.Marketfigure {
  background: #e6ddf5;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  text-align: center;
  margin-left: 30px;
  margin-right: 22px;
  overflow: hidden;
}
.MarketPopoverMore > div span {
  text-align: right;
  padding-right: 17px;
  font-family: PingFang SC;
  font-weight: 400;
  font-size: 14px;
  color: #000000;
}
.MarketPopoverMore > div div {
  padding: 20px 0 22px 20px;
}
.MarketPopoverMore > div:first-child,
.MarketPopoverMore > div:nth-child(2) {
  margin-bottom: 25px;
}
.MarketPopoverMore > div:nth-child(2n) {
  margin-left: 28px;
}
.MarketPopoverMore > div {
  width: 140px;
  height: 105px;
  border-radius: 8px;
  background: #f3f6fb;
}
.MarketPopoverMore {
  width: 368px;
  padding: 30px;
}
.MarketEquityTime {
  font-family: PingFang SC;
  font-weight: 400;
  font-size: 14px;
  color: #8aa3cc;
}
.MarketEquityNum span:last-child {
  margin-left: 12px;
}
.MarketEquityNum {
  height: 14px;
  font-family: PingFang SC;
  font-weight: bold;
  font-size: 14px;
  color: #000000;
  margin-bottom: 12px;
}
.MarketEquity {
  height: 68px;
  background: url("../../assets/img/home-quanyi.png") no-repeat;
  background-size: 100% 100%;
  padding: 18px 13px;
  margin-top: 29px;
  margin-bottom: 30px;
}
.MarketFootmark b {
  color: #0a5ef9;
  margin-left: 5px;
}
.MarketFootmark span {
  font-size: 14px;
  color: #000000;
  font-family: PingFang SC;
}
.MarketFootmark {
  width: 100%;
  padding: 18px 21px;
  background: #eee;
  border-radius: 8px;
  margin-top: 28px;
  margin-bottom: 39px;
}
.MarketSettings span:last-child {
  font-weight: 400;
  color: #b4b4b4;
}
.MarketSettings span:first-child {
  font-weight: 500;
  color: #000000;
  padding: 10px 0 20px 0;
}
.MarketSettings span {
  font-family: PingFang SC;
  font-size: 14px;
  padding: 10px 0 20px 20px;
}
.MarketSettings {
  margin-top: 9px;
}
</style>
