district.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <view class="district-page">
  3. <u-navbar
  4. @leftClick="goBack"
  5. title="志愿者招募"
  6. bgColor="rgba(255,255,255,0)"
  7. :placeholder="true"
  8. titleStyle="font-weight:bold;color:#000000"
  9. ></u-navbar>
  10. <view class="district-content">
  11. <view class="district-list">
  12. <view
  13. v-for="item in districtList"
  14. :key="item.key"
  15. class="district-item"
  16. >
  17. <view class="district-button" @click="selectDistrict(item)">
  18. <text class="district-button-text">{{ item.name }}</text>
  19. </view>
  20. <text class="district-button-subtext">需招募岗位数:{{ item.recruitCount }}</text>
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. export default {
  28. data() {
  29. return {
  30. type: '',
  31. districtList: []
  32. };
  33. },
  34. onLoad(options) {
  35. this.type = options.type || '';
  36. this.getVolunteerNumber();
  37. },
  38. methods: {
  39. getTypeField() {
  40. const typeFieldMap = {
  41. volunteer: 'volunteer',
  42. xuanjiang: 'xuanjiang',
  43. publicize: 'publicize'
  44. };
  45. return typeFieldMap[this.type] || '';
  46. },
  47. getDistrictRecruitCount(item = {}) {
  48. const typeField = this.getTypeField();
  49. if (!typeField) {
  50. return 0;
  51. }
  52. const count = Number(item[typeField]);
  53. return Number.isNaN(count) ? 0 : count;
  54. },
  55. getDistrictName(item = {}) {
  56. return item.name || item.title || '';
  57. },
  58. normalizeDistrictList(list = []) {
  59. return list.map((item, index) => ({
  60. ...item,
  61. key: item.region_id || item.id || item.title || `district_${index}`,
  62. name: item.title || item.name || '',
  63. recruitCount: this.getDistrictRecruitCount(item)
  64. }));
  65. },
  66. getVolunteerNumber() {
  67. this.$api.getVolunteerNumber({ main_body_id: 1 }, (res) => {
  68. const responseData = res && res.data ? res.data : res || {};
  69. const districtList = Array.isArray(responseData.list) ? responseData.list : [];
  70. this.districtList = this.normalizeDistrictList(districtList);
  71. });
  72. },
  73. goBack() {
  74. uni.navigateBack({
  75. fail() {
  76. uni.switchTab({
  77. url: '/pages/index/index'
  78. });
  79. }
  80. });
  81. },
  82. selectDistrict(item) {
  83. if (!item.recruitCount) {
  84. this.$common.errorToShow('当前无岗位需求');
  85. return;
  86. }
  87. const query = [`regionName=${encodeURIComponent(this.getDistrictName(item))}`];
  88. if (item.region_id !== undefined && item.region_id !== null && item.region_id !== '') {
  89. query.push(`region_id=${encodeURIComponent(item.region_id)}`);
  90. }
  91. if (this.type) {
  92. query.unshift(`type=${encodeURIComponent(this.type)}`);
  93. }
  94. uni.navigateTo({
  95. url: `/index_fenbao/fuWu/baoMing/baoMing2?${query.join('&')}`
  96. });
  97. }
  98. }
  99. };
  100. </script>
  101. <style scoped>
  102. .district-page {
  103. min-height: 100vh;
  104. display: flex;
  105. flex-direction: column;
  106. box-sizing: border-box;
  107. background-image: url('https://wwgj.wenlvti.net/uploads/20260318/2663cbc99de9048f820be7badf3fb1e6.png');
  108. background-repeat: no-repeat;
  109. background-position: center top;
  110. background-size: 100% 100%;
  111. }
  112. .district-content {
  113. flex: 1;
  114. display: flex;
  115. align-items: flex-start;
  116. justify-content: center;
  117. box-sizing: border-box;
  118. padding: 8vh 0 60rpx;
  119. }
  120. .district-list {
  121. width: 100%;
  122. display: flex;
  123. flex-direction: column;
  124. align-items: center;
  125. }
  126. .district-item {
  127. width: 80%;
  128. margin-bottom: 56rpx;
  129. display: flex;
  130. flex-direction: column;
  131. align-items: center;
  132. }
  133. .district-button {
  134. width: 100%;
  135. height: 110rpx;
  136. display: flex;
  137. align-items: center;
  138. justify-content: center;
  139. background-image: url('https://wwgj.wenlvti.net/uploads/20260318/ad8233a3c8306fbb2fc2ff5738f0fcb4.png');
  140. background-repeat: no-repeat;
  141. background-position: center;
  142. background-size: 100% 100%;
  143. }
  144. .district-item:last-child {
  145. margin-bottom: 0;
  146. }
  147. .district-button-text {
  148. color: #ffffff;
  149. font-size: 52rpx;
  150. font-weight: 600;
  151. line-height: 1;
  152. letter-spacing: 8rpx;
  153. text-indent: 8rpx;
  154. }
  155. .district-button-subtext {
  156. margin-top: 18rpx;
  157. color: #6a412c;
  158. font-size: 24rpx;
  159. line-height: 1.2;
  160. }
  161. </style>