index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <view class="all-services-page">
  3. <nav-bar title="全部分类" :showBack="false"></nav-bar>
  4. <!-- 顶部搜索栏 -->
  5. <view class="header-search">
  6. <view class="search-input-wrap">
  7. <uni-icons type="search" size="14" color="#999"></uni-icons>
  8. <input class="search-input" v-model="searchValue" placeholder="搜索服务内容"
  9. placeholder-class="placeholder-style" />
  10. </view>
  11. </view>
  12. <!-- 主体分类区域 -->
  13. <view class="main-content">
  14. <!-- 左侧侧边栏 -->
  15. <scroll-view scroll-y class="sidebar">
  16. <view v-for="(item, index) in allData" :key="index"
  17. :class="['sidebar-item', { active: activeSidebar === index }]" @click="activeSidebar = index">
  18. <text>{{ item.title }}</text>
  19. </view>
  20. </scroll-view>
  21. <!-- 右侧服务列表 -->
  22. <scroll-view scroll-y class="content-view">
  23. <view class="category-section" v-for="(cat, index) in currentCategories" :key="index">
  24. <view class="service-grid">
  25. <view class="service-cell" v-for="(service, sIndex) in cat.items" :key="sIndex"
  26. @click="onServiceClick(service)">
  27. <view class="icon-wrapper">
  28. <image :src="service.icon" class="service-icon" mode="aspectFit"></image>
  29. </view>
  30. <text class="service-name">{{ service.name }}</text>
  31. </view>
  32. </view>
  33. </view>
  34. </scroll-view>
  35. </view>
  36. <custom-tabbar></custom-tabbar>
  37. </view>
  38. </template>
  39. <script setup>
  40. import { ref, computed, onMounted } from 'vue'
  41. import navBar from '@/components/nav-bar/index.vue'
  42. import customTabbar from '@/components/custom-tabbar/index.vue'
  43. import { listAll as getClassifications } from '@/api/service/classification'
  44. import { listAll as getServices } from '@/api/service/list'
  45. const searchValue = ref('')
  46. const activeSidebar = ref(0)
  47. const allData = ref([])
  48. const currentCategories = computed(() => {
  49. if (allData.value.length === 0 || !allData.value[activeSidebar.value]) return []
  50. return allData.value[activeSidebar.value].categories
  51. })
  52. const loadData = async () => {
  53. try {
  54. const [classifications, services] = await Promise.all([
  55. getClassifications(),
  56. getServices()
  57. ])
  58. console.log('分类数据:', classifications)
  59. console.log('服务数据:', services)
  60. allData.value = classifications.map(classification => {
  61. const categoryServices = services.filter(
  62. service => service.classificationId === classification.id
  63. )
  64. console.log(`分类 ${classification.name} 的服务:`, categoryServices)
  65. return {
  66. title: classification.name,
  67. categories: [{
  68. items: categoryServices.map(service => ({
  69. ...service,
  70. name: service.name,
  71. icon: service.iconUrl,
  72. type: service.id
  73. }))
  74. }]
  75. }
  76. })
  77. console.log('最终数据结构:', allData.value)
  78. } catch (error) {
  79. console.error('加载服务数据失败:', error)
  80. uni.showToast({ title: '加载失败', icon: 'none' })
  81. }
  82. }
  83. onMounted(() => {
  84. loadData()
  85. })
  86. const onServiceClick = (service) => {
  87. if (service.id) {
  88. uni.setStorageSync('currentService', service)
  89. uni.navigateTo({ url: `/pages/service/detail/index?serviceId=${service.id}` })
  90. } else {
  91. uni.showToast({ title: service.name + ' 功能即将上线', icon: 'none' })
  92. }
  93. }
  94. </script>
  95. <style lang="scss" scoped>
  96. .all-services-page {
  97. height: 100vh;
  98. display: flex;
  99. flex-direction: column;
  100. background-color: #fff;
  101. }
  102. .header-search {
  103. padding: 16rpx 32rpx;
  104. background-color: #fff;
  105. border-bottom: 1rpx solid #f2f2f2;
  106. }
  107. .search-input-wrap {
  108. flex: 1;
  109. display: flex;
  110. align-items: center;
  111. background: #f5f5f5;
  112. border-radius: 32rpx;
  113. padding: 12rpx 20rpx;
  114. gap: 12rpx;
  115. }
  116. .search-input {
  117. flex: 1;
  118. font-size: 26rpx;
  119. }
  120. .placeholder-style {
  121. color: #999;
  122. font-size: 26rpx;
  123. }
  124. .main-content {
  125. flex: 1;
  126. display: flex;
  127. overflow: hidden;
  128. }
  129. .sidebar {
  130. width: 200rpx;
  131. background-color: #f7f8fa;
  132. }
  133. .sidebar-item {
  134. padding: 28rpx 0;
  135. text-align: center;
  136. font-size: 26rpx;
  137. color: #666;
  138. position: relative;
  139. }
  140. .sidebar-item.active {
  141. background-color: #fff;
  142. color: #333;
  143. font-weight: bold;
  144. }
  145. .sidebar-item.active::before {
  146. content: '';
  147. position: absolute;
  148. left: 0;
  149. top: 50%;
  150. transform: translateY(-50%);
  151. width: 6rpx;
  152. height: 40rpx;
  153. background-color: #f7ca3e;
  154. border-radius: 0 6rpx 6rpx 0;
  155. }
  156. .content-view {
  157. flex: 1;
  158. padding: 32rpx;
  159. }
  160. .category-section {
  161. margin-bottom: 48rpx;
  162. }
  163. .service-grid {
  164. display: flex;
  165. flex-wrap: wrap;
  166. }
  167. .service-cell {
  168. width: 33.33%;
  169. display: flex;
  170. flex-direction: column;
  171. align-items: center;
  172. margin-bottom: 32rpx;
  173. }
  174. .icon-wrapper {
  175. width: 96rpx;
  176. height: 96rpx;
  177. background-color: #fff;
  178. border-radius: 24rpx;
  179. display: flex;
  180. align-items: center;
  181. justify-content: center;
  182. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
  183. margin-bottom: 16rpx;
  184. }
  185. .service-icon {
  186. width: 56rpx;
  187. height: 56rpx;
  188. }
  189. .service-name {
  190. font-size: 24rpx;
  191. color: #666;
  192. text-align: center;
  193. }
  194. </style>