<script setup>
import DraggableButton from "@/pages/components/goHome.vue";
/**
 * name：
 * user：selectDoctor
 * date：2024年9月24日 16:24:50
 */
import { ref } from "vue";
import { $api, $response, $image } from "@/api";
import { onShow } from "@dcloudio/uni-app";
import { useStore } from "@/store";
const $store = useStore();
let dqDate = ref("");
let yytjInfo = ref({}); // 预约信息
let user_person=ref({});
const $props = defineProps({
  date: {
    type: String,
    default: "",
  },
  month: {
    type: String,
    default: "",
  },
});


const mountedAction = () => {
  uni.showLoading({
    title: "加载中",
  });
  user_person.value= $store.getUser();
  yytjInfo.value = $store.getYytjInfo();
  yytjInfo.value = {
  	doctor_date: "",
  	doctor_name: "",
	doctor_id:"",
  	nmrIndex: -1,
  	...yytjInfo.value,
  }
  dqDate.value = $props.date ? $props.date : "";
  if (dqDate.value || $props.month) {
    getdoctorList(); // 获取医生列表
  }
};
const doctor_list = ref(false);

const getdoctorList = async () => {
  // 获取 体检报告列表
  let obj = {
	hospital: $store.save.hospital,
    date: dqDate.value,
	month:$props.month,
	person_id:user_person.value.person_id
  };
  const response = await $api("DoctorGetList", obj);
  $response(response, () => {
    console.log(response, "response");
    doctor_list.value = response.data.list;
    uni.hideLoading();
  });
};
const config_ref = ref(null);
const configRef = (e) => {
  if (!config_ref.value) {
    config_ref.value = e;
    mountedAction();
  }
};
const clickDoctor = (item) => {
  yytjInfo.value.doctor_name = item.name;
  yytjInfo.value.doctor_id = item.id;
  yytjInfo.value.nmrIndex = -1;
  $store.setYytjInfo(yytjInfo.value);
  if($props.month=='all'){
	  uni.navigateTo({
	  	url:'/pages/main/ysdate/ysdate_new'
	  })
  }else{
	  // 关闭当前页面携带医生名称返回上一个，，并且携带item.name
	  uni.navigateBack({
	    delta: 1,
	  });
  }
 
};

onShow(() => {
	console.log($props.month);
  if (!!config_ref.value) {
    mountedAction();
  }
});
</script>
<template>
  <DraggableButton />
  <view>
    <view v-if="!!$store.config">
      <view :ref="configRef"></view>
    </view>
    <view class="pb-40rpx">
      <view class="h-38rpx  pl-20rpx pr-20rpx box-border">
		  <view style="height: 20rpx;"></view>
        <view
          style="box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0, 0, 0, 0.04)"
          class="pb-80rpx pt-30rpx rounded-15rpx bg-#fff"
        >
		<view v-if="doctor_list.length>0">
			<view v-for="(item, index) in doctor_list" :key="index" class="p-10rpx">
			  <view class="flex flex-row text-#8B8B8B text-23rpx">
			    <image :src="$image(item.head_img)" class="w-170rpx h-226rpx mr-20rpx"></image>
			    <view class="flex-1 flex flex-col flex-justify-start pr-20rpx">
			      <view class="text-#0E0E0E text-36rpx">
			        {{ item.name }}
			        <span class="text-26rpx text-#515151 ml-10rpx">{{
			          item.level
			        }}</span>
			      </view>
			      <view class="mt-33rpx mb-10rpx line-clamp-1">
			        <text v-if="false">{{ item.hospital }}:</text>
			        <text>{{ item.time }}</text>
			      </view>
			      <view class="line-clamp-2">
			        {{ item.desc }}
			      </view>
			      <view
			        @click="clickDoctor(item)"
			        class="ml-a mt-25rpx w-190rpx h-55rpx bg-#239EA3 rounded-33rpx text-#fff text-21rpx flex flex-justify-center items-center"
			      >
			        预约此医生
			      </view>
			    </view>
			  </view>
			  <view class="w-100% h-1rpx bg-#E6E9E9 mt-15rpx" > </view>
			</view>
		</view>
		<view v-else>
			<view v-if="doctor_list!==false" style="font-size: 26rpx; text-align: center;color: #ccc;padding-top: 40rpx;">当前日期暂无医生</view>
		</view>
          
        </view>
      </view>
    </view>
  </view>
</template>
<style scoped></style>
