<template>
    <view class="result-all">
        <view v-for="(card, cardIndex) in cardList" :key="cardIndex">
            <!-- 医院主卡 -->
            <ala-special-hospital
                v-if="card.tpl === 'feed_single_hospital' && card.result && cardIndex === 0"
                :hospital-info="card.result"
            />
            <!-- 医院卡推荐列表 -->
            <ala-recommend-hospital
                v-if="card.tpl === 'feed_suggest_hospital' && card.result"
                :hospital-info="card.result"
                :index="cardIndex"
            />
            <!-- 医生卡 -->
            <ala-special-doctor
                v-if="card.tpl === 'doctor_card' && card.result"
                :title="CARDTITLE"
                :current-index="cardIndex"
                :doctor-info="card.result"
            />
            <!-- 医生推荐卡 -->
            <ala-recommend-doctor
                v-if="card.tpl === 'recommend_doctor_card' && card.result"
                :current-index="cardIndex"
                :doctor-info="card.result"
                :title="CARDTITLE"
                :doctor-title="card.title"
                @onJumpChild="onJump(card)"
            />
            <!-- 医典 -->
            <view
                v-if="card.type === 'yidian'"
                class="card-cont"
                :class="showLogClass"
                data-show="yd-card"
                :data-extra="showLogExtraMap.yd"
            >
                <card-yd-drugs
                    v-if="card.yidian && card.yidian.type === 'drugs'"
                    :data="card.yidian"
                    @cardDrugs="cardTrigger('card')"
                />
                <card-yd-disease
                    v-else
                    :yidian="card.yidian"
                    @cardDisease="cardTrigger('card')"
                />
                <view
                    v-if="card.title"
                    @tap.stop="onJump(card)"
                >
                    <card-item-bottom-more/>
                </view>
            </view>
            <!-- 图文卡片 -->
            <view
                v-else-if="card.type === 'article' && card.article && card.article.length"
                class="card-cont"
                :class="showLogClass"
                data-show="article-card"
                :data-extra="showLogExtraMap.article"
            >
                <view
                    v-if="card.title"
                    class="item-title c-font-17 searchArticle"
                    @tap.stop="onJump(card)"
                >
                    <rich-text :nodes="card.title"/>
                </view>
                <card-recommend-item
                    v-for="(item, index) in card.article"
                    :key="index"
                    :top-line="index !== 0"
                    :title="item.title"
                    :card-type="card.type"
                    :doctor="{
                        name: item.expertName,
                        rank: item.expertRank,
                        label: item.hospitalTag,
                        hospital: item.hospitalName,
                    }"
                    :url="item.unifiUrl"
                    :image="item.img"
                    :page="'pages/brand/search/index'"
                    :module="'search-recommend-general'"
                    @tap="articleCardClick"
                    @articlesDetailDot="cardTrigger('article')"
                />
                <view
                    v-if="card.title"
                    @tap.stop="onJump(card)"
                >
                    <card-item-bottom-more/>
                </view>
            </view>
            <!-- 视频卡片 -->
            <view
                v-else-if="card.type === 'video' && card.video && card.video.length"
                class="card-cont"
                :class="showLogClass"
                data-show="video-card"
                :data-extra="showLogExtraMap.video"
            >
                <view
                    v-if="card.title"
                    class="item-title c-font-17"
                    @tap.stop="onJump(card)"
                >
                    <rich-text :nodes="card.title"/>
                </view>
                <card-recommend-item
                    v-for="(item, index) in card.video"
                    :key="index"
                    :top-line="index !== 0"
                    :title="item.title"
                    :card-type="card.type"
                    :doctor="{
                        name: item.expertName,
                        rank: item.expertRank,
                        label: item.hospitalTag,
                        hospital: item.hospitalName,
                    }"
                    :url="item.unifiUrl"
                    show-play
                    :image="item.img"
                    :page="'pages/brand/search/index'"
                    :module="'search-recommend-general'"
                />
                <view
                    v-if="card.title"
                    @tap.stop="onJump(card)"
                >
                    <card-item-bottom-more/>
                </view>
            </view>
            <!-- 问答卡片 -->
            <view v-else-if="card.wenda && card.wenda.length" class="card-cont">
                <view
                    v-if="card.title"
                    class="item-title c-font-17"
                    @tap.stop="onJump(card)"
                >
                    <rich-text :nodes="card.title"/>
                </view>
                <view class="c-gap-inner-left-large c-gap-inner-right-large">
                    <card-wenda
                        v-for="(item, index) in card.wenda"
                        :key="index"
                        :wenda="item"
                        show-border
                    />
                </view>
                <view
                    v-if="card.title"
                    @tap.stop="onJump(card)"
                >
                    <card-item-bottom-more/>
                </view>
            </view>
            <!-- 问诊 -->
            <view
                v-else-if="card.expert || card.quick"
                class="card-cont"
                :class="showLogClass"
                data-show="wz-card"
                :data-extra="showLogExtraMap.wz"
            >
                <view
                    v-if="card.title"
                    class="item-title c-font-17"
                    @tap.stop="onJump(card)"
                >
                    <rich-text :nodes="card.title"/>
                </view>
                <view v-if="card.quick" class="item-wz-doctor">
                    <card-wz-doctor :expert="card.quick" :show-border="true"/>
                </view>
                <template v-if="card.expert && card.expert.length">
                    <view
                        v-for="(item, index) in card.expert"
                        :key="index"
                        class="item-wz-doctor"
                    >
                        <card-wz-doctor :expert="item" :show-border="index !== card.expert.length - 1 ? true : false"/>
                    </view>
                </template>
                <view
                    v-if="card.title"
                    class="c-gap-top-large"
                    @tap.stop="onJump(card)"
                >
                    <card-item-bottom-more/>
                </view>
            </view>
            <!-- 挂号 -->
            <view
                v-else-if="card.section && card.section.length"
                class="card-cont"
                :class="showLogClass"
                data-show="gh-card"
                :data-extra="showLogExtraMap.gh"
            >
                <view
                    v-if="card.title"
                    class="item-title c-font-17"
                    @tap.stop="onJump(card)"
                >
                    <rich-text :nodes="card.title"/>
                </view>
                <view class="item-gh-cont">
                    <view
                        v-for="(item, index) in card.section"
                        :key="index"
                        class="item-gh-li"
                    >
                        <navigate :url="item.unifiUrl">
                            <text class="item-gh-li-title c-font-17">{{ item.title }}</text>
                            <text class="item-gh-li-sub c-font-normal">{{ item.desc }}</text>
                        </navigate>
                    </view>
                </view>
                <view
                    v-if="card.title"
                    @tap.stop="onJump(card)"
                >
                    <card-item-bottom-more/>
                </view>
            </view>
            <!-- 挂号医院 -->
            <view
                v-else-if="card.hospitals && card.hospitals.length"
                class="card-cont"
                :class="showLogClass"
                data-show="gh-hosp-card"
                :data-extra="showLogExtraMap.gh"
            >
                <view
                    v-if="card.title"
                    class="item-title c-font-17"
                    @tap.stop="onJump(card)"
                >
                    <rich-text :nodes="card.title"/>
                </view>
                <view>
                    <card-gh-hospital
                        v-for="(item, index) in card.hospitals"
                        :key="index"
                        :hospital="item"
                    />
                </view>
                <view
                    v-if="card.title"
                    @tap.stop="onJump(card)"
                >
                    <card-item-bottom-more/>
                </view>
            </view>
            <!-- 挂号医院重构 -->
            <view
                v-else-if="card. hospitalList && card. hospitalList.length"
                class="card-cont"
                :class="showLogClass"
                data-show="gh-hosp-card"
                :data-extra="showLogExtraMap.gh"
            >
                <view
                    v-if="card.searchWord"
                    class="item-title c-font-17"
                    @tap.stop="onJump(card)"
                >
                    <text>
                        <text class="c-color-main">{{ card.searchWord }}</text>
                        <text>_医院挂号</text>
                    </text>
                </view>
                <view>
                    <card-gh-hospital
                        v-for="(item, index) in card. hospitalList"
                        :key="index"
                        :hospital="item"
                        restructure
                        :from="defaultFrom"
                        :word="card.searchWord"
                        :sf-ref="query.sf_ref || 'svcgh'"
                    />
                </view>
                <view
                    v-if="card.searchWord"
                    @tap.stop="onJump(card)"
                >
                    <card-item-bottom-more/>
                </view>
            </view>
            <!-- 挂号医生 -->
            <view
                v-else-if="card.experts && card.experts.length"
                class="card-cont"
                :class="showLogClass"
                data-show="gh-doctor-card"
                :data-extra="showLogExtraMap.gh"
            >
                <view
                    v-if="card.title"
                    class="item-title c-font-17"
                    @tap.stop="onJump(card)"
                >
                    <rich-text :nodes="card.title"/>
                </view>
                <view>
                    <card-gh-expert
                        v-for="(item, index) in card.experts"
                        :key="index"
                        :expert="item"
                        :sys-info="systemInfo"
                    />
                </view>
                <view
                    v-if="card.title"
                    @tap.stop="onJump(card)"
                >
                    <card-item-bottom-more/>
                </view>
            </view>
            <!-- 挂号重构医生 -->
            <view
                v-else-if="card.expertList && card.expertList.length"
                class="card-cont"
                :class="showLogClass"
                data-show="gh-doctor-card"
                :data-extra="showLogExtraMap.gh"
            >
                <view
                    v-if="card.searchWord"
                    class="item-title c-font-17"
                    @tap.stop="onJump(card)"
                >
                    <text>
                        <text class="c-color-main">{{ card.searchWord }}</text>
                        <text>_医生挂号</text>
                    </text>
                </view>
                <view>
                    <card-gh-expert
                        v-for="(item, index) in card.expertList"
                        :key="index"
                        :expert="item"
                        :sys-info="systemInfo"
                        :sf-ref="query.sf_ref || 'svcgh'"
                        :from="defaultFrom"
                        restructure
                    />
                </view>
                <view
                    v-if="card.searchWord"
                    @tap.stop="onJump(card)"
                >
                    <card-item-bottom-more/>
                </view>
            </view>
            <!-- 购药 -->
            <view
                v-else-if="card.drugs && card.drugs.length"
                class="card-cont"
                :class="showLogClass"
                data-show="gy-card"
                :data-extra="showLogExtraMap.gy"
            >
                <view
                    v-if="card.title"
                    class="item-title c-font-17"
                    @tap.stop="onJump(card)"
                >
                    <rich-text :nodes="card.title"/>
                </view>
                <slide-tip
                    v-if="card.topTip"
                    state
                    no-fixed
                    no-animate
                    background="#FFEFC3"
                >
                    <view class="c-line-clamp1 c-color-333 c-gap-inner-left-large c-gap-inner-right-large c-tal">
                        <c-icon
                            name="exclamation-circle c-gap-right-small"
                            font-size="12px"
                            :style="{
                                color: '#666',
                            }"
                        />
                        <text>{{ card.topTip.text }}</text>
                    </view>
                </slide-tip>
                <view class="gy-cont">
                    <card-gy-drug
                        :drugs="card.drugs"
                        :drug-cart="card.drugCart"
                        :ubc-log-search-all="{
                            type: 'clk',
                            value: 'yaopinka',
                        }"
                        logkey="searchAll"
                    />
                </view>
                <view
                    v-if="card.title"
                    @tap.stop="onJump(card)"
                >
                    <card-item-bottom-more/>
                </view>
            </view>
            <!-- 找医院 -->
            <view
                v-else-if="card.dataList && card.dataList.length"
                class="card-cont"
                :class="showLogClass"
                data-show="hosp-card"
                :data-extra="showLogExtraMap.hosp"
            >
                <view
                    v-if="card.title"
                    class="item-title c-font-17"
                    @tap.stop="onJump(card)"
                >
                    <rich-text :nodes="card.title"/>
                </view>
                <view v-if="card.type === 'zyy'" class="zyy-cont">
                    <card-zyy-hospital
                        v-for="(hos, index) in card.dataList"
                        :key="index"
                        :hospitaal="hos"
                        :is-shadow="false"
                        :border-bottom="true"
                        :ubc-log-search-all="{
                            type: 'clk',
                            value: 'yiyuanka',
                        }"
                        :is-last="index >= card.dataList.length - 1"
                        class="hospital-item c-gap-bottom-large"
                    />
                </view>
                <view
                    v-if="card.title"
                    @tap.stop="onJump(card)"
                >
                    <card-item-bottom-more/>
                </view>
            </view>
            <!-- 疫苗 & 体检-->
            <view v-else-if="card.packageList && card.packageList.length" class="card-cont">
                <view
                    v-if="card.title"
                    class="item-title c-font-17"
                    @tap.stop="onJump(card)"
                >
                    <rich-text :nodes="card.title"/>
                </view>
                <view v-if="card.packageList && card.packageList.length" class="zyy-cont">
                    <template v-if="card.type === 'physical'">
                        <physical-package
                            v-for="(item, index) in card.packageList"
                            :key="index"
                            :item-style="{
                                'box-shadow': '',
                                'margin-bottom': '20px',
                            }"
                            :package-info="item"
                            btn-color="#06CB9D"
                            :ubc-log-search-all="{
                                type: 'clk',
                                value: 'tijianka',
                            }"
                            :ubc="UBC"
                            :class="showLogClass"
                            data-show="tj-card"
                            :data-extra="showLogExtraMap.tj"
                        />
                    </template>
                    <view
                        v-else
                        data-show="ym-card"
                        :class="showLogClass"
                        :data-extra="showLogExtraMap.ym"
                    >
                        <package-item
                            v-for="(item, index) in card.packageList"
                            :key="index"
                            :package-info="item"
                            :item-style="{
                                'box-shadow': '',
                                'margin-bottom': '20px',
                            }"
                            :ubc-log-search-all="{
                                type: 'clk',
                                value: 'yimiaoka',
                            }"
                            btn-color="#06CB9D"
                            :log="item.level1"
                        />
                    </view>
                </view>
                <view
                    v-if="card.title"
                    @tap.stop="onJump(card)"
                >
                    <card-item-bottom-more/>
                </view>
            </view>
        </view>
        <view v-if="noData && needEmptyText" class="result-null">
            哎呀~没有相关结果了，请换个搜索关键词试试~
        </view>
    </view>
