增加替换接口的参数

This commit is contained in:
aixianling
2023-06-27 09:49:10 +08:00
parent cc1026765f
commit 8e0265232b

View File

@@ -83,7 +83,9 @@
<el-scrollbar class="AiWechatSelecter-list"> <el-scrollbar class="AiWechatSelecter-list">
<div class="user-wrapper"> <div class="user-wrapper">
<el-checkbox-group v-model="userIds" @change="onCheckboxChange"> <el-checkbox-group v-model="userIds" @change="onCheckboxChange">
<el-checkbox v-for="item in list" :label="item[props.id]" :key="item[props.id]" @change="e => onboxChange(item[props.id], e)">{{ item.name }}</el-checkbox> <el-checkbox v-for="item in list" :label="item[props.id]" :key="item[props.id]"
@change="e => onboxChange(item[props.id], e)">{{ item.name }}
</el-checkbox>
</el-checkbox-group> </el-checkbox-group>
</div> </div>
<AiEmpty v-if="!list.length"></AiEmpty> <AiEmpty v-if="!list.length"></AiEmpty>
@@ -99,7 +101,9 @@
@size-change="getList" @size-change="getList"
@current-change="getList"> @current-change="getList">
<div class="paginationPre" v-if="isMultiple"> <div class="paginationPre" v-if="isMultiple">
<el-checkbox :disabled="!list.length" :indeterminate="isIndeterminate" @change="onAllChange" v-model="isCheckAll">全选</el-checkbox> <el-checkbox :disabled="!list.length" :indeterminate="isIndeterminate" @change="onAllChange"
v-model="isCheckAll">全选
</el-checkbox>
</div> </div>
</el-pagination> </el-pagination>
</el-scrollbar> </el-scrollbar>
@@ -129,7 +133,7 @@
</template> </template>
<script> <script>
export default { export default {
name: 'AiUserSelecter', name: 'AiUserSelecter',
model: { model: {
prop: 'value', prop: 'value',
@@ -171,7 +175,8 @@
id: 'id' id: 'id'
} }
} }
} },
actions: {default: () => ({})}
}, },
data() { data() {
@@ -204,33 +209,26 @@
}, },
computed: { computed: {
isHasOptionSlot () { isHasOptionSlot() {
return this.$slots.option return this.$slots.option
}, },
isHasSlot () { isHasSlot() {
return this.$slots.default return this.$slots.default
}, },
isIndeterminate () { isIndeterminate() {
const arr = this.chooseUser.filter(v => { const arr = this.chooseUser.filter(v => {
return this.list.map(v => v.id).includes(v.id) return this.list.map(v => v.id).includes(v.id)
}) })
this.isCheckAll = !!(arr.length === this.list.length && this.list.length);
if (arr.length === this.list.length && this.list.length) {
this.isCheckAll = true
} else {
this.isCheckAll = false
}
return arr.length !== 0 && arr.length < this.list.length return arr.length !== 0 && arr.length < this.list.length
}, },
defaultChecked () { defaultChecked() {
if (!this.value) { if (!this.value) {
return [] return []
} }
this.chooseUser = JSON.parse(JSON.stringify(this.value.map(item => { this.chooseUser = JSON.parse(JSON.stringify(this.value.map(item => {
return { return {
...item, ...item,
@@ -242,15 +240,20 @@
}))) })))
return this.value.map(v => v[this.props.id]) return this.value.map(v => v[this.props.id])
} },
action: v => ({
tree: "/app/wxcp/wxdepartment/listAll",
users: `/app/wxcp/wxuser/list`,
...v.actions
})
}, },
watch: { watch: {
unitName (val) { unitName(val) {
this.$refs.tree.filter(val) this.$refs.tree.filter(val)
}, },
isShow (val) { isShow(val) {
if (val) { if (val) {
this.chooseUser = JSON.parse(JSON.stringify(this.value.map(item => { this.chooseUser = JSON.parse(JSON.stringify(this.value.map(item => {
return { return {
@@ -266,14 +269,14 @@
}, },
disabledList: { disabledList: {
handler () { handler() {
this.getList() this.getList()
}, },
deep: true deep: true
} }
}, },
mounted () { mounted() {
this.getTree() this.getTree()
this.getList() this.getList()
@@ -302,12 +305,12 @@
}, },
methods: { methods: {
clearAll () { clearAll() {
this.userIds = [] this.userIds = []
this.chooseUser = [] this.chooseUser = []
}, },
onAllChange (e) { onAllChange(e) {
if (e) { if (e) {
if (!this.chooseUser.length) { if (!this.chooseUser.length) {
this.chooseUser = [ this.chooseUser = [
@@ -329,13 +332,13 @@
this.userIds = this.chooseUser.map(v => v[this.props.id]) this.userIds = this.chooseUser.map(v => v[this.props.id])
}, },
showSelecter () { showSelecter() {
if (this.disabled) return if (this.disabled) return
this.isShow = true this.isShow = true
}, },
onTreeChange (e) { onTreeChange(e) {
this.search.departmentId = e.id || '' this.search.departmentId = e.id || ''
this.search.current = 1 this.search.current = 1
@@ -344,7 +347,7 @@
}) })
}, },
reset () { reset() {
this.isReeset = false this.isReeset = false
this.$nextTick(() => { this.$nextTick(() => {
@@ -352,7 +355,7 @@
}) })
}, },
onboxChange (id, v) { onboxChange(id, v) {
if (!this.isMultiple) { if (!this.isMultiple) {
const checked = this.list.filter(v => v[this.props.id] === id) const checked = this.list.filter(v => v[this.props.id] === id)
if (v) { if (v) {
@@ -369,7 +372,7 @@
} }
}, },
onCheckboxChange (ids) { onCheckboxChange(ids) {
this.$nextTick(() => { this.$nextTick(() => {
const checked = this.list.filter(v => ids.includes(v[this.props.id])) const checked = this.list.filter(v => ids.includes(v[this.props.id]))
const unChecked = this.list.filter(v => !ids.includes(v[this.props.id])) const unChecked = this.list.filter(v => !ids.includes(v[this.props.id]))
@@ -392,22 +395,16 @@
}) })
}, },
arrDeduplication (arr) { arrDeduplication(arr) {
var hash = {} const hash = {};
arr = arr.reduce(function(item, next) { arr = arr.reduce(function (item, next) {
hash[next.id] ? '' : hash[next.id] = true && item.push(next) hash[next.id] = hash[next.id] || item.push(next)
return item return item
}, []) }, [])
return arr return arr
}, },
removeUser(index, item) {
onCheckChange (e, isChoosed, isSunChoosed) {
this.$nextTick(() => {
})
},
removeUser (index, item) {
this.chooseUser.splice(index, 1) this.chooseUser.splice(index, 1)
this.userIds.splice(this.userIds.findIndex(v => v === item.id), 1) this.userIds.splice(this.userIds.findIndex(v => v === item.id), 1)
@@ -438,7 +435,7 @@
getList() { getList() {
this.loading = true this.loading = true
this.instance.post(`/app/wxcp/wxuser/list`, null, { this.instance.post(this.action.users, null, {
params: { params: {
...this.search, ...this.search,
departmentId: this.search.departmentId, departmentId: this.search.departmentId,
@@ -471,27 +468,20 @@
}) })
}, },
getTree () { getTree() {
this.instance.post(`/app/wxcp/wxdepartment/listAll?unitName=${this.unitName}`).then(res => { this.instance.post(this.action.tree, null, {
if (res.code === 0) { params: {unitName: this.unitName}
let parent = res.data.map(v => { }).then(res => {
v.label = v.name if (res?.data) {
v.children = [] this.unitList = this.$arr2tree(res.data)
const defaultRoot = this.unitList.at(0)?.id
return v this.defaultExpanded = [defaultRoot].filter(Boolean) || []
}).filter(e => !e.parentid)[0] this.search.departmentId = defaultRoot
if (!this.defaultExpanded.length) {
this.defaultExpanded = [parent.id]
}
this.search.departmentId = parent.id
this.addChild(parent, res.data)
this.unitList = [parent]
} }
}) })
}, },
onClose (item, index) { onClose(item, index) {
this.chooseUser.splice(index, 1) this.chooseUser.splice(index, 1)
this.userIds.splice(this.userIds.findIndex(v => v === item.id), 1) this.userIds.splice(this.userIds.findIndex(v => v === item.id), 1)
@@ -506,7 +496,7 @@
return data.name.indexOf(value) !== -1 return data.name.indexOf(value) !== -1
}, },
onConfirm () { onConfirm() {
if (!this.isMultiple && this.chooseUser.length > 1) { if (!this.isMultiple && this.chooseUser.length > 1) {
return this.$message.error('不能多选') return this.$message.error('不能多选')
} }
@@ -524,11 +514,11 @@
this.isShow = false this.isShow = false
} }
} }
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.AiWechatSelecter { .AiWechatSelecter {
box-sizing: border-box; box-sizing: border-box;
.AiWechatSelecter-userlist { .AiWechatSelecter-userlist {
@@ -615,9 +605,9 @@
} }
} }
} }
} }
.AiWechatSelecter-container { .AiWechatSelecter-container {
display: flex; display: flex;
height: 480px; height: 480px;
@@ -636,6 +626,7 @@
margin-bottom: 0; margin-bottom: 0;
} }
} }
img { img {
width: 27px; width: 27px;
height: 27px; height: 27px;
@@ -643,7 +634,7 @@
} }
} }
:deep( .el-tree ){ :deep( .el-tree ) {
width: fit-content; width: fit-content;
min-width: 100%; min-width: 100%;
background: transparent; background: transparent;
@@ -711,7 +702,7 @@
cursor: pointer; cursor: pointer;
user-select: none; user-select: none;
:deep( .el-checkbox__label ){ :deep( .el-checkbox__label ) {
display: none; display: none;
} }
@@ -742,8 +733,8 @@
height: calc(100% - 40px); height: calc(100% - 40px);
padding: 8px 0; padding: 8px 0;
:deep( .el-scrollbar__wrap ){ :deep( .el-scrollbar__wrap ) {
margin-bottom: 0!important; margin-bottom: 0 !important;
overflow-x: hidden; overflow-x: hidden;
} }
} }
@@ -751,7 +742,7 @@
.AiWechatSelecter-container__left { .AiWechatSelecter-container__left {
flex: 1; flex: 1;
:deep( .el-scrollbar__wrap ){ :deep( .el-scrollbar__wrap ) {
overflow-x: auto; overflow-x: auto;
} }
} }
@@ -764,10 +755,10 @@
.user-wrapper { .user-wrapper {
position: relative; position: relative;
padding-bottom: 40px!important; padding-bottom: 40px !important;
} }
:deep( .el-pagination ){ :deep( .el-pagination ) {
position: absolute; position: absolute;
bottom: 0px; bottom: 0px;
left: 0; left: 0;
@@ -779,6 +770,7 @@
justify-content: flex-end; justify-content: flex-end;
background: #fcfcfc; background: #fcfcfc;
padding: 10px 10px; padding: 10px 10px;
.paginationPre { .paginationPre {
display: flex; display: flex;
align-items: center; align-items: center;
@@ -824,7 +816,7 @@
.user-wrapper { .user-wrapper {
padding: 0 10px; padding: 0 10px;
:deep( .el-checkbox ){ :deep( .el-checkbox ) {
display: block; display: block;
margin-right: 0; margin-right: 0;
} }
@@ -839,6 +831,7 @@
.tags-wrapper { .tags-wrapper {
padding: 0 8px; padding: 0 8px;
} }
.el-tag { .el-tag {
margin: 0 8px 8px 0px; margin: 0 8px 8px 0px;
color: #222222; color: #222222;
@@ -896,5 +889,5 @@
text-align: center; text-align: center;
} }
} }
} }
</style> </style>