<template>
<view
@tap="click"
class="u-cell"
:class="{ 'u-border-bottom': borderBottom, 'u-border-top': borderTop, 'u-col-center': center, 'u-cell--required': required }"
hover-stay-time="150"
:hover-class="hoverClass"
:style="{
backgroundColor: bgColor
}"
>
<u-icon
:size="iconSize"
:name="icon"
v-if="icon"
:custom-style="iconStyle"
class="u-cell__left-icon-wrap"
></u-icon>
<view class="u-flex" v-else>
<slot name="icon"></slot>
</view>
<view
class="u-cell_title"
:style="[
{
width: titleWidth ? titleWidth + 'rpx' : 'auto'
},
titleStyle
]"
>
<block v-if="title">{{ title }}</block>
<slot name="title" v-else></slot>
<view class="u-cell__label" v-if="label || $slots.label" :style="[labelStyle]">
<block v-if="label">{{ label }}</block>
<slot name="label" v-else></slot>
</view>
</view>
<view class="u-cell__value" :style="[valueStyle]">
<block class="u-cell__value" v-if="value">{{ value }}</block>
<slot v-else></slot>
</view>
<u-icon
v-if="arrow"
name="arrow-right"
:style="[arrowStyle]"
class="u-icon-wrap u-cell__right-icon-wrap"
></u-icon>
<view class="u-flex" v-if="$slots['right-icon']">
<slot name="right-icon"></slot>
</view>
</view>
</template>
<script>
export default {
name: 'u-cell-item',
props: {
icon: {
type: String,
default: ''
},
title: {
type: [String, Number],
default: ''
},
value: {
type: [String, Number],
default: ''
},
label: {
type: [String, Number],
default: ''
},
borderBottom: {
type: Boolean,
default: true
},
borderTop: {
type: Boolean,
default: false
},
hoverClass: {
type: String,
default: 'u-cell-hover'
},
arrow: {
type: Boolean,
default: true
},
center: {
type: Boolean,
default: false
},
required: {
type: Boolean,
default: false
},
titleWidth: {
type: [Number, String],
default: ''
},
arrowDirection: {
type: String,
default: 'right'
},
titleStyle: {
type: Object,
default() {
return {}
}
},
valueStyle: {
type: Object,
default() {
return {}
}
},
labelStyle: {
type: Object,
default() {
return {}
}
},
bgColor: {
type: String,
default: 'transparent'
},
index: {
type: [String, Number],
default: ''
},
useLabelSlot: {
type: Boolean,
default: false
},
iconSize: {
type: [Number, String],
default: 17
},
iconStyle: {
type: Object,
default() {
return {}
}
}
},
data() {
return {}
},
computed: {
arrowStyle() {
let style = {}
if (this.arrowDirection == 'up') style.transform = 'rotate(-90deg)'
else if (this.arrowDirection == 'down') style.transform = 'rotate(90deg)'
else style.transform = 'rotate(0deg)'
return style
}
},
methods: {
click() {
this.$emit('click', this.index)
}
}
}
</script>
<style lang="scss" scoped>
@import '../../libs/css/style.components.scss';
.u-cell {
position: relative;
display: flex;
box-sizing: border-box;
width: 100%;
padding: 10rpx 16rpx;
font-size: 14rpx;
line-height: 24rpx;
color: #606266;
background-color: #fff;
text-align: left;
}
.u-cell_title {
font-size: 14rpx;
}
.u-cell__left-icon-wrap {
margin-right: 5rpx;
font-size: 16rpx;
}
.u-cell__right-icon-wrap {
margin-left: 5rpx;
color: #969799;
font-size: 14rpx;
}
.u-cell__left-icon-wrap,
.u-cell__right-icon-wrap {
display: flex;
align-items: center;
height: 24rpx;
}
.u-cell-border:after {
position: absolute;
box-sizing: border-box;
content: ' ';
pointer-events: none;
right: 0;
left: 0;
top: 0;
border-bottom: 1px solid #e4e7ed;
-webkit-transform: scaleY(0.5);
transform: scaleY(0.5);
}
.u-cell-border {
position: relative;
}
.u-cell__label {
margin-top: 6rpx;
font-size: 13rpx;
line-height: 18rpx;
color: #909399;
word-wrap: break-word;
}
.u-cell__value {
overflow: hidden;
text-align: right;
vertical-align: middle;
color: #909399;
font-size: 13rpx;
}
.u-cell__title,
.u-cell__value {
flex: 1;
}
.u-cell--required {
overflow: visible;
display: flex;
align-items: center;
}
.u-cell--required:before {
position: absolute;
content: '*';
left: 8px;
margin-top: 4rpx;
font-size: 7px;
color: #fa3534;
}
</style>