<template>
  <view class="container">
    <view class="content">
      <view class="userInfoTopFixe">
        <userInfo :userInfo="currentUser" type="member" bgClass="bgLinGra"></userInfo>
      </view>
      <view class="doctor_list" v-if="!showNoData">
        <view class="doctor_item displayFlexLeft" v-for="(item, index) in doctorList" :key="index">
          <view class="doctor_item_img">
            <image :src="item.Url || iconUrl.icon_doctor" mode="widthFix"></image>
          </view>
          <view class="doctor_item_nav displayFlexLeft">
            <view class="displayFlexBetween" style="width: 100%;">
              <view class="doctor_item_nav_tit">
                <view class="doctor_item_nav_subtit displayFlexLeft">
                  <text class="doctor_item_nav_subtit_val">{{ item.DoctorName }}</text>
                  <text class="doctor_item_nav_subtit_txt boderColorCustom_F08 colorCustom_F08">{{ item.DoctorTitle }}</text>
                </view>
                <text class="doctor_item_nav_subtit_dept">科室：{{ item.DeptName }}</text>
              </view>
              <view class="colorCustom boderColorCustom goBtn" @click="goto(item)">去预约</view>
            </view>
            <view class="doctor_item_info">擅长：{{ item.Spec || '-' }}</view>
          </view>
        </view>
      </view>
      <view v-else class="noData displayFlexCol">
        <noData :value="noDataTip"></noData>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { common, pagesPatientFn } from '@/utils';
import icon from '@/utils/icon';
import { REQUEST_CONFIG } from '@/config';
import { queryHistoryBaseDoctor } from '@/pagesPatient/service/yygh';
import userInfo from '@/pagesPersonal/st1/components/userInfo/userInfo.vue';
import noData from '@/pages/st1/components/noData/noData.vue';

const app = getApp();

const iconUrl = ref(icon);
const showNoData = ref(false); // 是否显示暂无数据
const noDataTip = ref('暂无历史预约医生信息'); // 暂无数据提示信息
const doctorList = ref<any[]>([]); // 医生列表
const currentUser = ref({});

onLoad(() => {
  main();
});

const main = async () => {
  let cUser = app.globalData.currentUser;
  let result: any[] = [];
  let isShowNoData = true;
  
  let queryData = {
    HosId: app.globalData.districtId || app.globalData.hosId,
    QueryLocal: "1",
    MemberIds: cUser.memberId,
  };
  
  let resp = await queryHistoryBaseDoctor(queryData);
  
  if (!common.isEmpty(resp)) {
    resp.map((item: any) => {
      /**如果医生头像没有域名 添加域名 */
      if (item.Url && item.Url.indexOf('http') == '-1') {
        item.Url = REQUEST_CONFIG.BASE_URL + item.Url;
      }
      if (item.Url) {
          item.Url = item.Url.replace(/\\/g, '/');
      }
    });
    result = resp;
    isShowNoData = false;
  }
  
  currentUser.value = cUser;
  doctorList.value = result;
  showNoData.value = isShowNoData;
};

const goto = (item: any) => {
  const mockEvent = {
    currentTarget: {
      dataset: {
        item: item
      }
    }
  };
  pagesPatientFn.handleRouter(mockEvent, 'yyghClinicMsg');
};

const back = () => {
  common.navigateBack(1);
};
</script>

<style scoped>
@import "@/pagesPatient/st1/static/css/yyghHistoryDoctor.css";
</style>
