index.vue 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <view class="user-select-popup">
  3. <view class="popup-header">
  4. <text class="popup-title">选择宠主</text>
  5. <view class="close-btn" @click="$emit('close')">
  6. <uni-icons type="closeempty" size="20" color="#999"></uni-icons>
  7. </view>
  8. </view>
  9. <view class="search-wrap">
  10. <uni-icons type="search" size="14" color="#999"></uni-icons>
  11. <input class="search-input" v-model="keyword" placeholder="搜索姓名/手机号" />
  12. </view>
  13. <scroll-view scroll-y class="user-list">
  14. <view class="user-item" v-for="user in filteredUsers" :key="user.id" @click="onSelect(user)">
  15. <view class="user-avatar">
  16. <uni-icons type="person" size="20" color="#aaa"></uni-icons>
  17. </view>
  18. <view class="user-info">
  19. <text class="user-name">{{ user.name }}</text>
  20. <text class="user-phone">{{ user.phone }}</text>
  21. </view>
  22. <uni-icons type="right" size="14" color="#ccc"></uni-icons>
  23. </view>
  24. <view class="empty-tip" v-if="filteredUsers.length === 0">
  25. <text>暂无匹配用户</text>
  26. </view>
  27. </scroll-view>
  28. </view>
  29. </template>
  30. <script setup>
  31. import { ref, computed } from 'vue'
  32. const emit = defineEmits(['close', 'select'])
  33. const keyword = ref('')
  34. const users = ref([
  35. { id: 1, name: '张先生', phone: '13800138000' },
  36. { id: 2, name: '李小姐', phone: '13900139000' },
  37. { id: 3, name: '王先生', phone: '13612345678' },
  38. { id: 4, name: '赵女士', phone: '13911112222' }
  39. ])
  40. const filteredUsers = computed(() => {
  41. if (!keyword.value) return users.value
  42. const kw = keyword.value.toLowerCase()
  43. return users.value.filter(u => u.name.toLowerCase().includes(kw) || u.phone.includes(kw))
  44. })
  45. const onSelect = (user) => {
  46. emit('select', user)
  47. }
  48. </script>
  49. <style lang="scss" scoped>
  50. .user-select-popup { height: 100vh; background: #fff; display: flex; flex-direction: column; }
  51. .popup-header { display: flex; align-items: center; justify-content: center; position: relative; padding: 32rpx; border-bottom: 1rpx solid #f5f5f5; }
  52. .popup-title { font-size: 32rpx; font-weight: bold; color: #333; }
  53. .close-btn { position: absolute; right: 32rpx; }
  54. .search-wrap { display: flex; align-items: center; background: #f5f5f5; border-radius: 32rpx; padding: 16rpx 24rpx; margin: 24rpx 32rpx; gap: 12rpx; }
  55. .search-input { flex: 1; font-size: 28rpx; }
  56. .user-list { flex: 1; padding: 0 32rpx; }
  57. .user-item { display: flex; align-items: center; padding: 28rpx 0; border-bottom: 1rpx solid #f5f5f5; }
  58. .user-avatar { width: 80rpx; height: 80rpx; border-radius: 50%; background: #f5f5f5; display: flex; align-items: center; justify-content: center; margin-right: 24rpx; }
  59. .user-info { flex: 1; }
  60. .user-name { display: block; font-size: 30rpx; font-weight: bold; color: #333; }
  61. .user-phone { display: block; font-size: 26rpx; color: #666; margin-top: 4rpx; }
  62. .empty-tip { text-align: center; padding: 80rpx 0; font-size: 28rpx; color: #999; }
  63. </style>