<template>
  <view class="container" :hidden="!showCon">
    <view class="content">
      <view class="search">
        <view class="search_box">
          <input :class="[isFocus ? 'search_input' : 'search_input_none']" 
                 placeholder="请输入医生名称搜索" 
                 :placeholder-class="isFocus ? 'placeholder' : 'placeholder_none'" 
                 v-model="searchValue" 
                 @focus="focusFn('focus')" />
          <image :class="['search_icon', isFocus ? 'search_icon_none' : '']" :src="iconUrl.search"></image>
          <image class="remove_icon" v-if="isFocus" :src="iconUrl.cha" @click.stop="focusFn('blur')"></image>
          <view v-if="isFocus" :class="['search_confirm', 'backgroundCustom_F08', isFocus ? 'search_confirm_active' : '']" @click="searchClick">搜索</view>
        </view>
      </view>
      <view class="doctorList" v-if="doctorList.length > 0">
        <view class="doctor_list">
          <view class="doctor_item" v-for="(doctorItem, doctorIndex) in doctorList" :key="doctorIndex">
            <view class="doctor_item_nav displayFlexLeft" @click="doctorInfoClick(doctorItem)">
              <view class="doctor_item_nav_img">
                <image :src="doctorItem.DoctorPhotoUrl || iconUrl.icon_doctor" mode="widthFix"></image>
              </view>
              <view class="doctor_item_nav_tit">
                <view class="doctor_item_nav_subtit">
                  <text class="doctor_item_nav_subtit_val">{{doctorItem.DoctorName}}</text>
                  <text v-if="doctorItem.DoctorTitle || doctorItem.Title || doctorItem.LczcName" class="doctor_item_nav_subtit_txt">
                    {{doctorItem.DoctorTitle || doctorItem.Title || doctorItem.LczcName}}
                  </text>
                </view>
                <view v-if="doctorItem.Spec || doctorItem.DoctorSkill" class="doctor_itemStyle">
                  <view class="doctor_item_nav_info">
                    {{doctorItem.Spec || doctorItem.DoctorSkill}} 
                  </view>
                  <view class="doctor_item_list colorCustom">
                    详情
                  </view>
                </view>
              </view>
            </view>
          </view>
        </view>
      </view>
      <view class="noData" v-if="doctorList.length == 0">
        <noData value="暂无数据"></noData> 
      </view>
    </view>
    <doctorInfo v-model:doctorInfoIsShow="doctorInfoIsShow" :doctorInfo="doctorInfoData"></doctorInfo>
  </view>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { common } from '@/utils';
import icon from '@/utils/icon';
import { deptAndDocApiList } from '@/pagesPatient/service/new/index';
import noData from '@/pages/st1/components/noData/noData.vue';
import doctorInfo from '@/pagesPatient/st1/components/doctorInfo/doctorInfo.vue';

const iconUrl = icon;
const isFocus = ref(false);
const searchValue = ref('');
const doctorList = ref<any[]>([]);
const showCon = ref(false);
const doctorInfoIsShow = ref(false);
const doctorInfoData = ref({});
const queryBean = ref<any>({});
const app = getApp();

onLoad((options: any) => {
  let qb = options.queryBean ? JSON.parse(options.queryBean) : { HospitalId: app.globalData.hosId, DeptId: '' };
  queryBean.value = qb;
  uni.setNavigationBarTitle({
    title: qb.DeptName ? qb.DeptName : '专家介绍'
  });
  main();
});

const main = () => {
  queryUserListV2();
};

const queryUserListV2 = async (sv: string = '') => {
  let list: any[] = [];
  let queryData = {
    Hospitalid: queryBean.value.HospitalId,
    DeptId: queryBean.value.DeptId,
    DoctorName: sv,
  };
  let res = await deptAndDocApiList(queryData);
  if (common.isNotEmpty(res)) {
    list = res;
  }
  doctorList.value = list;
  showCon.value = true;
};

const doctorInfoClick = (item: any) => {
  doctorInfoIsShow.value = true;
  doctorInfoData.value = item;
};

const focusFn = (type: string) => {
  if (type === 'focus') {
    isFocus.value = true;
  } else {
    isFocus.value = false;
    searchValue.value = '';
    queryUserListV2();
  }
};

