level-address-book.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <view>
  3. <view class="cu-bar fixed" :style="style" :class="[NavBarColor]">
  4. <view class="cuIcon-back margin-left" @tap="backRoute()"><text class="margin-left-sm">返回</text></view>
  5. <view class="content" :style="[{top:StatusBar + 'px'}]">
  6. 通讯录
  7. </view>
  8. </view>
  9. <!-- 展示标题 -->
  10. <view class="bg-gray text-gray padding" :style="[{marginTop:CustomBar+'px'}]">
  11. {{ levelTitle }}
  12. </view>
  13. <!-- 展示部门和用户 -->
  14. <view class="cu-list menu sm-border">
  15. <view class="cu-item" v-for="(item, index) in comList" :key="item.key" @tap="goMember(item)">
  16. <image class="line2-icon" src="/static/folder.png"></image>
  17. <view class="content margin-left-sm">
  18. <view class="text-grey">{{item.title}}</view>
  19. </view>
  20. </view>
  21. <view class="cu-item" v-for="(item,index) in childrenUserList" :key="index" @click="goMemberInfo(item)">
  22. <view class="cu-avatar round lx" :style="[{backgroundImage:'url('+ item.avatar +')'}]"></view>
  23. <view class="content margin-left-sm">
  24. <view class="text-grey">{{item.realname}}</view>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. import { getFileAccessHttpUrl } from "../../api/api.js"
  32. export default {
  33. name: "level-address-book",
  34. data(){
  35. return{
  36. CustomBar:this.CustomBar,
  37. StatusBar:this.StatusBar,
  38. NavBarColor:this.NavBarColor,
  39. value:"",
  40. derpartment:'通讯录',
  41. comList:[],
  42. childrenUserList:[],
  43. metaList:[],
  44. depart2Url:'/sys/sysDepart/queryTreeList',
  45. queryTreeByKeyWord:'/sys/sysDepart/queryTreeByKeyWord',
  46. queryUserByDid:'/sys/user/appQueryByDepartId',
  47. // departUrl:'/sys/user/userDepartList',
  48. level:0,
  49. titleArray:[],
  50. parentId:''
  51. }
  52. },
  53. computed:{
  54. levelTitle(){
  55. if(this.titleArray && this.titleArray.length>0){
  56. return this.titleArray.join(' > ')
  57. }
  58. console.log("this.titleArray",this.titleArray)
  59. return '企业通讯录'
  60. },
  61. style() {
  62. var StatusBar= this.StatusBar;
  63. var CustomBar= this.CustomBar;
  64. var style = `height:${CustomBar}px;padding-top:${StatusBar}px;`;
  65. return style
  66. }
  67. },
  68. onLoad() {
  69. console.log("this.CustomBar",this.CustomBar)
  70. this.loadList()
  71. },
  72. methods: {
  73. backRoute() {
  74. console.log("this.level",this.level)
  75. console.log("this.parentId",this.parentId)
  76. if(this.level==0){
  77. // 返回首页
  78. this.$Router.replaceAll({name: 'index'})
  79. }else{
  80. //正常列表的回退 只要找parentId的parent的data
  81. this.getCyclePnode(this.metaList,'');
  82. //还需要设置 title
  83. this.titleArray.pop();
  84. this.level--;
  85. }
  86. },
  87. onRefresh(){
  88. this.comList=[]
  89. this.childrenUserList=[]
  90. this.titleArray=[]
  91. this.loadList()
  92. },
  93. loadList() {
  94. console.log("loadList==>$Route",this.$Route)
  95. if(this.$Route.query.level){
  96. let params=this.$Route.query
  97. this.level=params.level;
  98. this.comList=params.comList;
  99. this.metaList=params.metaList;
  100. this.childrenUserList=params.childrenUserList;
  101. this.derpartment=params.derpartment;
  102. this.parentId=params.parentId;
  103. this.titleArray=params.titleArray;
  104. return;
  105. }
  106. this.$http.get(this.queryTreeByKeyWord).then(res => {
  107. console.log("部门通讯树::", res)
  108. if (res.data.success) {
  109. console.log("部门::", res.data.result.departList)
  110. if(res.data.result.departList && res.data.result.departList.length >0){
  111. for (let item of res.data.result.departList) {
  112. console.log("item::",item);
  113. this.comList.push(item)
  114. this.metaList.push(item)
  115. }
  116. this.derpartment = this.comList[0].title
  117. }
  118. }
  119. }).catch(e => {
  120. console.log("queryTreeByKeyWord 请求错误", e)
  121. })
  122. },
  123. getUser(departId,title){
  124. this.$http.get(this.queryUserByDid,{params:{departId:departId}}).then(res => {
  125. this.childrenUserList=res.data.result;
  126. for(let item of this.childrenUserList){
  127. item.departName=title
  128. this.avatarHandler(item)
  129. }
  130. })
  131. },
  132. avatarHandler(item){
  133. let avatar = item.avatar
  134. if(avatar){
  135. let url = getFileAccessHttpUrl(avatar);
  136. item.avatar = url
  137. }else{
  138. if(item.sex=='2'){
  139. item.avatar = 'https://static.jeecg.com/upload/test/avatar_girl_1595818025488.png';
  140. }else{
  141. item.avatar = 'https://static.jeecg.com/upload/test/avatar_boy_1595818012577.png';
  142. }
  143. }
  144. },
  145. goMember(item){
  146. let params = {...item}
  147. if (params.children && params.children.length>0){
  148. this.level++;
  149. this.comList=[];
  150. this.childrenUserList=[];
  151. for (let item of params.children) {
  152. this.comList.push(item)
  153. }
  154. this.getUser(params.id,params.title)
  155. this.titleArray.push(params.title);
  156. this.parentId = params.id;
  157. this.derpartment = params.title;
  158. }else{
  159. console.log("params==>toMember",params)
  160. params.level=this.level;
  161. params.comList=this.comList;
  162. params.metaList=this.metaList;
  163. params.childrenUserList=this.childrenUserList;
  164. params.derpartment=this.derpartment;
  165. params.parentId=this.parentId;
  166. params.titleArray=this.titleArray;
  167. this.$Router.push({name: 'member',params:params})
  168. }
  169. },
  170. getCyclePnode(arr, pid){
  171. for(let item of arr){
  172. if(item.id == this.parentId){
  173. this.comList = arr;
  174. this.childrenUserList=[];
  175. this.derpartment = this.comList[0].title
  176. this.parentId = pid;
  177. this.getUser(this.parentId,item.title)
  178. break;
  179. }
  180. if(item.children && item.children.length>0){
  181. this.getCyclePnode(item.children, item.id)
  182. }
  183. }
  184. },
  185. goMemberInfo: function (item){
  186. console.log("item",item)
  187. let parmas = {...item}
  188. console.log("parmas",parmas)
  189. parmas.page='levelAddressBook'
  190. this.$Router.push({name: 'addressDetail',params:parmas})
  191. },
  192. }
  193. }
  194. </script>
  195. <style>
  196. .line2-icon {
  197. width: 25px;
  198. height: 20px;
  199. }
  200. </style>