123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442 |
- <template>
- <div class="dept">
- <div class="tree">
- <treeList :data="treeListData" v-model="sourceList.pagination.tenantId" node-key="id" @change="treeChange"> </treeList>
- </div>
- <div class="content">
- <byTable
- :hideTable="true"
- :hidePagination="true"
- :config="config"
- :loading="loading"
- highlight-current-row
- :selectConfig="selectConfig"
- :table-events="{
- //element talbe事件都能传
- select: select,
- }"
- :action-list="[
- {
- text: $t('dept.addDept'),
- action: () => openModal('add'),
- disabled: !sourceList.pagination.tenantId,
- },
- ]"
- @get-list="getList">
- <template #slotName="{ item }">
- {{ item.createTime }}
- </template>
- </byTable>
- <el-table
- v-loading="loading"
- :data="sourceList.data"
- row-key="deptId"
- style="padding: 0 20px; box-sizing: border-box"
- :tree-props="{
- children: 'children',
- hasChildren: 'hasChildren',
- }">
- <el-table-column prop="deptName" :label="$t('dept.deptName')" width="260"></el-table-column>
- <el-table-column prop="orderNum" :label="$t('common.serialNumber')" width="100"></el-table-column>
- <el-table-column prop="type" :label="$t('dept.deptType')" width="100" :formatter="(row) => showType(row.type)"> </el-table-column>
- <el-table-column :label="$t('common.createTime')" align="center" prop="createTime" width="200">
- <template #default="scope">
- <span>{{ parseTime(scope.row.createTime) }}</span>
- </template>
- </el-table-column>
- <el-table-column :label="$t('common.operation')" align="center" class-name="small-padding fixed-width">
- <template #default="scope">
- <el-button link type="primary" @click="getDtl(scope.row)">{{$t('common.edit')}}</el-button>
- <el-button link type="primary" @click="handleAdd(scope.row)">{{$t('common.add')}}</el-button>
- <el-button v-if="scope.row.parentId != 0" link type="primary" @click="listDelete(scope.row)">{{$t('common.delete')}}</el-button>
- </template>
- </el-table-column>
- </el-table>
- </div>
- <el-dialog :title="modalType == 'add' ? $t('common.add') : $t('common.edit')" v-if="dialogVisible" v-model="dialogVisible" width="500" v-loading="loading">
- <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="byform">
- <template #account>
- <el-input style="width: 150px; margin-right: 10px" v-model="formData.data.userName" :placeholder="$t('dept.pleaseEnterTheUsername')"></el-input>
- <el-input style="width: 150px; margin-right: 10px" v-model="formData.data.password" :placeholder="$t('dept.pleaseEnterThePassword')"></el-input>
- <span style="color: #409eff; cursor: pointer" @click="newPassword">{{$t('dept.randomGeneration')}}</span>
- </template>
- </byForm>
- <template #footer>
- <el-button @click="dialogVisible = false" size="large">{{$t('common.cancel')}}</el-button>
- <el-button type="primary" v-no-double-click="submitForm" size="large" :loading="submitLoading">{{$t('common.confirm')}}</el-button>
- </template>
- </el-dialog>
- <el-dialog title="修改密码" v-model="roomDialogVisible" width="500" :before-close="handleClose" v-loading="loading">
- <template #footer>
- <el-button @click="roomDialogVisible = false" size="large">{{$t('common.cancel')}}</el-button>
- <el-button type="primary" @click="submitTree('byform')" size="large" :loading="submitLoading">{{$t('common.confirm')}}</el-button>
- </template>
- </el-dialog>
- </div>
- </template>
- <script setup>
- /* eslint-disable vue/no-unused-components */
- import { ElMessage, ElMessageBox } from "element-plus";
- import byTable from "@/components/byTable/index";
- import byForm from "@/components/byForm/index";
- import treeList from "@/components/treeList/index";
- import { computed, defineComponent, ref } from "vue";
- const loading = ref(false);
- const submitLoading = ref(false);
- const sourceList = ref({
- data: [],
- pagination: {
- total: 3,
- pageNum: 1,
- pageSize: 10,
- },
- });
- const { proxy } = getCurrentInstance();
- let dialogVisible = ref(false);
- let modalType = ref("add");
- let rules = ref({
- parentId: [{ required: true, message: proxy.t('dept.pleaseSelectTheParentDept'), trigger: "blur" }],
- orderNum: [{ required: true, message: proxy.t('dept.serialNumberCannotBeEmpty'), trigger: "blur" }],
- deptName: [{ required: true, message: proxy.t('dept.deptNameCannotBeEmpty'), trigger: "blur" }],
- type: [{ required: true, message: proxy.t('dept.deptTypeCannotBeEmpty'), trigger: "change" }],
- });
- const selectConfig = computed(() => {
- return [];
- });
- const config = computed(() => {
- return [
- {
- attrs: {
- label: proxy.t('dept.deptName'),
- prop: "deptName",
- },
- },
- {
- attrs: {
- label: proxy.t('dept.deptType'),
- prop: "type",
- align: "left",
- },
- render(type) {
- return type == 0 ? "公司" : type == 1 ? "业务中心" : type == 2 ? "部门" : "组";
- },
- },
- {
- attrs: {
- label: proxy.t('common.serialNumber'),
- prop: "nickName",
- },
- },
- {
- attrs: {
- label: proxy.t('common.createTime'),
- prop: "createTime",
- },
- },
- {
- attrs: {
- label: proxy.t('common.operation'),
- width: "200",
- align: "right",
- },
- // 渲染 el-button,一般用在最后一列。
- renderHTML(row) {
- return [
- {
- attrs: {
- label: proxy.t('common.edit'),
- type: "primary",
- text: true,
- },
- el: "button",
- click() {
- getDtl(row);
- },
- },
- {
- attrs: {
- label: proxy.t('common.delete'),
- type: "danger",
- text: true,
- },
- el: "button",
- click() {},
- },
- ];
- },
- },
- ];
- });
- let formData = reactive({
- data: {
- orderNum: 1,
- },
- });
- const formOption = reactive({
- inline: true,
- labelWidth: 100,
- itemWidth: 100,
- rules: [],
- });
- const byform = ref(null);
- const treeListData = ref([]);
- const formConfig = computed(() => {
- return [
- {
- type: "treeSelect",
- prop: "parentId",
- label: proxy.t('dept.parentDept'),
- data: [],
- },
- {
- type: "input",
- prop: "deptName",
- label: proxy.t('dept.deptName'),
- required: true,
- itemWidth: 50,
- //disabled:true,
- itemType: "text",
- },
- {
- type: "select",
- prop: "type",
- label: proxy.t('dept.deptType'),
- required: true,
- data: [
- {
- label: proxy.t('dept.company'),
- value: 1,
- },
- {
- label: proxy.t('dept.businessCenter'),
- value: 2,
- },
- {
- label: proxy.t('dept.department'),
- value: 3,
- },
- {
- label: proxy.t('dept.group'),
- value: 4,
- },
- ],
- },
- {
- type: "select",
- label: proxy.t('dept.deptManager'),
- prop: "leaderId",
- itemWidth: 50,
- clearable: true,
- data: [],
- },
- {
- type: "select",
- label: proxy.t('dept.deptDirector'),
- prop: "directorId",
- clearable: true,
- itemWidth: 50,
- data: [],
- },
- {
- type: "input",
- prop: "orderNum",
- label: proxy.t('common.serialNumber'),
- required: true,
- itemWidth: 50,
- //disabled:true,
- itemType: "number",
- },
- ];
- });
- const newPassword = () => {
- formData.data.password = generatePassword();
- };
- const generatePassword = () => {
- var length = 12,
- charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
- password = "";
- for (var i = 0, n = charset.length; i < length; ++i) {
- password += charset.charAt(Math.floor(Math.random() * n));
- }
- return password;
- };
- const getTreeList = () => {
- proxy.post("/tenantInfo/list").then((message) => {
- message.map((item) => {
- item.label = item.enterpriseName;
- item.id = item.tenantId;
- item.children = [];
- });
- treeListData.value = message;
- console.log(treeListData.value);
- });
- };
- const getList = async (req) => {
- if (req) {
- req.deptName = req.keyword;
- }
- sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
- loading.value = true;
- proxy.get("/tenantDept/list", sourceList.value.pagination).then((message) => {
- recursive(message.data);
- sourceList.value.data = proxy.handleTree(message.data, "deptId");
- console.log(sourceList.value);
- formConfig.value[0].data = proxy.handleTree(message.data, "deptId");
- console.log(formConfig.value[0].data);
- setTimeout(() => {
- loading.value = false;
- }, 200);
- });
- };
- const treeChange = (e) => {
- sourceList.value.pagination.tenantId = e.id;
- getList({ tenantId: e.id });
- };
- const handleAdd = (row) => {
- dialogVisible.value = true;
- modalType.value = "add";
- console.log(row);
- formData.data = {
- parentId: row.deptId,
- tenantId: row.tenantId,
- };
- };
- const openModal = () => {
- dialogVisible.value = true;
- modalType.value = "add";
- formData.data = {
- orderNum: 1,
- };
- getUserList();
- };
- const TreetenantId = ref("");
- const selection = ref({
- data: [],
- });
- const select = (_selection, row) => {
- selection.value.data = _selection;
- console.log(_selection.length);
- };
- const tree = ref(null);
- const submitForm = () => {
- byform.value.handleSubmit((valid) => {
- const method = modalType.value == "add" ? "POST" : "PUT";
- console.log(method);
- if (!formData.data.parentId) formData.data.parentId = 0;
- formData.data.leaderId = formData.data.leaderId ? formData.data.leaderId : '-1';
- formData.data.directorId = formData.data.directorId ? formData.data.directorId : '-1';
- proxy
- .post(
- "/tenantDept",
- {
- ...formData.data,
- tenantId: formData.data.tenantId ? formData.data.tenantId : sourceList.value.pagination.tenantId,
- },
- method
- )
- .then((res) => {
- ElMessage({
- message: modalType.value == "add" ? proxy.t('common.addSuccess') : proxy.t('common.editSuccess'),
- type: "success",
- });
- dialogVisible.value = false;
- getList();
- });
- });
- };
- const recursive = (data) => {
- data.map((item) => {
- item.label = item.deptName;
- item.id = item.deptId;
- if (item.children) {
- recursive(item.children);
- } else {
- item.children = [];
- }
- });
- };
- const listDelete = (row) => {
- // 弹窗提示是否删除
- ElMessageBox.confirm(proxy.t('common.thisOperationWillPermanentlyDeleteTheData'),proxy.t('common.prompt'), {
- confirmButtonText: proxy.t('common.confirm'),
- cancelButtonText: proxy.t('common.cancel'),
- type: "warning",
- }).then(() => {
- // 删除
- proxy.post("/tenantDept/" + row.deptId, {}, "delete").then((res) => {
- ElMessage({
- message: proxy.t('common.deleteSuccess'),
- type: "success",
- });
- getList();
- });
- });
- };
- const showType = (type) => {
- return type == 0 ?
- proxy.t('dept.company') : type == 1 ?
- proxy.t('dept.businessCenter') : type == 2 ?
- proxy.t('dept.department') :
- proxy.t('dept.group');
- };
- const getDtl = (row) => {
- formData.data = { ...row };
- formData.data.leaderId = formData.data.leaderId == '-1' ? '' : formData.data.leaderId;
- formData.data.directorId = formData.data.directorId == '-1' ? '' : formData.data.directorId;
- sourceList.value.pagination.tenantId = row.tenantId;
- getUserList()
- modalType.value = "edit";
-
- dialogVisible.value = true;
- };
- const getUserList = () => {
- proxy
- .get("/tenantUser/list", {
- pageNum: 1,
- pageSize: 10000,
- tenantId: sourceList.value.pagination.tenantId,
- })
- .then((message) => {
- message.rows.map((item) => {
- item.label = item.nickName;
- item.id = item.userId;
- });
-
- formConfig.value[3].data = message.rows;
- formConfig.value[4].data = message.rows;
-
-
- });
- };
- getUserList();
- getTreeList();
- getList();
- </script>
- <style lang="scss" scoped>
- .dept {
- padding: 20px;
- display: flex;
- justify-content: space-between;
- .tree {
- width: 300px;
- }
- .content {
- width: calc(100% - 320px);
- }
- }
- </style>
|