<template>
<view>
<u-popup
:zoom="zoom"
mode="center"
:popup="false"
:z-index="uZIndex"
v-model="value"
:length="width"
:mask-close-able="maskCloseAble"
:border-radius="borderRadius"
@close="popupClose"
:negative-top="negativeTop"
>
<view class="u-model">
<view v-if="showTitle" class="u-model-title u-line-1 modal-bg" :style="[titleStyle]">
<view class="placeholder"></view>
<view class="model-title-text">{{ title }}</view>
<image src="/static/base-module/common/guanbi.png" class="header-img" @tap="cancel('icon')"></image>
</view>
<view class="u-model-content">
<view :style="[contentStyle]" v-if="$slots.default">
<slot />
</view>
<view v-else class="u-model-content-message" :style="[contentStyle]">{{ content }}</view>
</view>
<view class="u-model-footer u-border-top" v-if="showCancelButton || showConfirmButton">
<view
:class="!showCancelButton ? 'hidden' : ''"
:hover-stay-time="100"
hover-class="btn-hover"
class="u-model-footer-button u-model-footer-button-cancel btn-gray100"
type="default"
:style="[cancelBtnStyle]"
@tap="cancel"
>{{cancelText}}</view>
<view
v-if="showConfirmButton"
:hover-stay-time="100"
:hover-class="asyncClose ? 'none' : 'btn-hover'"
class="u-model-footer-button hairline-left u-model-footer-button-ok btn-blue100"
:style="[confirmBtnStyle]"
@tap="confirm"
>
<u-loading mode="circle" :color="confirmColor" v-if="loading"></u-loading>
<block v-else>{{confirmText}}</block>
</view>
</view>
</view>
</u-popup>
</view>
</template>
<script>
export default {
name: 'u-modal',
props: {
value: {
type: Boolean,
default: false
},
zIndex: {
type: [Number, String],
default: ''
},
title: {
type: [String],
default: '提示'
},
width: {
type: [Number, String],
default: 300
},
content: {
type: String,
default: '内容'
},
showTitle: {
type: Boolean,
default: true
},
showConfirmButton: {
type: Boolean,
default: true
},
showCancelButton: {
type: Boolean,
default: false
},
confirmText: {
type: String,
default: '确认'
},
cancelText: {
type: String,
default: '取消'
},
confirmColor: {
type: String,
default: '#fff'
},
cancelColor: {
type: String,
default: 'rgba(0,0,0,1)'
},
borderRadius: {
type: [Number, String],
default: 4
},
titleStyle: {
type: Object,
default() {
return {}
}
},
contentStyle: {
type: Object,
default() {
return {}
}
},
cancelStyle: {
type: Object,
default() {
return {}
}
},
confirmStyle: {
type: Object,
default() {
return {}
}
},
zoom: {
type: Boolean,
default: true
},
asyncClose: {
type: Boolean,
default: false
},
maskCloseAble: {
type: Boolean,
default: false
},
negativeTop: {
type: [String, Number],
default: 0
},
cancelImg: {
type: String,
default: ''
}
},
data() {
return {
loading: false
}
},
computed: {
cancelBtnStyle() {
return Object.assign({ color: this.cancelColor }, this.cancelStyle)
},
confirmBtnStyle() {
return Object.assign({ color: this.confirmColor }, this.confirmStyle)
},
uZIndex() {
return this.zIndex ? this.zIndex : this.$u.zIndex.popup
}
},
watch: {
value(n) {
if (n === true) this.loading = false
}
},
methods: {
confirm() {
this.$emit('confirm')
if (this.asyncClose) {
this.loading = true
} else {
this.$emit('input', false)
}
},
cancel(icon) {
this.$emit('cancel',icon)
this.$emit('input', false)
setTimeout(() => {
this.loading = false
}, 300)
},
popupClose() {
this.$emit('input', false)
},
clearLoading() {
this.loading = false
}
}
}
</script>
<style lang="scss" scoped>
@import '../../libs/css/style.components.scss';
/deep/ .uni-scroll-view{
border-radius:rpx(16) ;
}
.btn-hover {
background-color: rgb(230, 230, 230);
}
.u-model {
height: auto;
overflow: hidden;
font-size: 16rpx;
width: 100%;
background: #e1e1e1;
box-shadow:0px rpx(8) rpx(8) 0px rgba(0,0,0,0.16);
border-radius:rpx(16);
&-title {
padding-top: 24rpx;
font-weight: 500;
text-align: center;
color: $u-main-color;
border-radius:rpx(16) rpx(16) 0 0;
}
&-content {
&-message {
height: 88rpx;
font-size: 15rpx;
color: rgba(0, 0, 0, 1);
display: flex;
margin-top: 21.42rpx;
margin-left: 16.48rpx;
font-size: 12.36rpx;
}
}
&-footer {
display: flex;
justify-content: space-between;
background: rgba(225, 225, 225, 1);
border-radius:0px 0px rpx(16) rpx(16);
.hidden {
visibility: hidden;
}
&-button {
height: 27.77rpx;
line-height: 27.77rpx;
font-size: 12.36rpx;
display: flex;
justify-content: center;
align-items: center;
box-sizing: border-box;
font-family:SourceHanSansCN-Medium,SourceHanSansCN;
width: 82.41rpx;
margin-bottom: rpx(60);
border-radius: 4px;
display: flex;
justify-content: center;
// text-shadow:0px 0.5px 0px rgba(255,255,255,1);
}
.u-model-footer-button-cancel {
margin-left: rpx(60);
}
.u-model-footer-button-ok {
margin-right: rpx(60);
}
}
.u-model-title {
padding-top: 0;
height: rpx(120);
padding: 0 rpx(30);
display: flex;
border-radius:rpx(16) rpx(16) 0 0;
align-items: center;
justify-content: space-between;
font-weight: bold;
//background: linear-gradient(
//180deg,
//rgba(248, 248, 248, 1) 0%,
//rgba(218, 218, 218, 1) 52%,
//rgba(208, 208, 208, 1) 100%
//);
// border-bottom: rpx(2) solid #A1A1A1;
position: relative;
&::after {
position: absolute;
content: '';
background-color: #a1a1a1;
display: block;
width: 100%;
height: 1px;
transform: scale(1, 0.5);
top: 38.4rpx;
left: 0;
}
.placeholder {
width: 18.68rpx;
height: 18.68rpx;
}
.model-title-icon {
// margin-right: 16px;
border: 1px solid rgba(135, 135, 135, 1);
border-radius: 50%;
padding: 5px 5px;
background: linear-gradient(
180deg,
rgba(254, 254, 255, 1) 0%,
rgba(209, 211, 216, 1) 100%
);
box-shadow: 0px 1px 0px 0px rgba(255, 255, 255, 1);
font-weight: bold;
}
.header-img {
width: rpx(68.45);
height: rpx(68.45);
//margin-right: 17.3rpx;
}
.model-title-icon:active {
background: #ccc;
color: #fff;
}
}
.u-model-content-message {
background: rgba(225, 225, 225, 1);
}
/deep/ .u-border-top:after {
border-top-width: 0px;
}
}
.model-title-text{
font-size: rpx(52);
}
</style>