const searchClick = () => {
  if (common.isEmpty(searchValue.value)) {
    common.showModal('请输入搜索科室或医生');
    return;
  }
  queryUserListV2(searchValue.value);
};
</script>

<style lang="scss" scoped>
@import '@/pagesPatient/st1/static/css/search.wxss';

.content{
  height: 100%;
}
.content {
  padding-top: 110upx;
  position: relative;
  z-index: 10;
}

.search_con {
  width: 100%;
  position: fixed;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  top: 0;
  left: 0;
  z-index: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.search_con_inner {
  width: 100%;
  background-color: #fff;
  padding: 0 0 10upx 30upx;
}

.search_con_list {
  overflow: auto;
  padding-top: 110upx;
  -webkit-overflow-scrolling: touch;
}

.search_con_list_inner {
  width: 100%;
  display: inline-block;
  margin-top: -1px;
}

.search_con_item {
  font-size: 32upx;
  padding: 36upx 0;
  color: #222326;
}
.date_list {
  background-color: #fff;
  padding: 20upx 6upx 20upx 30upx;
  white-space: nowrap;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
  z-index: 2;
}

.date_item {
  width: 140upx;
  height: 144upx;
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: #F1F1F6;
  color: #222326;
  border-radius: 24upx;
  margin-right:24upx;
  font-size: 32upx;
  vertical-align: middle;
}
.month {
  margin-top: 10upx;
}

.date_item_all {
  font-size: 32upx;
}

.doctor_list {
  padding: 0 30upx;
  display: inline-block;
  width: 100%;
}

.doctor_item {
  background: #fff;
  border-radius: 24upx;
  margin: 30upx 0;
  padding: 20upx 30upx 32upx;
}

.doctor_item_nav {
  display: flex;
  position: relative;
  padding: 17upx 0;
}

.doctor_item_nav_img {
  width: 88.3upx;
  height: 88.3upx;
  border-radius: 50%;
  margin-right: 25upx;
  overflow: hidden;
}

.doctor_item_nav_tit {
  width: 82%;
}

.doctor_item_nav_subtit_val {
  font-size: 32upx;
  font-family: PingFang SC;
  font-weight: 800;
  color: #222326;
  margin-right: 12upx;
}

.doctor_item_nav_subtit_txt {
  height: 36upx;
  line-height: 28upx;
  font-size: 24upx;
  font-family: PingFang SC;
  padding: 0upx 7upx;
  position: relative;
  display: inline-block;
  background: #FFFBF4;

}
.doctor_item_list{
  font-size: 28upx;
  font-family: Source Han Sans CN;
  font-weight: 500;
  line-height: 40upx;
  text-align: end;
  display: flex;
  justify-content: right;
  align-items: flex-end;
}
.doctor_item_nav_info {
  font-size: 28upx;
  font-family: Source Han Sans CN;
  font-weight: 500;
  color: #62626D;
  line-height: 40upx;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  width: 450upx;
}

.time_list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}

.time_item {
  margin: 23upx 25upx 0 0;
  width: 196upx;
  height: 110upx;
  line-height: 110upx;
  background: #F1F1F6;
  border-radius: 20upx;
  font-size: 28upx;
  color: #222326;
  text-align: center;
  position: relative;
}
.time_item:nth-child(3n){
  margin-right: 0;
}
.nav {
  height: 100upx;
  padding:0 30upx;
  background-color: #fff;
  border-radius: 0 0 30upx 30upx;
  font-size: 30upx;
  color: #43434A;
  position: relative;
  z-index: 2;
}

.nav_val {
  margin-right: 30upx;
}

.nav_inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}

.nav_tit_val {
  white-space: nowrap;
}


.bottom {
  width: 16upx;
  height: 16upx;
  margin-left: 16upx;
}

.time_item_img {
  width: 61upx;
  height: 54upx;
  position: absolute;
  right: 0;
  top: 0;
}
.time_item_stop view{
  color: #8A8A99;
}
.doctorList{
  overflow: auto;
  height: 100%;
}
.doctor_itemStyle{
  display: flex;
  flex-direction: row;
  font-size: 28upx;
  font-family: Source Han Sans CN;
  font-weight: 500;
  color: #62626D;
  line-height: 40upx;
  margin-top: 10upx;
}
.search_icon{
  left:32%
}
.search_icon_none {
  left: 20upx;
}
</style>