phone-search-list.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <view class="page">
  3. <view class="header">
  4. <view class="input-view">
  5. <uni-icon type="search" size="22" color="#666666"></uni-icon>
  6. <input class="input" type="text" placeholder="输入要搜索的联系人" @input="handleInput" :focus="true" />
  7. </view>
  8. </view>
  9. <view class="search-main" v-if="keyword">
  10. <view class="search-main-errtitle" v-if="hasNoData">无搜索结果</view>
  11. <view class="uni-list">
  12. <view class="uni-list-cell" hover-class="none" v-for="(item,index) of list" @tap="goDetails(item.user_id)" :key="index">
  13. <view class="uni-media-list">
  14. <view class="uni-media-list-logo">
  15. <image :src="staticPhoto + item.photo" :lazy-load="true"></image>
  16. </view>
  17. <view class="uni-media-list-body">
  18. <view class="uni-list-cell-navigate">{{item.name}}</view>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import uniIcon from '../../components/uni-ui/uni-icon/uni-icon.vue';
  28. import _get from '../../common/_get';
  29. import _hook from '../../common/_hook';
  30. import _data from '../../common/_data';
  31. export default {
  32. components:{
  33. uniIcon
  34. },
  35. props:["phones"],
  36. data() {
  37. return {
  38. keyword: '',
  39. list: [],
  40. timer: null
  41. }
  42. },
  43. onShow(){
  44. _hook.routeSonHook();
  45. },
  46. onLoad(){
  47. },
  48. computed:{
  49. hasNoData () {
  50. return !this.list.length;
  51. },
  52. staticPhoto(){
  53. return _data.staticPhoto();
  54. },
  55. },
  56. watch:{
  57. keyword () {
  58. if(this.timer) {
  59. clearTimeout(this.timer);
  60. }
  61. if(!this.keyword){
  62. this.list = [];
  63. return
  64. }
  65. let _this = this;
  66. this.timer = setTimeout(() => {
  67. const result = [];
  68. let arr = Object.values(_this.phones);
  69. for (let i = 0,j = arr.length;i < j;i++) {
  70. arr[i].data.forEach((item) => {
  71. if(item.name.indexOf(_this.keyword) > -1) {
  72. result.push(item);
  73. }
  74. });
  75. }
  76. _this.list = result;
  77. },100);
  78. }
  79. },
  80. methods:{
  81. handleInput (e) {
  82. this.keyword = e.detail.value
  83. },
  84. goDetails(user_id){
  85. uni.navigateTo({
  86. url: '../details/index?user_id=' + user_id,
  87. });
  88. },
  89. }
  90. }
  91. </script>
  92. <style>
  93. .search-main {
  94. height: 100%;
  95. padding-bottom: 20upx;
  96. background-color:#fff;
  97. overflow: hidden;
  98. }
  99. .search-main-errtitle {
  100. width: 100%;
  101. height: 92upx;
  102. line-height: 92upx;
  103. font-size: 32upx;
  104. padding: 0 20upx;
  105. border-bottom: 1px solid #e5e5e5;
  106. }
  107. .header {
  108. display: flex;
  109. flex-direction: row;
  110. padding: 10px 15px;
  111. align-items: center;
  112. }
  113. .input-view {
  114. display: flex;
  115. align-items: center;
  116. flex-direction: row;
  117. background-color: #e7e7e7;
  118. height: 30px;
  119. border-radius: 5px;
  120. padding: 0 10px;
  121. flex: 1;
  122. }
  123. .input {
  124. flex: 1;
  125. padding: 0 5px;
  126. height: 24px;
  127. line-height: 24px;
  128. font-size: 16px;
  129. }
  130. </style>