<template>
    <view class="pack-item" :style="itemStyle">
        <view @tap="toDetail(cagencyInfo)">
            <view class="pack-item-cont">
                <view class="pack-item-img">
                    <c-image
                        has-compress
                        :src="cagencyInfo.logo"
                        width="100%"
                        height="100%"
                        mode="aspectFit"
                        :extra="{column: 3}"
                        :hack-white-stroke="false"
                        :is-round="false"
                    />
                </view>
                <view class="pack-item-right">
                    <view class="pack-desc">
                        <view class="pack-name-wrapper">
                            <!-- tag -->
                            <text class="pack-item-label c-font-medium">{{ cagencyInfo.nameLabel }}</text>
                            <text class="pack-item-name c-font-medium c-font-ellipsis">{{ cagencyInfo.name }}</text>
                        </view>

                        <view v-if="cagencyInfo.tags && cagencyInfo.tags.length" class="pack-tag-wrapper">
                            <c-label
                                v-for="(item, index) in cagencyInfo.tags"
                                :key="index"
                                :font-size="12"
                                :height="14"
                                :line-height="14"
                                :text="item"
                                color="#858585"
                                border-color="rgba(133,133,133,0.50)"
                                bg-color="rgba(133,133,133,0.06)"
                                custom
                                class="new-gap-right-small"
                            />
                        </view>
                        <view class="pack-address c-color c-font-normal">
                            <view
                                v-show="cagencyInfo.distance"
                                class="pack-address-name c-gap-inner-right-small c-line-clamp1"
                            >
                                距您{{ cagencyInfo.distance }}
                            </view>
                        </view>
                    </view>
                    <view class="pack c-font-normal">
                        <!-- 券后价样式 -->
                        <view v-show="cagencyInfo && cagencyInfo.lowPrice">
                            <text class="c-font-normal act-price red">
                                <text class="act-price--small">¥</text>{{ cagencyInfo.lowPriceBefore }}.<text
                                    class="act-price--small"
                                >{{ cagencyInfo.lowPriceAfter }}起</text>
                            </text>
                            <text v-show="cagencyInfo.sales" class="c-font-normal grey c-margin-left-right">
                                已售{{ cagencyInfo.sales }}
                            </text>
                            <!-- <text v-show="cagencyInfo.perPrice" class="c-font-normal grey">
                                人均￥{{ cagencyInfo.perPrice }}
                            </text> -->
                        </view>
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
/**
 * @file 推荐医院Item
 * @author xueyanhui@baidu.com
 * @categories 业务组件
 * @tags [component]
 */

/* global Page swan  getApp */
import CLabel from '@baidu/med-ui/components/Label/Label';
import CImage from '@components/common/image';
import {navigate} from '@utils/navigate';
import {ubcSend} from '@utils/log';

