<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">
      <div class="c-left">
        <p class="cl-header">
          项目所属机构
        </p>
        <el-menu default-active="0" class="el-menu-vertical-demo">
          <el-menu-item @click="selUnit('0')" index="0">
            <el-icon><icon-menu /></el-icon>
            <span>全部</span>
          </el-menu-item>
          <el-menu-item @click="selUnit(item)" :index="(index + 1).toString()" v-for="(item, index) of units">
            <el-icon><icon-menu /></el-icon>
            <span>{{ item.deptName }}</span>
          </el-menu-item>

        </el-menu>
      </div>

      <div class="c-right">
        <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(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 scaleList">{{ item.label }}</span>
                  </div>
                </div>

                <div class="search-item">
                  <div class="item-title">
                    <span>评审阶段：</span>
                  </div>
                  <div class="item-content">
                    <span @click="handleFind(2, 0)"
                      :class="conditionList[2] == 0 ? 'item-text active' : 'item-text'">全部</span>
                    <span @click="handleFind(2, parseInt(item.value))"
                      :class="conditionList[2] == item.value ? 'item-text active' : 'item-text'"
                      v-for="item in item_stage">{{ 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-name">
                <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="silk">
                  <span>{{ item_stage[parseInt(item.reviewSn) - 1]?.label }}</span>
                </div> -->
                <div class="card-top">
                  <p class="title">{{ item.productName }}</p>
                </div>
              </template>
              <div class="card-bot">
                <p>
                  <span>项目类型：</span>
                  <span>{{ project_type[parseInt(item.productType) - 1]?.label }}</span>
                </p>
                <p>
                  <span>项目年份：</span>
                  <span>{{ item.createTime?.slice(0, 4) }}年</span>
                </p>
                <p>
                  <span>评审阶段：</span>
                  <span>{{ item.reviewSn ? item_stage[parseInt(item.reviewSn) - 1]?.label : '暂无'}}</span>
                </p>
                <p>
                  <span>项目规模：</span>
                  <span>{{ item.productScale }}万

                  </span>

                </p>
              </div>

              <template #footer>
                <div class="card-footer">
                  <span><el-icon style="margin-right: 6px;"><HomeFilled /></el-icon>{{ item.workUnit }}</span>
                  <span>项目全景</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>



  </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';

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,

  productName:'',
  deptId:'',

  productType: undefined,
  minProductScale:'',
  maxProductScale:'',
  reviewSn:undefined,

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

/** 查询expert列表 */
const getList = async () => {
  loading.value = true;
  const res = await projectList(proxy?.addDateRange(queryData, dateRange.value, 'start')).finally(() => { loading.value = false; })
  dataList.value = res.rows;
  total.value = res.total;
}
const units = ref([]);
const clearName = ()=>{
  queryData.productName = null ;
  getList();
}
const clearTime = ()=>{
  dateRange.value = ['', ''];
  getList();
}
const getUnit = async () => {
  const res = await unitList().finally(() => { });
  units.value = res.data;

}
const selUnit = (unit)=>{
  if (unit !== '0') {
    queryData.deptId = unit.deptId
  }
  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.productType = null : queryData.productType = v;
        break;
      case 1:
        if(v == 0){
          queryData.minProductScale = null; queryData.maxProductScale = null
        }else if(v == 1){
          queryData.minProductScale = null; queryData.maxProductScale = '100'
        }else if(v == 2){
          queryData.minProductScale = '100'; queryData.maxProductScale = '500'
        }else if(v == 3){
          queryData.minProductScale = '500'; queryData.maxProductScale = '1000'
        }else if(v == 4){
          queryData.minProductScale = '1000'; queryData.maxProductScale = null
        }
        break;
      case 2:
        v == 0 ? queryData.reviewSn = null : queryData.reviewSn = v;
        break;
      default:
        break;
    };
  })

  getList();

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

  // loading.value = false;
}


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

onActivated(() => {
  getList();
})
onMounted(async () => {
  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;
      }
      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-name {
  .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%;
  display: flex;
  justify-content: space-between;

  .c-left {
    width: 12%;
    padding-right: 0.5vw;
    // background-color: #0066CC;

    .cl-header {
      position: relative;
      padding-left: 1vw;
      font-size: 1rem;
      margin: 0;
      margin-bottom: 1vh;
    }

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

    .el-menu-item.is-active {
      background-color: #3366CC;
      color: #fff;
    }

  }

  .c-right {
    width: 88%;
  }
}
</style>
