street-match.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <view class="match-page">
  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. export default {
  44. components: {
  45. AddressPicker
  46. },
  47. data() {
  48. return {
  49. filterStreetId: null,
  50. matching: false,
  51. matchResult: null,
  52. familyCount: {},
  53. teacherCount: {}
  54. }
  55. },
  56. methods: {
  57. onFilterChange(data) {
  58. this.filterStreetId = data.streetId
  59. },
  60. async doMatch() {
  61. if (!this.filterStreetId) {
  62. uni.showToast({ title: '请选择街道', icon: 'none' })
  63. return
  64. }
  65. this.matching = true
  66. try {
  67. // 获取匹配范围
  68. const matchRes = await matchByStreet(this.filterStreetId)
  69. this.matchResult = matchRes.data
  70. // 统计各级别的家庭数
  71. if (matchRes.data.streetIds) {
  72. this.familyCount.street = await this.countFamilies(matchRes.data.streetIds)
  73. this.teacherCount.street = await this.countTeachers(matchRes.data.streetIds)
  74. }
  75. if (matchRes.data.districtStreetIds) {
  76. this.familyCount.district = await this.countFamilies(matchRes.data.districtStreetIds)
  77. this.teacherCount.district = await this.countTeachers(matchRes.data.districtStreetIds)
  78. }
  79. if (matchRes.data.cityStreetIds) {
  80. this.familyCount.city = await this.countFamilies(matchRes.data.cityStreetIds)
  81. this.teacherCount.city = await this.countTeachers(matchRes.data.cityStreetIds)
  82. }
  83. } catch (e) {
  84. console.error('匹配失败', e)
  85. uni.showToast({ title: '匹配失败', icon: 'none' })
  86. } finally {
  87. this.matching = false
  88. }
  89. },
  90. async countFamilies(streetIds) {
  91. if (!streetIds || streetIds.length === 0) return 0
  92. try {
  93. const res = await countFamiliesByStreetIds(streetIds)
  94. return res.data || 0
  95. } catch (e) {
  96. return 0
  97. }
  98. },
  99. async countTeachers(streetIds) {
  100. if (!streetIds || streetIds.length === 0) return 0
  101. try {
  102. const res = await countTeachersByStreetIds(streetIds)
  103. return res.data || 0
  104. } catch (e) {
  105. return 0
  106. }
  107. }
  108. }
  109. }
  110. </script>
  111. <style scoped>
  112. .match-page {
  113. min-height: 100vh;
  114. background: #f5f5f5;
  115. padding: 20rpx;
  116. }
  117. .page-title {
  118. font-size: 36rpx;
  119. font-weight: bold;
  120. color: #333;
  121. padding: 30rpx 0;
  122. }
  123. .filter-section {
  124. background: #fff;
  125. border-radius: 16rpx;
  126. padding: 20rpx;
  127. margin-bottom: 20rpx;
  128. }
  129. .section-title {
  130. font-size: 30rpx;
  131. color: #333;
  132. font-weight: bold;
  133. margin-bottom: 20rpx;
  134. }
  135. .filter-actions {
  136. margin-top: 30rpx;
  137. }
  138. .match-btn {
  139. width: 100%;
  140. height: 88rpx;
  141. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  142. color: #fff;
  143. border-radius: 44rpx;
  144. font-size: 32rpx;
  145. }
  146. .result-section {
  147. background: #fff;
  148. border-radius: 16rpx;
  149. padding: 20rpx;
  150. }
  151. .match-level {
  152. background: #f9f9f9;
  153. padding: 20rpx;
  154. border-radius: 8rpx;
  155. margin-bottom: 20rpx;
  156. }
  157. .level-title {
  158. font-size: 28rpx;
  159. font-weight: bold;
  160. color: #333;
  161. margin-bottom: 10rpx;
  162. }
  163. .match-count {
  164. font-size: 26rpx;
  165. color: #666;
  166. }
  167. </style>