<template>
    <nav-bar id="navBar" ref="navBar" :navbar-data="navbarData"></nav-bar>
    <view :style="{ marginTop: height +'px', height: 'calc(100vh - '+ height +'px)', overflow: 'auto' }"
        class="doctor-info">
        <view class="itdc-head">
            <view class="itdc-head-bg" :style="{ background: 'url(' + headerBg + ') no-repeat', backgroundSize: '100% 100%' }">
            </view>
            <view class="itdc-head-content">
                <view class="itdc-head-content-top">
                    <view class="itdc-head-portrait">
                        <view class="itdc-image" :style="'background:url(' + (doctorDetail.image ? doctorDetail.image : imgHost + '/images/icon/avatar_doctor_act.png') +') no-repeat;background-size: 100%;'" />
                        <image style="height:0rpx;width:0rpx;" onerror="imageError" :src="doctorDetail.image ? doctorDetail.image : imgHost + '/images/icon/avatar_doctor_act.png'" />
                    </view>
                    <view>
                        <view class="itdc-head-content-top-text">
                            <text>{{ doctorDetail.doctorName }}</text>
                            <text>{{ doctorDetail.title }}</text>
                            <text>{{ doctorDetail.locDesc }}</text>
                        </view>
                        <view style="display:flex;justify-content: space-between;align-items: center; padding: 10rpx 0;">
                            <view>
                                <uni-rate :value="doctorDetail.score" :size="14" allow-half void-icon="star" readonly
                                    color="#FA541C" void-color="#fff" />
                            </view>
                            <view>
                                <!-- <van-button type="info" size="mini" round>关注</van-button>
							    <van-button color="#ccc" type="default" size="mini" round>已关注</van-button> -->
                            </view>
                        </view>
                        <view>
                            咨询量：<text style="color:#13C2C2FF;">{{ doctorDetail.totalNum }}</text>
                            <text v-if="doctorDetail.resTime"><text style="color:#13C2C2FF;">{{ doctorDetail.resTime
                            }}</text>响应</text>
                            <view style="float: right;">
                                <van-button type="info" square size="mini" icon="plus" @tap="doctorSave" v-if="concernFlag === ''">关 注</van-button>
                                <van-button type="default" size="mini" plain @tap="deleteDoctor" v-if="concernFlag === 'Y'">取消关注</van-button>
                            </view>
                        </view>
                    </view>
                </view>
                <view @tap.stop="introduceDetial" class="doctor-list-introduce border-top-before">
                    <text :class="targer ? '' : 'after-text-css'">{{ doctorDetail.introduce || '暂无该医生描述。' }}</text>
                    <view v-if="introCss" @tap.stop="introTarget" style="color:#1890FF;">{{ targer ? '展开' : '收起' }}</view>
                </view>
            </view>
        </view>
        <view class="choose-doctor-content">
            <view class="choose-doctor-date">
                <view class="choose-doctor-tabs">
                    <view class="cdt-header border-bottom-after">{{ schedulingDate.length > 0 ? schDate : '暂无排班' }}</view>
                    <view v-if="schedulingDate.length != 0" class="choose-doctor-tabs-header border-bottom-after">
                        <view v-for="(item, index) in schedulingDate" :key="index" class="choose-doctor-tabs-header-content" :class="schDate === item.date ? 'active-tabs' : ''" @tap.stop="onChange" :data-page="item">
                            <view class="cdthc-week">{{ item.showWeek }}</view>
                            <view class="cdthc-title">{{ item.showTitle }}</view>
                            <view :class="item.type === 'A' ? 'cdthc-number' : 'cdthc-no-number'">{{ item.typeDesc }}</view>
                        </view>
                    </view>
				    <block v-if="locList && locList.length > 0">
                    <van-dropdown-menu>
                        <van-dropdown-item :title="locDesc" id="LocList">
                            <van-tree-select :items="locList" :main-active-index="mainActiveIndex" :active-id="locID" @click-nav="onClickNav" @click-item="onClickItem" style="overflow:auto;height:600rpx;" />
                        </van-dropdown-item>
                    </van-dropdown-menu>
				    </block>
                </view>


                <!-- catchtap="{{doctorDetail.videoFlag=='Y'?'turnVideo':''}}" -->
                <!-- <view class="choose-doctor-date-content">
				<view class="choose-doctor-date-content-top">
					<view class="choose-doctor-date-content-content border-bottom-after">
						<image src="{{imgHost}}/images/icon/video.png" class="image-css"></image>
						<view class="choose-doctor-date-content-top-text">
							<view class="turn-title">视频看诊</view>
							<view>续方开药、送药上门。家属可视频陪诊。</view>
						</view>
					</view>
				</view>
				<view class="choose-doctor-date-content-bottom border-bottom-after" wx:if="{{consulationType!='A'}}">
					<view class="choose-doctor-date-content-bottom-left">

					</view>
					<view class="choose-doctor-date-content-bottom-right">
						<view class="choose-doctor-date-content-bottom-right-price">

						</view>
						<view class="choose-doctor-date-content-bottom-right-btn">
							<van-button round disabled type="default" size="small">{{consulationDesc}}</van-button>
						</view>
					</view>
				</view>
				<view class="choose-doctor-date-content-bottom border-bottom-after" wx:if="{{consulationType=='A'}}">
					<view class="choose-doctor-date-content-bottom-left">
						<text>{{doctorDetail && doctorDetail.videoWaitNum ? doctorDetail.videoWaitNum : 0}}</text>
						人看诊中
					</view>
					<view class="choose-doctor-date-content-bottom-right">
						<view class="choose-doctor-date-content-bottom-right-price">
							<text class="price-ico">￥</text>
							<text>{{doctorDetail.videoPrice}}</text>
						</view>

						<view class="choose-doctor-date-content-bottom-right-btn">
							<van-button round disabled type="default" size="small" wx:if="{{doctorDetail.videoFlag=='N'}}">暂无排班
							</van-button>
							<van-button round type="info" size="small" wx:if="{{doctorDetail.videoFlag==='Y'}}" data-type="3"
								catchtap="showPopup">预约看诊</van-button>
							<van-button round disabled type="default" size="small" wx:if="{{doctorDetail.videoFlag=='F'}}">约满
							</van-button>
						</view>
					</view>
				</view>
			</view> -->



                <!-- <view class="choose-doctor-date-content">
				<view class="choose-doctor-date-content-top">
					<view class="choose-doctor-date-content-content border-bottom-after">
						<image src="{{imgHost}}/images/icon/grCon.png" class="image-css"></image>
						<view class="choose-doctor-date-content-top-text">
							<view class="turn-title">图文咨询</view>
							<view>随时发送图文与医生进行沟通</view>
						</view>
					</view>
				</view>
				<view class="choose-doctor-date-content-bottom" wx:if="{{consulationType!='A'}}">
					<view class="choose-doctor-date-content-bottom-left"></view>
					<view class="choose-doctor-date-content-bottom-right">
						<view class="choose-doctor-date-content-bottom-right-price"></view>
						<view class="choose-doctor-date-content-bottom-right-btn">
							<van-button round disabled type="default" size="small">{{consulationDesc}}</van-button>
						</view>
					</view>
				</view>
				<view class="choose-doctor-date-content-bottom" wx:if="{{consulationType=='A'}}">
					<view class="choose-doctor-date-content-bottom-left">
						<text>{{doctorDetail && doctorDetail.imageWaitNum ? doctorDetail.imageWaitNum : 0}}</text>人咨询中
					</view>
					<view class="choose-doctor-date-content-bottom-right">
						<view class="choose-doctor-date-content-bottom-right-price">
							<text class="price-ico">￥</text>
							<text>{{doctorDetail.imagePrice}}</text>
						</view>
						<view class="choose-doctor-date-content-bottom-right-btn">
							<van-button round disabled type="default" size="small" wx:if="{{doctorDetail.imageFlag=='N'}}">暂无排班
							</van-button>
							<van-button round type="info" size="small" wx:if="{{doctorDetail.imageFlag==='Y'}}" data-type="2"
								catchtap="turnGraphic">立即咨询</van-button>
							<van-button round disabled type="default" size="small" wx:if="{{doctorDetail.imageFlag=='F'}}">约满
							</van-button>
						</view>
					</view>
				</view>
			</view> -->

                <view class="choose-doctor-date-content">
                    <view class="choose-doctor-date-content-top">
                        <view class="choose-doctor-date-content-content border-bottom-after">
                            <image :src="imgHost + '/images/icon/icon_registration.png'" class="image-css"></image>
                            <view class="choose-doctor-date-content-top-text">
                                <view class="turn-title">预约挂号</view>
                                <view>挂号后到医院现场就诊</view>
                            </view>
                        </view>
                    </view>
                    <view class="choose-doctor-date-content-bottom" v-if="consulationType != 'A'">
                        <view class="choose-doctor-date-content-bottom-left"></view>
                        <view class="choose-doctor-date-content-bottom-right">
                            <view class="choose-doctor-date-content-bottom-right-price"></view>
                            <view class="choose-doctor-date-content-bottom-right-btn">
                                <van-button round disabled type="default" size="small">{{ consulationDesc }}</van-button>
                            </view>
                        </view>
                    </view>
                    <view class="choose-doctor-date-content-bottom" v-if="consulationType == 'A'">
                        <view class="choose-doctor-date-content-bottom-left">
                            <text>{{ doctorDetail && doctorDetail.opNum ? doctorDetail.opNum : 0 }}</text>人咨询中
                        </view>
                        <view class="choose-doctor-date-content-bottom-right">
                            <view class="choose-doctor-date-content-bottom-right-price">
                                <text class="price-ico">￥</text>
                                <text>{{ doctorDetail.opPrice }}</text>
                            </view>
                            <view class="choose-doctor-date-content-bottom-right-btn">
                                <van-button round disabled type="default" size="small" v-if="doctorDetail.videoFlag === 'N'">暂无排班</van-button>
                                <van-button round type="info" size="small" dataType="3" v-if="doctorDetail.videoFlag === 'Y'" @tap="showPopup">预约挂号</van-button>
                                <van-button round disabled type="default" size="small" v-if="doctorDetail.videoFlag === 'F'">约满</van-button>
                            </view>
                        </view>
                    </view>
                </view>
            </view>
            <view class="choose-doctor-evaluate">
                <view class="choose-doctor-evaluate-title">患者评价 ({{ doctorDetail.commentNum }})</view>
                <view class="choose-doctor-evaluate-content">
                    <view>
                        <text>{{ doctorDetail.score }}</text>
                        医生分数
                    </view>
                    <view>
                        <text>{{ doctorDetail.commentPatNum || 0 }}</text>
                        评价人数
                    </view>
                </view>
            </view>
            <block v-if="doctorDetail && doctorDetail.commentList">
            <view class="choose-doctor-evaluation-content" v-for="(item, index) in doctorDetail.commentList.data"
                :key="index">
                <view class="choose-doctor-evaluation-content-header border-bottom-after">
                    <view class="choose-doctor-evaluation-content-header-left">
                        <text>{{ item.patName }}</text>
                        <uni-rate :value="item.grade" :size="12" allow-half void-icon="star" readonly color="#FA541C" />
                    </view>
                    <view>{{ item.createDate }} {{ item.createTime }}</view>
                </view>
                <view class="choose-doctor-evaluation-content-text">
                    <view>
                        用户评价：<text>{{ item.appraiseNote }}</text>
                    </view>
                    <view>
                        服务方式：<text>{{ item.typeDesc }}</text>
                    </view>
                </view>
            </view>
            </block>
            <van-popup :show="show" @close="onClose" position="bottom">
                <view class="logistics_view">
                    <view class="logistics_view-head">
                        <text>选择时段</text>
                    </view>
                    <scroll-view :scroll-y="true">
                        <view v-for="(schList, list) in schedulingList" :key="list">
                            <view class="consulTime">{{ schList.timeRange }}</view>
                            <view class="consul-list">
                                <view v-for="(resDetail, tip) in schList.resDetail" :key="tip" @tap="chooseRestTimeID" :data-usablenum="resDetail.usableNum" :id="resDetail.resTimeID" class="consul-list-item">
                                    <view :class="{'timeCroCheck consul-list-item-child': schTimeKey == resDetail.resTimeID, 'consul-list-item-child': schTimeKey !== resDetail.resTimeID, 'bg-gray-light': resDetail.usableNum == 0}">
                                        <view>{{ resDetail.timeDatail }}</view>
                                        <view>(余号：{{ resDetail.usableNum }})</view>
                                    </view>
                                </view>
                            </view>
                        </view>
                    </scroll-view>
                </view>
            </van-popup>
        </view>
    </view>
    <view style="height:0rpx;overflow:hidden;">
        <van-field autosize bindlinechange="checkIntroduceHeight" type="textarea" :value="doctorDetail.introduce == '' ? '暂无该医生描述。' : doctorDetail.introduce" />
    </view>
