index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <view class="user-list-page">
  3. <!-- 顶部操作栏 -->
  4. <view class="action-bar">
  5. <view class="search-box">
  6. <uni-icons type="search" size="14" color="#999"></uni-icons>
  7. <input type="text" v-model="searchValue" placeholder="搜索姓名/手机号" class="search-input" />
  8. </view>
  9. <picker :range="shopOptions" range-key="text" @change="onShopChange">
  10. <view class="filter-btn">
  11. <text>{{ shopOptions[filterShop].text }}</text>
  12. <uni-icons type="bottom" size="12" color="#666"></uni-icons>
  13. </view>
  14. </picker>
  15. <button size="mini" class="add-btn" @click="goToAdd">+ 新增</button>
  16. </view>
  17. <!-- 用户列表 -->
  18. <view class="list-container">
  19. <view class="user-card" v-for="user in users" :key="user.id">
  20. <view class="user-header">
  21. <image :src="user.avatar" class="user-avatar" mode="aspectFill"></image>
  22. <view class="user-info-main">
  23. <text class="user-name">{{ user.name }}</text>
  24. <text class="phone-row">{{ user.phone }}</text>
  25. </view>
  26. <view class="user-status">
  27. <switch :checked="user.isActive" color="#ff9800" style="transform: scale(0.6);"
  28. @change="onStatusChange(user)" />
  29. <text class="status-text">{{ user.isActive ? '正常' : '禁用' }}</text>
  30. </view>
  31. </view>
  32. <view class="user-body">
  33. <view class="info-row">
  34. <text class="label">住址:</text>
  35. <text class="value">{{ user.address }}</text>
  36. </view>
  37. <view class="info-grid">
  38. <view class="grid-cell" @click="goToPetList(user)">
  39. <text class="label">关联宠物</text>
  40. <text class="value text-warning">{{ user.petCount }}只</text>
  41. </view>
  42. <view class="grid-cell" @click="goToOrderList(user)">
  43. <text class="label">订单数量</text>
  44. <text class="value">{{ user.orderCount }}单</text>
  45. </view>
  46. </view>
  47. <view class="source-box">
  48. <text class="source-tag">{{ user.source }}</text>
  49. <text class="create-time">创建时间: {{ user.createTime }}</text>
  50. </view>
  51. </view>
  52. <view class="card-actions">
  53. <button size="mini" class="action-btn" @click.stop="goToDetail(user)">详情</button>
  54. <button size="mini" class="action-btn" @click.stop="goToEdit(user)">编辑</button>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </template>
  60. <script setup>
  61. import { ref } from 'vue'
  62. import userMockData from '@/mock/user.json'
  63. const searchValue = ref('')
  64. const filterShop = ref(0)
  65. const shopOptions = [{ text: '全部', value: 0 }, { text: '三里屯店', value: 1 }, { text: '浦东新区店', value: 2 }]
  66. const onShopChange = (e) => { filterShop.value = Number(e.detail.value) }
  67. const users = ref(userMockData)
  68. const goToAdd = () => uni.navigateTo({ url: '/pages/my/user/add/index' })
  69. const goToDetail = (user) => uni.navigateTo({ url: '/pages/my/user/detail/index' })
  70. const goToEdit = (user) => uni.navigateTo({ url: '/pages/my/user/edit/index' })
  71. const goToPetList = (user) => uni.navigateTo({ url: `/pages/my/pet/list/index?userId=${user.id}` })
  72. const goToOrderList = (user) => uni.reLaunch({ url: '/pages/order/list/index' })
  73. const onStatusChange = (user) => {
  74. user.isActive = !user.isActive
  75. uni.showToast({ title: user.isActive ? '已启用' : '已禁用', icon: 'none' })
  76. }
  77. </script>
  78. <style lang="scss" scoped>
  79. .user-list-page { min-height: 100vh; background: #f2f2f2; padding-bottom: 40rpx; }
  80. .action-bar { display: flex; align-items: center; padding: 20rpx 24rpx; background: #fff; gap: 16rpx; }
  81. .search-box { flex: 1; display: flex; align-items: center; background: #f5f5f5; border-radius: 32rpx; padding: 12rpx 20rpx; gap: 12rpx; }
  82. .search-input { flex: 1; font-size: 26rpx; background: transparent; }
  83. .filter-btn { display: flex; align-items: center; gap: 8rpx; background: #f5f5f5; border-radius: 32rpx; padding: 12rpx 20rpx; font-size: 24rpx; color: #666; }
  84. .add-btn { font-size: 24rpx; font-weight: bold; background: linear-gradient(90deg, #ffd53f, #ff9500); color: #333; border: none; border-radius: 32rpx; padding: 12rpx 24rpx; white-space: nowrap; }
  85. .list-container { padding: 24rpx; }
  86. .user-card { background: #fff; border-radius: 24rpx; padding: 28rpx; margin-bottom: 24rpx; }
  87. .user-header { display: flex; align-items: center; margin-bottom: 24rpx; padding-bottom: 24rpx; border-bottom: 1rpx solid #f9f9f9; }
  88. .user-avatar { width: 88rpx; height: 88rpx; border-radius: 50%; background: #f0f0f0; margin-right: 24rpx; }
  89. .user-info-main { flex: 1; }
  90. .user-name { display: block; font-size: 32rpx; font-weight: bold; color: #333; margin-bottom: 8rpx; }
  91. .phone-row { display: block; font-size: 26rpx; color: #666; }
  92. .user-status { display: flex; flex-direction: column; align-items: center; gap: 4rpx; }
  93. .status-text { font-size: 20rpx; color: #ff9800; }
  94. .user-body { font-size: 26rpx; }
  95. .info-row { display: flex; margin-bottom: 16rpx; }
  96. .label { color: #999; width: 100rpx; flex-shrink: 0; }
  97. .value { color: #333; flex: 1; }
  98. .info-grid { display: flex; background: #fdfdfd; border: 1rpx solid #f2f2f2; border-radius: 12rpx; padding: 20rpx; margin-bottom: 20rpx; }
  99. .grid-cell { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8rpx; }
  100. .grid-cell .label { width: auto; font-size: 24rpx; }
  101. .grid-cell .value { font-size: 30rpx; font-weight: bold; }
  102. .text-warning { color: #ff9800; }
  103. .source-box { background: #fff8e1; padding: 16rpx; border-radius: 8rpx; }
  104. .source-tag { display: block; color: #ff9800; font-weight: bold; font-size: 24rpx; margin-bottom: 8rpx; }
  105. .create-time { font-size: 22rpx; color: #a1887f; }
  106. .card-actions { display: flex; justify-content: flex-end; gap: 20rpx; margin-top: 24rpx; padding-top: 24rpx; border-top: 1rpx dashed #eee; }
  107. .action-btn { border: 1rpx solid #e0e0e0; color: #666; font-size: 24rpx; background: transparent; border-radius: 12rpx; padding: 8rpx 24rpx; }
  108. </style>