123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <template>
- <el-select
- v-model="searchValue"
- filterable
- :clearable="clearable"
- remote
- :multiple="multiple"
- :remote-method="remoteMethod"
- :loading="loading"
- :size="size"
- :placeholder="placeholder"
- :disabled="disabled"
- @change="changeSelect"
- >
- <el-option
- v-for="item in options"
- :key="item.idap"
- :label="item.name"
- :value="item.idap"
- @click.native="$emit('memberData', item)"
- >
- <div class="item-style">
- <div class="item-detail">{{ item.deptName }}</div>
- <div style="min-width:80px">{{ item.name }}</div>
- <div class="item-detail">{{ item.idap }}</div>
- </div>
- </el-option>
- </el-select>
- </template>
- <script>
- import { memberQueryMemberInfoByIDAPorName } from '@/api/projectIndex'
- export default {
- props: {
- value: {
- type: [String, Array, Object],
- default: '',
- required: false
- },
- placeholder: {
- type: String,
- default: '请输入姓名或邮箱前缀',
- required: false
- },
- size: {
- type: String,
- default: 'small',
- required: false
- },
- multiple: {
- type: Boolean,
- default: false,
- required: false
- },
- disabled: {
- type: Boolean,
- default: false,
- required: false
- },
- clearable: { // 是否支持清空
- type: Boolean,
- default: true,
- required: false
- }
- },
- data() {
- return {
- searchValue: this.value,
- loading: false,
- memberObj: {},
- options: [],
- firstGetArr: true // 是否第一次获取数组
- }
- },
- watch: {
- value: {
- handler(newV, oldV) {
- if (this.searchValue === newV) {
- return
- }
- if (newV === null) {
- this.multiple ? this.searchValue = [] : this.searchValue = ''
- } else {
- this.searchValue = newV
- }
- const type = Object.prototype.toString.call(this.searchValue)
- if (type.indexOf('Array') < 0) {
- this.remoteMethod(this.searchValue)
- } else if (type.indexOf('Array') > 0 && this.searchValue.length > 0 && this.firstGetArr) {
- this.initMore(this.searchValue)
- this.firstGetArr = false
- }
- },
- immediate: true
- }
- },
- mounted() {
- this.initMore(this.searchValue)
- },
- methods: {
- remoteMethod(query) {
- query !== '' ? this.getMember(query) : this.options = []
- },
- initMore(arr) { // 当多人时候,对数组每一个人员进行搜索
- for (const item of arr) {
- this.getMember(item, true)
- }
- },
- async getMember(query, initMore = false) {
- const res = await memberQueryMemberInfoByIDAPorName({ memberIDAP: query })
- if (res.data === null) {
- return
- }
- this.loading = false
- const weakMap = new Map()
- for (const item of res.data) {
- if (!weakMap.has(item.idap)) {
- weakMap.set(item.idap, item)
- }
- }
- initMore ? this.options = [...this.options, ...weakMap.values()] : this.options = [...weakMap.values()]
- },
- changeSelect(e) {
- if (this.searchValue === [] || this.searchValue === '') {
- this.searchValue = null
- }
- this.$emit('update:value', this.searchValue)
- if (this.multiple) {
- this.$emit('change', this.searchValue)
- } else {
- const confirm = this.options.find(item => item.idap === e)
- this.$emit('change', confirm)
- }
- }
- }
- }
- </script>
- <style scoped lang="scss">
- .item-style {
- display: flex;
- justify-content: flex-start;
- .item-detail {
- min-width:100px;
- color: #8492a6;
- font-size: 13px;
- overflow:hidden
- }
- }
- </style>
|