<template>
  <PageWrapper>
    <!-- 搜索框 -->
    <el-card shadow="hover" :bordered="false" class="custom-box-card">
      <h2 class="text-lg">搜索列表（预约）</h2>
      <div class="mt-4 text-center">
        <el-input
          :style="{ width: '320px' }"
          v-model="keywords"
          placeholder="请输入关键字"
          :prefix-icon="Search"
        />
      </div>
    </el-card>

    <!-- 预约部分 start -->
    <div class="mt-3 tab3">
      <el-card shadow="hover" class="mb-2 custom-box-card">
        <!-- 分类 -->
        <div class="p-5">
          <el-skeleton :rows="1" :loading="loading" style="width: 100%">
            <template #default>
              <div class="flex items-start classification justify-between mt-2.5">
                <div class="flex-none label">分类: </div>
                <div class="flex-grow">
                  <el-space wrap size="small" :class="!isCollapse ? 'height-limited' : ''">
                    <el-tag
                      size="large"
                      v-for="(item, index) in categoryListData"
                      :key="index"
                      @click="selectedHandle(index)"
                      :class="categoryIndex != index ? 'noSelected' : ''"
                      >{{ item.name }}</el-tag
                    >
                  </el-space>
                </div>
                <div
                  class="flex items-center justify-end flex-none cursor-pointer collapse-btn"
                  :style="`color:var(--el-color-primary-light-1)`"
                  @click="collapseHandle"
                  >{{ isCollapse ? '收起' : '展开' }}
                  <el-icon
                    ><arrow-up-bold class="ml-1" v-if="isCollapse" /><arrow-down-bold
                      class="ml-1"
                      v-else /></el-icon
                ></div>
              </div>
            </template>
          </el-skeleton>

          <div class="flex items-start items-center justify-between mt-4 classification">
            <div class="flex-none label">排序:</div>
            <div class="flex-grow">
              <el-radio-group v-model="radio">
                <el-radio :label="1">最新</el-radio>
                <el-radio :label="2">最热</el-radio>
              </el-radio-group>
            </div>
          </div>
        </div>
      </el-card>

      <!-- 预约 -->
      <el-row :gutter="12" class="list">
        <el-col
          :xs="12"
          :sm="8"
          :md="8"
          :lg="6"
          :xl="4"
          v-for="item in makeListData"
          :key="item.id"
        >
          <el-card shadow="hover" class="custom-box-card card">
            <div class="flex items-center px-4">
              <el-avatar :size="40" :src="item.avatar" />
              <span class="ml-2 text-base">{{ item.doctor }} 医师</span>
            </div>
            <dl class="px-4 my-4 c-gray">
              <dt>科室：{{ item.subject }}</dt>
              <dd>最后预约时间：{{ item.date }}</dd>
            </dl>
            <el-divider />
            <el-row class="grid-box">
              <el-col :span="6">
                <el-tooltip content="查看" placement="top" offset="-5">
                  <div class="wrap"
                    ><a
                      href="https://www.naiveadmin.com/home"
                      target="_blank"
                      class="flex items-center justify-center"
                      ><el-icon><eye-outlined /></el-icon></a
                  ></div>
                </el-tooltip>
              </el-col>
              <el-col :span="6" class="flex items-center justify-center">
                <el-tooltip content="导出" placement="top" offset="-5">
                  <div class="flex items-center justify-center wrap"
                    ><el-icon><export-outlined class="text-base" /></el-icon
                  ></div>
                </el-tooltip>
              </el-col>
              <el-col :span="6" class="flex items-center justify-center">
                <el-tooltip content="编辑" placement="top" offset="-5">
                  <div class="flex items-center justify-center wrap"
                    ><el-icon><edit-outlined class="text-base" /></el-icon
                  ></div>
                </el-tooltip>
              </el-col>
              <el-col :span="6" class="flex items-center justify-center">
                <el-dropdown trigger="hover">
                  <div class="flex items-center justify-center wrap"
                    ><el-icon><delete-outlined class="text-base" /></el-icon
                  ></div>
                  <template #dropdown>
                    <el-dropdown-menu>
                      <el-dropdown-item>删除</el-dropdown-item>
                      <el-dropdown-item>隐藏</el-dropdown-item>
                    </el-dropdown-menu>
                  </template>
                </el-dropdown>
              </el-col>
            </el-row>
          </el-card>
        </el-col>
      </el-row>

      <!-- 加载更多 -->
      <el-card shadow="hover" class="mt-3 text-center custom-box-card">
        <el-button :loading="loadingMore" @click="loadMore">加载更多</el-button>
      </el-card>
    </div>
  </PageWrapper>