</template>

<script>
import $http from "@/utils/https"
import Util from "@/utils/utils"
import { getHospList, switchHospital, dealSwitchHospital } from '@/utils/common';
import httpConfig from '@/utils/httpConfig'
import navBar from '@/components/navBar/index'
import VanDropdownMenu from '@/components/dropdown-menu/index'
import VanDropdownItem from '@/components/dropdown-item/index'
import VanTreeSelect from '@/components/tree-select/index'
import VanButton from '@/components/button/index'
import VanPopup from '@/components/popup/index'
const app = getApp();
export default {
    components: {
        'nav-bar': navBar,
        'van-dropdown-menu': VanDropdownMenu,
        'van-dropdown-item': VanDropdownItem,
        'van-button': VanButton,
        'van-popup': VanPopup,
        'van-tree-select': VanTreeSelect
    },
    data() {
        return {
            height: app.globalData.height,
            imgHost: httpConfig && httpConfig.imgHost,
            windowHost: httpConfig && httpConfig.ipDeault,
            navbarData: {
                isGoHome: true,
                isGoBack: true,
                title: "医生介绍"
            },
            targer: false,
            introCss: false,
            show: false,
            docObj: {},
            schedulingDate: [],
            locID: null,
            hisHospID: this.$cache.get('userData') ? this.$cache.get('userData').hisHospID : '',
            doctorDetail: {},
            schDate: "",
            schedulingList: [],
            headerBg: httpConfig.imgHost + "/images/icon/doctor-info-head-bg.png",
            follow: false, ///是否关注,
            consulationType: '',
            consulationDesc: "",
            concernFlag: '1',
            concerID: '',
            locList: [], // 科室列表数据
			schTimeKey: ''
        }
    },
    onLoad: function (options) {
        try {
			// #ifdef MP
            uni.hideBackHome() // 隐藏返回首页按钮
			// #endif
            app.globalData.patObj = {};
            app.globalData.writeObj = app.globalData && app.globalData.writeObj ? app.globalData.writeObj : {};
            let resetWriteObj = {
                ...app.globalData.writeObj,
                fileList: [],
                disesNote: "",
                schTimeKey: "",
                schDateKey: ""
            };
            app.globalData.writeObj = resetWriteObj;

            console.log("onLoad-options", options);

            // 支付宝独立处理
            // #ifdef MP-ALIPAY
            !options && (options = {})
			options['q'] = app.globalData.alipayQuery
            // #endif
            console.log('options.q', options.q)
            if (options && options.q) {
                this.scanningCode(options)
            } else {
                this.setData({
                    docObj: app.globalData.docObj,
                    locID: app.globalData.locObj.locID,
                    schDate: app.globalData.schDate
                }, () => {
                    this.getDocSchedulingDate();
                })
            }
        } catch (error) {
            uni.showToast({
                title: error,
                icon: 'none',
            })
        }
        // 支付宝处理
		// #ifdef MP-ALIPAY
        Util.resetGlobalDataParams(app,['alipayQuery'])
        // #endif
    },
    methods: {
		introduceDetial() {
			
		},
        // 扫码获取医生数据
        scanningCode(options) {
            console.log("触发了scanningCode", options)
            const self = this
            let { navbarData } = self;
			let qrCodeUrl = options.q
            console.log('判断字符串中是否包含?doctorId', decodeURIComponent(qrCodeUrl).indexOf("?doctorId"))
            if (decodeURIComponent(qrCodeUrl).indexOf("?doctorId") !== -1) { // 判断字符串中是否包含?doctorId
                let doctorID = decodeURIComponent(qrCodeUrl).split("=")[1];
                console.log("触发了doctorId", doctorID);
                let data = {
                    params: [{
                        extCode: doctorID
                    }]
                }
                $http.post("urlS", this, {
                        code: "03100128",
                        data: data,
                        namespace: "Y",
                        success: function (res) {
                            if (+res.errorCode === 0) {
                                this.scanningCode(res.result)
                            } else {
                                uni.showToast({
                                    title: res.errorMessage,
                                    icon: 'none',
                                })
                            }
                        },
                        error: function () {
                            uni.showToast({
                                title: '接口连接异常，请稍后重试。',
                                icon: 'none',
                            })
                        }
                    });
            } else {
                let qrUrl = decodeURIComponent(qrCodeUrl).split('/');
                let paramsObj = Util.decrypt(qrUrl[qrUrl.length - 1]);
                let jsonParse = JSON.parse(paramsObj);
                self.setData({
                    navbarData: {
                        ...navbarData,
                        isGoBack: 'home'
                    }
                })
                let userData = this.$cache.get('userData');
                if (userData && userData.hisHospID) {
                    self.setData({
                        docObj: jsonParse,
                        locID: jsonParse.locID,
                        schDate: self.getDate()
                    }, () => {
                        self.getDocSchedulingDate();
                    })
                } else {
					self.setData({
						docObj: jsonParse,
						locID: jsonParse.locID,
					},() => {
						// 获取医院数据
						self.getHospSelectData(jsonParse?.hospCode);
					})
                }
            }
        },

        ///关注或取关医生
        follow: function (e) {
            let docID = e.currentTarget.dataset.docid;
        },

        ///查询是否关注
        doctorQuery: Util.debounce(function () {
            const self = this
            let userData = this.$cache.get('userData');
            let data = {
                params: [{
                    openID: userData.openID || "",
                    patID: userData.hisPatID || "",
                    patNo: userData.hisPatNo || "",
                    hospCode: userData.hisHospID || "",
                    doctorType: "0",
                    doctorID: self.doctorDetail.doctorID
                }]
            }
            $http.post("urlS", self, {
                code: "03100113",
                data: data,
                namespace: "Y",
                success: function (res) {
                    if (+res.errorCode === 0) {
                        self.setData({
                            concernFlag: res.result.data[0] ? res.result.data[0].concernFlag : '',
                            concerID: res.result.data[0] ? res.result.data[0].concerID : ''
                        });
                    } else {
                        self.setData({
                            concernFlag: 'N'
                        });
                    }
                }
            });
        }),

        ///关注医生
        doctorSave: Util.debounce(function () {
            const self = this
            let userData = this.$cache.get('userData');
            let data = {
                params: [{
                    openID: userData.openID || "",
                    doctorID: self.doctorDetail.doctorID
                }]
            }
            $http.post("urlS", self, {
                code: "03100126",
                data: data,
                namespace: "Y",
                success: function (res) {
                    if (+res.errorCode === 0) {
                        self.setData({
                            concernFlag: 'Y'
                        }, () => {
                            self.doctorQuery()
                        })
                    }
                }
            });
        }),

        ///取消关注
        deleteDoctor: Util.debounce(function () {
            const self = this
            let userData = this.$cache.get('userData');
            let data = {
                params: [{
                    openID: userData.openID || "",
                    doctorID: self.doctorDetail.doctorID,
                    concerID: self.concerID
                }]
            }
            $http.post("urlS", self, {
                code: "03100127",
                data: data,
                namespace: "Y",
                success: function (res) {
                    if (+res.errorCode === 0) {
                        self.setData({
                            concernFlag: ''
                        })
                    }
                }
            });
        }),


        ///选择挂号日期
        onChange(event) {
            const self = this
            let type = event.currentTarget.dataset.page.type
            let desc = ""
            if (type == 'F') {
                desc = "约满";
            } else if (type == 'U') {
                desc = "暂无排班";
            } else if (type == 'S') {
                desc = "停诊";
            };
            self.setData({
                schDate: event.currentTarget.dataset.page.date,
                consulationType: type,
                consulationDesc: desc
            }, () => {
                app.globalData.schDate = event.currentTarget.dataset.page.date
                self.getDoctorList()
            });
        },

        ///选择预约时间
        chooseRestTimeID: Util.debounce(function (event) {
			const _this = this
			console.log(event)
			const { usablenum } = event.currentTarget.dataset
			if(usablenum == 0) {
				return
			}
            this.setData({
                schTimeKey: event.currentTarget.id
            }, () => {
                app.globalData.writeObj.schTimeKey = event.currentTarget.id
				setTimeout(() => {
					_this.gotoWrite(event);
				}, 600)
            })
        }),

        ///跳转到咨询页面
        gotoWrite: function (event) {
            uni.navigateTo({
                url: "../videoConsultation/videoConsulWriteContent/videoConsulWriteContent"
            })
        },

        ///根据科室ID和医生ID获取排班日期
        getDocSchedulingDate: function (param) {
            console.log("03100039")
            const self = this
            let userData = this.$cache.get('userData') || {};
            let data = {
                params: [{
                    doctorID: self.docObj.doctorID,
                    locID: self.locID,
                    hospCode: userData.hisHospID || '',
                    imageFlag: "Y",
                    videoFlag: "Y",
                    opFlag: "N"
                }]
            }
            $http.post("urlS", self, {
                namespace: "Y",
                code: "03100039",
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        for (let i = 0; i < res.result.length; i++) {
                            res.result[i].showWeek = res.result[i].week ? Util.digitalConversionWeek(+res.result[i].week) : '';
                            res.result[i].showTitle = res.result[i].currentFlag === 'Y' ? '今天' : res.result[i].title.slice(3);
                            if (res.result[i].type === 'U') {
                                res.result[i].typeDesc = '无号'
                            } else if (res.result[i].type === 'A') {
                                res.result[i].typeDesc = '有号'
                            } else if (res.result[i].type === 'F') {
                                res.result[i].typeDesc = '约满'
                            } else {
                                res.result[i].typeDesc = '停诊'
                            }
                        };
                        let type = res.result[0].type
                        let desc = ""
                        if (type == 'F') {
                            desc = "约满";
                        } else if (type == 'U') {
                            desc = "暂无排班";
                        } else if (type == 'S') {
                            desc = "停诊";
                        };
                        self.setData({
                            schedulingDate: res.result,
                            schDate: (!self.schDate) ? (res.result.length > 0 ? res.result[0].date : "") : (self.schDate == (res.result.length > 0 ? res.result[0].date : "") ? self.schDate : (res.result.length > 0 ? res.result[0].date : "")),
                            consulationDesc: desc,
                            consulationType: type
                        }, () => {
                            if (res.result.length > 0 && res.result[0].type === 'A') {
                                self.getDoctorList();
                            } else {
                                self.getDoctor();
                            }
                        });
                    } else {
                        self.setData({
                            schedulingDate: []
                        });
                    }
                }
            });
        },

        ///查询未排班医生信息
        getDoctor: function () {
            const self = this
            let userData = this.$cache.get('userData') || {};
            let data = {
                params: [{
                    doctorID: this.docObj.doctorID,
                    locID: this.locID,
                    hospCode: userData.hisHospID || '',
                    patID: userData.hisPatID
                }]
            }
            uni.showLoading({
                mask: true
            })
            $http.post("urlS", self, {
                namespace: "Y",
                code: "03100109",
                data: data,
                success: function (res) {
                    uni.hideLoading();
                    if (+res.errorCode === 0) {
                        let doctorDetail = res.result ? { ...res.result } : {};
                        console.log(doctorDetail)
                        doctorDetail.image = doctorDetail && doctorDetail.image.indexOf("http") !== -1 ? doctorDetail.image : self.windowHost + doctorDetail.image;
                        self.setData({
                            doctorDetail
                        }, () => {
                            // console.log(12321321321, res.result)
                            self.doctorQuery();

                        });
                    } else {
                        self.setData({
                            doctorDetail: {}
                        });
                    }
                }
            });
        },

        ///
        showPopup(event) {
            console.log(event)
            let type = event.currentTarget.dataset.type
            app.globalData.reservationEntrance = type;
            this.setData({
                show: true
            }, () => {
                this.getDocSchedulingList(type)
            });

        },

        onClose() {
            this.setData({
                show: false
            });
        },

        //图片加载出错，替换为默认图片
        imageError(e) {
            let { imgHost, doctorDetail } = this;
            doctorDetail.image = imgHost + "/images/photo/f142d48773ef4137205a3172ed83aa48.png";
            this.setData({ doctorDetail });
            console.log(doctorDetail.image)
        },

        ///查询当前医生信息
        getDoctorList: function () {
            console.log("03100038")
            const self = this
            let userData = this.$cache.get('userData') || {};
            let data = {
                params: [{
                    doctorID: self.docObj.doctorID,
                    locID: self.locID,
                    hospCode: userData.hisHospID || '',
                    imageFlag: "Y",
                    videoFlag: "Y",
                    opFlag: "Y",
                    userID: "",
                    date: self.schDate,
                    patID: userData.hisPatID
                }]
            }
            uni.showLoading({
                mask: true
            })
            $http.post("urlS", self, {
                namespace: "Y",
                code: "03100038",
                data: data,
                success: function (res) {
                    uni.hideLoading();
                    if (+res.errorCode === 0) {
                        if (res.result.data.length > 0) {
                            console.log(self.consulationShow)
                            app.globalData.docObj = res.result.data[0]
                            app.globalData.locObj.locID = self.locID
                            app.globalData.schDate = self.schDate
                            let doctorDetail = res.result && res.result.data && res.result.data.length > 0 ? { ...res.result.data[0] } : {};
                            doctorDetail.image = doctorDetail && doctorDetail.image.indexOf("http") !== -1 ? doctorDetail.image : self.windowHost + doctorDetail.image;
                            self.setData({
                                doctorDetail,
                                consulationShow: false
                            }, () => {
                                console.log(12321321321, res.result.data[0])
                                self.doctorQuery();
                            });
                        } else {
                            self.setData({
                                consulationShow: true
                            });
                            self.getDoctor();
                        }
                    } else {
                        self.setData({
                            doctorDetail: {}
                        });
                    }
                }
            });
        },

        ///跳转到视频咨询
        turnVideo: Util.debounce(function () {
            uni.navigateTo({
                url: "../../../index/pages/videoConsultation/videoConsulChooseDate/videoConsulChooseDate",

            })
        }),

        ///跳转到图文咨询
        turnGraphic: Util.debounce(function (e) {
            app.globalData.reservationEntrance = e.currentTarget.dataset.type
            uni.navigateTo({
                url: "../../../index/pages/graphicConsultation/graphicConsulWriteContent/graphicConsulWriteContent",
            })
        }),

        ///根据科室ID和医生ID获取排班列表（弹出层）
        getDocSchedulingList: function (type) {
            const self = this
            let data = {
                params: [{
                    date: self.schDate,
                    doctorID: self.docObj.doctorID,
                    locID: self.locID,
                    hospCode: self.hisHospID,
                    videoFlag: type === '3' ? "Y" : undefined,
                    opFlag: type === '4' ? "Y" : undefined,
                }]
            }
            uni.showLoading({
                mask: true
            })
            $http.post("urlS", self, {
                namespace: "Y",
                code: "03100040",
                data: data,
                success: function (res) {
                    uni.hideLoading();
                    if (+res.errorCode === 0) {
                        self.setData({
                            schedulingList: res.result
                        });
                    } else {
                        self.setData({
                            schedulingList: []
                        });
                    }
                }
            });
        },

        ///判断是否需要部分隐藏医生介绍
        checkIntroduceHeight(e) {
            let count = e.detail.lineCount;
            let self = this;
            console.log("sdfsdfsdfsdfsd", count)
            if (count > 2) {
                self.setData({
                    targer: true,
                    introCss: true
                })
            }
        },

        ///展示隐藏医生介绍
        introTarget() {
            this.setData({
                targer: this.targer ? false : true
            })
        },

        // 获取医院数据
        getHospSelectData: async function (hospCode) {
            const _this = this
            let userData = this.$cache.get('userData');
            if (!(userData && userData.openID)) {
                let count = _this.count ? _this.count : 1;
                if (count > 10) {
                    return;
                }
                setTimeout(() => {
                    _this.getHospSelectData(hospCode);
                }, 300)
                _this.count++
                return;
            }
			
			uni.showLoading();
			await getHospList(app, hospCode)
				.then(res => {
					uni.hideLoading()
					_this.setData({
					    schDate: _this.getDate()
					}, () => {
					    setTimeout(() => {
					        _this.getDocSchedulingDate()
					    }, 300)
					});
				})
				.catch(error => {})
			
			
            // let data = {
            //     params: []
            // }
            // $http.post("urlS", self, {
            //     code: "02010009",
            //     data: data,
            //     success: function (res) {
            //         if (+res.errorCode === 0) {
            //             if (res.result && res.result.length === 1) {
            //                 let hospOneData = res.result[0];
            //                 this.$cache.set('userData', {
            //                     ...userData,
            //                     hospID: hospOneData.hospID,
            //                     hospDesc: hospOneData.hospDesc,
            //                     hisHospID: hospOneData.hisHospID,
            //                     hospAddress: hospOneData.hospAddress,
            //                     telephone: hospOneData.telephone,
            //                     menuMode: hospOneData.menuMode,
            //                     serviceCall: hospOneData.serviceCall,
            //                     serviceCallTips: hospOneData.serviceCallTips,
            //                     upLoadUrl: hospOneData.upLoadUrl,
            //                     downLoadUrl: hospOneData.downLoadUrl,
            //                 })
            //                 app.globalData.SDKAPPID = +hospOneData.imAppID;
            //                 app.globalData.SECRETKEY = hospOneData.imSecret;
            //             } else if (res.result.length > 1) {
            //                 let isHosp = false;
            //                 let newHospData = {};
            //                 for (var i = 0; i < res.result.length; i++) {
            //                     if (res.result[i].hisHospID === options.hospCode) {
            //                         isHosp = true;
            //                         newHospData = res.result[i];
            //                         break;
            //                     }
            //                 }
            //                 if (isHosp) {
            //                     this.$cache.set('userData', {
            //                         ...userData,
            //                         hospID: newHospData.hospID,
            //                         hospDesc: newHospData.hospDesc,
            //                         hisHospID: newHospData.hisHospID,
            //                         hospAddress: newHospData.hospAddress,
            //                         telephone: newHospData.telephone,
            //                         menuMode: newHospData.menuMode,
            //                         serviceCall: newHospData.serviceCall,
            //                         serviceCallTips: newHospData.serviceCallTips,
            //                         upLoadUrl: newHospData.upLoadUrl,
            //                         downLoadUrl: newHospData.downLoadUrl,
            //                     })
            //                     app.globalData.SDKAPPID = +newHospData.imAppID;
            //                     app.globalData.SECRETKEY = newHospData.imSecret;
            //                 }
            //             }
            //             self.setData({
            //                 docObj: options,
            //                 locID: options.locID,
            //                 schDate: self.getDate()
            //             }, () => {
            //                 setTimeout(() => {
            //                     self.getDocSchedulingDate()
            //                 }, 300)
            //             });
            //         }
            //     }
            // });
        },

        // 获取当前日期
        getDate() {
            var d = new Date();
            var date = (d.getFullYear()) + "-" + (d.getMonth() + 1) + "-" + (d.getDate());
            return date;
        },
    }
}
</script>

