<template>
<u-popup
mode="bottom"
:border-radius="borderRadius"
:popup="false"
v-model="value"
:maskCloseAble="maskCloseAble"
length="auto"
:safeAreaInsetBottom="safeAreaInsetBottom"
@close="popupClose"
:z-index="uZIndex"
>
<view class="u-tips u-border-bottom" v-if="tips.text" :style="[tipsStyle]">{{tips.text}}</view>
<block v-for="(item, index) in list" :key="index">
<view
@touchmove.stop.prevent
@tap="itemClick(index)"
:style="[itemStyle(index)]"
class="u-action-sheet-item"
:class="[index < list.length - 1 ? 'u-border-bottom' : '']"
hover-class="u-hover-class"
:hover-stay-time="150"
>{{item.text}}</view>
</block>
<view class="u-gab" v-if="cancelBtn"></view>
<view
@touchmove.stop.prevent
class="u-actionsheet-cancel u-action-sheet-item"
hover-class="u-hover-class"
:hover-stay-time="150"
v-if="cancelBtn"
@tap="close"
>{{cancelText}}</view>
</u-popup>
</template>
<script>
export default {
name: 'u-action-sheet',
props: {
maskCloseAble: {
type: Boolean,
default: true
},
list: {
type: Array,
default() {
return []
}
},
tips: {
type: Object,
default() {
return {
text: '',
color: '',
fontSize: '13'
}
}
},
cancelBtn: {
type: Boolean,
default: true
},
safeAreaInsetBottom: {
type: Boolean,
default: false
},
value: {
type: Boolean,
default: false
},
borderRadius: {
type: [String, Number],
default: 0
},
zIndex: {
type: [String, Number],
default: 0
},
cancelText: {
type: String,
default: "取消"
}
},
computed: {
tipsStyle() {
let style = {}
if (this.tips.color) style.color = this.tips.color
if (this.tips.fontSize) style.fontSize = this.tips.fontSize + 'rpx'
return style
},
itemStyle() {
return index => {
let style = {}
if (this.list[index].color) style.color = this.list[index].color
if (this.list[index].fontSize)
style.fontSize = this.list[index].fontSize + 'rpx'
return style
}
},
uZIndex() {
return this.zIndex ? this.zIndex : this.$u.zIndex.popup
}
},
methods: {
close() {
this.popupClose()
this.$emit('close')
},
popupClose() {
this.$emit('input', false)
},
itemClick(index) {
this.$emit('click', index)
this.$emit('input', false)
}
}
}
</script>
<style lang="scss" scoped>
@import '../../libs/css/style.components.scss';
.u-tips {
font-size: 13rpx;
text-align: center;
padding: 17rpx 0;
line-height: 1;
color: #909399;
}
.u-action-sheet-item {
display: flex;
line-height: 1;
justify-content: center;
align-items: center;
font-size: rpx(45);
padding: rpx(61) 0;
background: #EBEBEB;
font-weight: bold;
}
.u-gab {
height: rpx(20);
background-color: #BEBEBE;
}
.u-actionsheet-cancel {
font-weight: bold;
font-size: rpx(45);
color:rgba(0,0,0,1);
}
.u-border-bottom:after{
border: 0 solid #BEBEBE;
border-bottom-width:rpx(2)
}
</style>