|
@@ -1,26 +1,26 @@
|
|
|
<!-- -->
|
|
|
<template>
|
|
|
<div class="company">
|
|
|
- <searchAdd isButtom="查询">
|
|
|
+ <searchAdd isButtom="查询" @event="getDeptApi">
|
|
|
<template #searchConter>
|
|
|
<el-form-item label="公司名称">
|
|
|
- <el-input v-model="datas.input" placeholder="请输入公司名称" clearable />
|
|
|
+ <el-input v-model="datas.search" placeholder="请输入公司名称" clearable style="width: 200px;"/>
|
|
|
</el-form-item>
|
|
|
</template>
|
|
|
</searchAdd>
|
|
|
<bg istitle="公司列表">
|
|
|
- <template #btn>
|
|
|
+ <template #btn v-if="store.state.isuserInfo&&store.state.isuserInfo.deptId==0">
|
|
|
<el-form :inline="true" class="demo-form-inline">
|
|
|
<el-form-item label="添加一级目录">
|
|
|
- <el-input v-model="datas.input" placeholder="请输入添加一级目录" clearable />
|
|
|
+ <el-input v-model="datas.params.deptName" placeholder="请输入添加一级目录" clearable style="width: 150px;" />
|
|
|
</el-form-item>
|
|
|
<el-form-item style="margin-right: 20px;">
|
|
|
- <el-button type="primary">添加</el-button>
|
|
|
+ <el-button type="primary" @click="firstOrder">添加</el-button>
|
|
|
</el-form-item>
|
|
|
</el-form>
|
|
|
</template>
|
|
|
<template #bg>
|
|
|
- <el-tree :data="data" :props="defaultProps" accordion draggable>
|
|
|
+ <el-tree :data="datas.dataTree" :props="defaultProps">
|
|
|
<template #default="{ node, data }">
|
|
|
<span class="custom-tree-node">
|
|
|
<span>
|
|
@@ -34,7 +34,7 @@
|
|
|
<el-button @click.stop="addFun(node, data)" type="primary">新增子级</el-button>
|
|
|
<el-button @click.stop="editFun(node, data)" style="margin-left: 20px;"
|
|
|
type="success">编辑</el-button>
|
|
|
- <el-button @click.stop="addFun(node, data)" style="margin-left: 20px;"
|
|
|
+ <el-button @click.stop="EnterFun(node, data)" style="margin-left: 20px;"
|
|
|
type="warning">进入</el-button>
|
|
|
<el-button @click.stop="delFun(node, data)" style="margin-left: 20px;"
|
|
|
type="danger">删除</el-button>
|
|
@@ -49,51 +49,91 @@
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
import bg from '@/components/bg.vue'
|
|
|
-import { ElMessage, ElMessageBox } from 'element-plus'
|
|
|
+import { ElMessage, ElMessageBox, ElNotification } from 'element-plus'
|
|
|
import searchAdd from "@/components/searchAdd.vue";
|
|
|
import { reactive } from "vue";
|
|
|
+import { companyDept, postTree,deleteTree,putTree,postEnter } from "@/api";
|
|
|
+import router from '@/router';
|
|
|
+import { useStore } from "vuex";
|
|
|
+const store = useStore()
|
|
|
const datas = reactive({
|
|
|
- input: ''
|
|
|
+ search: '',//搜索
|
|
|
+ params: {//添加目录参数
|
|
|
+ deptName: '',
|
|
|
+ parentId: 0,
|
|
|
+ },
|
|
|
+ dataTree: []
|
|
|
})
|
|
|
-/**
|
|
|
- *
|
|
|
- * @param val 子传值
|
|
|
- */
|
|
|
-const eventFn = (val: any) => {
|
|
|
- console.log('/', val);
|
|
|
+const defaultProps = {
|
|
|
+ children: 'children',
|
|
|
+ label: 'deptName',
|
|
|
+}
|
|
|
+// 公司列表
|
|
|
+const getDeptApi = async () => {
|
|
|
+ const result:any = await companyDept({ deptName: datas.search })
|
|
|
+ if (result.code == 200) datas.dataTree = result.data
|
|
|
+}
|
|
|
+getDeptApi()
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+//添加一级目录
|
|
|
+const firstOrder = async () => {
|
|
|
+ if (!datas.params.deptName) {
|
|
|
+ ElNotification({
|
|
|
+ title: '格式错误',
|
|
|
+ message: '哎呀,目录名称输入好像不正确哦',
|
|
|
+ type: 'error',
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ datas.params.parentId = 0
|
|
|
+ posTreeApi()
|
|
|
+}
|
|
|
+//添加目录Api
|
|
|
+const posTreeApi = async () => {
|
|
|
+ const result:any = await postTree(datas.params)
|
|
|
+ if (result.code == 200 && result.msg == '创建成功') getDeptApi()
|
|
|
}
|
|
|
/**
|
|
|
* 新增字节
|
|
|
*/
|
|
|
const addFun = (node: any, data: any) => {
|
|
|
- ElMessageBox.prompt('请输入正确子目录名称', '提示', {
|
|
|
+ ElMessageBox.prompt('请输入目录名称', '提示', {
|
|
|
confirmButtonText: '确定',
|
|
|
cancelButtonText: '取消',
|
|
|
inputPattern: /\S/,
|
|
|
- inputErrorMessage: '子目录不允许为空',
|
|
|
+ inputErrorMessage: '目录不允许为空',
|
|
|
draggable: true,
|
|
|
- inputValue: data ? data.label : ''
|
|
|
}).then(({ value }) => {
|
|
|
- ElMessage.success(value)
|
|
|
+ datas.params.parentId = data.id
|
|
|
+ datas.params.deptName = value
|
|
|
+ posTreeApi()
|
|
|
}).catch(() => {
|
|
|
- ElMessage.info('取消新增子目录')
|
|
|
+ ElMessage.info('取消新增目录')
|
|
|
})
|
|
|
}
|
|
|
/**
|
|
|
- * 新增字节
|
|
|
+ * 编辑字节
|
|
|
*/
|
|
|
const editFun = (node: any, data: any) => {
|
|
|
- ElMessageBox.prompt('请输入正确子目录名称', '提示', {
|
|
|
+ ElMessageBox.prompt('请输入目录名称', '提示', {
|
|
|
draggable: true,
|
|
|
confirmButtonText: '确定',
|
|
|
cancelButtonText: '取消',
|
|
|
inputPattern: /\S/,
|
|
|
- inputErrorMessage: '子目录不允许为空',
|
|
|
- inputValue: data.label
|
|
|
- }).then(({ value }) => {
|
|
|
- ElMessage.success(value)
|
|
|
+ inputErrorMessage: '目录不允许为空',
|
|
|
+ inputValue: data.deptName ? data.deptName : ''
|
|
|
+ }).then(async ({ value }) => {
|
|
|
+ const params = {
|
|
|
+ id: data.id,
|
|
|
+ deptName:value
|
|
|
+ }
|
|
|
+ const result:any = await putTree(params)
|
|
|
+ console.log('编辑成功',result)
|
|
|
+ if (result.code == 200 && result.msg == '更新成功') getDeptApi()
|
|
|
}).catch(() => {
|
|
|
- ElMessage.info('取消新增子目录')
|
|
|
+ ElMessage.info('取消编辑目录')
|
|
|
})
|
|
|
}
|
|
|
/**
|
|
@@ -106,77 +146,25 @@ const delFun = (node: any, data: any) => {
|
|
|
draggable: true,
|
|
|
type: 'warning',
|
|
|
center: true,
|
|
|
- }).then(() => {
|
|
|
- ElMessage.success('删除成功')
|
|
|
+ }).then(async () => {
|
|
|
+ const result:any = await deleteTree({id:data.id})
|
|
|
+ if (result.code == 200 && result.msg == '删除成功') getDeptApi()
|
|
|
}).catch(() => {
|
|
|
ElMessage.info('取消删除')
|
|
|
})
|
|
|
}
|
|
|
-interface Tree {
|
|
|
- label: string
|
|
|
- children?: Tree[]
|
|
|
-}
|
|
|
-const defaultProps = {
|
|
|
- children: 'children',
|
|
|
- label: 'label',
|
|
|
+
|
|
|
+/**
|
|
|
+ * 进入公司
|
|
|
+ * @param node
|
|
|
+ * @param data 当前行数据
|
|
|
+ */
|
|
|
+const EnterFun = (node: any, data: any) => {
|
|
|
+ postEnter({id:data.id})
|
|
|
+ router.push('/home')
|
|
|
}
|
|
|
-const data: Tree[] = [
|
|
|
- {
|
|
|
- label: '公司名称 one 1',
|
|
|
- children: [
|
|
|
- {
|
|
|
- label: '公司名称 two 1-1',
|
|
|
- children: [
|
|
|
- {
|
|
|
- label: '公司名称 three 1-1-1',
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
- {
|
|
|
- label: '公司名称 one 2',
|
|
|
- children: [
|
|
|
- {
|
|
|
- label: '公司名称 two 2-1',
|
|
|
- children: [
|
|
|
- {
|
|
|
- label: '公司名称 three 2-1-1',
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
- {
|
|
|
- label: '公司名称 two 2-2',
|
|
|
- children: [
|
|
|
- {
|
|
|
- label: '公司名称 three 2-2-1',
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
- {
|
|
|
- label: '公司名称 one 3',
|
|
|
- children: [
|
|
|
- {
|
|
|
- label: '公司名称 two 3-1',
|
|
|
- children: [
|
|
|
- {
|
|
|
- label: '公司名称 three 3-1-1',
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
- {
|
|
|
- label: '公司名称 two 3-2',
|
|
|
- children: [
|
|
|
- {
|
|
|
- label: '公司名称 three 3-2-1',
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
-]
|
|
|
+
|
|
|
+
|
|
|
|
|
|
</script>
|
|
|
<style lang="scss">
|