工作碎片,记录今日弹框样式,
<template>
<div>
<el-dialog
:visible.sync="isCertDialog"
:close-on-click-modal='false'
class="hk-popup-main"
:modal-append-to-body='false'
:before-close="onClose">
<div class="title-top">证书
<span>{{activeCertList.length}}/30</span>
</div>
<div class="hk-diale-title">
<el-tag
:key="tag"
v-for="(tag, index) in activeCertList"
closable
:disable-transitions="false"
@close="handleClose(tag,index)">
{{tag}}
</el-tag>
<el-autocomplete
class="inline-input"
v-model="querySearchValue"
@input="changeInput"
:fetch-suggestions="querySearch"
placeholder="请选择或输入证书,最多30个"
@select="handleSelect"
>
<template slot-scope="{ item }">
<div class="name" v-html="item.viewName">{{ item.viewName }}</div>
</template>
</el-autocomplete>
<el-button class="popup-but" @click="onCertificate">确认</el-button>
</div>
<div class="cont-main">
<div class="cert-catgory" v-for="(item, index) in certCateList" :key="index" :label="item.name">
<div class="cert-catgory-label">{{item.name}}</div>
<div class="cert-item-list">
<span class="cert-item" v-for="(cert,certIndex) in item.children" :key="cert.id"
:class="(activeCertList.includes(cert.name) || (selectParIndex == index && selectChildIndex == certIndex)) ? 'selected' : ''"
:style="'order:'+certIndex*2" @click="onSelectCert(cert,certIndex,index)">{{cert.name}}</span>
<div class="cert-item-levels" v-if="isSelectOrder && (selectParIndex == index)" :style="'order:'+isSelectOrder">
<div class="cert-item-title">证书层次:</div>
<el-checkbox-group v-model="activeCertList">
<el-checkbox v-for="child in selectOrderList" :key="child.id" :label="child.name"></el-checkbox>
</el-checkbox-group>
</div>
</div>
</div>
</div>
</el-dialog>
</div>
</template>
<script>
import { getSystemCertCateTree, getFindSysCertName } from '@/api/public'
export default {
name: 'el-CertificatePopup',
props: {
isCertDialog: Boolean,
customaryList: Array
},
data () {
return {
tabPosition: 'left',
activeCertList: [],
certCateList: [],
isSelectOrder: null,
selectChildIndex: null,
selectOrderList: [],
selectParIndex: 0,
querySearchValue: '',
findSysCertList: []
}
},
created () {
// 测试数据列表
this.getSystemCertCate()
},
mounted () {
if (this.customaryList && this.customaryList.length > 0) {
this.activeCertList = this.customaryList.slice()
}
},
methods: {
handleSelect(event) {
console.log(event);
this.querySearchValue = ''
if (this.activeCertList.length >= 30) {
this.$message.warning({
message: '最多只能添加30个证书'
})
return
}
if(!this.activeCertList.includes(event.name)){
// includes()方法判断是否包含某一元素,返回true或false表示是否包含元素,对NaN一样有效
// filter()方法用于把Array的某些元素过滤掉,filter()把传入的函数依次作用于每个元素,
// 然后根据返回值是true还是false决定保留还是丢弃该元素:生成新的数组
// this.activeCertList=this.activeCertList.filter(function (ele){return ele != event.name;});
// console.log(event)
// console.log(event.name)
this.activeCertList.push(event.name);
} else{
this.$message.warning({
message: '已经选择,请勿重复选择'
})
}
},
changeInput() {
this.getFindSysCert(this.querySearchValue);
},
getFindSysCert(value) {
getFindSysCertName({certName: value}).then(res => {
if (res.code == 'SUCCESS') {
console.log('检索成功')
console.log(res.data)
this.findSysCertList = res.data.list || [];
}
}).catch(err => {
this.$message.error({
message: err.message
})
})
},
querySearch(queryString, cb) {
// 调用 callback 返回建议列表的数据
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
let restaurants = this.findSysCertList;
let results = restaurants
// queryString
// ? restaurants.filter(this.createFilter(queryString))
// : restaurants;
cb(results);
}, 300 * Math.random());
},
createFilter(queryString) {
return (restaurant) => {
return (restaurant.toLowerCase().indexOf(queryString.toLowerCase()) !== -1);
};
},
onSelectCert (event,index,parIndex) {
this.selectParIndex = parIndex
this.selectChildIndex = index
if (this.activeCertList.length >= 30) {
this.$message.warning({
message: '最多只能添加30个证书'
})
return
}
if (event.children && event.children.length>0) {
if (index%2==0) {
this.isSelectOrder = (index*2) + 3
} else {
this.isSelectOrder = (index*2) + 1
}
this.selectOrderList = event.children
} else {
this.isSelectOrder = null
if(this.activeCertList.includes(event.name)){
// includes()方法判断是否包含某一元素,返回true或false表示是否包含元素,对NaN一样有效
// filter()方法用于把Array的某些元素过滤掉,filter()把传入的函数依次作用于每个元素,
// 然后根据返回值是true还是false决定保留还是丢弃该元素:生成新的数组
this.activeCertList=this.activeCertList.filter(function (ele){return ele != event.name;});
}else{
this.activeCertList.push(event.name);
}
}
},
getSystemCertCate () {
getSystemCertCateTree().then(res => {
if (res.code == 'SUCCESS') {
this.certCateList = res.data
}
}).catch(err => {
this.$message({
message: err.message
})
})
},
// 弹框传值
toggleContent (event) {
this.$emit('submit', event);
},
// 确认
onCertificate () {
this.$emit('submit',this.activeCertList)
},
// 关闭弹框
onClose () {
this.$emit('close',false)
},
// 弹框title
handleClose(tag) {
this.activeCertList.splice(this.activeCertList.indexOf(tag), 1)
},
},
watch: {
customaryList () {
if (this.customaryList && this.customaryList.length > 0) {
this.activeCertList = this.customaryList.slice()
}
}
},
}
</script>
<style lang="less" scoped>
// 弹框样式
@deep: ~'>>>';
.hk-popup-main {
@{deep}.el-dialog {
border-radius: 8px;
.el-dialog__header {
// display: none;
padding: 0;
}
.title-top {
height: 60px;
padding-left: 25px;
line-height: 60px;
font-size: 16px;
font-family: 'PingFang-SC-Medium';
font-weight: 500;
color: #414C69;
span {
font-size: 14px;
font-family: 'PingFang-SC-Medium';
font-weight: 500;
color: #00C250;
margin-left: 16px;
letter-spacing: 1px;
}
}
}
.cont-main {
height: 420px;
overflow-y: scroll;
&::-webkit-scrollbar { /*滚动条整体样式*/
width: 3px; /*高宽分别对应横竖滚动条的尺寸*/
height: 1px;
background-color: transparent;
}
&::-webkit-scrollbar-thumb { /*滚动条里面小方块*/
border-radius: 2px;
border: 2px solid #dddddd;
box-shadow: 2px 0 0 #dddddd inset;
}
&::-webkit-scrollbar-thumb:hover {
box-shadow: 2px 0 0 #dddddd inset;
}
.cert-catgory {
display: flex;
&:nth-child(odd) {
background: #f9fafb;
border-bottom: 1px solid #f9fafb;
}
}
.cert-catgory-label {
width: 200px;
border-right: 1px solid #f2f3f3;
padding: 12px 20px;
display: flex;
justify-content: center;
flex-direction: column;
font-size: 14px;
color: #414a60;
line-height: 20px;
}
.cert-item-list {
flex: 1;
display: flex;
flex-wrap: wrap;
line-height: 24px;
width: 0;
padding: 5px 0;
font-size: 13px;
}
.cert-item {
width: 50%;
padding: 5px 20px;
display: block;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
cursor: pointer;
font-size: 14px;
font-family: 'PingFang-SC-Medium';
font-weight: 500;
color: #414C69;
&:hover,&.selected {
color: #00C250;
}
}
.cert-item-levels {
background: #fff;
width: 100%;
display: flex;
flex-wrap: wrap;
padding: 5px 0;
margin-bottom: -5px;
}
.cert-item-title {
padding: 5px 20px;
width: 100%;
color: #51586d;
}
@{deep}.el-checkbox-group {
width: 100%;
}
@{deep}.el-checkbox {
line-height: 20px;
padding: 0px 20px;
margin: 0;
width: 50%;
font-size: 14px;
font-family: 'PingFang-SC-Medium';
font-weight: 500;
color: #8993AD;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
.el-checkbox__input {
box-sizing: border-box;
}
}
}
@{deep}.inline-input {
width: 200px;
font-size: 14px;
font-family: 'PingFang-SC-Medium';
font-weight: 500;
color: #D3D6DD;
.el-input {
height: 100%;
}
.el-input__inner {
border: none;
padding-right: 0;
padding-left: 0;
}
}
}
.el-dialog__body {
padding: 0 0 20px 0;
.el-tabs--left .el-tabs__active-bar.is-left, .el-tabs--left .el-tabs__nav-wrap.is-left::after {
right: auto;
left: 0;
}
.el-tabs {
&.el-tabs--left {
overflow-y: scroll;
&::-webkit-scrollbar { /*滚动条整体样式*/
width: 6px; /*高宽分别对应横竖滚动条的尺寸*/
height: 1px;
background-color: transparent;
}
&::-webkit-scrollbar-thumb { /*滚动条里面小方块*/
border-radius: 2px;
border: 5px solid #726b6b;
box-shadow: 5px 0 0 #726b6b inset;
}
&::-webkit-scrollbar-thumb:hover {
box-shadow: 5px 0 0 #4A4A4A inset;
}
}
}
.el-tabs--left .el-tabs__active-bar.is-left {
width: 4px;
}
.el-tabs__nav-prev, .el-tabs__nav-next {
display: none;
}
.el-tabs__nav-scroll {
overflow: visible;
}
.el-tabs__nav-wrap.is-left {
width: 190px;
overflow-y: scroll;
.el-tabs__nav-scroll {
.el-tabs__nav.is-left {
background-color: #f9fafb;
.el-tabs__item.is-left {
&.is-active {
background-color: #fff;
}
}
}
}
&::-webkit-scrollbar {
display:none;
}
.el-tabs__item.is-left {
text-align: center;
}
}
// 右边title
.hk-diale-title {
min-height: 50px;
border-top: 1px solid #e2e2e2;
border-bottom: 1px solid #e2e2e2;
padding-left: 20px;
// line-height: 50px;
position: relative;
padding-right: 100px;
display: flex;
justify-content: flex-start;
// align-items: center;
flex-wrap: wrap;
@{deep} .el-tag {
font-size: 12px;
font-family: 'PingFang-SC-Medium';
font-weight: 500;
color: #8993AD;
height: 24px;
padding: 0 12px;
line-height: 24px;
background: #EEF0F5;
border-radius: 12px;
border-color: #EEF0F5;
margin-right: 10px;
margin-top: 12px;
.el-tag__close {
display: inline-block;
width: 16px;
height: 16px;
background: #CBCED6;
border-radius: 50%;
color: #fff;
vertical-align: 1px;
&:hover {
color: #fff;
// background: #00C250;
}
}
}
.el-tag + .el-tag{
margin-left: 0;
}
.button-new-tag {
margin-left: 10px;
height: 32px;
line-height: 30px;
padding-top: 0;
padding-bottom: 0;
}
.popup-but {
position: absolute;
right: 20px;
top: 10px;
width: 72px;
height: 28px;
padding: 0;
background: #00C250;
border-radius: 14px;
font-size: 14px;
font-family: 'PingFang-SC-Medium';
font-weight: 500;
color: #FFFFFF;
border: none;
text-align: center;
}
}
// 右边主要内容
.hk-table {
@{deep}.hk-bable-tr {
// float: left;
width: 230px;
height: 40px;
line-height: 40px;
padding-left: 20px;
cursor: pointer;
&:hover {
color: #00C250;
}
.el-checkbox-button__inner {
border: none;
box-shadow: none;
}
&.is-checked {
.el-checkbox-button__inner {
color: #00C250;
background: transparent;
border: none;
}
}
}
}
}
// 按钮
.hk-dialog-but {
&:last-child.el-button {
border: 1px solid #00C250;
background-color: #00C250;
color: #fff;
}
}
</style>
使用方法
<certificatePopup :isCertDialog="isCertDialog" @submit="onSelectCertificate"
@close="onClose" :customaryList="certList"></certificatePopup>
import certificatePopup from '@/components/popup/certificatePopup'
// 弹框
onSelectCertificate (data) {
// 获取的参数
console.log(data)
this.isCertDialog = false
},
onClose () {
this.isCertDialog = false
}