<template>
    <!--选择科室-->
    <view class="choose-loc-search">
        <view class="search-box">
            <uni-search-bar :value="descripts" placeholder="搜索科室" @input="onChange" />
        </view>
        <!-- <view class="msg">
    		<view>当前进行中问诊<text style="font-size:30rpx;margin:0 10rpx">1</text>个</view>
    		<view class="msg-right">
    			<text style="margin-right:20rpx">暂无未读消息</text>
    			<van-icon size="28rpx" color="#333333" name="arrow" />
    		</view>
    	</view> -->
    </view>
    <view :style="{ height: 'calc(100vh - 228rpx)', overflow: 'auto' }" class="choose-loc-tree">
        <view class="tips" v-if="!locList">
            <text class="star">*</text>
            <text>备注：当前暂无线上问诊排班信息，可前往门诊挂号</text>
        </view>
        <van-tree-select height="calc(100vh - 228rpx)" style="overflow: auto" v-if="locList" :items="locList" :arrow="true"
            :main-active-index="locClassifyID" @click-nav="onClickNav" @click-item="onClickItem" />
    </view>
</template>

<script>
import $http from '@/utils/https';
import Util from '@/utils/utils';
import VanTreeSelect from '@/components/tree-select/index.vue';
const app = getApp();
export default {
    components: {
        'van-tree-select': VanTreeSelect
    },
    props: {
        path: {
            type: String,
            default: ''
        },
        flag: {
            type: Boolean,
            default: false
        }
    },
    data() {
        return {
            hisHospID: '',
            locList: null,
            descripts: "",
            locClassifyID: 0
        }
    },
    mounted() {
        app.globalData.patObj = {};
        const userData = this.$cache.get('userData')
        if(userData) {
            this.setData({
                hisHospID: userData.hisHospID
            },() => {
                this.getLocList();
            })
        }
    },
    methods: {
        onClickNav(e) {
            // console.log('onClickNav', e)
            this.setData({
                locClassifyID: e.index || 0
            });
        },

        onClickItem: Util.debounce(function (e) {
            console.log('onClickItem', e)
            app.globalData.locObj = {
                'locID': e.id,
                'locDesc': e.text
            }
            uni.navigateTo({
                url: this.path,
            })
        }),

        onChange: Util.debounce(function (e) {
            // console.log(e)
            this.setData({
                descripts: e
            }, () => {
                this.getLocList();
            });
        }),

        //调接口获取科室列表
        getLocList: function () {
            const self = this
            // console.log('获取科室列表')
            let entrance = app.globalData.reservationEntrance;
            let data = {
                params: [{
                    hospCode: this.hisHospID,
                    descripts: this.descripts,
                    imageFlag: this.flag && entrance === '2' ? "Y" : undefined,
                    videoFlag: !this.flag && entrance === '3' ? "Y" : undefined,
                    freeFlag: entrance === '1' ? "Y" : undefined,
                    opFlag: entrance === '4' ? "Y" : undefined,
                }]
            }
            uni.showLoading({
                mask: true
            })
            $http.post("urlS", this, {
                namespace: "Y",
                code: "03100037",
                data: data,
                success: function (res) {
                    console.log(res)
                    uni.hideLoading();
                    if (+res.errorCode === 0) {
                        const resData = res.result.data && res.result.data.length > 0 && res.result.data.map(item => {
                            item['disabled'] = false
                            return item
                        })
                        console.log(resData)
                        self.setData({
                            locList: resData
                        });
                    } else {
                        self.setData({
                            locList: null
                        });
                    }
                }
            });
        }
    }
}
</script>

<style>
.search-box {
    background: #fff;
}

.choose-loc-search .van-search {
    background: #f5f4f4 !important;
}

.choose-loc-search .van-search .van-search__content {
    background: #fff !important;
}

.choose-loc-tree .tips {
    padding: 40rpx 24rpx;
}

.choose-loc-tree .tips .star {
    font-size: 28rpx;
    color: #ff3300;
    margin-right: 16rpx;
}

.choose-loc-tree .tips .text {
    font-size: 28rpx;
}

.msg {
    height: 60rpx;
    background: #E6F2FF;
    font-size: 26rpx;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #007AFF;
    line-height: 36rpx;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12rpx 24rpx;
}

.msg-right {
    display: flex;
    align-items: center;
    font-size: 22rpx;
    font-family: PingFangSC-Regular, PingFang SC;
    color: #999999;
    line-height: 32rpx;
}
</style>