addressbook.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <view class="main">
  3. <cu-custom bgColor="bg-blue_default">
  4. <block slot="content">通讯录</block>
  5. </cu-custom>
  6. <view class=" text-center flex tab-custom" style="height: 45px;line-height: 45px;">
  7. <u-tabs :list="list" @click="changeParent" lineWidth="30" lineHeight="1" lineColor="#ffffff" :activeStyle="{
  8. color: '#ffffff',
  9. fontWeight: 'bold',
  10. transform: 'scale(1.05)'
  11. }" :inactiveStyle="{
  12. color: '#fff',
  13. transform: 'scale(1)'
  14. }" itemStyle=" height: 34px;"></u-tabs>
  15. </view>
  16. <!-- <view class="tree">
  17. <ly-tree :tree-data="officeList" :props="props" node-key="id" :checkOnClickNode="true" :showRadio="false"
  18. :show-checkbox="false" :checkOnlyLeaf="false" ref="officeTree" />
  19. </view> -->
  20. <view>
  21. <u-cell-group class="cell_group__title" v-for="(item, index) in indexList" :key="index"
  22. :title="indexList[index].name">
  23. <u-cell class="book_info" v-for="user in getUser(indexList[index].id)">
  24. <view class="book_info_title" slot="title">
  25. {{user.name}}
  26. </view>
  27. <u-avatar v-if="user.photo!=''" slot="icon" shape="circle" size="40" :src="BASE_URL + user.photo"
  28. customStyle="margin: -3px 5px -3px 0"></u-avatar>
  29. <u-avatar v-else slot="icon" shape="circle" size="35" src="../../static/img/avatar.png"
  30. customStyle="margin: -3px 5px -3px 0"></u-avatar>
  31. <view v-if="user.mobile || user.phone" class="ellipsis-description text-gray" slot="label">
  32. {{user.mobile + ' ' + user.phone}}
  33. </view>
  34. <view v-if="user.mobile || user.phone" class="flex" slot="value">
  35. <u-icon @click="toPhone(user)" size="30" style="margin-right: 10px;" name="../../static/img/icon_dh.png"></u-icon>
  36. <u-icon @click="copyPhone(user)" v-if="user.mobile || user.phone" size="30"
  37. name="../../static/img/icon_fz.png"></u-icon>
  38. </view>
  39. </u-cell>
  40. </u-cell-group>
  41. </view>
  42. <u-modal :show="show" title="选择号码" :showConfirmButton="false" :showCancelButton="true" @cancel="show = false">
  43. <view class="slot-content">
  44. <view v-for="(item,index) in phones" :key="index">
  45. <view @click="toPhone(item)" class="modal_content">{{item}}</view>
  46. </view>
  47. </view>
  48. </u-modal>
  49. <u-overlay :show="loading">
  50. <view class="warp">
  51. <view class="rect"><u-button plain loading loadingText="加载中"></u-button></view>
  52. </view>
  53. </u-overlay>
  54. </view>
  55. </template>
  56. <script>
  57. import userService from '@/api/sys/userService'
  58. import officeService from "@/api/sys/officeService"
  59. import BASE_URL from '@/config.js'
  60. export default {
  61. data() {
  62. return {
  63. loading: true,
  64. show: false,
  65. indexList: [],
  66. officeList: [],
  67. userList: [],
  68. total: 0,
  69. searchUserName: '',
  70. list: [],
  71. phones: [],
  72. }
  73. },
  74. props: {
  75. props: {
  76. type: Object,
  77. default: () => {
  78. return {
  79. children: 'children',
  80. label: 'name'
  81. }
  82. }
  83. }
  84. },
  85. created() {
  86. officeService.treeData().then(data => {
  87. this.officeList = data
  88. this.list = this.officeList.filter((item) => {
  89. if (item.type == "1") {
  90. return true
  91. }
  92. })
  93. this.list.sort((a, b) => b.name.localeCompare(a.name) || b.name.localeCompare(a
  94. .name));
  95. userService.list({
  96. current: 1,
  97. size: 10000
  98. }).then((res) => {
  99. this.userList = res.records
  100. this.indexList = this.list[0].children
  101. this.total = res.total
  102. this.loading = false
  103. }).catch((e) => {
  104. throw e
  105. })
  106. })
  107. },
  108. methods: {
  109. // 切换部门
  110. changeParent(e) {
  111. this.indexList = e.children
  112. },
  113. // 获取用户
  114. getUser(id) {
  115. let b = this.userList.filter(item => item.officeDTO && item.officeDTO.id == id)
  116. return b
  117. },
  118. // 打电话
  119. toPhone(user) {
  120. if (user.mobile || user.phone) {
  121. if (user.mobile != '' && user.phone == '') {
  122. uni.makePhoneCall({
  123. phoneNumber: user.mobile //仅为示例
  124. });
  125. } else if (user.mobile == '' && user.phone != '') {
  126. uni.makePhoneCall({
  127. phoneNumber: user.phone //仅为示例
  128. });
  129. } else if (user.mobile != '' && user.phone != '') {
  130. this.phones = []
  131. this.phones.push(user.mobile)
  132. this.phones.push(user.phone)
  133. this.show = true
  134. }
  135. } else {
  136. this.show = false
  137. uni.makePhoneCall({
  138. phoneNumber: user //仅为示例
  139. });
  140. }
  141. },
  142. // 复制号码
  143. copyPhone(user) {
  144. uni.setClipboardData({
  145. data: user.phone + " " + user.mobile,
  146. success: function() {
  147. uni.showToast({
  148. title: '复制成功',
  149. icon: 'success'
  150. });
  151. }
  152. });
  153. },
  154. }
  155. }
  156. </script>
  157. <style lang="scss">
  158. .warp {
  159. display: flex;
  160. align-items: center;
  161. justify-content: center;
  162. height: 100%;
  163. }
  164. .book_info {
  165. background-color: #fefefe;
  166. }
  167. .book_info .cell_group__title span {
  168. // background-color: #ededed;
  169. font-size: 18px !important;
  170. }
  171. .book_info .ellipsis-description {
  172. font-size: 12px !important;
  173. margin-top: 10px;
  174. }
  175. .main .tab-custom {
  176. justify-content: center;
  177. align-items: center;
  178. background-color: #36a7f3;
  179. }
  180. .main .modal_content {
  181. height: 40px;
  182. line-height: 40px;
  183. border-bottom: 1px solid #ededed;
  184. z-index: 10;
  185. }
  186. .book_info_title {
  187. color: #21b7fc;
  188. }
  189. .list {
  190. &__item {
  191. @include flex;
  192. padding: 6px 12px;
  193. align-items: center;
  194. &__avatar {
  195. height: 35px;
  196. width: 35px;
  197. border-radius: 3px;
  198. }
  199. &__user-name {
  200. font-size: 16px;
  201. margin-left: 10px;
  202. color: $u-main-color;
  203. }
  204. }
  205. &__footer {
  206. color: $u-tips-color;
  207. font-size: 14px;
  208. text-align: center;
  209. margin: 15px 0;
  210. }
  211. }
  212. </style>