|
@@ -6,7 +6,6 @@
|
|
ref="select"
|
|
ref="select"
|
|
placeholder="请选择"
|
|
placeholder="请选择"
|
|
clearable
|
|
clearable
|
|
- filterable
|
|
|
|
remote
|
|
remote
|
|
multiple
|
|
multiple
|
|
:disabled="disabled"
|
|
:disabled="disabled"
|
|
@@ -27,121 +26,102 @@
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script>
|
|
<script>
|
|
- export default {
|
|
|
|
- name: 'user-components',
|
|
|
|
- props: {
|
|
|
|
- userIds: {
|
|
|
|
- type: Array,
|
|
|
|
- default: () => []
|
|
|
|
- },
|
|
|
|
- disabled: {
|
|
|
|
- type: Boolean,
|
|
|
|
- default: false
|
|
|
|
- }
|
|
|
|
|
|
+import {selectUsers} from '@/api/user'
|
|
|
|
+export default {
|
|
|
|
+ name: 'user-components',
|
|
|
|
+ props: {
|
|
|
|
+ userIds: {
|
|
|
|
+ type: Array,
|
|
|
|
+ default: () => []
|
|
},
|
|
},
|
|
- data () {
|
|
|
|
- return {
|
|
|
|
- value: [],
|
|
|
|
- current: 1,
|
|
|
|
- size: 10,
|
|
|
|
- name: '',
|
|
|
|
- options: [],
|
|
|
|
- loading: false,
|
|
|
|
- noMore: false
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- watch: {
|
|
|
|
- userIds (value) {
|
|
|
|
- this.value = value
|
|
|
|
- // 检查缺失item
|
|
|
|
- this.checkItems(value)
|
|
|
|
- }
|
|
|
|
|
|
+ disabled: {
|
|
|
|
+ type: Boolean,
|
|
|
|
+ default: false
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ data () {
|
|
|
|
+ return {
|
|
|
|
+ value: [],
|
|
|
|
+ current: 1,
|
|
|
|
+ size: 10,
|
|
|
|
+ name: '',
|
|
|
|
+ options: [],
|
|
|
|
+ loading: false,
|
|
|
|
+ noMore: false
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ watch: {
|
|
|
|
+ userIds (value) {
|
|
|
|
+ this.value = value
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ mounted () {
|
|
|
|
+ this.init()
|
|
|
|
+ },
|
|
|
|
+ methods: {
|
|
|
|
+ async init () {
|
|
|
|
+ this.getList()
|
|
},
|
|
},
|
|
- mounted () {
|
|
|
|
- this.init()
|
|
|
|
|
|
+ remoteMethod (query) {
|
|
|
|
+ this.options = []
|
|
|
|
+ this.current = 1
|
|
|
|
+ this.name = query
|
|
|
|
+ this.getList()
|
|
},
|
|
},
|
|
- methods: {
|
|
|
|
- async init () {
|
|
|
|
- this.getList()
|
|
|
|
- },
|
|
|
|
- remoteMethod (query) {
|
|
|
|
- this.options = []
|
|
|
|
- this.current = 1
|
|
|
|
- this.name = query
|
|
|
|
- this.getList()
|
|
|
|
- },
|
|
|
|
- getList () {
|
|
|
|
- this.$http({
|
|
|
|
- url: this.$http.adornUrl(`/user-service/user/list`),
|
|
|
|
- method: 'get',
|
|
|
|
- params: this.$http.adornParams({
|
|
|
|
- 'current': this.current,
|
|
|
|
- 'size': this.size,
|
|
|
|
- 'name': this.name
|
|
|
|
- })
|
|
|
|
- }).then(({data}) => {
|
|
|
|
- if (data && data.code === '200') {
|
|
|
|
- if (this.current > data.data.pages) {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- // this.noMore = data.data.records.length >= 10
|
|
|
|
- data.data.records.forEach(item => {
|
|
|
|
- this.options.push({
|
|
|
|
- label: item.name + ' (' + item.orgName + ')',
|
|
|
|
- value: item.userId
|
|
|
|
- })
|
|
|
|
|
|
+ getList () {
|
|
|
|
+ selectUsers({current: this.current, size: this.size, userIds: this.userIds}).then(({data}) => {
|
|
|
|
+ if (data && data.code === '200') {
|
|
|
|
+ // 获取已选用户
|
|
|
|
+ if (data.data.selectedItems) {
|
|
|
|
+ data.data.selectedItems.forEach(item => {
|
|
|
|
+ let i = this.options.findIndex(i => i.value === item.userId)
|
|
|
|
+ if (i === -1) {
|
|
|
|
+ this.options.push({
|
|
|
|
+ label: item.name + ' (' + item.orgName + ')',
|
|
|
|
+ value: item.userId
|
|
|
|
+ })
|
|
|
|
+ }
|
|
})
|
|
})
|
|
- } else {
|
|
|
|
- this.options = []
|
|
|
|
}
|
|
}
|
|
- })
|
|
|
|
- },
|
|
|
|
- handleClick () {
|
|
|
|
- this.loadMore()
|
|
|
|
- },
|
|
|
|
- loadMore () {
|
|
|
|
- this.current ++
|
|
|
|
- this.getList()
|
|
|
|
- },
|
|
|
|
- checkItem (code) {
|
|
|
|
- if (!code || !this.options) return
|
|
|
|
- let i = this.options.findIndex(item => item.value === code)
|
|
|
|
- if (i > -1) return
|
|
|
|
- // info
|
|
|
|
- this.$http({
|
|
|
|
- url: this.$http.adornUrl(`/user-service/user/info/${code}`),
|
|
|
|
- method: 'get'
|
|
|
|
- }).then(({data}) => {
|
|
|
|
- if (data && data.code === '200' && data.data) {
|
|
|
|
|
|
+ // 获取分页数据
|
|
|
|
+ if (!data.data.pageUsers || data.data.pageUsers.pages < this.current) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ this.noMore = data.data.pageUsers.records.length >= 10
|
|
|
|
+ data.data.pageUsers.records.forEach(item => {
|
|
this.options.push({
|
|
this.options.push({
|
|
- label: data.data.name + ' (' + data.data.orgName + ')',
|
|
|
|
- value: data.data.userId
|
|
|
|
|
|
+ label: item.name + ' (' + item.orgName + ')',
|
|
|
|
+ value: item.userId
|
|
})
|
|
})
|
|
- }
|
|
|
|
- })
|
|
|
|
- },
|
|
|
|
- checkItems (ids) {
|
|
|
|
- if (!ids) return
|
|
|
|
- ids.forEach(id => {
|
|
|
|
- this.checkItem(id)
|
|
|
|
- })
|
|
|
|
- },
|
|
|
|
- onChange (item) {
|
|
|
|
- this.$emit('change', item)
|
|
|
|
- },
|
|
|
|
- cancelReadOnly (onOff) {
|
|
|
|
- this.$nextTick(() => {
|
|
|
|
- if (!onOff) {
|
|
|
|
- const input = this.$refs.select.$el.querySelector('.el-input__inner')
|
|
|
|
- const timer = setTimeout(() => {
|
|
|
|
- input.removeAttribute('readonly')
|
|
|
|
- clearTimeout(timer)
|
|
|
|
- }, 200)
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
|
|
+ })
|
|
|
|
+ } else {
|
|
|
|
+ this.options = []
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ handleClick () {
|
|
|
|
+ this.loadMore()
|
|
|
|
+ },
|
|
|
|
+ loadMore () {
|
|
|
|
+ this.current ++
|
|
|
|
+ this.getList()
|
|
|
|
+ },
|
|
|
|
+ onChange (item) {
|
|
|
|
+ this.$emit('change', item)
|
|
|
|
+ },
|
|
|
|
+ cancelReadOnly (onOff) {
|
|
|
|
+ this.$nextTick(() => {
|
|
|
|
+ if (!onOff) {
|
|
|
|
+ const input = this.$refs.select.$el.querySelector('.el-input__inner')
|
|
|
|
+ const timer = setTimeout(() => {
|
|
|
|
+ input.removeAttribute('readonly')
|
|
|
|
+ clearTimeout(timer)
|
|
|
|
+ }, 200)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+}
|
|
</script>
|
|
</script>
|
|
|
|
|
|
<style scoped>
|
|
<style scoped>
|