<style>
.itdc-head {
  /* max-height: 390rpx; */
  padding: 10rpx 24rpx 0 24rpx;
  position: relative;
  margin-bottom: 10rpx;
}

.itdc-head-bg {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 168rpx;
  z-index: -1;
}

.itdc-head-content {
  /* max-height: 380rpx; */
  background: #fff;
  overflow: hidden;
  border-radius: 10rpx;
}

.itdc-head-content-top {
  width: 100%;
  padding: 32rpx;
  padding-bottom: 24rpx;
  box-sizing: border-box;
}

.itdc-head-portrait {
  float: left;
  margin-right: 24rpx;
  text-align: center;
}

.itdc-image {
  width: 120rpx;
  height: 120rpx;
  border-radius: 50%;
  margin-bottom: 10rpx;
  background-size: 100%;
}

.itdc-head-content-top-text {
  font-size: 28rpx;
  color: #666;
}

.itdc-head-content-top-text text:nth-child(1) {
  font-size: 36rpx;
  font-weight: 600;
  color: #333;
}

.itdc-head-content-top-text text:nth-child(2) {
  margin: 0 16rpx;
}

.itdc-head-content-top .van-rate {
  border-radius: 10rpx;
  width: 240rpx;
  height: 40rpx;
  margin: 16rpx 0;
  line-height: 40rpx;
  background: #feeee8;
  display: flex;
  justify-content: space-between;
  padding: 0 12rpx;
  padding-bottom: 4rpx;
  align-items: center;
  box-sizing: border-box;
}

