<template>
  <div class="home">
    <nav-bar />
    <div class="search">
      <div class="container">
        <!-- <router-link to="search"
          ><img src="../assets/search1.png" />输入搜索关键词</router-link
        > -->
        <div class="searchBox">
          <input
            type="text"
            v-model="paramsData.name"
            placeholder="输入搜索关键词"
            @blur="handleSearch()"
          />
          <img src="../assets/search1.png" />
        </div>
      </div>
    </div>

    <van-tabs class="order_tab" @click="tabClick">
      <van-tab v-for="item in cateList" :key="item.id">
        <template #title>
          {{ item.name }}
        </template>

        <van-list
          v-model="loading"
          :finished="finished"
          finished-text="没有更多了"
          @load="loadMore"
        >
          <ul>
            <li v-for="li in list" :key="li.id">
              <van-cell
                :title="li.name"
                :value="li.price"
                :label="li.explain"
                :to="'Hospital_xmcx_detail?id=' + li.id"
              />
            </li>
          </ul>
        </van-list>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
import { apiGetxmfl, apiGetxmList } from "@/request/api.js";
import { Toast } from "vant";
export default {
  components: {},
  mounted() {
    console.log(this.$route.meta.title);
    this.title = this.$route.meta.title;
  },
  data() {
    return {
      active: 0,
      title: "",
      flag: false,
      paramsData: {
        type: "",
        page: 1,
        pagesize: 10,
        name: "",
      },
      cateList: [],
      list: [],
    };
  },
  mounted() {
    this.getCateData();
  },
  methods: {
    // 获取分类列表
    getCateData() {
      apiGetxmfl().then((res) => {
        this.loading = false;
        this.cateList = res.data;
        this.paramsData.type = res.data[0].id;
        this.getlistData();
      });
    },
    // 获取列表
    getlistData() {
      apiGetxmList(this.paramsData).then((res) => {
        this.loading = false;
        if (res.data.length < this.paramsData.pagesize) {
          this.finished = true;
          console.log(this.finished);
        }
        this.list = res.data;
      });
    },
    tabClick(e) {
      this.paramsData.type = this.cateList[e].id;
      this.getlistData();
    },
    loadMore() {
      if (!this.finished) {
        this.paramsData.page += 1;
        this.getlistData();
      }
    },
    handleSearch() {
      this.paramsData.page = 1;
      this.finished = false;
      this.list = [];
      this.getData();
    },
  },
};
</script>


<style scoped lang="scss">
.search a {
  background: #f1f1f1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 64px;
  border-radius: 32px;
  font-size: 28px;
  color: #999;
  margin: 30px 0px;
}

.search a img {
  width: 28px;
  height: 28px;
  margin-right: 10px;
}
.searchBox {
  position: relative;
  width: 100%;
  height: 64px;
  border-radius: 32px;
  font-size: 28px;
  color: #999;
  margin: 30px 0px;
}
.searchBox input {
  width: 100%;
  height: 100%;
  border-radius: 32px;
  background: #f1f1f1;
  border: none;
  text-align: center;
  padding-left: 30px;
  box-sizing: border-box;
}
.searchBox img {
  position: absolute;
  top: 18px;
  left: 230px;
  width: 28px;
  height: 28px;
  margin-right: 10px;
}
.van-tabs {
  display: flex;
}

::v-deep .van-tabs--line .van-tabs__wrap {
  height: calc(100vh - 124px);
  overflow-y: auto;
  width: 158px;
}
::v-deep .van-tabs__nav--line {
  display: block;
  background: #e6e6e6;
}
::v-deep .van-cell__title {
  width: calc(100% - 150px);
  flex: inherit;
}
::v-deep .van-cell__value {
  width: 150px;
  flex: inherit;
  color: #d62e25;
  font-size: 36px;
}
::v-deep .van-tab {
  height: 116px;
  flex: inherit;
}
::v-deep .van-tab--active {
  background: #fff;
  position: relative;
}

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

::v-deep .van-tabs__line {
  display: none;
}

::v-deep .van-tabs__content {
  width: calc(100% - 158px);
}
</style>
