<template>
    <view>
        <nav-bar :navbarData="navbarData"></nav-bar>
        <view class="locList" :style="'margin-top: ' + (height * 2 + 90) + 'rpx; height: calc(100vh - ' + (height * 2 + 10) + 'rpx)'">
            <view class="locItem" :class="{ 'locItem-active': curLoc == index }" v-for="(item, index) in locList" :key="index">
                <view class="locItem-main">
                    <view class="locInfo">{{ item.logonLocDesc }}</view>
                    <view class="locMeta">
                        <text class="hospdesc">{{ item.logonHospDesc }}</text>
                        <text class="metaSep">·</text>
                        <text class="hospdesc groupdesc">{{ item.logonGroupDesc }}</text>
                        <text class="metaSep">·</text>
                        <text class="hospdesc roledesc">{{ item.logonGroupDesc }}</text>
                    </view>
                </view>
                <view class="locItem-check" v-if="curLoc == index">
                    <text class="checkIcon">✓</text>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
import Cache from '../../../../utils/cache';
import navBar from '@/pages/components/navbar/index';
// pages/tabBar/personalcenter/locList/locList.js
import { $http } from '../../../../config/https.js';
const app = getApp();
export default {
    components: {
        navBar
    },
    data() {
        return {
            locList: [],
            curLoc: '',
            navbarData: {
                background: '',
                title: '科室角色切换',
                //导航栏 中间的标题
                height: '100',
                bottom: true,
                isGoBack: true,
                cleanPat: 'Y'
            },
            height: app.globalData.height
        };
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {},
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.getLocList();
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
    methods: {
        getLocList: function () {
            let that = this;
            let userData = Cache.get('userData');
            let data = {
                params: [
                    {
                        currentLocFlag: 'Y',
                        language: 'CN',
                        userCode: userData.userCode
                    }
                ]
            };
            $http.post('urlDeault', that, {
                code: '01040043',
                data: data,
                success: function (res) {
                    let errorCode = res.errorCode;
                    if (errorCode == '0') {
                        let currentIndex = -1;
                        let logonLocAry = res.result.logonLocAry;
                        // 只保留门诊医师角色的数据
                        let filteredLocAry = [];
                        for (var i = 0; i < logonLocAry.length; i++) {
                            let locInfo = logonLocAry[i];
                            if (locInfo.logonGroupDesc === '门诊医师') {
                                if (locInfo.logonLocID == userData.locID && locInfo.logonHospID == userData.hospID && locInfo.logonGroupID == userData.groupID) {
                                    currentIndex = filteredLocAry.length;
                                }
                                filteredLocAry.push(locInfo);
                            }
                        }
                        this.setData({
                            locList: filteredLocAry,
                            curLoc: currentIndex
                        });
                    }
                }
            });
        }
    }
};
</script>
<style>
page {
    background: #f4f6fa;
}

.locList {
    box-sizing: border-box;
    height: 100%;
    width: 100%;
    overflow-y: auto;
    padding: 8rpx 24rpx calc(16rpx + env(safe-area-inset-bottom));
    background: #f4f6fa;
}

.locList-tip {
    padding: 16rpx 8rpx 14rpx;
}

.locList-tip-text {
    font-size: 24rpx;
    color: #8b98a8;
    line-height: 34rpx;
}

.locItem {
    display: flex;
    flex-direction: row;
    align-items: center;
    min-height: 112rpx;
    padding: 22rpx 28rpx;
    margin-bottom: 16rpx;
    background: #ffffff;
    border-radius: 16rpx;
    box-shadow: 0 6rpx 20rpx rgba(15, 23, 42, 0.05);
    box-sizing: border-box;
    transition: background 0.15s;
}

.locItem-hover {
    background: #f7f9fc;
}

.locItem-active {
    background: #eaf4ff;
    box-shadow: 0 6rpx 20rpx rgba(22, 135, 255, 0.12);
}

.locItem-main {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.locInfo {
    font-size: 32rpx;
    font-weight: 600;
    color: #1f2329;
    line-height: 44rpx;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.locItem-active .locInfo {
    color: #1687ff;
}

.locMeta {
    margin-top: 10rpx;
    display: flex;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    line-height: 36rpx;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hospdesc {
    font-size: 24rpx;
    color: #8b98a8;
    line-height: 36rpx;
}

.metaSep {
    margin: 0 10rpx;
    color: #c8ced6;
    font-size: 24rpx;
    line-height: 36rpx;
}

.groupdesc {
    color: #8b98a8;
}

.roledesc {
    color: #1687ff;
    font-weight: 500;
}

.locItem-check {
    flex: 0 0 auto;
    width: 48rpx;
    height: 48rpx;
    margin-left: 16rpx;
    border-radius: 50%;
    background: #1687ff;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.checkIcon {
    color: #ffffff;
    font-size: 30rpx;
    line-height: 1;
    font-weight: 700;
}
</style>
