<template>
  <div class="home">
    <nav-bar/>
    <div class="search">
      <div class="searchBox" @click="search">
        <router-link to="search">搜索科室、医生</router-link>
      </div>
    </div>

    <div class="ksbox">
      <van-tabs class="order_tab" @click="tabClick" line-width="0px" color="#fff">
        <van-tab v-for="item in ksCate" :key="item.id">
          <template #title>
            {{ item.name }}
          </template>

          <ul>
            <li v-for="li in ksList" :key="li.id">
              <van-cell
                  :title="li.name"
                  is-link
                  :to="'Hospital_ksjs_detail?id=' + li.id"
              />
            </li>
          </ul>
        </van-tab>
      </van-tabs>
    </div>
    <!-- <van-tabs class="order_tab">
      <van-tab v-for="item in list" :key="item.id">
        <template #title>
          {{ item.name }}
        </template>
        <ul>
          <li v-for="li in item.childrens" :key="li.id">
            <van-cell
              :title="li.name"
              is-link
              :to="'Hospital_ksjs_detail?id=' + li.id"
            />
          </li>
        </ul>
      </van-tab>
    </van-tabs> -->
  </div>
</template>

<script>
import {apiGetjksfl, apiGetksLsist, apiGetksGroupall} from "@/request/api.js";
import {Toast} from "vant";

export default {
  components: {},
  data() {
    return {
      active: 0,
      title: "",
      flag: false,
      loading: false,
      finished: false,
      list: [],
      // 科室分类
      ksCate: [],
      paramsData: {
        type: "",
        page: 1,
        pagesize: 1000,
        name: "",
      },
      //   科室列表
      ksList: [],
    };
  },
  mounted() {
    this.getKscateData();
    // this.getData();
  },
  methods: {
    search() {
      this.$router.push({path: "/Search"})
    },
    getData() {
      apiGetksGroupall().then((res) => {
        this.loading = false;
        this.list = res.data;
        // console.log(this.list);
        // this.paramsData.type = res.data[0].id;
        // this.getKslistData();
      });
    },
    // 获取分类列表
    getKscateData() {
      apiGetjksfl().then((res) => {
        this.loading = false;
        this.ksCate = res.data;
        this.paramsData.type = res.data[0].id;
        this.getKslistData();
      });
    },
    // 获取科室列表
    getKslistData() {
      apiGetksLsist(this.paramsData).then((res) => {
        this.loading = false;
        if (res.data.length < this.paramsData.pagesize) {
          this.finished = true;
          //console.log(this.finished);
        }
        this.ksList = res.data;
        //console.log(this.ksCate);
      });
    },
    tabClick(e) {
      this.paramsData.type = this.ksCate[e].id;
      this.getKslistData();
    },
    loadMore() {
      if (!this.finished) {
        this.paramsData.page += 1;
        this.getKslistData();
      }
    },
    handleSearch() {
      this.paramsData.page = 1;
      this.finished = false;
      this.list = [];
      this.ksList = [];
      this.getKslistData();
      //   this.getData();
    },
  },
};
</script>


<style scoped lang="scss">

.search {
  width: 100%;
  height: 1rem;
  position: fixed;
  z-index: 2;
}

.searchBox {
  width: calc(100% - 1rem);
  border-radius: 0.5rem;
  background: #f1f1f1;
  text-align: center;
  line-height: 1rem;
  font-size: 0.375rem;
  position: absolute;
  left: 0.5rem;

}

.ksbox {
  position: absolute;
  top: 2.5rem;
  z-index: 1;
}

.van-tabs {
  display: flex;
  color: #fff;

}

::v-deep .van-tabs--line .van-tabs__wrap {
  height: calc(100% - 1rem);
  overflow-y: auto;
  width: 4rem;
  color: #fff;
}

::v-deep .van-tabs__nav--line {
  display: block;
  background: #fff;
}

::v-deep .van-tab {
  height: 1rem;
  flex: inherit;
}

::v-deep .van-tab--active {
  background: #e6e6e6;
  position: relative;
}

::v-deep .van-tab--active::after {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translate(0, -50%);
  width: 0.1rem;
  height: 1rem;
  background: #46c3b0;
}


</style>