.choose-doctor-content {
  width: 100%;
  padding: 0 24rpx;
  margin-bottom: 10rpx;
  box-sizing: border-box;
}

.doctor-list-introduce {
  width: 100%;
  padding: 16rpx 29rpx 16rpx 25rpx;
  box-sizing: border-box;
  /* height:190rpx; */
  overflow: hidden;
}

.doctor-list-introduce text {
  width: 100%;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-box-orient: vertical;
  color: #666;
  line-height: 48rpx;
  text-indent: 2em;
  font-size: 28rpx;
  word-wrap: break-word;
}

.after-text-css {
  -webkit-line-clamp: 0 !important;
  display: block !important;
}

.choose-doctor-date {
  background: #fff;
  width: 100%;
  box-sizing: border-box;
  border-radius: 10rpx;
}

.cdt-header {
  text-align: center;
  height: 56rpx;
  line-height: 56rpx;
  font-size: 28rpx;
  color: #666;
}

.choose-doctor-tabs-header {
  display: flex;
  width: 100%;
  padding: 24rpx 0;
  box-sizing: border-box;
  justify-content: space-around;
}

.choose-doctor-tabs-header-content {
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 80rpx;
  height: 136rpx;
  color: #666;
  font-size: 28rpx;
  font-weight: bold;
  align-items: center;
}

