<template>
<view
class="u-card"
@tap.stop="click"
:class="{ 'u-border': border, 'u-card-full': full, 'u-card--border': borderRadius > 0 }"
:style="{
borderRadius: borderRadius + 'rpx',
margin: margin
}"
>
<view
v-if="showHead"
class="u-card__head"
:style="[{padding: padding + 'rpx'}, headStyle]"
:class="{
'u-border-bottom': headBorderBottom
}"
@tap="headClick"
>
<view v-if="!$slots.head" class="u-flex u-row-between">
<view class="u-card__head--left u-flex u-line-1" v-if="title">
<image
:src="thumb"
class="u-card__head--left__thumb"
mode="aspectfull"
v-if="thumb"
:style="{
height: thumbWidth + 'rpx',
width: thumbWidth + 'rpx',
borderRadius: thumbCircle ? '100rpx' : '6rpx'
}"
></image>
<text
class="u-card__head--left__title u-line-1"
:style="{
fontSize: titleSize + 'rpx',
color: titleColor
}"
>
{{ title }}
</text>
</view>
<view class="u-card__head--right u-line-1" v-if="subTitle">
<text
class="u-card__head__title__text"
:style="{
fontSize: subTitleSize + 'rpx',
color: subTitleColor
}"
>
{{ subTitle }}
</text>
</view>
</view>
<slot name="head" v-else />
</view>
<view @tap="bodyClick" class="u-card__body" :style="[{padding: padding + 'rpx'}, bodyStyle]"><slot name="body" /></view>
<view
v-if="showFoot"
class="u-card__foot"
@tap="footClick"
:style="[{padding: $slots.foot ? padding + 'rpx' : 0}, footStyle]"
:class="{
'u-border-top': footBorderTop
}"
>
<slot name="foot" />
</view>
</view>
</template>
<script>
export default {
name: 'u-card',
props: {
full: {
type: Boolean,
default: false
},
title: {
type: String,
default: ''
},
titleColor: {
type: String,
default: '#303133'
},
titleSize: {
type: [Number, String],
default: '15'
},
subTitle: {
type: String,
default: ''
},
subTitleColor: {
type: String,
default: '#909399'
},
subTitleSize: {
type: [Number, String],
default: '13'
},
border: {
type: Boolean,
default: true
},
index: {
type: [Number, String, Object],
default: ''
},
margin: {
type: String,
default: '15rpx'
},
borderRadius: {
type: [Number, String],
default: '13'
},
headStyle: {
type: Object,
default() {
return {};
}
},
bodyStyle: {
type: Object,
default() {
return {};
}
},
footStyle: {
type: Object,
default() {
return {};
}
},
headBorderBottom: {
type: Boolean,
default: true
},
footBorderTop: {
type: Boolean,
default: true
},
thumb: {
type: String,
default: ''
},
thumbWidth: {
type: [String, Number],
default: '30'
},
thumbCircle: {
type: Boolean,
default: false
},
padding: {
type: [String, Number],
default: '15'
},
showHead: {
type: Boolean,
default: true
},
showFoot: {
type: Boolean,
default: true
}
},
data() {
return {};
},
methods: {
click() {
this.$emit('click', this.index);
},
headClick() {
this.$emit('head-click', this.index);
},
bodyClick() {
this.$emit('body-click', this.index);
},
footClick() {
this.$emit('foot-click', this.index);
}
}
};
</script>
<style lang="scss" scoped>
@import "../../libs/css/style.components.scss";
.u-card {
position: relative;
overflow: hidden;
font-size: 14rpx;
background-color: #ffffff;
box-sizing: border-box;
&-full {
// 如果是与屏幕之间不留空隙,应该设置左右边距为0
margin-left: 0 !important;
margin-right: 0 !important;
}
&--border:after {
border-radius: 13rpx;
}
&__head {
&--left {
color: #303133;
&__thumb {
margin-right: 13rpx;
}
&__title {
max-width: 200rpx;
}
}
&--right {
color: #909399;
margin-left: 6rpx;
}
}
&__body {
color: #606266;
}
&__foot {
color: #909399;
}
}
</style>