<template>
  <nav-bar :navbar-data="navbarData"></nav-bar>
  <view class="common" :style="{ marginTop: height +'px' }">
    <view class="choose-loc-search">
      <uni-search-bar :value="descripts" placeholder="搜索科室" @change="onChange" />
    </view>
    <view :style="{ height: 'calc(100vh - 228rpx)', overflow: 'auto' }" class="all-loc-tree">
      <van-tree-select height="calc(100vh - 228rpx)" style="overflow:auto;" :items="locList"
        :main-active-index="locClassifyID" @click-nav="onClickNav" @click-item="onClickItem" />
    </view>
  </view>
</template>

<script>
import $http from "@/utils/https"
import Util from "@/utils/utils"
import navBar from '@/components/navBar/index'
import VanTreeSelect from '@/components/tree-select/index'
const app = getApp();
export default {
  components: {
    'nav-bar': navBar,
    'van-tree-select': VanTreeSelect
  },
  data() {
    return {
      height: app.globalData.height,
      navbarData: {
        isGoHome: true,
        isGoBack: true,
        title: "选择科室"
      },
      hisHospID: null,
      locList: [],
      descripts: ""
    }
  },
  onLoad() {
    const userData = this.$cache.get('userData')
    if (userData) {
      this.hisHospID = userData.hisHospID
    }
    this.getLocList();
  },
  methods: {
    onClickNav(e) {
      this.locClassifyID = e && e.index || 0
    },

    onClickItem: Util.debounce(function (e) {
      var locID = e.id
      var locDesc = e.text
      uni.navigateTo({
        url: "../searchDoctorLoc/searchDoctorLoc?locID=" + locID + "&locDesc=" + locDesc,
      })
    }),

    onChange: Util.debounce(function (e) {
      this.descripts = e.detail
      this.getLocList();
    }),

    ///调接口获取科室列表
    getLocList: function () {
      let data = {
        params: [{
          hospCode: this.hisHospID,
          descripts: this.descripts,
          imageFlag: "Y",
          videoFlag: "Y"
        }]
      }
      uni.showLoading({
        mask: true
      })
      $http.post("urlS", this, {
        namespace: "Y",
        code: "03100037",
        data: data,
        success: function (res) {
          uni.hideLoading();
          if (+res.errorCode === 0) {
            this.locList = res.result.data
          } else {
            this.locList = []
          }
        }
      });
    },
  },
}
</script>

<style>
.choose-loc-search  {
  background: #fff !important;
}

.van-icon,
.van-icon:before {
  font-size: 40rpx;
}

.van-field__input {
  font-size: 32rpx;
}

.all-loc-tree .van-tree-select__item::before {
  content: ' ';
  position: absolute;
  right: 24rpx;
  top: 32rpx;
  width: 16rpx;
  height: 16rpx;
  border-top: 4rpx solid #AAAAAA;
  border-right: 4rpx solid #AAAAAA;
  transform: rotate(45deg);
}
</style>
