<template>
  <view class="w-full h-full flex-col">
    <view class="flex-1 back-F6F6F6  flex-col">
      <view class="px-15 pt-15">
        <BasicTitle title="我的应用" :isBorder="false" line/>
        <view class="white-bg-color py-15 grid gridCols-4  mt-15 r-md">
          <view class="flex-col-center" @click="tokhpj">
            <image class="wi-88 he-88" src="/static/base/1.png"/>
            <view class="font-12 mt-8">考核评价</view>
          </view>
          <view class="flex-col-center" @click="tossp">
            <image class="wi-88 he-88" src="/static/base/2.png"/>
            <view class="font-12 mt-8">随手拍</view>
          </view>
          <view class="flex-col-center" @click="navigateTo('/pages/view/quantitativeAssessment/distribute/distribute')">
            <image class="wi-88 he-88" src="/static/base/3.png"/>
            <view class="font-12 mt-8">分配</view>
          </view>
          <view class="flex-col-center" @click="navigateTo('/pages/view/quantitativeAssessment/quantitativeSummary/quantitativeSummary')">
            <image class="wi-88 he-88" src="/static/base/4.png"/>
            <view class="font-12 mt-8">量化汇总</view>
          </view>
        </view>
      </view>
      <view class="px-15 mt-15">
        <BasicTabs ref="tabsRef" :list="tabs" bar-width="100rpx" :current="current" @change="tabsChange"/>
      </view>
      <view class="flex-1 ov-hidden">
        <view v-if="current==0" class="wh-full">
          <BasicListLayout @register="register">
            <template v-slot="{data,index}">
              <view @click="onlhkh(data)" class="white-bg-color r-md p-15 mb-15 flex-row ">
                <view class="flex-1">
                  <view class="font-w-500 flex-row">
                    <view class="mr-5">{{ data.fullName }}</view>
                    <view class="mr-5">{{ data.score }}分</view>
                    本周得分{{ data.score ? (300 + parseFloat(data.score)) : 300 }}
                  </view>
                  <view class="grid gridCols-4 mt-15 gapY-15">
                    <template v-for="(item,key) in inspectItems">
                      <view class="flex-col-center">
                        <view class="font-w-500">{{ item.name }}</view>
                        <view class="mt-5" v-if="data['item'+item.id]">{{ data['item' + item.id] }}</view>
                        <view class="wi-45 he-45 mt-5" v-else>
                          <image src="/static/base/tb.jpg" class="wh-full"></image>
                        </view>
                      </view>
                    </template>
                  </view>
                  <!--                  <template v-for="(arr,key) in data.items">-->
                  <!--                    <view class="font-14 font-w-500  mt-15">{{ key }}</view>-->
                  <!--                    <view class="font-14 mt-6" v-for="(item,index) in arr">-->
                  <!--                      {{ item.inspectStandard }},{{-->
                  <!--                        item.scoreType == 2 ? '扣' : '加'-->
                  <!--                      }}{{ Math.abs(item.score) }}分;-->
                  <!--                    </view>-->
                  <!--                  </template>-->
                </view>
              </view>
            </template>
          </BasicListLayout>
        </view>
        <view v-if="current==1" class="wh-full">
          <BasicListLayout @register="sspregister">
            <template v-slot="{data,index}">
              <view @click="onssp(data)" class="white-bg-color r-md p-15 mb-15 flex-col">
                <view class="mb-15">
                  <view class="font-w-500 flex-row">
                    <view class="mr-5">{{ data.fullName }}</view>
                    <view class="mr-5" v-if="data.studentName">{{ data.studentName }}</view>
                    {{ data.purpose }}
                  </view>
                  <view class="font-12 mt-15" v-html="data.content">
                  </view>
                </view>
                <view class="flex-row flex-wrap list_box">
                  <view class=" r-md mr-15 flex-row" v-for="(item,key) in data.pic.split(',')">

                    <image v-if="/\.(jpg|jpeg|png|gif|bmp|webp|tiff|svg)$/i.test(item)" :src="imagUrl(item)"
                           class="wi-160 he-160"></image>
                    <view @click.stop="videoplay(imagUrl(item))" class="wi-260 he-360 po-re"
                          v-if="/\.(mp4|avi|mov|wmv|flv|mkv|webm)$/i.test(item)">
                      <video class="wi-260 he-360"
                             :src="imagUrl(item)"></video>
                      <view class="uni-video-cover1">
                        <svg t="1729239497913" class="icon" viewBox="0 0 1024 1024" version="1.1"
                             xmlns="http://www.w3.org/2000/svg" p-id="4290" width="40" height="40">
                          <path
                              d="M512 853.333333c-187.733333 0-341.333333-153.6-341.333333-341.333333s153.6-341.333333 341.333333-341.333333 341.333333 153.6 341.333333 341.333333-153.6 341.333333-341.333333 341.333333z m0-85.333333c140.8 0 256-115.2 256-256s-115.2-256-256-256-256 115.2-256 256 115.2 256 256 256z m128-256l-213.333333 128V384l213.333333 128z"
                              fill="#e6e6e6" p-id="4291"></path>
                        </svg>
                      </view>
                    </view>
                  </view>
                </view>
                <view style="text-align: right">{{ data.createdTime.split(" ")[0] }}</view>
              </view>
            </template>
          </BasicListLayout>
        </view>

        <view v-if="current==2" class="wh-full po-re">
          <!--          <view class="po-ab inset-0 ov-auto p-15">-->
          <!--            <template v-for="(data,index) in totzggList">-->
          <!--           </template>-->
          <!--          </view>-->
          <BasicListLayout @register="tzggregister">
            <template v-slot="{data,index}">
              <view class="white-bg-color r-md p-15 mb-15 flex-row items-center" @click="totzgg(data)">
                <view class="wi-100 he-100 r-50 mr-10" v-if="data.thumbnails">
                  <image :src="imagUrl(data.thumbnails)"
                         class="wh-full"></image>
                </view>
                <view class="flex-1">
                  <view class="font-w-500">{{ data.title }}</view>
                  <view class="font-12 text-ellipsis-1 mt-5" v-html="data.description"></view>
                </view>
              </view>
            </template>
          </BasicListLayout>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import {navigateTo, reLaunch, showToast} from "@/utils/uniapp";
