<template>
  <jx-empty title="没有找到店铺评分" v-if="scoreList.length == 0" />

  <view class="score-root">
    <view
      class="score-item"
      v-for="score in scoreList"
      :key="score.id"
      @click="toDetail(score.id)"
    >
      <view
        class="score-icon"
        :class="{
          level1: score.level === 1,
          level2: score.level === 2,
          level3: score.level === 3,
          level0: score.level === 0,
        }"
      ></view>
      <view class="left">
        <view class="storeName">{{ score.storeName }}</view>
        <view class="date"
          >({{ timeFormatD(score.beginTime) }}~{{
            timeFormatD(score.endTime)
          }})</view
        >
      </view>
      <view class="right">{{ score.totalScore }}分</view>
    </view>
  </view>

  <!-- 公共组件 -->
  <jx-loading />
</template>

<script lang="ts" setup>
import merchant from "@/api/https/merchant"
import { getStorage } from '@/utils/storage'
import toast from '@/utils/toast'
import { timeFormatD } from '@/utils/tools'
import { onLoad } from '@dcloudio/uni-app'
import { ref } from 'vue'

/**
 * 获取店铺评分
 */
onLoad(async () => {
  await getStoreScore()
})
interface ScoreListType {
  beginTime: string
  endTime: string
  id: number
  level: number
  storeID: number
  storeName: string
  totalScore: number
}
const scoreList = ref<Array<ScoreListType>>([])
async function getStoreScore() {
  let data = {
    storeID: getStorage('storeID'),
    weekIndex: -1,
  }
  let scoreRes = await merchant.get_weekly_store_score(data)
  if (scoreRes.code == 0) {
    scoreList.value = scoreRes.data || []
  } else {
    toast('店铺评分数据异常')
  }
}

/**
 * 查看你评分详情
 */
function toDetail(id: number) {
  uni.navigateTo({
    url: `/subPages/merchantChild/storeScoreDetaile/storeScoreDetaile?weekIndex=${id}`,
  })
}
</script>

<style lang="scss" scoped>
@import './storeScore.scss';
</style>