<template>
|
<basic-container>
|
<avue-crud ref="crud" :data="data" :option="options" :page.sync="page" @current-change="currentChange"
|
@size-change="sizeChange" @row-dblclick="handleRowClick" @row-update="handleUpdate"
|
@selection-change="selectChange">
|
<template slot="menuLeft">
|
<el-button v-if="permissionList.saveBtn" plain size="small" type="success" @click="savaHandler">保存</el-button>
|
<el-button v-if="permissionList.syncBtn" plain size="small" type="primary" @click="syncHandler">同步</el-button>
|
<span style="width: 200px;display: inline-block">
|
<el-select slot="prepend" v-model="searchSelect" placeholder="请选择" size="small">
|
<el-option v-for="item in searchData" :key="item.prop" :label="item.label" :value="item.prop"
|
></el-option>
|
</el-select>
|
</span>
|
<span style="margin-left: 5px">
|
<el-input v-model="searchValue" class="attrSearch" clearable placeholder="请输入内容"
|
prefix-icon="el-icon-search"
|
size="small" type="text"></el-input>
|
<el-button v-if="permissionList.searchBtn" icon="el-icon-search" plain size="small" type="primary"
|
@click="searchHandler"> 搜索</el-button>
|
</span>
|
</template>
|
</avue-crud>
|
</basic-container>
|
</template>
|
|
<script>
|
import {getGroupAttrPoolALlList, editGroupAttr, syncGroupAttrMapping} from '@/api/vciAttrbute'
|
import {getPage} from "@/api/omd/OmdAttribute";
|
import {mapGetters} from "vuex";
|
|
export default {
|
name: "vciAttribute",
|
data() {
|
return {
|
searchSelect: "groupAttrKey",
|
searchValue: '',
|
searchData: [
|
{
|
label: "集团属性编号",
|
prop: "groupAttrKey",
|
align: "left",
|
display: false,
|
width: 200,
|
required: true
|
}, {
|
label: "集团属性名称",
|
prop: "groupAttrName",
|
align: "left",
|
display: false
|
}
|
],
|
data: [],
|
options: {
|
height: 'auto',
|
calcHeight: 20,
|
headerAlign: "center",
|
border: true,
|
selection: true,
|
tip: false,
|
index: true,
|
refreshBtn: false,
|
searchShowBtn: false,
|
addBtn: false,
|
delBtn: false,
|
$cellEdit: true,
|
rowKey: 'oid',
|
cellBtn: true,
|
highlightCurrentRow: true,
|
column: [
|
{
|
label: '集团属性编号',
|
prop: 'groupAttrKey'
|
},
|
{
|
label: '集团属性名称',
|
prop: 'groupAttrName'
|
},
|
{
|
label: '属性编号',
|
prop: 'codeMetaAttrKey'
|
},
|
{
|
label: '属性名称',
|
prop: 'codeMetaAttrName',
|
type: 'select',
|
cell: true,
|
filterable: true,
|
change: (val) => {
|
if (!this.ChangeStatus) {
|
this.ChangeName = val.value
|
this.status = true;
|
}
|
},
|
props: {
|
label: 'codeMetaAttrName',
|
value: 'codeMetaAttrOid',
|
},
|
dicData: []
|
}
|
]
|
},
|
page: {
|
pageSize: 10,
|
currentPage: 1,
|
total: 0
|
},
|
selectList: [],
|
ChangeName: '',
|
ChangeStatus: false
|
}
|
},
|
created() {
|
this.onLoad()
|
this.codeColumnOnload()
|
},
|
computed: {
|
codeMetaColumn() {
|
return this.options.column.find(column => column.prop === 'codeMetaAttrName');
|
},
|
...mapGetters(["permission"]),
|
permissionList() {
|
return {
|
saveBtn: this.vaildData(this.permission.vciAttribute.attribute_save, false),
|
syncBtn: this.vaildData(this.permission.vciAttribute.attribute_sync, false),
|
searchBtn: this.vaildData(this.permission.vciAttribute.attribute_search, false),
|
}
|
},
|
},
|
methods: {
|
searchHandler() {
|
console.log(this.searchSelect)
|
const params = {
|
[`conditionMap[${this.searchSelect}_like]`]: this.searchValue,
|
page: this.page.currentPage,
|
limit: this.page.pageSize
|
}
|
getGroupAttrPoolALlList(params).then(res => {
|
const data = res.data.data;
|
this.data = data.records;
|
this.page.total = data.total;
|
})
|
},
|
codeMetaDis() {
|
for (const item of this.data) {
|
if (item.codeMetaAttrOid && item.codeMetaAttrKey && item.codeMetaAttrName) {
|
if (this.codeMetaColumn.dicData.length >= 1) {
|
const targetObject = this.codeMetaColumn.dicData.find(obj => obj.codeMetaAttrName === item.codeMetaAttrName);
|
}
|
// targetObject.disabled = true;
|
}
|
}
|
},
|
selectChange(list) {
|
this.selectList = list;
|
},
|
async onLoad() {
|
const params = {
|
page: this.page.currentPage,
|
limit: this.page.pageSize
|
}
|
getGroupAttrPoolALlList(params).then(res => {
|
const data = res.data.data;
|
this.data = data.records;
|
this.page.total = data.total;
|
})
|
},
|
codeColumnOnload() {
|
getPage(1, -1).then(res => {
|
const data = res.data.data;
|
this.codeMetaColumn.dicData = data.records.filter(item => item.name && item.name.trim() !== "") // 过滤掉name为空的属性
|
.map(item => {
|
return {
|
codeMetaAttrOid: item.oid,
|
codeMetaAttrKey: item.id,
|
codeMetaAttrName: item.name,
|
disabled: false
|
}
|
})
|
})
|
},
|
handleRowClick(row, column) {
|
if (column.label === '属性名称') this.$refs.crud.rowCell(row, row.$index)
|
},
|
async handleUpdate(row, index, done) {
|
if (!row.codeMetaAttrName) {
|
this.$message.warning('请选择要保存的属性名称!');
|
done();
|
return;
|
}
|
|
// row.codeMetaAttrName因为下拉框value值原因绑定为codeMetaAttrOid
|
let updataList = []
|
// console.log(this.ChangeName)
|
// console.log(row.codeMetaAttrName)
|
// if (this.ChangeName && this.ChangeName === row.codeMetaAttrName) {
|
// updataList = this.codeMetaColumn.dicData.find(item => item.codeMetaAttrOid === row.codeMetaAttrOid)
|
// } else {
|
// console.log('2')
|
// updataList = this.codeMetaColumn.dicData.find(item => item.codeMetaAttrOid === row.codeMetaAttrName)
|
// }
|
updataList = this.codeMetaColumn.dicData.find(item => item.codeMetaAttrOid === row.codeMetaAttrName)
|
|
// 因为row里面的值是不正确的 重新赋值一遍
|
if (updataList) {
|
const {codeMetaAttrOid, codeMetaAttrKey, codeMetaAttrName} = updataList;
|
Object.assign(row, {
|
codeMetaAttrOid: codeMetaAttrOid,
|
codeMetaAttrKey: codeMetaAttrKey.toLowerCase(),
|
codeMetaAttrName: codeMetaAttrName
|
});
|
}
|
|
const objet = {
|
oid: row.oid,
|
groupAttrKey: row.groupAttrKey,
|
groupAttrName: row.groupAttrName,
|
codeMetaAttrOid: row.codeMetaAttrOid,
|
codeMetaAttrKey: row.codeMetaAttrKey,
|
codeMetaAttrName: row.codeMetaAttrName
|
}
|
|
const response = await editGroupAttr([objet])
|
if (response.data.success) {
|
this.$message.success('保存成功!')
|
}
|
done()
|
},
|
async savaHandler() {
|
if (this.selectList.length <= 0) {
|
this.$message.warning('请选择一条数据后进行保存!')
|
} else {
|
const hasTrueValue = this.selectList.some(item => !item.$cellEdit);
|
if (hasTrueValue) {
|
this.$message.warning('请开启编辑后进行保存!')
|
return
|
}
|
const codeMetaInput = this.selectList.some(item => item.codeMetaAttrName === "");
|
if (codeMetaInput) {
|
this.$message.warning('请检查已勾选数据中是否存在未选择的项!');
|
return
|
}
|
let saveList = []
|
for (const item of this.selectList) {
|
const updataList = this.codeMetaColumn.dicData.find(column => column.codeMetaAttrOid === item.codeMetaAttrName);
|
if (updataList) {
|
const {codeMetaAttrOid, codeMetaAttrKey, codeMetaAttrName} = updataList;
|
Object.assign(item, {
|
codeMetaAttrOid: codeMetaAttrOid,
|
codeMetaAttrKey: codeMetaAttrKey.toLowerCase(),
|
codeMetaAttrName: codeMetaAttrName
|
});
|
}
|
item.$cellEdit = false;
|
saveList.push({
|
oid: item.oid,
|
groupAttrKey: item.groupAttrKey,
|
groupAttrName: item.groupAttrName,
|
codeMetaAttrOid: item.codeMetaAttrOid,
|
codeMetaAttrKey: item.codeMetaAttrKey,
|
codeMetaAttrName: item.codeMetaAttrName
|
})
|
}
|
const response = await editGroupAttr(saveList)
|
if (response.data.success) {
|
this.$message.success('保存成功!')
|
await this.onLoad()
|
}
|
|
}
|
},
|
async syncHandler() {
|
if (this.selectList.length <= 0) {
|
this.$message.warning('请至少选择一条数据进行同步!')
|
} else {
|
const syncList = [];
|
for (const item of this.selectList) {
|
syncList.push({
|
groupAttrKey: item.groupAttrKey,
|
groupAttrName: item.groupAttrName,
|
})
|
}
|
const response = await syncGroupAttrMapping(syncList)
|
if (response.data.success) {
|
this.$message.success(response.data.msg);
|
|
await this.onLoad()
|
}
|
}
|
},
|
currentChange(currentPage) {
|
this.page.currentPage = currentPage;
|
|
this.onLoad()
|
},
|
sizeChange(pageSize) {
|
this.page.pageSize = pageSize;
|
|
this.onLoad()
|
},
|
}
|
}
|
</script>
|
|
<style scoped>
|
|
</style>
|