</template>

<script>
/**
 * @file 搜索综合
 * @author chenshuo04
 * @categories 业务组件
 * @tags [component]
 */
import CIcon from '@baidu/med-ui/components/Icon/Icon';
import SlideTip from '../common/slide-tip';
import CardWzDoctor from './card-wz-doctor';
import CardGyDrug from './card-gy-drug';
import CardZyyHospital from '../zyy/hospital-item';
import CardYdDisease from './card-yd-disease';
import CardYdDrugs from './card-yd-drugs';
import CardWenda from './card-wenda';
import CardRecommendItem from '../speTopic/Recommend/RecommendItem';
import CardGhExpert from './card-gh-expert';
import CardGhHospital from './card-gh-hospital';
import CardItemBottomMore from './card-item-bottom-more';
import PackageItem from '../physical/PackageItem';
import PhysicalPackage from '../physical/PhysicalPackage';
import AlaSpecialHospital from './ala-special-hospital';
import AlaRecommendHospital from './ala-recommend-hospital';
import AlaSpecialDoctor from './ala-special-doctor';
import AlaRecommendDoctor from './ala-recommend-doctor.vue';
import Navigate from '../common/navigate';
import {navigate} from '../../utils/navigate';
import {request} from '../../utils/request';
import {getSystemInfo} from '@baidu/med-utils/lib/Mars/system';
import {getQueryObject, rand} from '@utils/core';
import {ubcSend, CollectLog} from '@utils/log';
import {getPageLocation} from '@utils/location';
import * as Conf from '@utils/conf';
const UBC = {
    type: 'clk',
    value: 'search',
    ext: {
        pd: 'tj',
        value_type: 'search_all',
    }
};

