<script setup lang="ts">
import type { type_dyaw_xlfw_zxhd, type_dyaw_xlfw_zxhd_log, type_archives_item } from '~/types';
import { Search } from '@element-plus/icons-vue'
import user from '~/store/user';
import router from '@/router';
let dyaw_xlfw_zxhd = $ref<type_dyaw_xlfw_zxhd | undefined>()
let dyaw_xlfw_zxhd_list = $ref<type_dyaw_xlfw_zxhd[] | undefined>()

const emits = defineEmits<{
  (event: 'openRtcDialog', dyaw_xlfw_zxhd: type_dyaw_xlfw_zxhd, type: 'audio' | 'video'): void;
}>()

const props = defineProps<{updateFnList:Function[]}>()

const searchValue = $ref('搜索')
watch(
  () => searchValue,
  async (val, oldVal) => {
    if (oldVal === '搜索') return;
    dyaw_xlfw_zxhd_list = (await request({
      url: '/dyaw/xlfw_zxhd/index',
      data: {
        dxz_tea_user_id: user.user_id,
        dxz_stu_user_realname: searchValue === '搜索' ? undefined : searchValue,
        limit: 20,
        last_msg: 1
      }
    })).data.page_data
  }
)


// let timer: NodeJS.Timeout;
// (async function loop() {
//   dyaw_xlfw_zxhd_list = (await request({
//     url: '/dyaw/xlfw_zxhd/index',
//     data: {
//       dxz_tea_user_id: user.user_id,
//       dxz_stu_user_realname: searchValue === '搜索' ? undefined : searchValue,
//       limit: 20,
//       last_msg: 1
//     }
//   })).data.page_data
//   if (dyaw_xlfw_zxhd !== undefined) {
//     const temp = dyaw_xlfw_zxhd_list!.find(item => item.dxz_stu_user_id === dyaw_xlfw_zxhd!.dxz_stu_user_id)
//     if (temp?.dxz_id !== dyaw_xlfw_zxhd?.dxz_id) {
//       dyaw_xlfw_zxhd = temp
//     }
//   }

//   timer = setTimeout(async () => {
//     await loop();
//   }, 60 * 1000);
// })();

function handleClickStuCard(stu: type_dyaw_xlfw_zxhd) {
  sessionStorage.setItem('dyaw_xlfw_zxhd', JSON.stringify(stu))
  router.push({
    name: 'teacher_consult_chat',
  })
}



// onBeforeUnmount(() => {
//   clearInterval(timer)
// })

function onClickLeft() {
  router.back()
}

</script>

<template>
  <van-nav-bar title="咨询页面" left-text="" left-arrow @click-left="onClickLeft"
    style="--van-nav-bar-background:#397FF6;--van-nav-bar-icon-color:#fff;--van-nav-bar-title-text-color:#fff;--van-nav-bar-title-font-size:18px;--van-nav-bar-text-color:#fff;" />
  <div class="p-10px flex-auto flex flex-col justify-start bg-white space-y-4">
    <el-input autocomplete="off" name="searchValue" v-model="searchValue" size="large" :prefix-icon="Search"
      @focus="searchValue = ''" clearable placeholder="搜索"
      :style="`${searchValue === '搜索' && '--ep-input-text-color:var(--ep-text-color-placeholder);'}`"></el-input>

    <remote-list url="/dyaw/xlfw_zxhd/index" loop :d="{
      dxz_tea_user_id: user.user_id,
      dxz_stu_user_realname: searchValue === '搜索' ? undefined : searchValue,
      limit: 20,
      last_msg: 1
    }" class="mt-2 flex-auto">
      <template #default="{ row: item }">
        <chat-stu-card :d="item" @click="handleClickStuCard(item)" class="h-68px"
          style="border-bottom: 1px solid #f3f4f6;"></chat-stu-card>
      </template>
    </remote-list>
  </div>
</template>

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