<template>
|
<select-king
|
ref="selectKing"
|
v-model="selectVal"
|
:disabled="isDataBase"
|
optionsWidth="300px"
|
placeholder="请选择分析"
|
>
|
<div class="type-library">
|
<!-- 多选状态显示 start -->
|
<div v-if="isCheckBox">
|
<div class="library-list clearfix">
|
<div
|
class="float-left pl-1 alarm-item"
|
v-for="(item,index) in SDKDicCheck"
|
:key="index"
|
v-show="item.value"
|
>
|
<span class="border-left px-1"></span>
|
<el-checkbox class="alarm-checkBox mb-0" v-model="item.status"></el-checkbox>
|
<a
|
:title="item.name"
|
:class="['alarm-name',item && item.status ?'active':'']"
|
@click="selectCheck({ index, val:!!item.status})"
|
>{{item.name}}</a>
|
</div>
|
</div>
|
<div class="py-1 text-center">
|
<b-btn variant="primary" size="sm" @click="submitCheck" class="mr10">确定</b-btn>
|
<b-btn variant="secondary" size="sm" class="mr10" @click="cancel">取消</b-btn>
|
</div>
|
</div>
|
<!-- 多选状态显示 end -->
|
<!-- 单选状态显示 start -->
|
<div v-else>
|
<div class="library-list clearfix">
|
<div class="float-left pl-1 alarm-item" v-for="(item,index) in SDKDic" :key="index">
|
<span class="border-left px-1"></span>
|
<a
|
:title="item.name"
|
:class="['alarm-name',item && item.status ?'active':'']"
|
@click="selectCheck({ index, val:!!item.status},'radio')"
|
>{{item.name}}</a>
|
</div>
|
</div>
|
<div class="py-1 text-right" v-if="SDKDic.length>1">
|
<b-btn variant="primary" class="mr10" @click="isCheckBox=!isCheckBox">多选</b-btn>
|
</div>
|
</div>
|
<!-- 单选状态显示 end -->
|
</div>
|
</select-king>
|
</template>
|
<script>
|
import selectKing from '@/components/selectKing'
|
import { FormItem, Form, CheckboxGroup, Checkbox } from 'element-ui'
|
import { getAllSDKDic } from '@/server/common.js'
|
export default {
|
name: 'keyword',
|
components: {
|
elFormItem: FormItem,
|
elCheckboxGroup: CheckboxGroup,
|
elCheckbox: Checkbox,
|
elForm: Form,
|
selectKing
|
},
|
props: ['isDataBase'],
|
data() {
|
return {
|
selectVal: '全部分析',
|
isCheckBox: false,
|
sdkType: [], // 分析val
|
SDKDic: [
|
{
|
name: '全部分析',
|
value: '',
|
status: true
|
}
|
],
|
SDKDicCheck: [
|
{
|
name: '全部分析',
|
value: '',
|
status: true
|
}
|
]
|
}
|
},
|
computed: {},
|
methods: {
|
// 获取数据
|
async initData() {
|
const res = await getAllSDKDic()
|
if (res && res.success && res.data) {
|
let list = res.data && res.data.length ? res.data : []
|
list = list.map(item => {
|
return {
|
name: item,
|
value: item,
|
status: false
|
}
|
})
|
|
this.SDKDic = [
|
{
|
name: '全部分析',
|
value: '',
|
status: true
|
},
|
...JSON.parse(JSON.stringify(list))
|
]
|
this.SDKDicCheck = [
|
{
|
name: '全部分析',
|
value: '',
|
status: true
|
},
|
...JSON.parse(JSON.stringify(list))
|
]
|
}
|
},
|
commonCheck({ index, val, type = 'checkBox' }) {
|
const dataList = JSON.parse(JSON.stringify(this.SDKDicCheck))
|
if (type === 'radio') {
|
dataList.map((iteam, index) => {
|
dataList[index].status = false
|
})
|
dataList[index].status = true
|
} else {
|
dataList[index].status = !val
|
dataList[0].status = false
|
}
|
return dataList
|
},
|
selectCheck({ index, val }, type) {
|
const jsonArr = this.commonCheck({ index, val, type })
|
if (type === 'radio') {
|
// 单选选择库
|
this.SDKDic = [...jsonArr]
|
this.SDKDicCheck = [...jsonArr]
|
// 提交数据
|
this.emitData()
|
} else {
|
this.SDKDicCheck = [...jsonArr]
|
}
|
},
|
submitCheck() {
|
const jsonArr = JSON.parse(JSON.stringify(this.SDKDicCheck))
|
this.SDKDic = [...jsonArr]
|
this.isCheckBox = false
|
|
// 提交数据
|
this.emitData()
|
},
|
cancel() {
|
const jsonArr = JSON.parse(JSON.stringify(this.SDKDic))
|
this.SDKDicCheck = [...jsonArr]
|
this.isCheckBox = false
|
},
|
/* 多选视图操作 end */
|
emitData() {
|
// 根据记录选择值
|
let valNames = []
|
let sdkType = []
|
|
this.SDKDic.filter(item => item && item.status).map(item => {
|
item.name && valNames.push(item.name)
|
item.value && sdkType.push(item.value)
|
})
|
|
// 设置selcet val显示
|
this.selectVal = valNames.join('/')
|
// 关闭下拉
|
this.$refs.selectKing.close()
|
// 拼接实际value
|
const json = {
|
valNames,
|
sdkType,
|
data: this.SDKDic
|
}
|
this.$emit('submitData', json)
|
},
|
init() {
|
/* 进行清空 */
|
const SDKArr = this.SDKDic.map(item => {
|
item.status = item.value === ''
|
return item
|
})
|
this.SDKDic = [...JSON.parse(JSON.stringify(SDKArr))]
|
this.SDKDicCheck = [...JSON.parse(JSON.stringify(SDKArr))]
|
this.emitData()
|
}
|
},
|
created() {
|
this.initData()
|
},
|
watch: {}
|
}
|
</script>
|
<style lang="scss" scoped>
|
.type-library {
|
.select-liby {
|
padding: 2px 20px 2px 0;
|
a {
|
cursor: pointer;
|
}
|
a.active {
|
font-weight: 600;
|
text-decoration: underline;
|
}
|
a:hover {
|
color: #ccc;
|
}
|
a.active:hover {
|
color: #333;
|
}
|
}
|
}
|
.library-list {
|
h6 {
|
height: 30px;
|
line-height: 30px;
|
cursor: pointer;
|
}
|
.alarm-item {
|
line-height: 30px;
|
|
.alarm-icon {
|
display: inline-block;
|
vertical-align: middle;
|
width: 15px;
|
height: 15px;
|
line-height: 15px;
|
background: #d9534f;
|
border-radius: 50%;
|
overflow: hidden;
|
text-align: center;
|
color: #fff;
|
}
|
.alarm-name {
|
display: inline-block;
|
vertical-align: middle;
|
line-height: 15px;
|
padding: 2px 4px;
|
max-width: 100px;
|
cursor: pointer;
|
}
|
.alarm-name.active {
|
background: #35bde7;
|
color: #fff;
|
}
|
}
|
}
|
</style>
|