<script setup lang='ts'>
import { RouteLocationRaw, useRouter } from 'vue-router'
import { Status } from '~/store/info'
import tabContainer from './container.vue'


const router = useRouter()
function routerPush(_route: RouteLocationRaw) {
  router.push(_route)
}

// const tableData = ref([])
// const total = ref(0)

const queryForm = reactive({
  dc_grade_id: '',
  dc_subject_id: '',
  dc_check: '',
  dc_keyword: '',
  page: 1,
})

// watch(queryForm, () => {
//   doQuery()
// }, { deep: true, immediate: true })

// function doQuery() {
//   request({
//     url: '/dyaw/ctfx/index',
//     data: {
//       ...queryForm,
//       sm_id: user.sm_info.sm_id,
//       create_user_id: user.user_id
//     }
//   }).then(res => {
//     if (res.code === "1") {
//       tableData.value = res.data.page_data
//       total.value = parseInt(res.data.total_rows)
//     }
//   })
// }

// function doDelete() {
//   request({
//     url: '/dyaw/ctfx/delete',
//     data: {
//       dc_id: multipleSelection.value.map(item => item.dc_id)
//     }
//   }).then(
//     res => {
//       if (res.code === "1") {
//         ElMessage.success('删除成功')
//         doQuery()
//       }
//     }
//   )
// }


// TODO: 临时处理
function translateString(str: string) {
  return str
}
function onClickLeft() {
  history.back()
}

function getGradeAndSubject({ grade, subject }: { grade: string, subject: string }) {
  console.log(grade, subject)
  queryForm.dc_grade_id = grade
  queryForm.dc_subject_id = subject
}

</script>

<template>
  <tab-container>
  <template #nav>
    <van-nav-bar title="错题分析" left-text="返回" left-arrow @click-left="onClickLeft" />
  </template>

  <div class="flex justify-between items-center sticky top-90px z-100 bg-light-50">
    <van-search v-model="queryForm.dc_keyword" placeholder="请输入搜索关键词" class="flex-auto" background="transparent" />
    <span class="pr-10px">
      <multi-tree-select @confirm="getGradeAndSubject"></multi-tree-select>
    </span>
  </div>

  <remote-list url="/dyaw/ctfx/index" :d="{
    ...queryForm,
  }" class="mt-2 flex-none">
    <template #default="{ row: d }">
        <van-cell>
          <div class="cursor-pointer rounded shadow-dark-100 px-4 py-2 shadow-md drop-shadow-md h-110px space-y-2"
            @click="routerPush({ name: 'admin_indey_detail', params: { id: d.dc_id } })">
            <div class="flex justify-between">
              <div class="flex space-x-2">
                <van-tag type="primary">{{ d.dc_keyword }}</van-tag>
                <div class="text-xl whitespace-nowrap overflow-ellipsis overflow-hidden max-w-160px">{{ d.dc_title }}
                </div>
              </div>
              <div :class="d.dc_check === '1' ? 'text-green-500' : d.dc_check === '2' ? 'text-red-500' : 'text-blue-500'">
                {{ Status[d.dc_check] }}</div>
            </div>
            <div class="flex space-x-6 text-gray-500">
              <div>{{ d.dc_grade_name }}</div>
              <div>{{ d.dc_subject_name }}</div>
            </div>

            <div class="text-left text-sm text-gray-500 whitespace-nowrap overflow-ellipsis overflow-hidden">{{
              translateString(d.dc_content) }}</div>
          </div>
        </van-cell>

      </template>
    </remote-list>

  </tab-container>
</template>

