street-match.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <view class="match-page" :style="{ '--font-scale': fontScale }">
  3. <view class="page-title">区域匹配</view>
  4. <view class="filter-section">
  5. <view class="section-title">选择街道</view>
  6. <address-picker
  7. v-model="filterStreetId"
  8. @change="onFilterChange"
  9. />
  10. <view class="filter-actions">
  11. <button class="match-btn" @click="doMatch" :loading="matching">开始匹配</button>
  12. </view>
  13. </view>
  14. <view class="result-section" v-if="matchResult">
  15. <view class="section-title">匹配结果</view>
  16. <view class="match-level" v-if="matchResult.streetMatch">
  17. <view class="level-title">街道级匹配</view>
  18. <view class="match-count">
  19. 找到 {{ familyCount.street || 0 }} 个家庭,
  20. {{ teacherCount.street || 0 }} 个成长规划师
  21. </view>
  22. </view>
  23. <view class="match-level" v-if="matchResult.districtMatch">
  24. <view class="level-title">区县级匹配</view>
  25. <view class="match-count">
  26. 找到 {{ familyCount.district || 0 }} 个家庭,
  27. {{ teacherCount.district || 0 }} 个成长规划师
  28. </view>
  29. </view>
  30. <view class="match-level" v-if="matchResult.cityMatch">
  31. <view class="level-title">城市级匹配</view>
  32. <view class="match-count">
  33. 找到 {{ familyCount.city || 0 }} 个家庭,
  34. {{ teacherCount.city || 0 }} 个成长规划师
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. import AddressPicker from '@/components/address-picker.vue'
  42. import { matchByStreet, countFamiliesByStreetIds, countTeachersByStreetIds } from '@/utils/api.js'
  43. import fontScaleMixin from '@/mixins/font-scale.js'
  44. export default {
  45. mixins: [fontScaleMixin],
  46. components: {
  47. AddressPicker
  48. },
  49. data() {
  50. return {
  51. filterStreetId: null,
  52. matching: false,
  53. matchResult: null,
  54. familyCount: {},
  55. teacherCount: {}
  56. }
  57. },
  58. methods: {
  59. onFilterChange(data) {
  60. this.filterStreetId = data.streetId
  61. },
  62. async doMatch() {
  63. if (!this.filterStreetId) {
  64. uni.showToast({ title: '请选择街道', icon: 'none' })
  65. return
  66. }
  67. this.matching = true
  68. try {
  69. // 获取匹配范围
  70. const matchRes = await matchByStreet(this.filterStreetId)
  71. this.matchResult = matchRes.data
  72. // 统计各级别的家庭数
  73. if (matchRes.data.streetIds) {
  74. this.familyCount.street = await this.countFamilies(matchRes.data.streetIds)
  75. this.teacherCount.street = await this.countTeachers(matchRes.data.streetIds)
  76. }
  77. if (matchRes.data.districtStreetIds) {
  78. this.familyCount.district = await this.countFamilies(matchRes.data.districtStreetIds)
  79. this.teacherCount.district = await this.countTeachers(matchRes.data.districtStreetIds)
  80. }
  81. if (matchRes.data.cityStreetIds) {
  82. this.familyCount.city = await this.countFamilies(matchRes.data.cityStreetIds)
  83. this.teacherCount.city = await this.countTeachers(matchRes.data.cityStreetIds)
  84. }
  85. } catch (e) {
  86. console.error('匹配失败', e)
  87. uni.showToast({ title: '匹配失败', icon: 'none' })
  88. } finally {
  89. this.matching = false
  90. }
  91. },
  92. async countFamilies(streetIds) {
  93. if (!streetIds || streetIds.length === 0) return 0
  94. try {
  95. const res = await countFamiliesByStreetIds(streetIds)
  96. return res.data || 0
  97. } catch (e) {
  98. return 0
  99. }
  100. },
  101. async countTeachers(streetIds) {
  102. if (!streetIds || streetIds.length === 0) return 0
  103. try {
  104. const res = await countTeachersByStreetIds(streetIds)
  105. return res.data || 0
  106. } catch (e) {
  107. return 0
  108. }
  109. }
  110. }
  111. }
  112. </script>
  113. <style scoped lang="scss">
  114. .match-page {
  115. min-height: 100vh;
  116. background: $facade-fill-2;
  117. padding: 20rpx;
  118. }
  119. .page-title {
  120. font-size: calc(36rpx * var(--font-scale, 1));
  121. font-weight: bold;
  122. color: $facade-text-strong;
  123. padding: $uni-space-lg 0;
  124. }
  125. .filter-section {
  126. background: $app-surface;
  127. border-radius: 16rpx;
  128. padding: 20rpx;
  129. margin-bottom: 20rpx;
  130. }
  131. .section-title {
  132. font-size: calc(30rpx * var(--font-scale, 1));
  133. color: $facade-text-strong;
  134. font-weight: bold;
  135. margin-bottom: 20rpx;
  136. }
  137. .filter-actions {
  138. margin-top: $uni-space-lg;
  139. }
  140. .match-btn {
  141. width: 100%;
  142. height: 88rpx;
  143. background: linear-gradient(135deg, $accent-indigo 0%, $accent-indigo-deep 100%);
  144. color: $app-surface;
  145. border-radius: 24rpx;
  146. font-size: calc(32rpx * var(--font-scale, 1));
  147. }
  148. .result-section {
  149. background: $app-surface;
  150. border-radius: 16rpx;
  151. padding: 20rpx;
  152. }
  153. .match-level {
  154. background: $facade-fill-ghost-2;
  155. padding: 20rpx;
  156. border-radius: 8rpx;
  157. margin-bottom: 20rpx;
  158. }
  159. .level-title {
  160. font-size: calc(28rpx * var(--font-scale, 1));
  161. font-weight: bold;
  162. color: $facade-text-strong;
  163. margin-bottom: 10rpx;
  164. }
  165. .match-count {
  166. font-size: calc(26rpx * var(--font-scale, 1));
  167. color: $facade-text-body;
  168. }
  169. </style>