<template>
  <div class="p-2">
    <div class="p-left">
      <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 information_classify">{{ item.label }}</span>
                  </div>
                </div>

              </div>

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

        <el-card v-loading="loading" shadow="never" style="position: relative">
          <template #header>
            <div class="card-header">
              <p>帖子数据条数：{{ total }}</p>
              <div class="query-time">
                <el-input v-model="searchContent" style="max-width: 600px" placeholder="请输入帖子内容关键字搜索"
                  class="input-with-select" clearable @clear="handleFindcontent(0)" :prefix-icon="Search">
                </el-input>
                <el-button @click="handleFindcontent(1)" plain type="primary">查询</el-button>
              </div>
            </div>
          </template>

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

            <div v-for="item in dataList">

              <el-card @click="jumpToDetail(item)" v-loading="loading" shadow="hover">
                <template #header>
                  <div class="card-top">
                    <div class="info-header">
                      <img v-if="item.photograph" :src="item.photograph" alt="">
                      <img v-else src="@/assets/images/avatar.png" alt="">
                      <span>{{ item.deptName }}</span>
                      <el-divider direction="vertical"></el-divider>
                      <span>{{ item.userName }}</span>
                    </div>
                    <div class="top-time">
                      <span>{{ item.createTime }}</span>
                    </div>
                  </div>
                </template>
                <div class="card-bot">
                  <img v-if="item.informationImage" :src="item.informationImage" alt="">
                  <img v-else src="@/assets/images/login-background.jpg" alt="">
                  <div class="bot-con">
                    <h4>
                      {{ item.informationTitle }}</h4>
                    <p>{{ item.informationDetail }}</p>
                    <div>
                      <span><el-icon style="margin-right: 5px;"><ChatDotRound /></el-icon>回复 {{ item.commentCount }}</span>
                      <span><el-tag style="color: #fff;" color="#36d">{{ information_classify[parseInt(item.informationClassifyId) - 1]?.label }}</el-tag></span>
                    </div>
                  </div>
                </div>

              </el-card>

              <el-divider></el-divider>
            </div>
          </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>


      </div>
    </div>

    <div class="p-right">
      <el-card shadow="never">

        <div class="right-content">
          <h3>社区名称: {{ communityInfo.communityName }}</h3>
          <div class="count">
            <el-statistic title="社区成员" :value="personCount">
              <template #suffix>
                <el-icon style="vertical-align: -0.125em">
                  <User />
                </el-icon>
              </template>
            </el-statistic>

            <el-statistic title="社区内容" :value="topicCount">
              <template #suffix>
                <el-icon style="vertical-align: -0.125em">
                  <ChatLineRound />
                </el-icon>
              </template>
            </el-statistic>
          </div>
          <div class="txt">
            <h6>社区介绍</h6>
            <p>{{ communityInfo.communityIntroduce }}</p>
          </div>
        </div>

        <template #footer>
          <div class="right-footer">
            <h6>社区管理员</h6>
            <div class="info-footer">
              <img src="@/assets/images/avatar.png" alt="">
              <span>{{ communityInfo.deptName }}</span>
              <el-divider direction="vertical"></el-divider>
              <span>{{ communityInfo.userName }}</span>
            </div>
          </div>
        </template>
      </el-card>
    </div>


  </div>
</template>

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

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 { information_classify } = toRefs<any>(proxy?.useDict('information_classify'));
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 searchContent = ref('');

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

const queryData = reactive({
  pageNum: 1,
  pageSize: 10,
  status:'2',
  informationTitle: '',
  informationDetail: '',
  informationClassifyId:''

});
const dataList = ref([]);
//查询帖子标题
const handleSearch = () => {
  queryData.informationTitle = searchName.value;
  getList();
}
//查询帖子内容
const handleFindcontent = (type) => {
  type == 0 ? queryData.informationDetail = null:
  queryData.informationDetail = searchContent.value;
  getList();
}

/** 查询帖子信息 */
const getList = async () => {
  loading.value = true;
  queryData.status = '2';
  const res = await listLearningInformation(queryData);
  dataList.value = res.rows;
  total.value = res.total;
  loading.value = false;

}
const clearName = () => {
  queryData.informationTitle = 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.informationClassifyId = null : queryData.informationClassifyId = v.toString();
        break;
      default:
        break;
    };
  })

  getList();

  console.log(`conditionList`, conditionList);

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

  // loading.value = false;
}
const personCount = ref<number>(undefined);
const getSheQuCount = async ()=>{
  const res = await getPersonCount();
  if(res.code ==200){
    personCount.value = res.data;
  }
}
const topicCount = ref<number>(undefined);
const getTieZiCount = async ()=>{
  const res = await getTopicCount();
  if(res.code ==200){
    topicCount.value = res.data;
  }
}
const communityInfo = ref({
  communityName:undefined,
  communityIntroduce:undefined,
  deptName:undefined,
  userName:undefined,
});
const getCommunityInfo = async ()=>{
  const res = await getCommunity();
  if(res.code ==200){
    communityInfo.value = res.data;

  }
}

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

onActivated(() => {
  getSheQuCount();
  getTieZiCount();
  getCommunityInfo();
  getList();
})
onMounted(async () => {
  getSheQuCount();
  getTieZiCount();
  getCommunityInfo();
  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
      }
    }


  }

}

:deep(.content>.el-card>.el-card__body) {
  padding-left: 0 !important;
}

.list {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  height: 55vh;
  overflow-y: scroll;


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

    :deep(.el-card__header){
      padding: 5px !important;
    }
    :deep(.el-card__body){
      padding-bottom: 5px !important;
      // height: 250px;
      position: relative;
    }

    .card-top {
      display: flex;
      justify-content: space-between;
    }

    .info-header {
      display: flex;
      align-items: center;
      font-size: 12px;

      img {
        margin-left: 12px;
        width: 25px;
        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) {}
    }

    .top-time {
      span {
        font-size: 14px;
      }
    }

    .card-bot {
      display: flex;
      justify-content: space-between;
      height: 250px;
      position: relative;
      img {
        width: 20%;
        object-fit: contain;
      }

      .bot-con {
        width: 77%;
        position: relative;
        h4 {
          margin: 0;
          font-weight: bolder;
          font-size: 1.1rem;
        }

        p {
          margin: 0;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 4;
          margin: 1vh 0;
          font-size: 15px;
        }
        div{
          position: absolute;
          bottom: 5px;
          display: flex;
          width: 100%;
          justify-content: space-between;
          span:nth-child(1){
            display: flex;
            align-items: center;
          }
          span:nth-child(2){
            color: #0066CC;
          }
        }
      }
    }

    .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%;
}

.p-2 {
  display: flex;
  justify-content: space-between;
}

.p-left {
  width: 70%;
}

.p-right {
  width: 29.5%;

  .right-content {
    p {
      margin: 0;
    }

    .count {
      display: flex;
      justify-content: space-around;

      .el-statistic {
        width: 35%;
        padding: 10px 0;
        border-radius: 10px;
        text-align: center;
        background-color: rgba(0, 0, 0, 0.1);
      }
    }

    .txt {
      margin-top: 2vh;

      h6 {
        margin: 0;
        font-size: 0.9rem;
        margin-bottom: 1.5vh;
      }
    }
  }

  .right-footer {
    h6 {
      margin: 0;
      font-size: 0.9rem;
      padding: 10px 5px;
    }
  }

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

    img {
      margin-left: 12px;
      width: 8%;
      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;
  }
}
</style>
