<template>
    <navigate
        :url="targetUrl"
        @tap="drugTap"
    >
        <view class="drug c-row">
            <view
                class="c-span1 img-wrapper"
                :style="{
                    'width': width,
                }"
            >
                <view
                    class="img"
                    :style="{
                        'border-radius': radius,
                    }"
                >
                    <view
                        :class="{
                            status: statusText,
                        }"
                        class="img-inner"
                    >
                        <c-image
                            has-compress
                            :is-round="false"
                            :width="width"
                            :height="height"
                            def-src="https://med-drug.cdn.bcebos.com/%E7%99%BD%E5%9B%BE.jpg"
                            :src="headImage"
                            :radius="radius"
                            :extra="{column: 4}"
                            hack-bg="radial-gradient(rgba(0, 0, 0, 0) 30%, rgba(0, 0, 0, 0.05) 100%)"
                        />
                    </view>
                    <view
                        v-if="statusText"
                        :class="{
                            break: statusText.length > 3,
                        }"
                        class="status-text"
                    >
                        <view
                            class="status-text-inner c-font-small"
                        >
                            {{ statusText }}
                        </view>
                    </view>
                </view>
            </view>
            <view class="c-span5 main-info">
                <view
                    :style="titleStyle"
                    class="c-font-15 name c-line-clamp2"
                >
                    <c-label
                        v-if="label"
                        color="#fd503e"
                        solid
                        custom
                        :text="label"
                        class="c-gap-right-small"
                    />
                    <text class="font-333 text c-line-clamp2">{{ titleName }}</text>
                </view>
                <view v-if="subTitle" class="c-font-13 c-line-clamp1 c-color-gray">{{ subTitle }}</view>
                <view
                    v-if="sales || textName"
                    class="c-font-13 c-line-clamp1"
                >
                    <text class="c-color-gray c-gap-right-middle">{{ sales }}</text>
                    <text class="c-color-gray">{{ textName }}</text>
                </view>
                <view
                    v-if="tags && tags.length"
                    class="c-font-small c-color-gray"
                >
                    <text
                        v-for="(tag, t) in tags"
                        :key="t"
                    ><text v-if="t !== 0 " class="s-line">|</text>{{ tag }}</text>
                </view>
                <view
                    v-if="spec"
                    :style="specStyle"
                    class="c-font-13 c-line-clamp1"
                >
                    <text class="c-color-gray">{{ specTitle }}{{ spec }}</text>
                </view>
                <view
                    v-if="tipsText"
                    class="c-font-13 tips-text"
                >
                    {{ tipsText }}
                </view>
                <view
                    v-if="priceBottom"
                    :class="{
                        'c-gap-top': priceGapTop,
                    }"
                    class="c-line-clamp1 price-bottom"
                >
                    <text class="c-font-13">￥</text>
                    <text v-if="priceFixed" class="font-18">{{ priceFixed }}</text>
                    <text v-else class="font-18">{{ price / 100 }}</text>
                </view>
            </view>
            <view class="c-span1 right-info">
                <view
                    v-if="priceFixed || price && !priceBottom"
                    class="price"
                >
                    <text
                        :style="priceCnStyle"
                        class="c-font-13"
                    >￥</text>
                    <text
                        v-if="priceFixed"
                        :style="priceStyle"
                        class="font-18"
                    >{{ priceFixed }}</text>
                    <text
                        v-else
                        :style="priceStyle"
                        class="font-18"
                    >{{ price / 100 }}</text>
                </view>
                <view v-if="orgPrice">
                    <rich-text
                        v-if="orgPrice"
                        class="c-color-gray"
                        :nodes="'<del>￥' + orgPrice / 100 + '</del>'"
                    />
                </view>
                <view v-if="priceTip" class="price-tip c-font-13">
                    {{ priceTip }}
                </view>
                <view
                    v-if="num"
                    :style="specStyle"
                    class="c-font-13 c-color-gray"
                >
                    x{{ num }}
                </view>
            </view>
        </view>
    </navigate>
