search.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <view class="content">
  3. <view v-if="" class="navbar" @click="showBar()">
  4. <image @click="showBar()" class="icon" src="../../static/pics/search.png"></image>
  5. <image @click="navigateToPage('add')" class="icon" src="../../static/pics/add.png"></image>
  6. <image @click="navigateToPage('setting')" class="icon" src="../../static/pics/setting.png"></image>
  7. </view>
  8. <view class="navbar" v-show="searchActive">
  9. <view class="uni-column">
  10. <view class="search-input">
  11. <input type="text" v-model="searchText" placeholder="输入号码或名字" @input="filterContacts"/>
  12. </view>
  13. <view class="search-img" @click="search()" >
  14. <image src="../../static/pics/search.png"></image>
  15. </view>
  16. </view>
  17. </view>
  18. <view class="text-area">
  19. <view v-if="filteredContacts.length" v-for="(item, id) in filteredContacts" :key="id">
  20. <view class="name-btn">
  21. <view class="con-mes">
  22. <text v-if="!item.displayName">{{item.phoneNumbers[0].value}}</text>
  23. <text v-else>{{ item.displayName }}</text>
  24. </view>
  25. <view class="btn" @click="CallPhone(item.phoneNumbers[0].value)">
  26. <image @click="CallPhone(item.phoneNumbers[0].value)" class="Call" src="../../static/pics/call-out.png"></image>
  27. </view>
  28. </view>
  29. </view>
  30. <view v-else class="notFind">
  31. 该号码或联系人不存在
  32. </view>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. export default {
  38. data() {
  39. return {
  40. searchText: '', // 用户输入的搜索文本
  41. list: [], // 原始联系人列表
  42. filteredContacts: [] ,// 过滤后的联系人列表
  43. f:[],
  44. }
  45. },
  46. mounted() {
  47. // 运行后直接调用
  48. this.ToGetMessage();
  49. /* this.ToGetHis(); */
  50. },
  51. methods: {
  52. //获取联系人信息
  53. ToGetMessage() {
  54. var that=this
  55. //获取通讯录对象
  56. plus.contacts.getAddressBook( plus.contacts.ADDRESSBOOK_PHONE, function( addressbook ) {
  57. addressbook.find(["displayName","phoneNumbers"],function(contacts){
  58. console.log(contacts);
  59. that.list = contacts;
  60. that.filteredContacts = that.list;
  61. }, function () {
  62. uni.showToast({
  63. title: '获取联系人失败',
  64. duration: 2000//在屏幕上显示的时间长度
  65. })
  66. },{multiple:true});//应该检索多个联系人
  67. }, function ( e ) {
  68. uni.showToast({
  69. title: '获取通讯录对象失败:' + e.message,
  70. duration: 2000
  71. })
  72. });
  73. },
  74. //拨打电话
  75. CallPhone(e){
  76. //调用HTML5 Plus框架提供的接口
  77. plus.device.dial(e,false);
  78. },
  79. filterContacts() {
  80. //实现模糊查找
  81. const searchText = this.searchText.toLowerCase();
  82. this.filteredContacts = this.list.filter(list => {
  83. return (list.displayName || '').toLowerCase().includes(searchText) ||
  84. list.phoneNumbers.some(phone => phone.value.toLowerCase().includes(searchText));
  85. });
  86. },
  87. search() {
  88. // 可以在这里添加更复杂的搜索逻辑
  89. this.filterContacts();
  90. }
  91. }
  92. }
  93. </script>
  94. <style>
  95. .null{
  96. }
  97. /* 其他样式保持不变 */
  98. .uni-column {
  99. width: 690rpx;
  100. height: 180rpx;
  101. border: 1px solid black;
  102. margin-top: 18rpx;
  103. border-radius: 20rpx;
  104. font-size: 50rpx;
  105. display: flex; /* 使用flex布局 */
  106. justify-content: space-between; /* 左右分布 */
  107. /* 其他样式保持不变 */
  108. }
  109. .search-input {
  110. width: 75%;
  111. /* 可以根据需要调整以下样式 */
  112. display: flex;
  113. align-items: center;
  114. }
  115. .search-img{
  116. width: 25%;
  117. /* 可以根据需要调整以下样式 */
  118. display: flex;
  119. border-left: 1px solid black;
  120. justify-content: center;
  121. align-items: center;
  122. }
  123. .search-input input {
  124. /* 根据需要调整输入框大小 */
  125. width: 90%; /* 例如90% */
  126. height: 80%; /* 例如80% */
  127. font-size: 50rpx;
  128. padding: 10px; /* 根据需要调整内边距 */
  129. }
  130. .search-img image {
  131. width: 50%; /* 例如30% */
  132. height: 50%; /* 保持与输入框一致的高度 */
  133. font-size: 50rpx;
  134. }
  135. .content {
  136. display: flex;
  137. flex-direction: column;
  138. align-items: center;
  139. justify-content: center;
  140. background-color: #F7F7F7;
  141. }
  142. .con-mes{
  143. display: flex;
  144. align-items: center;
  145. justify-content: center;
  146. width: 440rpx;
  147. height: 200rpx;
  148. border: none;
  149. background-color: white;
  150. border-radius: 20rpx 0rpx 0rpx 20rpx;
  151. }
  152. .name-btn{
  153. display: flex;
  154. align-items: center;
  155. justify-content: space-between;
  156. width: 690rpx;
  157. height: 200rpx;
  158. border: 1px solid black;
  159. margin-top: 18rpx;
  160. border-radius: 20rpx;
  161. font-size: 50rpx;
  162. }
  163. .text-area {
  164. height: 70%;
  165. display: flex;
  166. flex-direction: column;
  167. align-items: center;
  168. padding-top: 30%;
  169. }
  170. .btn {
  171. display: flex;
  172. justify-content: center;
  173. align-items: center;
  174. width: 250rpx;
  175. height: 200rpx;
  176. background-color: #ecfff3;
  177. border-radius: 0rpx 20rpx 20rpx 0rpx;
  178. }
  179. .Call{
  180. width:100rpx;
  181. height: 100rpx;
  182. object-fit: contain;
  183. }
  184. .navbar {
  185. display: flex;
  186. justify-content: space-around;
  187. align-items: center;
  188. width: 100%;
  189. background-color: #F8F8F8;
  190. height: 90px;
  191. position: fixed; /* 设置为固定定位 */
  192. top: 0; /* 与页面顶部的距离为0 */
  193. z-index: 999;
  194. }
  195. .icon{
  196. justify-content: space-around;
  197. width: 100rpx;
  198. height: 100rpx;
  199. }
  200. </style>