8c2786ebfc246ca31f2242686179a89ea99e41ef.svn-base 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <a-modal
  3. :title="title"
  4. :width="450"
  5. :visible="visible"
  6. :closable="false"
  7. :maskClosable="false">
  8. <template slot="footer">
  9. <a-button type="primary" @click="selectOk">确认</a-button>
  10. </template>
  11. <a-form-model>
  12. <a-form-model-item v-if="isMultiTenant" :labelCol="{span:4}" :wrapperCol="{span:20}" style="margin-bottom:10px" :validate-status="validate_status1">
  13. <a-tooltip placement="topLeft" >
  14. <template slot="title">
  15. <span>您有多个租户,请选择登录租户</span>
  16. </template>
  17. <a-avatar style="backgroundColor:#87d068" icon="gold" />
  18. </a-tooltip>
  19. <a-select @change="handleTenantChange" :class="{'valid-error':validate_status1=='error'}" placeholder="请选择登录租户" style="margin-left:10px;width: 80%">
  20. <a-icon slot="suffixIcon" type="gold" />
  21. <a-select-option v-for="d in tenantList" :key="d.id" :value="d.id">
  22. {{ d.name }}
  23. </a-select-option>
  24. </a-select>
  25. </a-form-model-item>
  26. <a-form-model-item v-if="isMultiDepart" :labelCol="{span:4}" :wrapperCol="{span:20}" style="margin-bottom:10px" :validate-status="validate_status2">
  27. <a-tooltip placement="topLeft" >
  28. <template slot="title">
  29. <span>您有多个部门,请选择登录部门</span>
  30. </template>
  31. <a-avatar style="backgroundColor:rgb(104, 208, 203);" icon="gold" />
  32. </a-tooltip>
  33. <a-select @change="handleDepartChange" :class="{'valid-error':validate_status2=='error'}" placeholder="请选择登录部门" style="margin-left:10px;width: 80%">
  34. <a-icon slot="suffixIcon" type="gold" />
  35. <a-select-option v-for="d in departList" :key="d.id" :value="d.orgCode">
  36. {{ d.departName }}
  37. </a-select-option>
  38. </a-select>
  39. </a-form-model-item>
  40. </a-form-model>
  41. </a-modal>
  42. </template>
  43. <script>
  44. import Vue from 'vue'
  45. import { putAction } from '@/api/manage'
  46. import { USER_INFO } from '@/store/mutation-types'
  47. export default {
  48. name: 'LoginSelectTenant',
  49. data(){
  50. return {
  51. visible: false,
  52. isMultiDepart:false,
  53. departList:[],
  54. isMultiTenant:false,
  55. tenantList:[],
  56. username:'',
  57. orgCode:'',
  58. tenant_id:'',
  59. validate_status1: "",
  60. validate_status2: "",
  61. }
  62. },
  63. computed:{
  64. title(){
  65. if(this.isMultiDepart && this.isMultiTenant){
  66. return '请选择租户和部门'
  67. }else if(this.isMultiDepart && !this.isMultiTenant){
  68. return '请选择部门'
  69. }else if(!this.isMultiDepart && this.isMultiTenant){
  70. return '请选择租户'
  71. }
  72. }
  73. },
  74. methods:{
  75. clear(){
  76. this.departList = []
  77. this.tenantList = []
  78. this.visible=false
  79. this.validate_status1=''
  80. this.validate_status2=''
  81. },
  82. bizDepart(loginResult){
  83. let multi_depart = loginResult.multi_depart
  84. //0:无部门 1:一个部门 2:多个部门
  85. if(multi_depart==0){
  86. this.$notification.warn({
  87. message: '提示',
  88. description: `您尚未归属部门,请确认账号信息`,
  89. duration:3
  90. });
  91. this.isMultiDepart = false
  92. }else if(multi_depart==2){
  93. this.visible=true
  94. this.isMultiDepart = true
  95. this.departList = loginResult.departs
  96. }else {
  97. this.isMultiDepart = false
  98. }
  99. },
  100. bizTenantList(loginResult) {
  101. let tenantList = loginResult.tenantList
  102. if (Array.isArray(tenantList)) {
  103. if (tenantList.length === 0) {
  104. this.isMultiTenant = false
  105. } else if (tenantList.length === 1) {
  106. this.tenant_id = tenantList[0].id
  107. this.isMultiTenant = false
  108. } else {
  109. this.visible = true
  110. this.isMultiTenant = true
  111. this.tenantList = tenantList
  112. }
  113. }
  114. },
  115. show(loginResult){
  116. this.clear();
  117. this.bizDepart(loginResult);
  118. let user = Vue.ls.get(USER_INFO)
  119. this.username = user.username
  120. this.bizTenantList(loginResult);
  121. if(this.visible===false){
  122. this.$store.dispatch('saveTenant', this.tenant_id);
  123. this.$emit('success')
  124. }
  125. },
  126. requestFailed (err) {
  127. this.$notification[ 'error' ]({
  128. message: '登录失败',
  129. description: ((err.response || {}).data || {}).message || err.message || "请求出现错误,请稍后再试",
  130. duration: 4,
  131. });
  132. this.loginBtn = false;
  133. },
  134. departResolve(){
  135. return new Promise((resolve, reject)=>{
  136. if(this.isMultiDepart===false){
  137. resolve();
  138. }else{
  139. let obj = {
  140. orgCode:this.orgCode,
  141. username:this.username
  142. }
  143. putAction("/sys/selectDepart",obj).then(res=>{
  144. if(res.success){
  145. const userInfo = res.result.userInfo;
  146. Vue.ls.set(USER_INFO, userInfo, 7 * 24 * 60 * 60 * 1000);
  147. this.$store.commit('SET_INFO', userInfo);
  148. //console.log("---切换组织机构---userInfo-------",store.getters.userInfo.orgCode);
  149. resolve();
  150. }else{
  151. this.requestFailed(res)
  152. this.$store.dispatch('Logout');
  153. reject();
  154. }
  155. })
  156. }
  157. })
  158. },
  159. selectOk(){
  160. if(this.isMultiTenant && !this.tenant_id){
  161. this.validate_status1='error'
  162. return false
  163. }
  164. if(this.isMultiDepart && !this.orgCode){
  165. this.validate_status2='error'
  166. return false
  167. }
  168. this.departResolve().then(()=>{
  169. this.$store.dispatch('saveTenant', this.tenant_id);
  170. if(this.isMultiTenant){
  171. this.$emit('success')
  172. }else{
  173. this.$emit('success')
  174. }
  175. }).catch(()=>{
  176. console.log('登录选择出问题')
  177. })
  178. },
  179. handleTenantChange(e){
  180. this.validate_status1 = ''
  181. this.tenant_id = e
  182. },
  183. handleDepartChange(e){
  184. this.validate_status2 = ''
  185. this.orgCode = e
  186. }
  187. }
  188. }
  189. </script>
  190. <style scoped>
  191. </style>