</template>

<script>
/**
* @file drug-order-item
* @author zhangeryi
*/
import Navigate from '../common/navigate';
import image from '../common/image';
import Label from '@baidu/med-ui/components/Label/LabelOld';
import {send} from '../../utils/log';
export default {
    config: {
        component: true
    },
    options: {
        addGlobalClass: true
    },
    props: {
        // 药品url
        targetUrl: {
            type: String
        },
        drugId: {
            type: String
        },
        headImage: {
            type: String
        },
        // 立即配送等label
        label: {
            type: String
        },
        // 商品标题
        titleName: {
            type: String
        },
        subTitle: {
            type: String
        },
        // 销量
        sales: {
            type: [String, Number]
        },
        // 店铺名称
        textName: {
            type: String
        },
        specTitle: {
            type: String
        },
        // 规格
        spec: {
            type: String
        },
        // 数量
        num: {
            type: [String, Number]
        },
        // 价格
        price: {
            type: [String, Number]
        },
        // 格式化后的价格
        priceFixed: {
            type: [String, Number]
        },
        statusText: {
            type: String
        },
        tipsText: {
            type: String
        },
        priceBottom: {
            'type': Boolean,
            'default': false
        },
        priceGapTop: {
            'type': Boolean,
            'default': true
        },
        titleStyle: {
            type: Object
        },
        specStyle: {
            type: Object
        },
        priceCnStyle: {
            type: Object
        },
        priceStyle: {
            type: Object
        },
        // 原始价格
        orgPrice: {
            type: [String, Number]
        },
        // 价格说明
        priceTip: {
            type: String
        },
        width: {
            type: String,
            default: '80px'
        },
        height: {
            type: String,
            default: '80px'
        },
        radius: {
            type: String,
            default: '.05rem'
        },
        tags: {
            type: Array
        },
        logkey: {
            type: String
        }
    },
    components: {
        'c-image': image,
        'navigate': Navigate,
        'c-label': Label
    },
    data() {
        return {
            theme: {
                gray: '#707379',
                red: '#fd503e'
            }
        };
    },
    mounted() {
    },
    methods: {
        drugTap() {
            this.$emit('drugTap', this.drugId);
            send({
                type: 'b',
                action: 'drugClick',
                extra: {
                    module: this.logkey
                }
            });
        }
    }
};
</script>
<style lang="less" scoped>
.b-inline {
    display: inline-block;
}

.drug {
    .img-wrapper {
        box-sizing: content-box;
        flex: none;
        padding-right: .08rem;

        .img {
            overflow: hidden;
            position: relative;

            &-inner {
                &.status {
                    opacity: .5;
                }
            }

            .status-text {
                position: absolute;
                width: 50px;
                height: 50px;
                left: 50%;
                top: 50%;
                margin-top: -25px;
                margin-left: -25px;
                border-radius: 50%;
                background: rgba(0, 0, 0, .5);
                color: #fff;
                text-align: center;
                display: flex;
                align-items: center;
                padding: 0 7px;
                box-sizing: border-box;

                &.break {
                    padding: 0 10px;
                }

                &-inner {
                    color: #fff;
                    line-height: 1.4;
                }
            }
        }
    }

    .main-info {
        padding-right: .1rem;
    }

    .name {
        margin-bottom: 0;

        .text {
            margin-bottom: 0;
        }
    }

    .tips-text {
        color: #fd503e;
        font-size: 12px;
        line-height: 18px;
        margin-top: 2px;
    }

    .price-bottom {
        color: #fd503e;
    }

    .price-tip {
        color: #f5a623;
    }

    .font-333 {
        color: #333;
    }

    .font-18 {
        font-size: 18px;
    }

    .right-info {
        white-space: nowrap;
        flex: none;
        width: auto;
        text-align: right;

        .price {
            color: #fd503e;
        }
    }

    .s-line {
        position: relative;
        top: -1px;
        font-size: 10px;
        padding: 0 5px;
    }
}
</style>