.active-tabs {
  background: #1890FF;
  color: #fff;
}

.cdthc-title {
  color: #333;
  font-size: 32rpx;
  font-weight: 600;
  margin: 6rpx 0;
}

.cdthc-number {
  color: #1890FF;
}

.cdthc-no-number {
  color: #ccc
}

.active-tabs .cdthc-title,
.active-tabs .cdthc-number,
.active-tabs .cdthc-no-number {
  color: #fff;
}

.choose-doctor-date-content-top {
  width: 100%;
  padding: 0 24rpx;
  box-sizing: border-box;
}

.choose-doctor-date-content-content {
  width: 100%;
  padding: 32rpx 0;
  display: flex;
  box-sizing: border-box;
}

.choose-doctor-date-content-top-text {
  font-size: 28rpx;
  color: #666;
}

.choose-doctor-date-content-top-text .turn-title {
  font-size: 32rpx;
  color: #333;
  font-weight: 600;
  margin-bottom: 4rpx;
}

.choose-doctor-date-content-top .image-css {
  width: 80rpx;
  height: 80rpx;
  margin-right: 20rpx;
}

.choose-doctor-date-content-bottom {
  width: 100%;
  padding: 0 24rpx;
  box-sizing: border-box;
  height: 110rpx;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.choose-doctor-date-content-bottom-left {
  color: #666;
  font-size: 28rpx
}

.choose-doctor-date-content-bottom-left text {
  color: #13C2C2;
}

.choose-doctor-date-content-bottom-right {
  display: flex;
  align-items: center;
}

.choose-doctor-date-content-bottom-right-price {
  margin-right: 16rpx;
  color: #FA541C;
  font-size: 32rpx;
}

.choose-doctor-date-content-bottom-right-price .price-ico {
  color: #999;
  font-size: 28rpx
}

.choose-doctor-date-content-bottom-right-btn .van-button {
  min-width: 160rpx;
  height: 60rpx;
  text-align: center;
  line-height: 60rpx;
}

.choose-doctor-evaluate-title {
  height: 100rpx;
  font-size: 32rpx;
  color: #333;
  font-weight: 600;
  line-height: 100rpx;
  padding: 0 24rpx;
  box-sizing: border-box;
}

.choose-doctor-evaluate-content {
  display: flex;
  background: #fff;
  border-radius: 10rpx;
  min-height: 117rpx;
  padding: 24rpx 0;
  width: 100%;
  box-sizing: border-box;
}

.choose-doctor-evaluate-content view {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-size: 28rpx;
  color: #666;
}

.choose-doctor-evaluate-content view:nth-child(1) {
  border-right: 1px solid #F5F4F4;
}

.choose-doctor-evaluate-content view text {
  font-size: 36rpx;
  color: #FA541C;
  margin-bottom: 4rpx;
}

.choose-doctor-evaluation-content {
  min-height: 230rpx;
  margin-top: 4rpx;
  border-radius: 10rpx;
  background: #fff;
}

.choose-doctor-evaluation-content:last-child {
  margin-bottom: 0;
}

.choose-doctor-evaluation-content-header {
  height: 92rpx;
  display: flex;
  padding: 0 24rpx;
  box-sizing: border-box;
  justify-content: space-between;
  align-items: center;
  color: #999;
  font-size: 28rpx;
}

.choose-doctor-evaluation-content-header-left text {
  font-size: 32rpx;
  color: #333;
  font-weight: 600;
  margin-right: 14rpx;
}

.choose-doctor-evaluation-content-text {
  width: 100%;
  padding: 24rpx 24rpx;
  box-sizing: border-box;
  font-size: 28rpx;
  color: #999;
}

.choose-doctor-evaluation-content-text view:nth-child(1) {
  margin-bottom: 8px;
}

.choose-doctor-evaluation-content-text text {
  color: #333;
}

.logistics_view {
    width: 100%;
    min-height: 380rpx;
    background: #fff;
}

.logistics_view-head {
  height: 98rpx;
  line-height: 98rpx;
  width: 100%;
  text-align: center;
  color: #333;
  font-size: 32rpx;
}

.consulTime {
  height: 72rpx;
  line-height: 72rpx;
  padding-left: 24rpx;
  font-size: 32rpx;
  font-weight: 600;
  color: #666;
  background: #FAF9F9;
  box-sizing: border-box;
}

.consul-list {
  width: 100%;
  padding: 24rpx;
  padding-bottom: 0;
  box-sizing: border-box;
  display: flex;
  flex-wrap: wrap;
}

.consul-list-item {
  width: 31%;
  margin-right: 3.5%
}

.consul-list-item-child {
  border: 1px solid #E1E1E1;
  border-radius: 10rpx;
  height: 94rpx;
  text-align: center;
  margin-bottom: 24rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #666;
  font-size: 28rpx;
}

.consul-list-item:nth-child(3n) {
  margin-right: 0;
}

.timeCroCheck {
  background: #1890FF;
  color: #fff;
}
</style>