<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 plain size="small" type="success" @click="savaHandler">保存</el-button>
|
<el-button plain size="small" type="primary" @click="syncHandler">同步</el-button>
|
</template>
|
</avue-crud>
|
</basic-container>
|
</template>
|
|
<script>
|
import {getGroupAttrPoolALlList, editGroupAttr,syncGroupAttrMapping} from '@/api/vciAttrbute'
|
import {getPage} from "@/api/omd/OmdAttribute";
|
|
export default {
|
name: "vciAttribute",
|
data() {
|
return {
|
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,
|
props: {
|
label: 'codeMetaAttrName',
|
value: 'codeMetaAttrOid',
|
},
|
dicData: []
|
}
|
]
|
},
|
page: {
|
pageSize: 10,
|
currentPage: 1,
|
total: 0
|
},
|
selectList: []
|
}
|
},
|
created() {
|
const params = {
|
'conditionMap[groupAttrKey_like]': 'RY_',
|
page: this.page.currentPage,
|
limit: this.page.pageSize
|
}
|
this.onLoad(params)
|
this.codeColumnOnload()
|
},
|
computed: {
|
codeMetaColumn() {
|
return this.options.column.find(column => column.prop === 'codeMetaAttrName');
|
}
|
},
|
methods: {
|
codeMetaDis() {
|
for (const item of this.data) {
|
if (item.codeMetaAttrOid && item.codeMetaAttrKey && item.codeMetaAttrName) {
|
console.log(this.codeMetaColumn)
|
console.log(this.codeMetaColumn.dicData)
|
if (this.codeMetaColumn.dicData.length >= 1) {
|
const targetObject = this.codeMetaColumn.dicData.find(obj => obj.codeMetaAttrName === item.codeMetaAttrName);
|
console.log(targetObject)
|
}
|
// targetObject.disabled = true;
|
}
|
}
|
},
|
selectChange(list) {
|
this.selectList = list;
|
},
|
async onLoad(params) {
|
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
|
const updataList = this.codeMetaColumn.dicData.find(item => item.codeMetaAttrOid === row.codeMetaAttrName)
|
|
// 因为row里面的值是不正确的 重新赋值一遍
|
const {codeMetaAttrOid, codeMetaAttrKey, codeMetaAttrName} = updataList;
|
Object.assign(row, {codeMetaAttrOid, codeMetaAttrKey, 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.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('请开启编辑后保存!')
|
} else {
|
let saveList = []
|
for (const item of this.selectList) {
|
const updataList = this.codeMetaColumn.dicData.find(p => p.codeMetaAttrOid === item.codeMetaAttrName);
|
const {codeMetaAttrOid, codeMetaAttrKey, codeMetaAttrName} = updataList;
|
Object.assign(item, {codeMetaAttrOid, codeMetaAttrKey, 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.data.success) {
|
this.$message.success('保存成功!')
|
}
|
}
|
}
|
},
|
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)
|
}
|
}
|
},
|
currentChange(currentPage) {
|
this.page.currentPage = currentPage;
|
const params = {
|
'conditionMap[groupAttrKey_like]': 'RY_',
|
page: this.page.currentPage,
|
limit: this.page.pageSize
|
}
|
this.onLoad(params)
|
},
|
sizeChange(pageSize) {
|
this.page.pageSize = pageSize;
|
const params = {
|
'conditionMap[groupAttrKey_like]': 'RY_',
|
page: this.page.currentPage,
|
limit: this.page.pageSize
|
}
|
this.onLoad(params)
|
},
|
}
|
}
|
</script>
|
|
<style scoped>
|
|
</style>
|