<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">

        <el-card v-loading="loading" shadow="never" style="position: relative">

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

            <el-card v-for="item in dataList" v-loading="loading" shadow="hover">

              <div class="card-bot">
                <img src="@/assets/images/file.png" alt="">
                <div>
                  <p>{{ item.name }}</p>
                  <el-button @click="downloadTool(item.url)" style="height: 25px;" type="primary" plain>下载</el-button>
                </div>
              </div>

            </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 { Search } from '@element-plus/icons-vue'
import { projectList, unitList } from '@/api/project/fullView/index';
import { ExpertVO, ExpertQuery, ExpertForm } from '@/api/expert/expert/types';
import { globalHeaders } from '@/utils/request';
import { listLearningTool } from '@/api/study/tool';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { sys_user_sex } = toRefs<any>(proxy?.useDict('sys_user_sex'));
const { project_type } = toRefs<any>(proxy?.useDict('project_type'));
const { item_stage } = toRefs<any>(proxy?.useDict('item_stage'));
const { work_professial_year } = toRefs<any>(proxy?.useDict('work_professial_year'));
const { unit_type } = toRefs<any>(proxy?.useDict('unit_type'));
const tech_qualification = ref([{ label: '全部', value: 0 }]);
const dateRange = ref<[DateModelType, DateModelType]>(['', '']);
const scaleList = ref([
  {
  label:'100万以下',
  value:'1'
  },
  {
  label:'100万~500万',
  value:'2'
  },
  {
  label:'500万~1000万',
  value:'3'
  },
  {
  label:'1000万以上',
  value:'4'
  },
])

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, 0])

const queryData = reactive({
  pageNum: 1,
  pageSize: 20,
  status: '2',
  name:'',

});
const dataList = ref([]);
//查询项目名称
const handleSearch = () => {
  queryData.name = searchName.value;
  getList();
}
//下载工具
const downloadTool =(item)=>{
  window.open(item)
}
/** 查询expert列表 */
const getList = async () => {
  loading.value = true;
  const res = await listLearningTool(queryData);
  dataList.value = res.rows;
  total.value = res.total;
  loading.value = false;
}
const clearName = ()=>{
  queryData.name = 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:
        break;
      case 1:
        break;
      case 2:
        break;
      default:
        break;
    };
  })

  getList();

  console.log(`conditionList`, conditionList);

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

}


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

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

  console.log(`tech_qualification`, tech_qualification);
  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 {
      display: flex;
      img{
        width: 25%;
        object-fit: contain;
      }
      div{
        margin-left: 1vw;
        p{
          margin: 0;
          font-weight: bolder;
          margin-bottom: 1vh;
        }
      }
    }

    .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;
      }
      span:nth-child(2)::after{
        content:" >>";


      }
    }

    :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>
