Blame view

ant-design-vue-jeecg/src/components/tools/DepartSelect.vue 4.11 KB
肖超群 authored
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<template>
  <a-modal
    :title="currTitle"
    :width="450"
    :visible="visible"
    :closable="false"
    :maskClosable="closable">
    <template slot="footer">
      <a-button v-if="closable" @click="close">关闭</a-button>
      <a-button type="primary" @click="departOk">确认</a-button>
    </template>

    <a-form>
      <a-form-item
        :labelCol="{span:4}"
        :wrapperCol="{span:20}"
        style="margin-bottom:10px"
        :validate-status="validate_status">
肖超群 authored
19
        <a-tooltip placement="topLeft">
肖超群 authored
20
21
22
          <template slot="title">
            <span>您隶属于多部门,请选择当前所在部门</span>
          </template>
肖超群 authored
23
          <a-avatar style="backgroundColor:#87d068" icon="gold"/>
肖超群 authored
24
        </a-tooltip>
肖超群 authored
25
26
27
        <a-select v-model="departSelected" :class="{'valid-error':validate_status=='error'}" placeholder="请选择登录部门"
                  style="margin-left:10px;width: 80%">
          <a-icon slot="suffixIcon" type="gold"/>
肖超群 authored
28
29
30
31
32
33
34
35
36
37
38
39
          <a-select-option
            v-for="d in departList"
            :key="d.id"
            :value="d.orgCode">
            {{ d.departName }}
          </a-select-option>
        </a-select>
      </a-form-item>
    </a-form>


  </a-modal>
肖超群 authored
40
肖超群 authored
41
42
43
</template>

<script>
肖超群 authored
44
45
46
47
import {getAction, putAction} from '@/api/manage'
import Vue from 'vue'
import store from '@/store/'
import {USER_INFO} from "@/store/mutation-types"
肖超群 authored
48
肖超群 authored
49
50
51
52
53
54
55
export default {
  name: 'DepartSelect',
  props: {
    title: {
      type: String,
      default: "部门选择",
      required: false
肖超群 authored
56
    },
肖超群 authored
57
58
59
60
    closable: {
      type: Boolean,
      default: false,
      required: false
肖超群 authored
61
    },
肖超群 authored
62
63
64
65
66
67
68
69
70
71
    username: {
      type: String,
      default: "",
      required: false
    }
  },
  watch: {
    username(val) {
      if (val) {
        this.loadDepartList()
肖超群 authored
72
      }
肖超群 authored
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
    }
  },
  data() {
    return {
      currTitle: this.title,
      visible: false,
      departList: [],
      departSelected: "",
      validate_status: "",
      currDepartName: "",
    }
  },
  created() {
    //this.loadDepartList()
  },
  methods: {
    loadDepartList() {
      return new Promise(resolve => {
        let url = "/sys/user/getCurrentUserDeparts"
        this.currDepartName = ''
        getAction(url).then(res => {
          if (res.success) {
            let departs = res.result.list
            let orgCode = res.result.orgCode
            if (departs && departs.length > 0) {
              for (let i of departs) {
                if (i.orgCode == orgCode) {
                  this.currDepartName = i.departName
                  break
肖超群 authored
102
103
104
                }
              }
            }
肖超群 authored
105
106
107
108
109
110
111
112
            this.departSelected = orgCode
            this.departList = departs
            if (this.currDepartName) {
              this.currTitle = "部门切换(当前部门 : " + this.currDepartName + ")"
            }

          }
          resolve()
肖超群 authored
113
        })
肖超群 authored
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
      })
    },
    close() {
      this.departClear()
    },
    departOk() {
      if (!this.departSelected) {
        this.validate_status = 'error'
        return false
      }
      let obj = {
        orgCode: this.departSelected,
        username: this.username
      }
      putAction("/sys/selectDepart", obj).then(res => {
        if (res.success) {
          const userInfo = res.result.userInfo;
          Vue.ls.set(USER_INFO, userInfo, 7 * 24 * 60 * 60 * 1000);
          store.commit('SET_INFO', userInfo);
          //console.log("---切换组织机构---userInfo-------",store.getters.userInfo.orgCode);
          this.departClear()
肖超群 authored
135
        }
肖超群 authored
136
137
138
      })
    },
    show() {
139
140
141
142
143
144
145
146
      // 如果组件传值username此处就不用loadDepartList了
      // this.loadDepartList().then(() => {
      //   this.visible = true
      //   if (!this.departList || this.departList.length <= 0) {
      //     this.$message.warning("您尚未设置部门信息!")
      //     this.departClear()
      //   }
      // })
肖超群 authored
147
148
149
150
151
152
153
154
    },
    departClear() {
      this.departList = []
      this.departSelected = ""
      this.visible = false
      this.validate_status = ''
      this.currDepartName = ""
    },
肖超群 authored
155
  }
肖超群 authored
156
157

}
肖超群 authored
158
159
</script>
<style scoped>
肖超群 authored
160
161
162
.valid-error .ant-select-selection__placeholder {
  color: #f5222d;
}
肖超群 authored
163
</style>