address-book.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <view>
  3. <cu-custom :bgColor="NavBarColor" :isBack="true" backRouterName="index">
  4. <block slot="backText">返回</block>
  5. <block slot="content">通讯录</block>
  6. </cu-custom>
  7. <view class="cu-bar bg-white search fixed" :style="[{top:CustomBar + 'px'}]">
  8. <view class="search-form round">
  9. <text class="cuIcon-search"></text>
  10. <input type="text" v-model="keyword" placeholder="输入搜索的关键词" confirm-type="search" @confirm="searchUserByKey"></input>
  11. </view>
  12. <view class="action">
  13. <button class="cu-btn bg-gradual-blue shadow-blur round" @tap="searchUserByKey">搜索</button>
  14. </view>
  15. </view>
  16. <scroll-view scroll-y class="indexes margin-top-xl" :scroll-into-view="'indexes-'+ listCurID" :style="[{top:'calc('+ CustomBar + 'px - 20px)',height:'calc(100vh - '+ CustomBar + 'px - 70px)'}]"
  17. :scroll-with-animation="true" :enable-back-to-top="true">
  18. <block v-for="(item,index) in list" :key="index">
  19. <view :class="'indexItem-' + item.name" :id="'indexes-' + item.name" :data-index="item.name">
  20. <view class="padding">{{item.name}}</view>
  21. <view class="cu-list menu-avatar no-padding" >
  22. <view class="cu-item" v-for="(items,sub) in userList" :key="sub" v-if="items.szm==item.name" @tap="toAddressDetail(items)">
  23. <view class="cu-avatar round lg" v-if="items.avatar" :style="[{ backgroundImage:'url(' + items.avatar + ')' }]"></view>
  24. <view class="cu-avatar round lg" v-else>{{item.name}}</view>
  25. <view class="content">
  26. <view class="text-grey">{{items.realname?items.realname:items.username}}</view>
  27. <view class="text-gray text-sm">
  28. {{items.orgCode}}
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. </block>
  35. </scroll-view>
  36. <view class="indexBar" :style="[{height:'calc(110vh - ' + CustomBar + 'px - 50px)'}]">
  37. <view class="indexBar-box" @touchstart="tStart" @touchend="tEnd" @touchmove.stop="tMove">
  38. <view class="indexBar-item" v-for="(item,index) in list" :key="index" :id="index" @touchstart="getCur" @touchend="setCur"> {{item.name}}</view>
  39. </view>
  40. </view>
  41. <!--选择显示-->
  42. <view v-show="!hidden" class="indexToast">
  43. {{listCur}}
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. import vPinyin from '@/common/util/vue-py.js';
  49. import {getFileAccessHttpUrl} from '@/api/api.js';
  50. export default {
  51. data() {
  52. return {
  53. StatusBar: this.StatusBar,
  54. CustomBar: this.CustomBar,
  55. hidden: true,
  56. listCurID: '',
  57. list: [],
  58. userList: [],
  59. listCur: '',
  60. keyword: '',
  61. queryUserByKeyWord:'/sys/user/appQueryUser'
  62. };
  63. },
  64. onLoad() {
  65. let list = [{}];
  66. for (let i = 0; i < 26; i++) {
  67. list[i] = {};
  68. list[i].name = String.fromCharCode(65 + i);
  69. }
  70. this.list = list;
  71. this.listCur = list[0];
  72. this.loadInfo()
  73. },
  74. onReady() {
  75. let that = this;
  76. uni.createSelectorQuery().select('.indexBar-box').boundingClientRect(function(res) {
  77. that.boxTop = res.top
  78. }).exec();
  79. uni.createSelectorQuery().select('.indexes').boundingClientRect(function(res) {
  80. that.barTop = res.top
  81. }).exec()
  82. },
  83. methods: {
  84. backTap(){
  85. this.$Router.replace({name:'index'})
  86. },
  87. toAddressDetail(item){
  88. let parmas = {...item}
  89. parmas.departName=parmas.orgCode
  90. this.$Router.push({name: 'addressDetail',params:parmas})
  91. },
  92. searchUserByKey(){
  93. this.loadInfo()
  94. },
  95. loadInfo(){
  96. this.$http.get(this.queryUserByKeyWord,{params:{'keyword':this.keyword}}).then(res=>{
  97. if (res.data.success) {
  98. console.log("res",res)
  99. let arr=res.data.result;
  100. let szuArr=[];
  101. this.userList = arr.map(item => {
  102. let { id,realname,avatar,username,phone,email,post,orgCode} = item
  103. let pinYin = username.toUpperCase();
  104. if(realname){
  105. //TODO 判断汉字的位置
  106. if(/.*[\u4e00-\u9fa5]+.*$/.test(realname)){
  107. pinYin=vPinyin.chineseToPinYin(realname);
  108. }
  109. }
  110. if(avatar){
  111. avatar=getFileAccessHttpUrl(avatar);
  112. }
  113. let event = {
  114. id, realname ,avatar,username,phone,email,post,orgCode,
  115. szm:pinYin.substr(0,1)
  116. }
  117. szuArr.push(event.szm)
  118. return event
  119. })
  120. this.list=this.list.filter(item=>szuArr.indexOf(item.name)!=-1)
  121. //this.list.unshift({name:"#"})
  122. }
  123. }).catch(err => {
  124. console.log(err);
  125. });
  126. },
  127. //获取文字信息
  128. getCur(e) {
  129. this.hidden = false;
  130. this.listCur = this.list[e.target.id].name;
  131. },
  132. setCur(e) {
  133. this.hidden = true;
  134. this.listCur = this.listCur
  135. },
  136. //滑动选择Item
  137. tMove(e) {
  138. let y = e.touches[0].clientY,
  139. offsettop = this.boxTop,
  140. that = this;
  141. //判断选择区域,只有在选择区才会生效
  142. if (y > offsettop) {
  143. let num = parseInt((y - offsettop) / 20);
  144. this.listCur = that.list[num].name
  145. };
  146. },
  147. //触发全部开始选择
  148. tStart() {
  149. this.hidden = false
  150. },
  151. //触发结束选择
  152. tEnd() {
  153. this.hidden = true;
  154. this.listCurID = this.listCur
  155. },
  156. indexSelect(e) {
  157. let that = this;
  158. let barHeight = this.barHeight;
  159. let list = this.list;
  160. let scrollY = Math.ceil(list.length * e.detail.y / barHeight);
  161. for (let i = 0; i < list.length; i++) {
  162. if (scrollY < i + 1) {
  163. that.listCur = list[i].name;
  164. that.movableY = i * 20
  165. return false
  166. }
  167. }
  168. }
  169. }
  170. }
  171. </script>
  172. <style>
  173. page {
  174. padding-top: 100upx;
  175. }
  176. .indexes {
  177. position: relative;
  178. }
  179. .indexBar {
  180. position: fixed;
  181. right: 0px;
  182. bottom: 0px;
  183. padding: 20upx 20upx 20upx 60upx;
  184. display: flex;
  185. align-items: center;
  186. }
  187. .indexBar .indexBar-box {
  188. width: 40upx;
  189. height: auto;
  190. background: #fff;
  191. display: flex;
  192. flex-direction: column;
  193. box-shadow: 0 0 20upx rgba(0, 0, 0, 0.1);
  194. border-radius: 10upx;
  195. }
  196. .indexBar-item {
  197. flex: 1;
  198. width: 40upx;
  199. height: 40upx;
  200. display: flex;
  201. align-items: center;
  202. justify-content: center;
  203. font-size: 24upx;
  204. color: #888;
  205. }
  206. movable-view.indexBar-item {
  207. width: 40upx;
  208. height: 40upx;
  209. z-index: 9;
  210. position: relative;
  211. }
  212. movable-view.indexBar-item::before {
  213. content: "";
  214. display: block;
  215. position: absolute;
  216. left: 0;
  217. top: 10upx;
  218. height: 20upx;
  219. width: 4upx;
  220. background-color: #f37b1d;
  221. }
  222. .indexToast {
  223. position: fixed;
  224. top: 0;
  225. right: 80upx;
  226. bottom: 0;
  227. background: rgba(0, 0, 0, 0.5);
  228. width: 100upx;
  229. height: 100upx;
  230. border-radius: 10upx;
  231. margin: auto;
  232. color: #fff;
  233. line-height: 100upx;
  234. text-align: center;
  235. font-size: 48upx;
  236. }
  237. </style>