d0921dd0cb48db4c3fa16279172b41e3091f6f93.svn-base 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <a-modal
  3. :title="currTitle"
  4. :width="450"
  5. :visible="visible"
  6. :closable="false"
  7. :maskClosable="closable">
  8. <template slot="footer">
  9. <a-button v-if="closable" @click="close">关闭</a-button>
  10. <a-button type="primary" @click="departOk">确认</a-button>
  11. </template>
  12. <a-form>
  13. <a-form-item
  14. :labelCol="{span:4}"
  15. :wrapperCol="{span:20}"
  16. style="margin-bottom:10px"
  17. :validate-status="validate_status">
  18. <a-tooltip placement="topLeft" >
  19. <template slot="title">
  20. <span>您隶属于多部门,请选择当前所在部门</span>
  21. </template>
  22. <a-avatar style="backgroundColor:#87d068" icon="gold" />
  23. </a-tooltip>
  24. <a-select v-model="departSelected" :class="{'valid-error':validate_status=='error'}" placeholder="请选择登录部门" style="margin-left:10px;width: 80%">
  25. <a-icon slot="suffixIcon" type="gold" />
  26. <a-select-option
  27. v-for="d in departList"
  28. :key="d.id"
  29. :value="d.orgCode">
  30. {{ d.departName }}
  31. </a-select-option>
  32. </a-select>
  33. </a-form-item>
  34. </a-form>
  35. </a-modal>
  36. </template>
  37. <script>
  38. import { getAction,putAction } from '@/api/manage'
  39. import Vue from 'vue'
  40. import store from '@/store/'
  41. import { USER_INFO } from "@/store/mutation-types"
  42. export default {
  43. name: 'DepartSelect',
  44. props:{
  45. title:{
  46. type:String,
  47. default:"部门选择",
  48. required:false
  49. },
  50. closable:{
  51. type:Boolean,
  52. default:false,
  53. required:false
  54. },
  55. username:{
  56. type:String,
  57. default:"",
  58. required:false
  59. }
  60. },
  61. watch:{
  62. username(val){
  63. if(val){
  64. this.loadDepartList()
  65. }
  66. }
  67. },
  68. data(){
  69. return {
  70. currTitle:this.title,
  71. visible:false,
  72. departList:[],
  73. departSelected:"",
  74. validate_status:"",
  75. currDepartName:"",
  76. }
  77. },
  78. created(){
  79. //this.loadDepartList()
  80. },
  81. methods:{
  82. loadDepartList(){
  83. return new Promise(resolve => {
  84. let url = "/sys/user/getCurrentUserDeparts"
  85. this.currDepartName=''
  86. getAction(url).then(res=>{
  87. if(res.success){
  88. let departs = res.result.list
  89. let orgCode = res.result.orgCode
  90. if(departs && departs.length>0){
  91. for(let i of departs){
  92. if(i.orgCode == orgCode){
  93. this.currDepartName = i.departName
  94. break
  95. }
  96. }
  97. }
  98. this.departSelected = orgCode
  99. this.departList = departs
  100. if(this.currDepartName){
  101. this.currTitle ="部门切换(当前部门 : "+this.currDepartName+")"
  102. }
  103. }
  104. resolve()
  105. })
  106. })
  107. },
  108. close(){
  109. this.departClear()
  110. },
  111. departOk(){
  112. if(!this.departSelected){
  113. this.validate_status='error'
  114. return false
  115. }
  116. let obj = {
  117. orgCode:this.departSelected,
  118. username:this.username
  119. }
  120. putAction("/sys/selectDepart",obj).then(res=>{
  121. if(res.success){
  122. const userInfo = res.result.userInfo;
  123. Vue.ls.set(USER_INFO, userInfo, 7 * 24 * 60 * 60 * 1000);
  124. store.commit('SET_INFO', userInfo);
  125. //console.log("---切换组织机构---userInfo-------",store.getters.userInfo.orgCode);
  126. this.departClear()
  127. }
  128. })
  129. },
  130. show(){
  131. //如果组件传值username此处就不用loadDepartList了
  132. this.loadDepartList().then(()=>{
  133. this.visible=true
  134. if(!this.departList || this.departList.length<=0){
  135. this.$message.warning("您尚未设置部门信息!")
  136. this.departClear()
  137. }
  138. })
  139. },
  140. departClear(){
  141. this.departList=[]
  142. this.departSelected=""
  143. this.visible=false
  144. this.validate_status=''
  145. this.currDepartName=""
  146. },
  147. }
  148. }
  149. </script>
  150. <style scoped>
  151. .valid-error .ant-select-selection__placeholder{
  152. color: #f5222d;
  153. }
  154. </style>