<template>
    <view>
        <!-- pages/myConsultRoom/page/InviteDoctor/InviteDoctor.wxml -->
        <nav-bar :navbarData="navbarData"></nav-bar>
        <view class="InviteDoctor" :style="'margin-top: ' + (height * 2 + 10) + 'rpx; height: calc(100vh - ' + (height * 2 + 10) + 'rpx)'">
            <view class="col-12 serachBotton">
                <view class="serachFind">
                    <icon type="search" class="serachicon" size="20" />
                    <input @input="selectTemplate" class="serachInput" placeholder="搜索科室、医生" />
                </view>
            </view>
            <van-collapse
                accordion
                :value="activeName"
                @change="onChange"
                class="InviteDoctor-van"
                :style="'height:calc(100vh - ' + (height * 2 - 2) + 'rpx);overflow:auto;width:100%;'"
            >
                <van-collapse-item :title="item.locDesc + ' ' + item.conut + '人'" :name="item.locID" v-for="(item, index) in admList" :key="index">
                    <view>
                        <van-radio-group :value="radio" @change="invite" slot="title" v-for="(itemName, index1) in item.child" :key="index1">
                            <van-cell-group>
                                <van-cell
                                    :title="itemName.userName + ' ' + itemName.title"
                                    clickable
                                    :data-userName="itemName.userName"
                                    :data-name="itemName.userID"
                                    @click="onClick($event, { userName: itemName.userName, name: itemName.userID })"
                                >
                                    <van-radio
                                        @tap.native="onClick($event, { userName: itemName.userName })"
                                        clickable
                                        slot="right-icon"
                                        :data-userName="itemName.userName"
                                        :name="itemName.userID"
                                    ></van-radio>
                                </van-cell>
                            </van-cell-group>

                            <!-- <van-cell>
						<van-radio clickable slot="right-icon" name="{{itemName.userID}}">{{itemName. userName}} {{itemName.title}}</van-radio>
					</van-cell> -->
                        </van-radio-group>
                    </view>
                </van-collapse-item>
            </van-collapse>
        </view>
        <view class="row">
            <view class="multiBtn-content">
                <button class="multiBtn-right" @tap="inviteToDoc">发送</button>
            </view>
        </view>
    </view>
</template>

<script>
import Cache from '../../../../utils/cache';
import navBar from '@/pages/components/navbar/index';
// pages/myConsultRoom/page/InviteDoctor/InviteDoctor.js
import { $http } from '../../../../config/https';
import messageUtil from '../../../../utils/message.js';
import Toast from '../../../../utils/toast';
const app = getApp();
export default {
    components: {
        navBar
    },
    data() {
        return {
            navbarData: {
                isGoBack: true,
                background: '',
                height: '100',
                title: '选择邀请医生',
                //导航栏 中间的标题
                bottom: false
            },

            admList: [],
            child: [],
            selectInfo: '',
            activeName: '',
            height: app.globalData.height,
            radio: '',
            userName: '',
            showpopup: false
        };
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {},
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
        this.getSearch();
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},
    /**
     * 组件的方法列表
     */
    methods: {
        // 清空
        clearn: function () {
            this.setData({
                activeName: [],
                admList: [],
                child: [],
                radio: ''
            });
        },

        onChange(event) {
            this.setData({
                activeName: event.detail
            });
        },

        invite(event) {
            if (event.detail == this.radio) {
                this.setData({
                    radio: ''
                });
                return;
            }
            this.setData({
                radio: event.detail
            });
        },

        onClick(event, _dataset) {
            /* ---处理dataset begin--- */
            this.handleDataset(event, _dataset);
            /* ---处理dataset end--- */
            const { name, username } = event.currentTarget.dataset;
            if (name == this.radio) {
                this.setData({
                    radio: ''
                });
                return;
            }
            this.setData({
                radio: name,
                userName: username
            });
        },

        selectTemplate: function (e) {
            this.setData(
                {
                    selectInfo: e.detail.value
                },
                () => {
                    this.getSearch();
                }
            );
        },

        getSearch: function () {
            const userData = Cache.get('userData');
            $http.post('urlDeault', this, {
                code: '03100162',
                data: {
                    params: [
                        {
                            hospCode: userData.hospCode,
                            hospID: userData.hospID,
                            locID: userData.locID,
                            userID: userData.userID,
                            searchCode: this.selectInfo
                        }
                    ]
                },
                success: function (res) {
                    let errorCode = res.errorCode;
                    if (errorCode === '0') {
                        this.setData({
                            admList: res.result //数据列表
                        });
                    }
                }
            });
        },

        /**
         * 选择邀请医生后发送
         */
        inviteToDoc: function (event) {
            let that = this;
            let locID = this.radio;
            if (!locID) {
                uni.showModal({
                    title: '提示',
                    content: '请选择邀请医师',
                    showCancel: false,
                    confirmText: '我知道了',
                    success(res) {}
                });
                return;
            }
            const userData = Cache.get('userData');
            const patientData = Cache.get('patientData');
            let toUser = 'user' + locID;
            let roomNo = patientData.roomNo;
            let userName = this.userName;
            let content = '已发送邀请给【' + userName + '】医生，您进入视频后，邀请医生才可进入视频!';
            let flag = messageUtil.handleSendMessage('I', '医生' + userData.userName + '邀请您视频问诊', toUser, '', roomNo, '', {
                error: 'Y',
                success: function () {
                    uni.showModal({
                        title: '提示',
                        content: content,
                        showCancel: false,
                        confirmText: '我知道了',
                        success(res) {
                            uni.navigateBack();
                        }
                    });
                    if (flag) {
                        that.setData({
                            showpopup: false
                        });
                    }
                },
                fail: function () {}
            });
        }
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {}
};
</script>
<style>
/* pages/myConsultRoom/page/InviteDoctor/InviteDoctor.wxss */
.InviteDoctor {
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;
    background: ffffff;
}
.InviteDoctor-van {
    overflow: auto;
}
.serachBotton {
    padding: 0 20rpx;
    box-sizing: border-box;
    background-color: #fff;
}
.serachInput {
    font-size: 32rpx;
}
.serachicon {
    float: left;
    width: 40rpx;
}
.serachFind {
    border: 1rpx solid #ccc;
    color: black;
    font-size: 28rpx;
    width: 60%;
    height: 60rpx;
    padding-top: 30rpx;
    float: left;
    border-radius: 5px;
    margin-top: 10rpx;
    padding-left: 5px;
    width: 100%;
}
.multiBtn-content {
    height: 100rpx;
    font-size: 30rpx;
    color: #fff;
    padding: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
}

.multiBtn-right {
    flex: 1;
    align-items: center;
    justify-content: center;
    display: flex;
    background-color: #1890ff;
    color: #ffffff;
    border-radius: 0 !important;
}
</style>