import {useLayout} from "@/components/BasicListLayout/hooks/useLayout";
import {
  cmsArticleFindPageApi,
  evaluationFindPageSummaryApi,
  getSchedulingPlanByUserIdApi,
  inspectItemFindAllsApi,
  readyToGoFindPageApi
} from "@/api/base/assesment";
import {imagUrl} from "@/utils";
import {onShow} from "@dcloudio/uni-app";
import {useUserStore} from "@/store/modules/user";
import Template from "@/components/BasicQrcode/_template/template.vue";
import {useDataStore} from "@/store/modules/data";
import {getUserViewApi} from "@/api/system/login";

const tabs = ['量化考核', '随手拍', '通知公告']
const current = ref(0)
const tabsRef = ref(null)

const {setData} = useDataStore()

function onssp(data: any) {
  setData({
    _show: true,
    ...data
  })
  navigateTo('/pages/view/quantitativeAssessment/casualShot/casualShot')
}

function videoplay(url: string) {
  navigateTo('/pages//view/quantitativeAssessment/index/playPage?url=' + encodeURIComponent(url))
}


function onlhkh(data: any) {
  setData(data)
  navigateTo('/pages/view/quantitativeAssessment/index/details?bjId=' + data.bjId)
}

function totzgg(data: any) {
  setData(data)
  navigateTo('/pages/view/quantitativeAssessment/index/noticeAnnouncement')
}

const {getUser, logout} = useUserStore();
const inspectItems: any = ref([]);

function tuichu() {
  logout()
  reLaunch('/pages/system/login/login')
}

const thirdId: any = ref('');


onShow(async () => {

  
  let res = await inspectItemFindAllsApi();
  inspectItems.value = res.result;
  await lhkh.reload()
  

  let userres = await getUserViewApi();


  if (userres && userres.result) {
    thirdId.value = userres.result.thirdId ? userres.result.thirdId : "";
  } else {
    thirdId.value = "";

  } 

})


const [register, lhkh] = useLayout({
  api: evaluationFindPageSummaryApi,
  param: {
    showWeek: 1
  },
  componentProps: {
    fixed: false,
    loadingMoreEnabled: false,
    auto: false
  },
})
const [sspregister, ssp] = useLayout({
  api: readyToGoFindPageApi,
  param: {
    showWeek: 1
  },
  componentProps: {
    fixed: false,
    loadingMoreEnabled: false,
    auto: false
  },
})

async function tokhpj() {
 

  if (thirdId.value) {

    let res = await getSchedulingPlanByUserIdApi();

    if (res.result && res.result.length > 0) {

      navigateTo('/pages/view/quantitativeAssessment/assessment/assessment')
    } else {

      showToast({title: "今日未分配!无法填报!"})
    }
  } else {

    showToast({title: "未配置权限!"})
  }
}

function tossp() {
  setData({});
  navigateTo('/pages/view/quantitativeAssessment/casualShot/casualShot')
}

const totzggList = ref<any>([])
cmsArticleFindPageApi({showWeek: 1}).then(res => {
  totzggList.value = res.rows
})

const [tzggregister, tzgg] = useLayout({
  api: cmsArticleFindPageApi,
  param: {
    showWeek: 1

  },
  componentProps: {
    fixed: false,
    loadingMoreEnabled: false,
    auto: false
  },
})

function tabsChange(index: any) {
  current.value = index
  if (index == 0) {
    lhkh.reload()
  }
  if (index == 1) {
    ssp.reload()
  }
  if (index == 2) {
    tzgg.reload()
  }
}

</script>
<style scoped lang="scss">
</style>