export default {
    config: {
        component: true
    },
    components: {
        CIcon,
        CardWzDoctor,
        CardGyDrug,
        CardYdDrugs,
        CardZyyHospital,
        CardYdDisease,
        CardRecommendItem,
        CardWenda,
        CardGhExpert,
        CardGhHospital,
        CardItemBottomMore,
        PackageItem,
        Navigate,
        SlideTip,
        PhysicalPackage,
        AlaSpecialHospital,
        AlaRecommendHospital,
        AlaSpecialDoctor,
        AlaRecommendDoctor
    },
    props: {
        /**
         * 接口数组
         */
        ajaxList: {
            type: Array,
            default: () => []
        },
        /**
         * 当前query
         */
        currentQuery: {
            type: String,
            default: ''
        },
        /**
         * 是否需要空态文案
         */
        needEmptyText: {
            type: Boolean,
            default: true
        },
        /**
         * 是否需要纠错
         */
        needCorrect: {
            type: Boolean,
            default: true
        },
        /**
         * ubc判断page
         */
        ubcByPage: {
            type: String,
            default: ''
        },
        /**
         * 使用的页面路由
         */
        curPage: {
            type: String,
            default: ''
        },
        /**
         * 页面参数
         */
        query: {
            type: Object,
            default() {
                return {};
            }
        }
    },
    data() {
        return {
            restAjaxList: [],
            cardList: [],
            isLoading: false,
            systemInfo: null,
            UBC,
            noData: false,
            showLogClass: 'showLogClass' + rand(6),
            showLogExtraMap: {},
            isCardFlag: false,
            currentIndex: 0,
            CARDTITLE: '找医生',
            defaultFrom: 'gh_search',
            city: null,
            // 是否为挂号重构
            isRestructed: 0,
            // 是否为首次加载，解决小程序首屏请求两次的问题
            firstLoad: true
        };
    },
    watch: {
        ajaxList(val) {
            // 判断小程序是否为首次加载，解决小程序首屏请求两次接口的问题
            if (process.env.MARS_ENV === 'swan' && this.firstLoad) {
                this.firstLoad = false;
                return;
            }

            if (val && val.length) {
                Object.assign(this, {
                    restAjaxList: [],
                    cardList: []
                });
                this.getList(val);
            }
        }
    },
    created() {
        let isRestructed = this.query.is_restructed || this.isRestructed;
        this.isRestructed = isRestructed;
        if (this.ajaxList && this.ajaxList.length) {
            Object.assign(this, {
                restAjaxList: [],
                cardList: []
            });
            if (isRestructed) {
                getPageLocation()
                    .then(city => {
                        this.city = city;
                        this.getList(this.ajaxList);
                    });
                return;
            }

            this.getList(this.ajaxList);
        }
        // 获取系统信息
        this.systemInfo = getSystemInfo();
        const resultAllName = ['yd', 'article', 'video', 'wz', 'gh', 'gy', 'hosp', 'ym', 'tj'];
        this.showLogExtraMap = resultAllName.reduce((cur, type) => {
            cur[type] = JSON.stringify({'type': `${type}-card`});
            return cur;
        }, {});
    },
    mounted() {
        this.$mpUpdated(() => {
            new CollectLog({
                SIGN: this.showLogClass,
                sendCallback: item => {
                    ubcSend({
                        type: 'view',
                        value: 'search-result-all',
                        page: this.curPage,
                        ext: {
                            pd: 'search',
                            item
                        }
                    });
                }
            });
        });
    },
    methods: {
        formatGoodAt(title) {
            return title
                .replace(new RegExp('<b>', 'g'), '<span style="color: #00c8c8;font-weight: bold;">')
                .replace(new RegExp('</b>', 'g'), '</span>');
        },
        cardTrigger(type) {
            if (type !== '') {
                const dotValue = type === 'card' ? 'ydss_citiaojieguoka' : 'ydss_wenzhangjieguo';
                this.ubcFunc('clk', dotValue);
            }
        },
        ubcFunc(type, value) {
            ubcSend({
                type: type,
                value: value,
                page: this.curPage
            });
        },
        onJump(item) {
            let p_str = '';
            if (item.type === 'yidian') {
                p_str = 'ydss_citiaojieguoka';
            }
            else if (item.type === 'article') {
                p_str = 'ydss_wenzhangjieguo';
            }
            this.ubcFunc('clk', p_str);

            switch (item.title) {
                case '疫苗':
                    item.changeNav = 'ym';
                    break;
                case '问医生':
                    item.changeNav = 'wz';
                    break;
                case '购药':
                    item.changeNav = 'gy';
                    break;
                case '体检预约服务':
                    item.changeNav = 'tj';
                    break;
                case '医生':
                    item.changeNav = 'ys';
                    break;
            }

            if (item.changeNav) {
                /**
                 * 切换nav
                 *
                 * @event change
                 */
                this.$emit('onNavChangeByChannel', item.changeNav);
            }
            else {
                let url = item.unifiUrl;
                if (this.isRestructed) {
                    url = this.getNavigateUrl(item);
                }
                navigate({
                    url
                });
            }

            // !!! 体检埋点
            if (item && item.title && item.title.indexOf('体检') > -1) {
                ubcSend({
                    type: 'clk',
                    value: 'tj_list',
                    ext: {
                        value_type: '',
                        value_id: item.title
                    }
                });
            }
        },

        /**
         * 获取跳转链接
         */
        getNavigateUrl(item) {
            let result = '';
            if (item.expertList && item.expertList.length) {
                // 跳转医生列表
                result = `/pages/guahao/expertlist/index?sf_ref=${this.query.sf_ref || 'svcgh'}`
                    + `&title=按医生&word=${item.searchWord}&from=${this.defaultFrom}&prepage=search`;
            }
            else if (item.hospitalList && item.hospitalList.length) {
                // 跳转医院列表
                result = `/pages/guahao/hospitallist/index?sf_ref=${this.query.sf_ref || 'svcgh'}`
                    + `&title=按医院&word=${item.searchWord}&from=${this.defaultFrom}&prepage=search`;
            }
            return result;
        },
        getList(data) {
            if (data) {
                const promiseArr = data.map(async item => {
                    let url = await this.handleRequestUrl(item);
                    return request({
                        url,
                        data: Object.assign(
                            {},
                            getQueryObject(item.url),
                            item.data,
                            this.needCorrect ? {} : {isec: '1'},
                            this.isRestructed ? this.city : {}
                        )
                    });
                });
                Promise.all(promiseArr)
                    .then(this.formatCard)
                    .then(cardList => cardList.filter(card => card.noResult !== 1))
                    .then(cardList => {
                        Object.assign(this, {cardList});
                        /**
                         * 设置loading
                         *
                         */
                        this.$emit('setLoading', false);
                        if (cardList.length === 0) {
                            this.noData = true;
                        }
                        else if (cardList.length && !this.isCardFlag && this.ubcByPage === 'ydSearch') {
                            this.isCardFlag = true;
                            for (let i = 0; i < cardList.length; i++) {
                                let dotValue = cardList[i].type === 'yidian' ? 'ydss_citiaojieguoka1'
                                    : (cardList[i].type === 'article' ? 'ydss_wenzhangjieguo1' : '');
                                this.$emit('resultAllViewUbc', dotValue);
                            }
                        }
                        else if (cardList.length && this.isRestructed) {
                            // 挂号重构
                            let ghRestructNoRes = 0;
                            cardList.forEach(item => {
                                const objKeys = Object.keys(item);
                                if (objKeys.indexOf('expertList') > -1
                                    && !(item.expertList && item.expertList.length)) {
                                    ghRestructNoRes++;
                                }
                                else if (objKeys.indexOf('hospitalList') > -1
                                    && !(item.hospitalList && item.hospitalList.length)) {
                                    ghRestructNoRes++;
                                }
                                if (item.expertList && item.expertList.length) {
                                    item.expertList = item.expertList.map(expert => {
                                        expert.goodAt = this.formatGoodAt(expert.goodAt);
                                        return expert;
                                    });
                                }
                            });
                            if (ghRestructNoRes === 2) {
                                this.noData = true;
                            }
                        }
                    })
                    .catch(err => {
                        console.log(err);
                    });
            }
        },

        // 挂号处理请求特殊处理
        async handleRequestUrl(item) {
            // TODO rd不好配置横向环境，gh先前端判断，运行稳定后再横向同学配置
            let url = item.url.split('?')[0];
            let q = this.query || {};
            // 没有is_restructed标识时，先请求兜底接口判断是否命中小流量再获取结果
            let goToNewRes;
            if (!this.isRestructed && item.tpl && item.tpl.indexOf('guahao') > -1) {
                try {
                    goToNewRes = await this.getGhGotoNewResult();
                }
                catch (e) {};
            }

            if (goToNewRes && goToNewRes.data && goToNewRes.data.goTo) {
                this.isRestructed = goToNewRes.data.goTo;
                // 首页搜索进入无定位城市code,获取城市数据
                if (!this.city) {
                    getPageLocation().then(city => {
                        this.city = city;
                    });
                }
            }

            if (this.isRestructed) {
                if (item.tpl === 'card_guahao_hospital') {
                    url = `${Conf.goApiHost}/guahao/api/smart/hospitallist?sf_ref=${q.sf_ref || 'svcgh'}`
                        + `&from=${this.defaultFrom}&pn=1&rn=3`;
                }
                else if (item.tpl === 'card_guahao_doctor') {
                    url = `${Conf.goApiHost}/guahao/api/smart/expertlist?sf_ref=${q.sf_ref || 'svcgh'}`
                        + `&from=${this.defaultFrom}&pn=1&rn=3`;
                }
            }

            return url;
        },

        /**
         * 挂号二跳兜底结果获取
         */
        getGhGotoNewResult() {
            const goToNewapi = '/guahao/api/smart/gotonew';
            const path = '/med/api/gh/search';
            return new Promise((resolve, reject) => {
                request({
                    url: `${Conf.goApiHost}${goToNewapi}`,
                    method: 'POST',
                    header: {
                        'content-type': 'application/json'
                    },
                    data: {
                        path
                    }
                })
                    .then(res => {
                        resolve(res);
                    })
                    .catch(err => {
                        reject(err);
                    });
            });
        },
        // 卡片数据预处理
        formatCard(datalist) {
            const _format = _datalist => {
                return _datalist.map((data, index) => {
                    let card = data.data || data;
                    // 标题处理
                    card.title && (card.title = this.formatGoodAt(card.title));
                    //  问诊专家处理
                    card.expert
                        && (card.expert = card.expert.map(item => {
                            item.goodAt = this.formatGoodAt(item.goodAt);
                            return item;
                        }));
                    // 找医院处理 j接口数据不规范
                    if (card.hpSearch) {
                        return {
                            type: 'zyy',
                            dataList: card.dataList.slice(0, 3),
                            title: card.header.title || '推荐医院',
                            unifiUrl: card.header.unifiUrl
                        };
                    }
                    return card;
                });
            };
            const head = datalist[0].data.head || {};
            this.$emit('errCorrect', head);

            if (datalist && datalist[0] && datalist[0].data && datalist[0].data.data) {
                return _format(datalist[0].data.data || []);
            }

            return _format(datalist);
        }
    }
};
</script>
<style lang="less" scoped>
.result-all {
    padding-left: 0.1rem;
    padding-right: 0.1rem;

    .item-title {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 1px solid #f1f1f1;
        padding: 0.1rem 0.13rem 0.1rem 0.13rem;
        color: #1f1f1f;
        font-family: PingFangSC-Medium;
    }

    .card-cont {
        border-radius: 12px;
        margin-bottom: 0.10rem;
        background: #fff;
        overflow: hidden;
    }

    .hospital-item {
        box-shadow: none;
    }

    .item-wz-doctor {
        padding-left: 0.13rem;
        padding-top: 0.15rem;
    }

    .item-gh-cont {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .item-gh-li {
        box-sizing: border-box;
        padding: 0.15rem 0;
        width: 50%;
        text-align: center;

        &:first-child {
            border-right: 1px solid #f1f1f1;
        }

        &-title {
            display: block;
            color: #333;
            font-weight: 600;
        }

        &-sub {
            color: #3f3f3f;
        }
    }

    .result-null {
        color: #999;
        text-align: center;
        padding-top: 50%;
    }
}
</style>
