index.vue 3.61 KB
Newer Older
“lixuyan”'s avatar
“lixuyan” committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
<template>
  <div class="ext-position-user-link-com">
    <el-select
      v-model="bindValue"
      size="small"
      filterable
      multiple
      remote
      value-key="targetId"
      :remote-method="remoteMethod"
      @change="UserChange"
      @remove-tag="removeTag"
    >
      <el-option
        v-for="citem in UserData"
        :key="citem.target.id"
        :label="`${citem.target.name}(${citem.target.userAccount})`"
        :value="citem"
        :disabled="citem.disabled"
      />
    </el-select>
  </div>
</template>

<script>
import { getUsersByAccount } from '@/api/user'
export default {
  name: 'ExtPositionUserLink',
  componentName: '站位长选择',
  components: {},
  props: {
    item: {
      type: Object,
      default: () => {
        return {}
      }
    },
    value: {
      type: Array,
      default: () => {
        return []
      }
jingnan's avatar
jingnan committed
43 44 45 46 47 48
    },
    basicData: {
      type: Object,
      default: () => {
        return {}
      }
“lixuyan”'s avatar
“lixuyan” committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
    }
  },
  data() {
    return {
      bindValue: '',
      UserData: [],
      removeTags: []
    }
  },
  computed: {},
  watch: {
    value: {
      immediate: true,
      deep: true,
      handler: function(val) {
        if (val) {
          if (val !== this.bindValue) {
            this.bindValue = val.filter(r => r.operator !== 'REMOVE')
            this.removeTags = val.filter(r => r.operator === 'REMOVE')
            val.forEach(element => {
              element.disabled = true
            })
            this.UserData = this.bindValue
          }
        }
      }
    }
  },
  methods: {
    remoteMethod(query) {
      if (query) {
        const params = { userAccount: query, containInnerUser: false }
        if (this.item.secret) {
          params.secretCode = this.$store.state.user.userInfo.secretCode
        }
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
        let subTypeName = ''
        switch (this.item.title) {
          case '计划员':
            subTypeName = 'PositionPlanner'
            break
          case '工程师':
            subTypeName = 'PositionEngineer'
            break
          case '站位长':
            subTypeName = 'ExtPositionUserLink'
            break
          case '准备工':
            subTypeName = 'PropareLink'
            break
          default:
            break
        }
“lixuyan”'s avatar
“lixuyan” committed
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
        getUsersByAccount(params).then(res => {
          const arr = []
          this.bindValue.forEach(item => {
            arr.push(item.targetId)
          })
          if (res.items) {
            this.UserData = res.items.map(element => {
              if (arr.includes(element.id)) {
                element.disabled = true
              } else {
                element.disabled = false
              }
              return {
                disabled: element.disabled,
                target: element,
jingnan's avatar
jingnan committed
116
                targetId: element.id,
117
                subTypeName: this.basicData && this.basicData.propareLinks && this.basicData.propareLinks[0] && this.basicData.propareLinks[0].subTypeName || this.basicData.extPositionUserLinks && this.basicData.extPositionUserLinks[0] && this.basicData.extPositionUserLinks[0].subTypeName || subTypeName || ''
“lixuyan”'s avatar
“lixuyan” committed
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
              }
            })
          } else {
            this.UserData = []
          }
        })
      } else {
        this.UserData = []
      }
    },
    UserChange(val) {
      const arr = this.removeTags.concat(val)
      this.$emit('input', arr)
    },
    removeTag(val) {
      if (val.sourceId || val.sourceId === 0) {
        this.removeTags.push({ ...val, operator: 'REMOVE' })
        const arr = this.bindValue.concat(this.removeTags)
        this.$emit('input', arr)
      }
    }
  }
}

</script>
<style lang='scss'>
</style>