street-match.vue 4.7 KB

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