<template>
<div class="content-box">
<div class="card filter">
<el-button type="primary" class="add-btn" @click="openDrawer('add', '新增非标准资产', [])">新增非标准资产</el-button>
<el-input v-model="filterText" class="filterTextInput" placeholder="请输入" clearable />
<div class="list-box">
<template v-if="filteredTreeData.length">
<div :class="['item', { active: activeTypeItem.id === item.id }]" v-for="item in filteredTreeData"
:key="item.id" @click="handleItemClick(item)">
<div>{{item.name}}</div>
<div class="right-opearte">
<span @click.stop="openDrawer('edit','编辑数据字典', item)"><i class="el-icon-edit"></i>编辑</span>
<span @click.stop="handleDelType(item)"><i class="el-icon-delete"></i>删除</span>
</div>
</div>
</template>
</div>
</div>
<div class="descriptions-box">
<div style="height:100%;width:100%" v-if="Object.keys(activeTypeItem).length">
<div class="box-tip card">
<el-button type="primary" class="add-btn" @click="openDrawer('childAdd', '新增字段', [])">新增字段</el-button>
</div>
<div class="table-main card" style="height: calc(100% - 65px);">
<div class="table-header">
<div v-if="toolButton" class="header-button-ri">
<slot name="toolButton">
<el-button :icon="Refresh" circle @click="refreshData" />
<el-button :icon="Operation" circle @click="openColSetting" />
</slot>
</div>
</div>
<el-table :data="tableData" border style="width: 100%" :header-cell-style="{ background: '#f5f7fa', color: '#606266', textAlign: 'center' }">
<el-table-column prop="fieldName" label="字段名称" align="center"/>
<el-table-column prop="isRequire" label="必填项" align="center" />
<el-table-column prop="sort" label="排序" align="center"/>
<el-table-column prop="status" label="状态" align="center">
<template #default="scope">
<ElTag :type="scope.row.status == 1 ? 'success' : 'danger'">{{scope.row.status == 1 ? '启用' :'禁用'}}</ElTag>
</template>
</el-table-column>
<el-table-column label="操作" align="center">
<template #default="scope">
<el-button type="primary" link @click="openDrawer('childEdit','编辑字段', scope.row)">编辑</el-button>
<el-button v-if="scope.row.status == '1'" type="primary" style="color:#FF0000" link
@click="changeStatus(scope.row,0)">禁用</el-button>
<el-button v-if="scope.row.status == '0'" type="primary" style="color:#49C625" link
@click="changeStatus(scope.row,1)">启用</el-button>
<el-button type="primary" link @click="deleteAccount(scope.row)">删除</el-button>
</template>
</el-table-column>
<!-- 无数据 -->
<template #empty>
<div class="table-empty">
<slot name="empty">
<img src="@/assets/images/notData.png" alt="notData" />
<div>暂无数据</div>
</slot>
</div>
</template>
</el-table>
<Pagination v-if="tableData.length > 0" :pageable="pagination" :handle-size-change="handleSizeChange"
:handle-current-change="handleCurrentChange" />
</div>
</div>
<div class="card empty" v-else>
<el-empty description="请先选择非标准资产"></el-empty>
</div>
</div>
<!-- 新增非标准字段 -->
<addNewFields ref="dialogAddNewFields" />
<!-- 列设置 -->
<ColSetting v-if="toolButton" ref="colRef" v-model:col-setting="colSetting" />
</div>
</template>
<script setup lang="ts" name="standardProductFieldManage">
import { ref, reactive,onMounted ,watch} from "vue";
import { ElTree,ElTable, FormInstance, FormRules, ElMessage,ElTag } from "element-plus";
import { Supplier } from "@/api/interface";
import Pagination from "@/components/ProTable/components/Pagination.vue";
import { ProTableInstance, ColumnProps,TypeProps } from "@/components/ProTable/interface";
import { Refresh, Operation, Search } from "@element-plus/icons-vue";
import ColSetting from "@/components/ProTable/components/ColSetting.vue";
import addNewFields from "@/views/system/standardProductFieldManage/addNewFields.vue";
import { nonstandardList, editNonstandard, editNonstandardClild, deleteNonstandard ,nonstandardClildList,statusNonstandardClild,deleteNonstandardClild} from '@/api/modules/public';
import { da } from "element-plus/es/locale";
import { useHandleData } from "@/hooks/useHandleData";
// 初始化参数
const treeData = ref<any[]>([]);
const filteredTreeData = ref<any[]>([]);
const activeTypeItem = ref<Record<string, any>>({});
const filterText = ref("");
const toolButton = ref(true)
// 右侧表格数据
const tableData = ref<any[]>([]);
const pagination = ref({
pageNum: 1,
pageSize: 10,
total: 0,
});
watch(
() => filterText.value,
(val) => {
if (!val) {
filteredTreeData.value = treeData.value;
} else {
const keyword = val.toLowerCase();
filteredTreeData.value = treeData.value.filter(item =>
item.name?.toLowerCase().includes(keyword)
);
}
},
{ immediate: true }
);
onMounted(async () => {
getTreeList()
})
// 左侧树、
const getTreeList = async () => {
const data = await nonstandardList({});
treeData.value = data || [];
filteredTreeData.value = data || []
// 编辑数据后,右侧数据更新
if (Object.keys(activeTypeItem.value).length > 0) {
getTableList()
}
}
// 点击左侧,更新右侧列表
const handleItemClick = async (data: any) => {
activeTypeItem.value = data;
getTableList()
}
const handleSizeChange = (size) => {
pagination.value.pageSize = size;
getTableList();
};
const handleCurrentChange = (currentPage) => {
pagination.value.pageNum = currentPage;
getTableList();
}
// 刷新
const refreshData = () => {
pagination.value.pageNum = 1
getTableList();
}
// 接收 columns 并设置为响应式
const tableColumns = reactive<ColumnProps[]>(treeData.value);
// column 列类型
const columnTypes: TypeProps[] = ["selection", "radio", "index", "expand", "sort"];
const colRef = ref();
const colSetting = treeData.value!.filter(item => {
console.log('item',tableData)
const { type, prop, isShow } = item;
return !columnTypes.includes(type!) && prop !== "operation" && isShow;
});
const openColSetting = () => {
console.log('23',tableData)
colRef.value.openColSetting();
}
// 调用列表接口
const getTableList = async () => {
const formData = {
assetNonStandardId: activeTypeItem.value.id,
pageNum: pagination.value.pageNum,
pageSize: pagination.value.pageSize,
};
const { code, msg, data } = await nonstandardClildList(formData)
if(code == 0) {
tableData.value = data.dataList;
pagination.value.total = data.totalCount;
} else {
ElMessage.error(msg);
}
}
// 表格配置项
const columns = reactive<ColumnProps<Supplier.pageList>[]>([
{
prop: "fieldName",
label: "单位名称",
},
])
// 新增,编辑
const dialogAddNewFields = ref<InstanceType<typeof addNewFields> | null>(null);
const openDrawer = async (type: string, title: string, row: any) => {
console.log('activeTypeItem.value',activeTypeItem.value)
const params = {
type: type,
title: title,
isView: false,
row: {...row},
activeTypeItem:{...activeTypeItem.value},
api: type == 'add' || type == 'edit' ? editNonstandard : editNonstandardClild,
getTableListData: getTreeList
}
dialogAddNewFields.value?.acceptParams(params);
}
// 删除资产
const handleDelType = async (params) => {
await useHandleData(deleteNonstandard, { id: params.id }, `确认删除`);
getTreeList()
}
// 修改状态
const changeStatus = async (row: Supplier.pageList,type:string) => {
await useHandleData(statusNonstandardClild, { id: row.id, status: type }, `确定${type == 1 ? '启用' : '禁用'}`);
getTreeList();
}
// 删除
const deleteAccount = async (row: Supplier.pageList) => {
await useHandleData(deleteNonstandardClild, { id: row.id }, `确认删除`);
getTreeList()
}
</script>
<style scoped lang="scss">
@use "@/styles/treeIndex.scss";
.list-box {
height: calc(100% - 95px);
margin-top: 10px;
overflow: auto;
}
.item {
display: flex;
justify-content: space-between;
padding: 5px 10px;
font-size: 14px;
color: #606266;
cursor: pointer;
border-radius: 4px;
&.active {
background: #e6f5f3 !important;
}
&:hover {
background: rgb(245 247 250);
}
span {
margin-left: 10px;
cursor: pointer;
i {
margin-right: 3px;
}
&:first-of-type {
color: #009688;
}
&:last-of-type {
color: #f56c6c;
}
}
}
.empty {
width: 100%;
height: 100%;
.el-empty {
transform: translate(0, 50%);
}
}
// .el-tables{
// height: calc(100% - 65px);
// }
.bindUserRight_bottom{
display: flex;
justify-content: flex-end;
margin-top: 20px;
}
</style><template>
<!-- 列设置 -->
<el-drawer v-model="drawerVisible" title="列设置" size="450px" :close-on-click-modal="false">
<div class="table-main">
<el-table :data="colSetting" :border="true" row-key="prop" default-expand-all
:tree-props="{ children: '_children' }">
<el-table-column prop="label" align="center" label="列名" />
<el-table-column v-slot="scope" prop="isShow" align="center" label="显示">
<el-switch v-model="scope.row.isShow"></el-switch>
</el-table-column>
<el-table-column v-slot="scope" prop="sortable" align="center" label="排序">
<el-switch v-model="scope.row.sortable"></el-switch>
</el-table-column>
<template #empty>
<div class="table-empty">
<img src="@/assets/images/notData.png" alt="notData" />
<div>暂无可配置列</div>
</div>
</template>
</el-table>
</div>
</el-drawer>
</template>
<script setup lang="ts" name="ColSetting">
import { ref } from "vue";
import { ColumnProps } from "@/components/ProTable/interface";
defineProps<{ colSetting: ColumnProps[] }>();
const drawerVisible = ref<boolean>(false);
const openColSetting = () => {
drawerVisible.value = true;
};
defineExpose({
openColSetting
});
</script>
<style scoped lang="scss">
.cursor-move {
cursor: move;
}
</style>
点击openColSetting,打开ColSetting列设置,传递table表头列给ColSetting弹窗界面,如何把表头传到子界面