组织修改

This commit is contained in:
aoli.qu 2021-09-08 17:29:09 +08:00
parent 2d96581ee0
commit fc77d32c22
1 changed files with 46 additions and 94 deletions

View File

@ -1,42 +1,7 @@
<template> <template>
<a-row :gutter="24" > <a-card :bordered="false">
<a-col :md="5" :sm="24" > <a-tabs default-active-key="1" >
<a-card :bordered="false" :loading="treeLoading"> <a-tab-pane key="1" tab="单位部门信息" @change="tabsCallback">
<div v-if="this.orgTree!='' ">
<a-tree
style="scroll:true"
:treeData="orgTree"
v-if="orgTree.length"
@select="handleClick"
:defaultExpandAll="true"
:defaultExpandedKeys="defaultExpandedKeys"
:replaceFields="replaceFields" />
</div>
<div v-else>
<a-empty :image="simpleImage" />
</div>
</a-card>
</a-col>
<a-col :md="19" :sm="24">
<a-card :bordered="false">
<div class="table-page-search-wrapper">
<a-form layout="inline">
<a-row :gutter="48">
<a-col :md="8" :sm="24">
<a-form-item label="机构名称" >
<a-input v-model="queryParam.name" allow-clear placeholder="请输入机构名称"/>
</a-form-item>
</a-col>
<a-col :md="8" :sm="24">
<a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
<a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
</a-col>
</a-row>
</a-form>
</div>
</a-card>
<a-card :bordered="false">
<div class="table-operator"> <div class="table-operator">
<a-button @click="$refs.orgForm.add()" icon="plus" type="primary" v-if="hasPerm('sys:org:add')">新增机构</a-button> <a-button @click="$refs.orgForm.add()" icon="plus" type="primary" v-if="hasPerm('sys:org:add')">新增机构</a-button>
</div> </div>
@ -46,6 +11,8 @@
:columns="columns" :columns="columns"
:data="loadData" :data="loadData"
:rowKey="(record) => record.id" :rowKey="(record) => record.id"
:showPagination="false"
:defaultExpandedRowKeys="expandedRowKeys"
> >
<span slot="action" slot-scope="text, record"> <span slot="action" slot-scope="text, record">
@ -57,14 +24,37 @@
</span> </span>
</s-table> </s-table>
<org-form ref="orgForm" @ok="handleOk" /> <org-form ref="orgForm" @ok="handleOk" />
</a-card> </a-tab-pane>
</a-col> <a-tab-pane key="2" tab="项目工程信息" @change="tabsCallback">
</a-row> <div class="table-operator">
<a-button @click="$refs.orgForm.add()" icon="plus" type="primary" v-if="hasPerm('sys:org:add')">新增项目</a-button>
</div>
<s-table
ref="table"
:columns="columns"
:data="loadData"
:rowKey="(record) => record.id"
:showPagination="false"
:defaultExpandedRowKeys="expandedRowKeys"
>
<span slot="action" slot-scope="text, record">
<a v-if="hasPerm('sys:org:edit')" @click="$refs.orgForm.edit(record)">编辑</a>
<a-divider type="vertical" v-if="hasPerm('sys:org:edit') & hasPerm('sys:org:delete')"/>
<a-popconfirm v-if="hasPerm('sys:org:delete')" placement="topRight" title="确认删除?" @confirm="() => singleDelete(record)">
<a>删除</a>
</a-popconfirm>
</span>
</s-table>
<org-form ref="orgForm" @ok="handleOk" />
</a-tab-pane>
</a-tabs>
</a-card>
</template> </template>
<script> <script>
import { STable } from '@/components' import { STable } from '@/components'
import { Empty } from 'ant-design-vue' import { orgList, orgDel } from '@/api/org/org'
import { orgList, orgDel, orgPage } from '@/api/org/org'
import OrgForm from './OrgForm' import OrgForm from './OrgForm'
import { listToTree } from '@/utils/util' import { listToTree } from '@/utils/util'
const rootParentId = 0 const rootParentId = 0
@ -78,6 +68,7 @@
return { return {
// //
queryParam: {}, queryParam: {},
expandedRowKeys: [],
// //
columns: [ columns: [
{ {
@ -99,30 +90,18 @@
], ],
// Promise // Promise
loadData: parameter => { loadData: parameter => {
return orgPage(Object.assign(parameter, this.queryParam)).then((res) => { return orgList(Object.assign(parameter, this.queryParam)).then((res) => {
return res const orgList = listToTree(res.data, [], rootParentId)
//
orgList.forEach(item => {
this.expandedRowKeys.push(item.id)
})
return orgList
}) })
},
orgTree: [],
selectedRowKeys: [],
selectedRows: [],
defaultExpandedKeys: [],
//
expandedKeys: [],
searchValue: '',
autoExpandParent: true,
treeLoading: true,
simpleImage: Empty.PRESENTED_IMAGE_SIMPLE,
replaceFields: {
children: 'children',
title: 'name',
key: 'id',
value: 'id'
} }
} }
}, },
created () { created () {
this.getOrgTree()
if (this.hasPerm('sys:org:edit') || this.hasPerm('sys:org:del')) { if (this.hasPerm('sys:org:edit') || this.hasPerm('sys:org:del')) {
this.columns.push({ this.columns.push({
title: '操作', title: '操作',
@ -133,27 +112,11 @@
} }
}, },
methods: { methods: {
/** tabsCallback (key) {
* 获取到机构树展开顶级下树节点考虑到后期数据量变大不建议全部展开 if (key === '1') {
*/ }
getOrgTree () { if (key === '2') {
orgList(Object.assign(this.queryParam)).then(res => { }
this.treeLoading = false
if (!res.code === 200 || !res.data.length) {
return
}
console.log(res.data)
this.orgTree = listToTree(res.data, [], rootParentId)
console.log(this.orgTree)
this.queryParam.parentId = this.orgTree[0].id
// api
for (var item of res.data) {
if (item.parentId === 0) {
this.defaultExpandedKeys.push(item.id)
}
}
this.$refs.table.refresh()
})
}, },
/** /**
* 删除 * 删除
@ -171,19 +134,8 @@
this.$message.error('删除错误:' + err.message) this.$message.error('删除错误:' + err.message)
}) })
}, },
handleClick (e) {
this.queryParam = {
pid: e.toString()
}
this.$refs.table.refresh(true)
},
handleOk () { handleOk () {
this.getOrgTree()
this.$refs.table.refresh() this.$refs.table.refresh()
},
onSelectChange (selectedRowKeys, selectedRows) {
this.selectedRowKeys = selectedRowKeys
this.selectedRows = selectedRows
} }
} }
} }