</template>

<script lang="ts" setup>
  import { ref, onMounted } from 'vue';
  import { Search, ArrowUpBold, ArrowDownBold } from '@element-plus/icons-vue';
  import { EyeOutlined, ExportOutlined, EditOutlined, DeleteOutlined } from '@vicons/antd';
  import { categoryList } from '@/api/comtemp/category';
  import { makeList } from '@/api/comtemp/make';

  const keywords = ref('');
  const loading = ref(true);
  const categoryIndex = ref(-1);
  const isCollapse = ref(false);
  const categoryListData = ref();
  const makeListData = ref();
  const pageSize = ref(12);
  const loadingMore = ref(false);
  const radio = ref(1);

  //获取分类列表
  async function getCategoryList() {
    const res = await categoryList();
    categoryListData.value = res && res.list ? res.list : [];
    loading.value = false;
  }

  //分类选中
  function selectedHandle(index) {
    categoryIndex.value = index;
  }

  //是否展开
  function collapseHandle() {
    isCollapse.value = !isCollapse.value;
  }

  //获取预约列表
  async function getMakeList() {
    const res = await makeList({ pageSize: pageSize.value });
    makeListData.value = res && res.list ? res.list : [];
    loadingMore.value = false;
  }

  //加载更多
  function loadMore() {
    loadingMore.value = true;
    pageSize.value = pageSize.value + 12;
    getMakeList();
  }

  onMounted(() => {
    //获取分类
    getCategoryList();
    //获取预约
    getMakeList();
  });
</script>

<style lang="scss" scoped>
  // 处理栅格
  .el-row {
    padding-top: 6px;
    margin: -6px;
    .el-row {
      padding-top: 0;
    }
  }
  .el-col {
    padding-top: 6px;
    padding-bottom: 6px;
  }
  // 卡片定制
  .custom-box-card {
    border: none;
  }

  //分类
  .classification {
    .label,
    .collapse-btn {
      height: 32px;
      font-size: 14px;
      line-height: 30px;
    }
    .label {
      width: 60px;
    }
    .collapse-btn {
      width: 60px;
    }
    .height-limited {
      height: 40px;
      overflow: hidden;
    }
    .el-tag {
      cursor: pointer;
    }
    .el-tag.noSelected {
      background-color: transparent;
      border-color: transparent;
      color: var(--el-color-info-lighter);
    }
  }

  //预约
  .tab3 {
    .list {
      .card :deep(.el-card__body) {
        padding: 16px 0 0;
        .el-divider {
          margin-bottom: 0;
        }
        .grid-box {
          .el-col {
            height: 60px;
            padding: 8px 0;
            .wrap {
              position: relative;
              width: 100%;
              height: 100%;
              color: var(--el-color-info-light);
              cursor: pointer;
              &::before {
                content: '';
                position: absolute;
                right: 0;
                top: 0;
                bottom: 0;
                width: 1px;
                background-color: var(--el-border-color-base);
              }
              a {
                height: 100%;
                color: var(--el-color-info-light);
              }
            }
            &:last-child .wrap {
              &::before {
                content: none;
              }
            }
          }
        }
      }
      .card:hover {
        box-shadow: rgba(0, 0, 0, 0.2) 0px 0px 20px;
      }
    }
  }
</style>
