From 9c9193a78e3a84b9a05aa348f85fdacd7c60f27a Mon Sep 17 00:00:00 2001 From: lideqin <694785430@qq.com> Date: Tue, 29 Aug 2023 18:57:24 +0800 Subject: [PATCH] =?UTF-8?q?[update]=20=E4=BF=AE=E6=94=B9=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=92=8C=E7=BB=84=E7=BB=87=E6=9C=BA=E6=9E=84?= =?UTF-8?q?=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../selection/UserOrOrganSelection.vue | 34 +++++++++---- .../selection/UserOrganSelectModal.vue | 49 ++++++++++++++----- 2 files changed, 62 insertions(+), 21 deletions(-) diff --git a/src/components/selection/UserOrOrganSelection.vue b/src/components/selection/UserOrOrganSelection.vue index ce6f4e70..c030c1a7 100644 --- a/src/components/selection/UserOrOrganSelection.vue +++ b/src/components/selection/UserOrOrganSelection.vue @@ -15,8 +15,8 @@ :value="checkedValue" @click="selectClick" > - - {{ item }} + + {{ item.title }} @@ -50,19 +50,20 @@ export default { type: Object, default: () => { return { - organ: '', - user: '' + organ: [], + user: [] } } } }, mounted () { - this.checkedValue = this.value.map(item => item.value) + this.selectOptions = this.value.organ.concat(this.value.user) + this.checkedValue = this.value.organ.concat(this.value.user).map(item => item.key) }, data () { return { checkedValue: [], - selectValue: [] + selectOptions: [] // 下拉框数据,为了回显 } }, methods: { @@ -70,13 +71,26 @@ export default { this.$refs.selectModal.open() }, selectChange (arrOne, arrTwo) { + console.log(arrOne, arrTwo) if (this.selectType === 'all') { - this.selectValue = [...arrOne, ...arrTwo] + this.selectOptions = arrOne.concat(arrTwo) + this.$emit('change', { + organ: arrOne, + user: arrTwo + }) } else { - this.selectValue = arrOne + this.selectOptions = arrOne + if (this.selectType === 'organ') { + this.$emit('change', { + organ: arrOne + }) + } else { + this.$emit('change', { + user: arrOne + }) + } } - this.checkedValue = this.selectValue.map(item => item.value) - this.$emit('change', this.selectType) + this.checkedValue = this.selectOptions.map(item => item.key) } }, model: { diff --git a/src/components/selection/UserOrganSelectModal.vue b/src/components/selection/UserOrganSelectModal.vue index 3b7944ee..834df338 100644 --- a/src/components/selection/UserOrganSelectModal.vue +++ b/src/components/selection/UserOrganSelectModal.vue @@ -73,12 +73,12 @@ @@ -90,7 +90,7 @@ :scroll="{x: 500}" :data-source="dataSourceUser" :pagination="ipaginationUser" - :row-selection="{ selectedRowKeys: selectedRowKeysUser, onChange: onSelectChangeUser, getCheckboxProps: getCheckboxPropsUser, type: type }" + :row-selection="{ selectedRowKeys: selectedRowKeysUser, onChange: onSelectChangeUser, type: type }" :loading="loadingLeft" @change="userLeftTableChange"> @@ -102,7 +102,8 @@ { + return { + key: item.key, + parentId: item.parentId, + title: item.title + } + }) || [] this.ipaginationOrgan.total = res.result.total } else { this.$message.warn(res.message) @@ -389,9 +397,18 @@ export default { }, // 组织机构左侧树的选择 onSelectChangeOrgan (selectedRowKeys, selectedRows) { - this.selectedRowKeysOrgan = selectedRows + this.selectedRowKeysOrgan = selectedRowKeys this.selectedRowsOrgan = selectedRows - this.dataSourceOrganRight.map(selectedRows) + if (this.type === 'checkbox') { + for (const rowIndex in selectedRows) { + if (!this.dataSourceOrganRight.find(item => item.key === selectedRows[rowIndex].key)) { + // 右侧不存在,追加到右侧表格 + this.dataSourceOrganRight.push(selectedRows[rowIndex]) + } + } + } else { + this.dataSourceOrganRight = selectedRows + } }, // 组织结构左侧树的复选框状态 getCheckboxPropsOrgan (record) { @@ -457,9 +474,18 @@ export default { }, // 用户左侧表的选择 onSelectChangeUser (selectedRowKeys, selectedRows) { - this.selectedRowKeysUser = selectedRows + this.selectedRowKeysUser = selectedRowKeys this.selectedRowsUser = selectedRows - this.dataSourceUserRight.map(selectedRows) + if (this.type === 'checkbox') { + for (const rowIndex in selectedRows) { + if (!this.dataSourceUserRight.find(item => item.id === selectedRows[rowIndex].id)) { + // 右侧不存在,追加到右侧表格 + this.dataSourceUserRight.push(selectedRows[rowIndex]) + } + } + } else { + this.dataSourceUserRight = selectedRows + } }, // 用户左侧表的复选框状态 getCheckboxPropsUser (record) { @@ -499,14 +525,15 @@ export default { } else { this.$emit('change', this.dataSourceUserRight) } + this.visible = false }, handleCancel () { this.close() }, close () { this.visible = false - this.dataSourceOrgan = [] - this.dataSourceUser = [] + // this.dataSourceOrgan = [] + // this.dataSourceUser = [] this.dataSourceOrganRight = [] this.dataSourceUserRight = [] this.selectedRowKeysOrgan = []