<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 project_type">{{ item.label }}</span>
                  </div>
                </div> -->

              <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, item.value)"
                    :class="conditionList[0] == item.value ? 'item-text active' : 'item-text'"
                    v-for="item in acvitity_classify">{{ 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, item.value)"
                    :class="conditionList[1] == item.value ? 'item-text active' : 'item-text'"
                    v-for="item in scaleList">{{ 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" :shortcuts="shortcuts" 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">

            <div class="card-bot">
              <img :src="item.activityPic" alt="">
              <p>{{ item.activityName }}</p>
              <div>
                <span>{{ item.activityStartTime }}~{{ item.activityEndTime }}</span>
                <span>{{ acvitity_classify[parseInt(item.activityClassify) - 1]?.label }}</span>
              </div>
              <span style="float: right;font-size: 0.8rem;background-color: #ddd;padding: 4px;border-radius: 5px;">{{ item.activityStatus == '1'?'未开始':item.activityStatus == '2'?'进行中':'已结束' }}</span>
            </div>

            <template #footer>
              <div class="card-footer">
                <img src="@/assets/images/avatar.png" alt="">
                <span>{{ item.deptName }}</span>
                <el-divider direction="vertical"></el-divider>
                <span>{{ item.userName }}</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 { Search } from '@element-plus/icons-vue'
import { listLearningActivity } from '@/api/study/activity/index';
import { ExpertVO, ExpertQuery, ExpertForm } from '@/api/expert/expert/types';
import { globalHeaders } from '@/utils/request';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { acvitity_classify } = toRefs<any>(proxy?.useDict('acvitity_classify'));
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: '未开始',
    value: '1'
  },
  {
    label: '进行中',
    value: '2'
  },
  {
    label: '已结束',
    value: '3'
  }
])

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 shortcuts = [
  {
    text: '最近一周',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setDate(start.getDate() - 7)
      return [start, end]
    },
  },
  {
    text: '最近一月',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setMonth(start.getMonth() - 1)
      return [start, end]
    },
  },
  {
    text: '最近三月',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setMonth(start.getMonth() - 3)
      return [start, end]
    },
  },
]
const queryData = reactive({
  pageNum: 1,
  pageSize: 20,

  activityName: '',
  activityStatus: '',
  activityClassify: undefined,
  status:'2',

  activityStartTime: '',
  activityEndTime: '',

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

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

}
const units = ref([]);
const clearName = () => {
  queryData.activityName = null;
  getList();
}
const clearTime = () => {
  dateRange.value = ['', ''];
  getList();
}
// const getUnit = async () => {
//   const res = await unitList().finally(() => { });
//   units.value = res.data;

// }
/** 条件查询列表 */
const handleFind = async (dictIndex, index) => {
  console.log(`11`);
  
  if (conditionList.value[dictIndex] == index) {
    return
  }
  conditionList.value[dictIndex] = index;
  conditionList.value.forEach((v, i) => {
    switch (i) {
      //数组第一项
      case 0:
        v == '0' ? queryData.activityClassify = null : queryData.activityClassify = v;
        break;
      //数组第二项
      case 1:
        v == '0' ? queryData.activityStatus = null : queryData.activityStatus = v;
        console.log(`queryData.activityStatus`,queryData.activityStatus);

        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/activityDetail', 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: 24%;
    margin-bottom: 1.5vh;
    margin-left: 0.6vw;
    cursor: pointer;
    position: relative;

    :deep(.el-card__footer) {
      border-top-style: dashed;
    }

    :deep(.el-card__body) {
      padding-bottom: 30px !important;
    }


    .card-bot {
      img {
        width: 100%;
        height: 200px;
        object-fit: cover;
      }

      p {
        margin: 0;
        font-size: 16px;
        font-weight: bolder;
        margin-bottom: 5px;
      }

      div {
        display: flex;
        justify-content: space-between;

        span {
          font-size: 12px;
        }
      }
    }

    .card-footer {
      display: flex;
      align-items: center;
      font-size: 12px;

      img {
        margin-left: 10px;
        width: 12%;
        aspect-ratio: 1;
        border: 0.5px solid black;
        border-radius: 50%;
      }

      span {
        font-size: 18px;
      }

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

      span:nth-child(4) {}
    }

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