<template>
<div>
<el-table v-loading="loading" element-loading-background="rgba(255, 255, 255, 0.7)" :data="foldTableData" border
style="width: 100%" :row-class-name="tableRowClassName" :row-key="getRowKeys" :span-method="arraySpanMethod"
:expand-row-keys="expands" :tree-props="{ children: 'children' }">
<el-table-column align="center" type="text" label-class-name="DisabledSelection" width="50" v-if="editState">
<template slot-scope="scope" v-if="scope.row.addRow">
<span @click="addRow(scope.row)" v-if="scope.row.parentType" class="hand el-icon-circle-plus"></span>
</template>
</el-table-column>
<!-- <el-table-column align="center" prop="index" label="序号" width="50"> </el-table-column> -->
<el-table-column align="left" prop="label" label="元数据类别" width="230"> </el-table-column>
<el-table-column align="center" prop="keys" label="属性名" width="300">
<template slot-scope="scope">
<div v-if="!scope.row.parentType">
<el-input v-if="scope.row.ModifyKeys" v-model="scope.row.keys" type="text" />
<span v-else>{{ scope.row.keys }}</span>
</div>
</template>
</el-table-column>
<el-table-column align="center" prop="value" label="属性值">
<template slot-scope="scope" v-if="!scope.row.parentType">
<el-input v-model="scope.row.value" type="textarea" />
<!-- <span v-else>{{ scope.row.value }}</span> -->
</template>
</el-table-column>
<el-table-column align="center" label="操作" v-if="editState">
<template slot-scope="scope" v-if="!scope.row.parentType">
<!-- <el-button v-if="scope.row.modify" type="text" @click="handleSave(scope.row)">保存</el-button>
<el-button v-else type="text" @click="handleEdit(scope.row, true)">编辑</el-button> -->
<el-button v-if="scope.row.ModifyKeys" @click="handleDelete(scope.row)" type="text">删除</el-button>
</template>
</el-table-column>
</el-table>
</div>
</template>
<script>
import { v4 as uuidv4 } from 'uuid';
export default {
dicts: ['metadate_type'],
data() {
return {
loading: false,
num: 10000,
expands: [],
foldTableData: [
{
children: [
{
ModifyKeys: false,
id:9,
keys:"子集",
value:"值"
},
{
ModifyKeys: false,
id: 19,
keys: "子集",
value: "值"
}
],
parentType: true,
id: 1,
label:'父级'
},
{
children: [
{
ModifyKeys: false,
id: 39,
keys: "子集",
value: "值"
},
{
ModifyKeys: false,
id: 49,
keys: "子集",
value: "值"
}
],
parentType: true,
id: 2,
label: '父级'
}
]
};
},
mounted() {
this.expands = [this.foldTableData[0]?.id.toString()]
},
methods: {
// 获取row的key值
getRowKeys(row) {
return '' + row.id + row.label + row.keys;
},
// 合并
arraySpanMethod({ row, column, rowIndex, columnIndex }) {
// 合并岗位
if (row.parentType) {
if (columnIndex === 1) {
return {
rowspan: 1,
colspan: 6
}
}
}
},
// 新增
addRow(row) {
this.expands = [row.id.toString()]
let obj = {
keys: '',
value: '',
id: uuidv4(),
ModifyKeys: true,
}
this.foldTableData.forEach(o => {
if (o.id === 9999999999999) {
o.children.push(obj)
}
})
},
// 删除
handleDelete(row) {
let curObj = this.foldTableData.find(o => o.id === 9999999999999)
let index = curObj?.children.findIndex(i => i.id === row.id)
curObj?.children.splice(index, 1)
},
// 设置失效行的class
tableRowClassName({ row, rowIndex }) {
if (!row.type && row.takeEffect === false) {
return 'warning-row';
}
return '';
},
}
};
</script>
<style lang='scss' scoped>
.hand {
cursor: pointer;
font-size: 18px;
}
</style>