<template>
  <div class="p-2">

    <div class="top-search">
      <el-input v-model="searchName" style="max-width: 600px" placeholder="请输入资料名称关键字搜索" class="input-with-select"
        clearable @clear="clearName" :prefix-icon="Search">
        <template #append>
          <el-button type="primary" @click="handleSearch">查询</el-button>
        </template>
      </el-input>
    </div>

    <div class="content">

      <transition :enter-active-class="proxy?.animate.searchAnimate.enter"
        :leave-active-class="proxy?.animate.searchAnimate.leave">
        <div v-show="showSearch" class="mb-[10px]">

          <el-card shadow="hover">
            <div class="search-list">

              <div class="search-item">
                <div class="item-title">
                  <span>资源类型：</span>
                </div>
                <div class="item-content">
                  <span @click="handleFind(0, 0)"
                    :class="conditionList[0] == 0 ? 'item-text active' : 'item-text'">全部</span>
                  <span @click="handleFind(0, parseInt(item.value))"
                    :class="conditionList[0] == item.value ? 'item-text active' : 'item-text'"
                    v-for="item in source_type">{{ item.label }}</span>
                </div>
              </div>

              <div class="search-item">
                <div class="item-title">
                  <span>资源分类：</span>
                </div>
                <div class="item-content">
                  <span @click="handleFind(1, 0)"
                    :class="conditionList[1] == 0 ? 'item-text active' : 'item-text'">全部</span>
                  <span @click="handleFind(1, parseInt(item.value))"
                    :class="conditionList[1] == parseInt(item.value) ? 'item-text active' : 'item-text'"
                    v-for="item in source_classify">{{ item.label }}</span>
                </div>
              </div>

            </div>

          </el-card>
        </div>
      </transition>

      <el-card v-loading="loading" shadow="hover" style="position: relative">
        <template #header>
          <div class="card-header">
            <p>资源数据条数：{{ total }}</p>
            <div class="query-time">
              <el-date-picker clearable v-model="dateRange" value-format="YYYY-MM-DD HH:mm:ss" type="datetimerange"
                @clear="clearTime" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
                :default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]"></el-date-picker>
              <el-button @click="getList" plain type="primary">查询</el-button>
            </div>
          </div>
        </template>

        <div v-if="dataList.length > 0" class="list">

          <el-card @click="jumpToDetail(item)" v-for="item in dataList" v-loading="loading" shadow="hover">
            <template #header>
              <div class="card-top">
                <p class="title">{{ item.resourceName }}</p>
              </div>
            </template>
            <div class="card-bot">
              <p>
                <span>作者：</span>
                <span>{{ item.author }}</span>
              </p>
              <p>
                <span>发表期刊：</span>
                <span>{{ item.publishJournal }}</span>
              </p>
              <p>
                <span>期刊号：</span>
                <span>{{ item.journalNo }}</span>
              </p>
              <p>
                <span>发表时间：</span>
                <span>{{ item.resourceTime }}

                </span>

              </p>
            </div>

            <template #footer>
              <div class="card-footer">
                <span>
                  <el-icon style="margin-right: 6px;">
                    <Management />
                  </el-icon>{{ source_type[parseInt(item.resourceType) - 1] ? source_type[parseInt(item.resourceType) - 1].label : ''}}</span>
                <span>{{ source_classify[parseInt(item.resourceClassify	) - 1] ? source_classify[parseInt(item.resourceClassify	) - 1].label : '' }}</span>
              </div>

            </template>
          </el-card>

        </div>

        <el-empty v-else-if="dataList.length == 0" description="暂无数据"></el-empty>



        <pagination v-show="total > 0" :total="total" v-model:page="queryData.pageNum"
          v-model:limit="queryData.pageSize" @pagination="getList" />
      </el-card>


    </div>



  </div>
</template>

<script setup name="Expert" lang="ts">
import { Management, Search } from '@element-plus/icons-vue'
import { listLearningResource } from '@/api/study/resource/index';
import { ExpertVO, ExpertQuery, ExpertForm } from '@/api/expert/expert/types';
import { globalHeaders } from '@/utils/request';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { project_type } = toRefs<any>(proxy?.useDict('project_type'));
const { item_stage } = toRefs<any>(proxy?.useDict('item_stage'));
const { source_classify, resource_status,source_type } = toRefs<any>(proxy?.useDict('source_classify', 'resource_status','source_type'));
const tech_qualification = ref([{ label: '全部', value: 0 }]);
const dateRange = ref<[DateModelType, DateModelType]>(['', '']);
const loading = ref(false);
const showSearch = ref(true);
const total = ref(0);
const router = useRouter();
const searchName = ref('');

const queryFormRef = ref<ElFormInstance>();
const expertFormRef = ref<ElFormInstance>();
//条件列表
const conditionList = ref([0, 0])

const queryData = reactive({
  pageNum: 1,
  pageSize: 10,


  resourceName: '',
  resourceType: '',
  resourceClassify: '',

  startTime: undefined,
  endTime: '',
  status: '2',
  reviewSn: undefined,

});
const dataList = ref([]);
//查询项目名称
const handleSearch = () => {
  queryData.resourceName = searchName.value;
  getList();
}

