phone-search-list.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <view>
  3. <view class="search">
  4. <input
  5. @input="handleInput"
  6. class="search-input"
  7. type="text"
  8. focus
  9. placeholder="请输入要搜索的联系人"
  10. />
  11. </view>
  12. <view class="search-main" v-if="keyword">
  13. <view class="search-main-errtitle" v-if="hasNoData">无搜索结果</view>
  14. <view class="search-main-title"
  15. hover-class="hover"
  16. @click="handleClick"
  17. :hover-start-time="20"
  18. :hover-stay-time="70"
  19. v-for="item of list"
  20. :key="item.id"
  21. :data-name="item.name"
  22. :data-id="item.id"
  23. :data-phoneNumber="item.phoneNumber">
  24. {{item.name}}
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. name:"phone-search-list",
  32. props:{
  33. phones:Object
  34. },
  35. data() {
  36. return {
  37. keyword:'',
  38. list:[],
  39. timer:null
  40. }
  41. },
  42. computed:{
  43. hasNoData () {
  44. return !this.list.length
  45. }
  46. },
  47. watch:{
  48. keyword () {
  49. if(this.timer) {
  50. clearTimeout(this.timer)
  51. }
  52. if(!this.keyword){
  53. this.list = []
  54. return
  55. }
  56. this.timer = setTimeout(()=>{
  57. const result = []
  58. for (let i in this.phones){
  59. this.phones[i].forEach((item)=>{
  60. if(item.spell.indexOf(this.keyword) > -1||item.name.indexOf(this.keyword) > -1){
  61. result.push(item)
  62. }
  63. })
  64. }
  65. this.list = result
  66. },100)
  67. }
  68. },
  69. methods:{
  70. handleInput (e) {
  71. this.keyword = e.detail.value
  72. },
  73. handleClick (e) {
  74. this.$emit('paramClick',e.target.dataset)
  75. }
  76. }
  77. }
  78. </script>
  79. <style>
  80. .hover{
  81. background-color: #eee;
  82. }
  83. .search{
  84. background-color: #fff;
  85. padding: 10upx 20upx;
  86. border-bottom: 1px solid #e5e5e5;
  87. }
  88. .search-input{
  89. font-size:28upx;
  90. border: 1px solid #e5e5e5;
  91. border-radius: 3px;
  92. padding: 10upx 20upx 10upx 20upx;
  93. }
  94. .search-main{
  95. height: 100%;
  96. padding-bottom: 20upx;
  97. background-color:#fff;
  98. overflow: hidden;
  99. }
  100. .search-main-errtitle,.search-main-title{
  101. width: 100%;
  102. height: 92upx;
  103. line-height: 92upx;
  104. font-size: 32upx;
  105. padding: 0 20upx;
  106. border-bottom: 1px solid #e5e5e5;
  107. }
  108. </style>