<template>
<cell>
<view :class="disabled ? 'uni-list-item--disabled' : ''" class="uni-list-item" @click="onClick">
<view class="uni-list-item__container" :class="{'uni-list-item--first':isFirstChild}">
<view v-if="thumb" class="uni-list-item__icon">
<image :src="thumb" class="uni-list-item__icon-img" />
</view>
<view class="uni-list-item__icon" v-if="iconsType">
<u-icon :size="iconSize" :color="iconColor" :name="iconsType" />
</view>
<view v-else-if="showExtraIcon" class="uni-list-item__icon">
<u-icon
:color="extraIcon.color"
:size="extraIcon.size"
:name="extraIcon.type"
class="uni-icon-wrapper"
/>
</view>
<view class="uni-list-item__content">
<slot />
<text class="uni-list-item__content-title">{{ title }}</text>
<view v-if="note.length>0">
<view
v-for="(item,index) in note"
:key="index"
class="uni-list-item__content-note font-ellipsis"
>{{ item }}</view>
</view>
</view>
<view class="uni-list-item__extra">
<slot name="right"></slot>
<text v-if="rightText" class="uni-list-item__extra-text">{{rightText}}</text>
<u-badge v-if="showBadge" :type="badgeType" :count="badgeText" :size="badgeSize" />
<switch
v-if="showSwitch"
:disabled="disabled"
:checked="switchChecked"
@change="onSwitchChange"
/>
<u-icon
v-if="showArrow"
:size="18"
class="uni-icon-wrapper"
color="#bbb"
name="arrow-right"
/>
</view>
</view>
</view>
</cell>
</template>
<script>
import uIcon from '../u-icon/u-icon.vue'
import uBadge from '../u-badge/u-badge.vue'
export default {
name: 'u-list-item',
components: {
uIcon,
uBadge
},
props: {
title: {
type: String,
default: ''
},
note: {
type: Array,
default: function() {
return []
}
},
disabled: {
type: [Boolean, String],
default: false
},
showArrow: {
type: [Boolean, String],
default: true
},
showBadge: {
type: [Boolean, String],
default: false
},
inverted: {
type: Boolean,
default: false
},
badgeSize: {
type: String,
default: 'normal'
},
showSwitch: {
type: [Boolean, String],
default: false
},
switchChecked: {
type: [Boolean, String],
default: false
},
badgeText: {
type: [String, Number],
default: ''
},
badgeType: {
type: String,
default: 'default'
},
rightText: {
type: String,
default: ''
},
thumb: {
type: String,
default: ''
},
iconsType: {
type: String,
default: ''
},
iconSize: {
type: Number,
default: 22
},
iconColor: {
type: String,
default: '#AAAAAA'
},
showExtraIcon: {
type: [Boolean, String],
default: false
},
extraIcon: {
type: Object,
default() {
return {
type: 'contact',
color: '#000000',
size: 20
}
}
}
},
inject: ['list'],
data() {
return {
isFirstChild: false
}
},
mounted() {
if (!this.list.firstChildAppend) {
this.list.firstChildAppend = true
this.isFirstChild = true
}
},
methods: {
onClick() {
this.$emit('click')
},
onSwitchChange(e) {
this.$emit('switchChange', e.detail)
}
}
}
</script>
<style lang="scss" scoped>
$list-item-pd: $uni-spacing-col-lg $uni-spacing-row-lg;
.uni-list-item {
font-size: 16rpx;
position: relative;
flex-direction: column;
justify-content: space-between;
padding-left: 15rpx;
/deep/ .u-badge {
position: static !important;
}
}
.uni-list-item--disabled {
opacity: 0.3;
}
.uni-list-item__container {
position: relative;
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
padding: 10rpx;
padding-left: 0;
flex: 1;
position: relative;
justify-content: space-between;
align-items: center;
}
.uni-list-item--first {
border-top-width: 0px;
}
.uni-list-item__container:after {
position: absolute;
top: 0;
right: 0;
left: 0;
height: 1px;
content: '';
-webkit-transform: scaleY(0.5);
transform: scaleY(0.5);
background-color: #c8c7cc;
}
.uni-list-item--first:after {
height: 0px;
}
.uni-list-item__content {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex: 1;
overflow: hidden;
flex-direction: column;
color: #3b4144;
}
.uni-list-item__content-title {
font-size: 14rpx;
color: #3b4144;
overflow: hidden;
}
.uni-list-item__content-note {
margin-top: 6rpx;
color: #999;
font-size: 12rpx;
overflow: hidden;
}
.uni-list-item__extra {
// width: 25%;
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
justify-content: flex-end;
align-items: center;
}
.uni-list-item__icon {
margin-right: 18rpx;
flex-direction: row;
justify-content: center;
align-items: center;
}
.uni-list-item__icon-img {
height: 26rpx;
width: 26rpx;
}
.uni-list-item__extra-text {
color: #999;
font-size: 12rpx;
}
</style>