<template>
  <div class="indexBackClass" id="stuwdkcDom">
    <div style="margin-top: 20px">
      <span style="margin-left: 30px; font-size: 24px; font-weight: 600">提醒信息</span>
    </div>
    <a-tabs v-model:activeKey="activeKey" style="padding: 10px">
      <a-tab-pane key="1" tab="未读">
        <div style="min-height: 70px">
          <a-row>
            <a-col :span="24" style="padding: 0 10px; margin-bottom: 10px" v-for="(item, index2) in dataSource" :key="index2">
              <a-row style="margin-top: 15px">
                <a-col :span="22" style="text-align: left; padding-left: 15px">
                  <div style="margin-top: 5px">{{ index2 + 1 }}、{{ item.content }}</div>
                </a-col>
                <a-col :span="2" style="text-align: right">
                  <a-button type="primary" @click="openKecheng(item)" style="margin-left: 10px">查看</a-button>
                </a-col>
              </a-row>
            </a-col>
            <a-col :span="24" v-show="dataSource.length == 0" style="text-align: center">
              <span style="line-height: 60px">暂无提醒</span>
            </a-col>
          </a-row>
        </div>
      </a-tab-pane>
      <a-tab-pane key="2" tab="已读" force-render>
        <div style="width: 100%; text-align: right; ">
          <RouterLink target='_blank' to="/site/teacherYiyueMore">查看更多</RouterLink>
        </div>
        <div style="min-height: 70px">
          <a-row>
            <a-col :span="24" style="padding: 0 10px; margin-bottom: 10px" v-for="(item, index2) in dataYySource" :key="index2">
              <a-row style="margin-top: 15px">
                <a-col :span="22" style="text-align: left; padding-left: 15px">
                  <div style="margin-top: 5px">{{ index2 + 1 }}、{{ item.content }}</div>
                </a-col>
                <a-col :span="2" style="text-align: right">
                  <a-button type="primary" @click="openKecheng(item)" style="margin-left: 10px">已读</a-button>
                </a-col>
              </a-row>
            </a-col>
            <a-col :span="24" v-show="dataYySource.length == 0" style="text-align: center">
              <span style="line-height: 60px">暂无提醒</span>
            </a-col>
          </a-row>
        </div>
      </a-tab-pane>
    </a-tabs>
  </div>
</template>

<script lang="ts" setup>
import { defHttp } from '/@/utils/http/axios';
import { ref, onMounted } from 'vue';
import { getSysConfig } from '/@/views/site/utils/index';
//用户相关
import { useUserStore } from '/@/store/modules/user';
const userStore = useUserStore();
const dataSource = ref([]);
const dataYySource = ref([]);
const activeKey = ref('1');
//进入就加载
onMounted(() => {
  loaddata();
  setInterval(() => {
    loaddata();
  }, 60 * 1000);
});
function loaddata() {
  defHttp
    .get({ url: '/zyDbtx/zyDbtx/list', params: { pageSize: 10, pageNo: 1, createBy: userStore.getUserInfo.username, flag: '0' } })
    .then((res) => {
      dataSource.value = res.records;
    });

  defHttp
    .get({ url: '/zyDbtx/zyDbtx/list', params: { pageSize: 10, pageNo: 1, createBy: userStore.getUserInfo.username, flag: '1' } })
    .then((res) => {
      dataYySource.value = res.records;
    });
}

function handleMore() {
  console.log('111111111111');



}

function openKecheng(record) {
  console.log(`🚀 ~ openKecheng ~ record:`, record);

  defHttp.post({ url: '/zyDbtx/zyDbtx/deleteById', params: { id: record.id } }).then((res) => {
    loaddata();
  });
  var url = '/zy/zuoyeMain';
  if (record.type == '5') {
    //当前作业
    url = '/zy/dqkcDqzy';
  } else if (record.type == '6') {
    //测验消息
    url = '/zy/ceshiWenjuan';
  } else if (record.type == '7') {
    //问卷消息
    url = '/zy/dcwjWenjuan';
  }
  url = url + '?rwbh=' + record.rwbh + '&xqxn=' + getSysConfig().flag1 + '&teano=' + record.fbr;
  window.open(url, '_blank');
}
</script>

<style lang="less" scoped>
.indexBackClass {
  background: #fff;
  margin: 20px 0;
  padding-bottom: 20px;
}

.jtkcTitleClass {
  background-image: linear-gradient(to right, #1c84c6, #67b4e5);
  color: white;
  line-height: 30px;
  padding: 3px 0 0 10px;
  font-weight: 600;
  height: 30px;
}
</style>
