addressbook.vue 5.3 KB

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