/** 查询expert列表 */
const getList = async () => {
  loading.value = true;
  const res = await listLearningResource(proxy?.addDateRange(queryData, dateRange.value, 'start')).finally(() => { loading.value = false; })
  dataList.value = res.rows;
  total.value = res.rows.length;
  console.log(`res`, res);

}
const clearName = () => {
  queryData.resourceName = null;
  getList();
}
const clearTime = () => {
  dateRange.value = ['', ''];
  getList();
}

/** 条件查询列表 */
const handleFind = async (dictIndex, index) => {
  if (conditionList.value[dictIndex] == index) {
    return
  }
  conditionList.value[dictIndex] = index;
  conditionList.value.forEach((v, i) => {
    switch (i) {
      case 0:
        v == 0 ? queryData.resourceType = null : queryData.resourceType = String(v);
        break;
      case 1:
        v == 0 ? queryData.resourceClassify = null : queryData.resourceClassify = String(v);
        break;
      default:
        break;
    };
  })

  getList();

  console.log(`conditionList`, conditionList);

}
/** 条件查询列表 */
const findSomeone = async () => {
  // loading.value = true;
  console.log(`queryData,queryData`, queryData);

  // loading.value = false;
}


/** 查看项目详情 */
const jumpToDetail = (row) => {
  console.log(row);
  const _id = row?.id;
  router.push({ path: '/study/resourceDetail', query: { id: _id } })
};

onActivated(() => {
  getList();
})
onMounted(async () => {

  console.log(`tech_qualification`, tech_qualification);
  // getUnit();
  getList();
});
</script>

<style scoped lang="scss">
.search-list {
  width: 100%;

  .search-item {
    width: 100%;
    display: flex;
    margin-bottom: 1vh;

    .item-title {
      width: auto;

      span {
        display: inline-block;
        text-wrap: nowrap;
        width: 7vw;
      }
    }

    .item-content {

      span {
        display: inline-block;
        margin-right: 1vw;
        cursor: pointer;
        font-weight: bolder;
        padding: 1px 4px;
      }

      span:hover {
        background-color: rgba(0, 0, 0, 0.1)
      }

      span.active {
        background-color: #36d;
        color: #fff
      }
    }


  }

}

.list {
  display: flex;
  flex-wrap: wrap;


  .el-card {
    width: 19%;
    margin-bottom: 1.5vh;
    margin-left: 0.6vw;
    cursor: pointer;
    position: relative;

    .silk {
      display: flex;
      justify-content: space-between;

      position: absolute;
      top: -8px;
      right: -8px;
      width: 150px;
      height: 150px;
      overflow: hidden;

      &::before,
      &::after {
        content: "";
        position: absolute;
      }

      &::before {
        left: 8px;
        width: 40px;
        height: 8px;
        border-radius: 8px 8px 0px 0px;
        background-color: var(--ribbon-primary-color);
        opacity: .6;
      }

      &::after {
        border-radius: 0px 8px 8px 0px;
        width: 8px;
        height: 40px;
        right: 0px;
        bottom: 8px;
        background-color: #0066FF;
        opacity: .6;
      }

      &>span {
        position: absolute;
        top: 20%;
        right: -40%;
        z-index: 2;
        width: 140%;
        height: 25px;
        overflow: hidden;
        transform: rotate(45deg);
        border: 1px dashed;
        box-shadow: 0 0 0 3px #0066FF, 0px 21px 5px -18px rgba(0, 0, 0, 0.6);
        background: #0066FF;

        /* 文本居中 */
        display: flex;
        justify-content: center;
        align-items: center;
        color: white;
      }

    }

    .card-top {
      .title {
        position: relative;
        padding-left: 0.8vw;
        height: 2vh;
        line-height: 2vh;
        margin: 0;
        font-size: 15px;
        font-weight: bolder;
      }

      .title::before {
        content: "";
        width: 5px;
        height: 20px;
        display: block;
        position: absolute;
        left: 0;
        top: 50%;
        transform: translateY(-50%);
        border-radius: 3px;
        background-color: #36d;
      }
    }

    .card-bot {
      p {
        margin: 0;
        display: flex;
        justify-content: space-between;
        font-size: 14px;
      }
    }

    .card-footer {
      display: flex;
      justify-content: space-between;
      font-size: 12px;

      span:nth-child(1) {
        padding-left: 5px;
        display: flex;
        align-items: center;
      }

      span:nth-child(2) {
        color: #36d;
      }

    }

    :deep(.el-card__footer) {
      padding: 8px;
    }
  }
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;

  p {
    margin: 5px 0;
    position: relative;
    padding-left: 1vw;
    font-size: 1.2rem;
  }

  p::before {
    content: "";
    width: 5px;
    height: 20px;
    display: block;
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    border-radius: 3px;
    background-color: #36d;
  }
}

.query-time {
  .el-input {
    width: 15vw;

  }

  .el-button {
    margin: 0 1vw 0 2vw;
  }
}

.top-search {
  padding: 4vh 0;
  text-align: center;

  .el-input {
    height: 5vh;

    :deep(.el-input-group__append) {
      cursor: pointer;
      width: 6vw;
      background-color: #0066CC;
      color: #fff;
    }
  }
}

.content {
  width: 100%;
}
</style>