export default {
    config: {
        component: true
    },
    options: {
        addGlobalClass: true
    },
    components: {
        CLabel,
        CImage
    },
    props: {
        /**
         * 医院信息
         */
        agencyInfo: {
            type: Object,
            default: () => {}
        },
        /**
         * 自定义套餐item颜色
         */
        itemStyle: {
            type: Object,
            default: () => ({
                'box-shadow': '0 10px 50px 0 rgba(0,0,0,0.06)',
                'margin-bottom': '20px'
            })
        },
        /**
         * 日志
         */
        log: String,
        /**
         * 券后价样式sigma=>强样式， normal=>弱样式，体检2.0统一改为弱样式
         */
        couponPriceStyle: {
            type: String,
            default: 'normal'
        },
        /**
         * 登录态
         */
        isLogin: {
            type: Number,
            default: 0
        },
        /**
         * 数据位
         */
        index: {
            type: Number,
            default: 0
        },
        /**
         * 按钮颜色
         */
        btnColor: {
            type: String,
            default: '#FD503E'
        },
        /**
         * 控制按钮disabled状态
         */
        btnDisabled: {
            type: Boolean
        },
        /**
         * 来源
         */
        source: {
            type: String,
            default: 'normal'
        },
        // ubc日志必传字段page
        page: {
            type: String,
            default: ''
        }
    },
    computed: {
        cagencyInfo() {
            // 老组件字段兼容
            let packageObj = {};
            Object.assign(packageObj, {
                address: this.agencyInfo.address || (this.agencyInfo.agency && this.agencyInfo.agency.name),
                // 划线价
                distance: this.agencyInfo.distance || (this.agencyInfo.agency && this.agencyInfo.agency.distance),
                storeid: this.agencyInfo.store_id,
                logo: this.agencyInfo.logo,
                name: this.agencyInfo.name,
                // 均价
                perPrice: this.agencyInfo.perPrice,
                // 限时价
                lowPrice: this.agencyInfo.lowPrice,
                lowPriceBefore: this.agencyInfo.lowPrice && this.agencyInfo.lowPrice.split('.')[0],
                lowPriceAfter: this.agencyInfo.lowPrice && this.agencyInfo.lowPrice.split('.')[1],
                sales: this.agencyInfo.sales,
                url: this.agencyInfo.url,
                tags: this.agencyInfo.tags,
                nameLabel: this.agencyInfo.nameLabel
            });
            return packageObj;
        },
        price() {
            let price = this.cagencyInfo.couponPrice || this.cagencyInfo.price;
            if (price) {
                const priceArr = price.toString().split('.');
                const int = priceArr[0];
                const dec = priceArr[1];
                return {
                    int,
                    dec
                };
            }
            return {};
        },
        button() {
            return this.agencyInfo.button;
        }
    },
    methods: {
        toDetail(info) {
            ubcSend({
                page: this.page,
                type: 'clk',
                value: 'hospital',
                ext: {
                    pd: 'tj',
                    value_type: 'list_id',
                    value_id: info.storeid
                }
            });
            navigate({url: info.url});
        }
    }
};
</script>
<style lang="less" scoped>
.pack-item {
    box-sizing: border-box;
    background-color: #fff;
    border-radius: 8px;

    &-label {
        color: #fff;
        background: #00c8c8;
        display: inline-block;
        border-radius: 24px;
        font-size: 12px;
        margin-right: 6px;
        width: 34px;
        height: 16px;
        line-height: 16px;
        text-align: center;
    }

    &-address {
        color: #858585;
        margin-top: 0.01rem;
    }

    &-cont {
        display: flex;
        position: relative;
    }

    &-right {
        flex: 1;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    &-img {
        width: 1.11rem;
        height: 0.88rem;
        border-radius: 6px;
        background-size: contain;
        background-position: center center;
        background-repeat: no-repeat;
        flex-shrink: 0;
        margin-right: 8px;
        border: 1px solid #e0e0e0;
        overflow: hidden;
    }

    &-name {
        flex: 1;
        color: #1f1f1f;
    }

    &-sales {
        color: #858585;
    }
}

.pack-tag-wrapper {
    display: flex;
    flex-wrap: wrap;
}

.pack-tag {
    display: inline;
    border-radius: 8px;
    margin-right: 5px;
    padding: 0 5px;
    word-break: keep-all;
    margin-bottom: 4px;
    line-height: 14px;
    border: 1px solid #f1f1f1;
    color: #999;
}

.pack {
    &-price {
        flex: 1;
        display: flex;
        justify-content: space-between;
        align-items: flex-end;

        &__fix {
            max-height: 0.27rem;
        }

        &-symbol {
            font-size: 13px;
            color: #fd503e;
            line-height: 10px;
            font-weight: 600;
        }

        &-now {
            font-weight: 600;
            font-size: 19px;
            color: #fd503e;
            line-height: 16px;
        }

        &-store {
            font-size: 13px;
            color: #858585;
            text-decoration: line-through;
            margin-left: 4px;
        }

        &-normal {
            color: #fd503e;
            margin-left: 4px;
        }

        &-symbol-color {
            color: #fd503e;
        }

        &-after {
            font-weight: bold;
        }

        .act-price-row {
            display: flex;
            justify-content: space-between;
            line-height: 20px;
            padding-bottom: 2px;
        }

        .act-price-img {
            width: 100%;
            height: 5.6vw;
            background: url('https://med-fe.cdn.bcebos.com/vaccine/dc572f0656ed56daacc645ccdf2aa948.png');
            background-size: 100% 100%;
            background-repeat: no-repeat;
            text-align: right;
        }

        .act-price-text {
            width: 58px;
            text-align: center;
            padding-right: 4px;
        }

        &-lowest {
            position: relative;
            bottom: 9px;
            display: inline-block;
            min-width: 70px;
            text-align: center;
            padding-right: 4px;
        }
    }

    &-address {
        display: flex;
        justify-content: space-between;
        color: #858585;

        &-name {
            flex: 1;
            overflow: hidden;
        }
    }
}
@media only screen and (max-width: 360px) {
    .act-price-row {
        font-size: 0.13rem;
    }
}

.new-gap-right-small {
    margin-right: 0.04rem;
}

.c-font-ellipsis {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pack-name-wrapper {
    display: flex;
    align-items: center;
}

.red {
    color: #fd503e;
}

.grey {
    color: #858585;
}

.act-price {
    font-size: 19px;

    &--small {
        font-size: 14px;
    }
}

.c-margin-left-right {
    margin: 0 8px 0 5px;
}
</style>
