<template>
    <view class="content">
        <!-- 重名医生 / 疾病科室下找医生 首位 -->
        <view v-if="currentIndex === 0">
            <view
                v-if="header.title || header.subTitle"
                class="duplicate-name"
                @tap="onNavtoSearch"
            >
                <view v-if="header.title" class="c-font-large">{{ header.title }}</view>
                <view v-if="header.subTitle" class="c-font-normal">{{ header.subTitle }}</view>
            </view>
        </view>
        <!-- 重名医生非首位 / 疾病科室下找医生 -->
        <view v-else>
            <view class="non-primacy" @tap="onNavtoSearch">
                <view class="non-primacy__title c-font-17">{{ title }}</view>
                <c-icon name="youjiantou"/>
            </view>
        </view>
        <view v-if="expertList && expertList.length > 0" class="space">
            <view
                v-for="(expert, index) in expertList"
                :key="index"
                :class="[
                    index === 0 ? 'expert-space' : '',
                    'expert-item',
                ]"
            >
                <!-- 对照组样式 -->
                <new-expert-item
                    v-if="new_card !== '1'"
                    :expert="expert"
                    :page-source="pageSource"
                />
                <!-- 实验中样式 -->
                <basic-doctor
                    v-else
                    :current-type="'0'"
                    :expert="expert"
                />
            </view>
        </view>
        <card-item-bottom-more v-if="expertList && expertList.length > 1" @tap="onNavtoSearch('clk')"/>
    </view>
</template>

<script>
/**
 * @file ala 医生推荐卡
 * @author 陈红帆
 */
import CIcon from '@baidu/med-ui/components/Icon/Icon';
import {navigate} from '../../utils/navigate';
import newExpertItem from '@components/doctor/new-expert-item';
import CardItemBottomMore from './card-item-bottom-more';
import BasicDoctor from '../doctor/basic-doctor';

export default {
    config: {
        component: true
    },
    components: {
        CardItemBottomMore,
        newExpertItem,
        CIcon,
        BasicDoctor
    },
    props: {
        doctorInfo: {
            type: Object,
            default: () => {}
        },
        currentIndex: {
            type: Number,
            default: 0
        },
        title: {
            type: String,
            default: ''
        },
        doctorTitle: {
            type: String,
            default: ''
        }
    },
    data() {
        return {
            result: {},
            header: {},
            expertList: [],
            pageSource: 'searchCard',
            navUrl: '',
            new_card: ''
        };
    },
    watch: {
        doctorInfo: {
            immediate: true,
            handler(val) {
                this.init(val);
            }
        }
    },
    methods: {
        init(params) {
            this.result = params || {};
            this.header = this.result.header || {};
            this.new_card = this.result.new_card;
            // 非重名医生复旦排行榜数据处理
            let expertInfoList = this.result.expertList || [];
            if (expertInfoList && expertInfoList.length) {
                this.expertList = expertInfoList.map(list => {
                    return JSON.parse(JSON.stringify(list));
                });
            }
            if (this.expertList && this.expertList.length) {
                this.expertList.map(list => {
                    if (list.labelList && list.labelList.length) {
                        list.labelList.map(item => {
                            item.label = item.label.replace(
                                /<[^>]*>(.*)<\/[^>]*>/gm,
                                '<span style="color: #4E6EF2">$1</span>'
                            );
                        });
                    }
                });
            }
            this.navUrl = this.result.url || '';
        },
        onNavtoSearch(value = '') {
            if (this.doctorTitle === '医生' && value === 'clk') {
                this.$emit('onJumpChild');
            } else {
                this.navUrl && navigate({url: this.navUrl});
            }

        }
    }
};

</script>

<style lang="less" scoped>
.content {
    border-radius: 12px;
    margin-bottom: 0.1rem;
    background: #fff;
}

.duplicate-name {
    color: #fff;
    border-radius: 12px 12px 0 0;
    padding: 12px 13px 12px;
    background-image: linear-gradient(134deg, #00cfa3 0%, #05cfcd 61%, #00d3ea 100%);
    margin-bottom: 11px;
}

.expert-item {
    padding: 9px 13px 0px;
}

.expert-space {
    padding-top: 0px;
}

.space {
    padding-bottom: 15px;
}

.non-primacy {
    display: flex;
    padding: 11px 13px 10px;
    border-bottom: 1px solid #f1f1f1;
    margin-bottom: 15px;

    &__title {
        flex: 1;
        color: #1f1f1f;
        font-weight: 700;
    }
}
</style>
