filter.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <template>
  2. <view class="container">
  3. <scroll-view scroll-y class="scroll-body">
  4. <!-- 历史搜索 -->
  5. <view class="section" v-if="historyList.length > 0">
  6. <view class="section-header">
  7. <text class="title">历史搜索</text>
  8. <image src="/static/icons/icon-delete.svg" class="delete-icon" mode="aspectFit" @click="clearHistory"></image>
  9. </view>
  10. <view class="tags-row">
  11. <view
  12. class="tag"
  13. :class="{ active: selectedHistory === item }"
  14. v-for="(item, index) in historyList"
  15. :key="index"
  16. @click="selectedHistory = item"
  17. >
  18. {{ item }}
  19. </view>
  20. </view>
  21. </view>
  22. <!-- 岗位类型 -->
  23. <view class="section">
  24. <view class="section-header">
  25. <text class="title">岗位类型</text>
  26. </view>
  27. <view class="tags-row">
  28. <view
  29. class="tag"
  30. :class="{ active: selectedJobType === item.dictValue }"
  31. v-for="(item, index) in jobTypes"
  32. :key="index"
  33. @click="selectedJobType = item.dictValue"
  34. >
  35. {{ item.dictLabel }}
  36. </view>
  37. </view>
  38. </view>
  39. <!-- 期望薪资 -->
  40. <view class="section">
  41. <view class="section-header">
  42. <text class="title">期望薪资 (K)</text>
  43. </view>
  44. <view class="salary-display">
  45. <text>{{ minSalary }} - {{ maxSalary }}K</text>
  46. </view>
  47. <view class="range-slider-wrap">
  48. <movable-area class="slider-track-area">
  49. <view class="slider-bg"></view>
  50. <view class="slider-active" :style="{ left: (minX + thumbHalf) + 'px', width: (maxX - minX) + 'px' }"></view>
  51. <movable-view class="slider-thumb" direction="horizontal" :x="minX" @change="onMinMove" :animation="false"></movable-view>
  52. <movable-view class="slider-thumb" direction="horizontal" :x="maxX" @change="onMaxMove" :animation="false"></movable-view>
  53. </movable-area>
  54. </view>
  55. </view>
  56. <!-- 工作经验 -->
  57. <view class="section">
  58. <view class="section-header">
  59. <text class="title">工作经验</text>
  60. </view>
  61. <view class="tags-row">
  62. <view
  63. class="tag"
  64. :class="{ active: selectedExperience === item.dictValue }"
  65. v-for="(item, index) in experiences"
  66. :key="index"
  67. @click="selectedExperience = item.dictValue"
  68. >
  69. {{ item.dictLabel }}
  70. </view>
  71. </view>
  72. </view>
  73. <!-- 学历要求 -->
  74. <view class="section">
  75. <view class="section-header">
  76. <text class="title">学历要求</text>
  77. </view>
  78. <view class="tags-row">
  79. <view
  80. class="tag"
  81. :class="{ active: selectedEducation === item.dictValue }"
  82. v-for="(item, index) in educations"
  83. :key="index"
  84. @click="selectedEducation = item.dictValue"
  85. >
  86. {{ item.dictLabel }}
  87. </view>
  88. </view>
  89. </view>
  90. <!-- 底部安全距离 -->
  91. <view style="height: 160rpx;"></view>
  92. </scroll-view>
  93. <!-- 底部操作栏 -->
  94. <view class="bottom-bar">
  95. <view class="btn reset-btn" @click="resetFilters">重置</view>
  96. <view class="btn confirm-btn" @click="confirmFilters">确定</view>
  97. </view>
  98. </view>
  99. </template>
  100. <script setup lang="js">
  101. import { ref, onMounted } from 'vue';
  102. import { getDicts } from '../../api/dict.js';
  103. // 历史搜索数据
  104. const historyList = ref([]);
  105. const selectedHistory = ref('');
  106. // 岗位类型
  107. const jobTypes = ref([]);
  108. const selectedJobType = ref('');
  109. // 期望薪资滑块状态
  110. const minSalary = ref(0);
  111. const maxSalary = ref(50);
  112. const minX = ref(0);
  113. const maxX = ref(0);
  114. const sliderWidth = ref(0);
  115. const thumbHalf = ref(0);
  116. const MAX_SALARY = 50; // 上限 50K
  117. // 工作经验
  118. const experiences = ref([]);
  119. const selectedExperience = ref('');
  120. // 学历要求
  121. const educations = ref([]);
  122. const selectedEducation = ref('');
  123. const loadDictionaries = () => {
  124. getDicts('main_position_type').then(res => {
  125. if (res.data) {
  126. jobTypes.value = res.data;
  127. }
  128. });
  129. getDicts('main_experience').then(res => {
  130. if (res.data) {
  131. experiences.value = res.data;
  132. }
  133. });
  134. getDicts('main_education').then(res => {
  135. if (res.data) {
  136. educations.value = res.data;
  137. }
  138. });
  139. };
  140. onMounted(() => {
  141. // 加载搜索历史
  142. const historyStr = uni.getStorageSync('search_history');
  143. if (historyStr) {
  144. try {
  145. historyList.value = JSON.parse(historyStr);
  146. } catch(e){}
  147. }
  148. loadDictionaries();
  149. // 延迟一小会儿,确保 DOM 已经挂载好
  150. setTimeout(() => {
  151. uni.createSelectorQuery().select('.slider-track-area').boundingClientRect(res => {
  152. if (res && res.width) {
  153. const thumbW = uni.upx2px(40);
  154. thumbHalf.value = thumbW / 2;
  155. sliderWidth.value = res.width - thumbW;
  156. updateThumbPositions();
  157. }
  158. }).exec();
  159. }, 300);
  160. });
  161. // 计算位置同步到界面
  162. const updateThumbPositions = () => {
  163. if (sliderWidth.value > 0) {
  164. minX.value = (minSalary.value / MAX_SALARY) * sliderWidth.value;
  165. maxX.value = (maxSalary.value / MAX_SALARY) * sliderWidth.value;
  166. }
  167. };
  168. const onMinMove = (e) => {
  169. if (e.detail.source === 'touch') {
  170. let newX = e.detail.x;
  171. if (newX > maxX.value) newX = maxX.value;
  172. minX.value = newX;
  173. minSalary.value = Math.round((newX / sliderWidth.value) * MAX_SALARY);
  174. }
  175. };
  176. const onMaxMove = (e) => {
  177. if (e.detail.source === 'touch') {
  178. let newX = e.detail.x;
  179. if (newX < minX.value) newX = minX.value;
  180. maxX.value = newX;
  181. maxSalary.value = Math.round((newX / sliderWidth.value) * MAX_SALARY);
  182. }
  183. };
  184. // 清除历史记录
  185. const clearHistory = () => {
  186. uni.showModal({
  187. title: '提示',
  188. content: '确认清空历史搜索?',
  189. success: (res) => {
  190. if (res.confirm) {
  191. historyList.value = [];
  192. selectedHistory.value = '';
  193. uni.removeStorageSync('search_history');
  194. }
  195. }
  196. });
  197. };
  198. // 确定筛选项
  199. const confirmFilters = () => {
  200. // 匹配选中的字典标签,若包含“不限”则重置为空字符串传给后端
  201. const expItem = experiences.value.find(i => i.dictValue === selectedExperience.value);
  202. const userExp = (expItem && expItem.dictLabel && expItem.dictLabel.includes('不限')) ? '' : selectedExperience.value;
  203. const eduItem = educations.value.find(i => i.dictValue === selectedEducation.value);
  204. const userEdu = (eduItem && eduItem.dictLabel && eduItem.dictLabel.includes('不限')) ? '' : selectedEducation.value;
  205. // 发送给岗位列表页面进行筛选
  206. const filterParams = {
  207. keyword: selectedHistory.value,
  208. jobType: selectedJobType.value,
  209. minSalary: minSalary.value,
  210. maxSalary: maxSalary.value,
  211. experience: userExp,
  212. education: userEdu
  213. };
  214. uni.$emit('updateFilters', filterParams);
  215. uni.showToast({
  216. title: '筛选已应用',
  217. icon: 'success'
  218. });
  219. setTimeout(() => {
  220. uni.navigateBack();
  221. }, 800);
  222. };
  223. // 重置过滤器
  224. const resetFilters = () => {
  225. selectedHistory.value = '';
  226. selectedJobType.value = '';
  227. minSalary.value = 0;
  228. maxSalary.value = 50;
  229. updateThumbPositions();
  230. selectedExperience.value = '';
  231. selectedEducation.value = '不限';
  232. };
  233. </script>
  234. <style lang="scss" scoped>
  235. .container {
  236. width: 100%;
  237. height: 100vh;
  238. background-color: #FFFFFF;
  239. display: flex;
  240. flex-direction: column;
  241. }
  242. .scroll-body {
  243. flex: 1;
  244. overflow-y: auto;
  245. padding: 24rpx 40rpx;
  246. box-sizing: border-box;
  247. }
  248. .section {
  249. margin-bottom: 40rpx;
  250. .section-header {
  251. display: flex;
  252. justify-content: space-between;
  253. align-items: center;
  254. margin-bottom: 24rpx;
  255. .title {
  256. font-size: 28rpx;
  257. font-weight: bold;
  258. color: #1A1A1A;
  259. }
  260. .delete-icon {
  261. width: 32rpx;
  262. height: 32rpx;
  263. opacity: 0.4;
  264. padding: 10rpx;
  265. }
  266. }
  267. .tags-row {
  268. display: flex;
  269. flex-wrap: wrap;
  270. gap: 16rpx;
  271. .tag {
  272. background-color: #FFFFFF;
  273. color: #555555;
  274. font-size: 24rpx;
  275. padding: 12rpx 30rpx;
  276. border-radius: 100rpx;
  277. border: 2rpx solid #E4E7ED;
  278. min-width: 130rpx;
  279. text-align: center;
  280. box-sizing: border-box;
  281. &.active {
  282. background-color: #1F6CFF;
  283. color: #FFFFFF;
  284. border-color: #1F6CFF;
  285. }
  286. }
  287. }
  288. }
  289. .salary-display {
  290. text-align: center;
  291. font-size: 28rpx;
  292. color: #1F6CFF;
  293. margin-bottom: 24rpx;
  294. font-weight: bold;
  295. }
  296. .range-slider-wrap {
  297. width: 100%;
  298. height: 60rpx;
  299. padding: 0 20rpx;
  300. box-sizing: border-box;
  301. }
  302. .slider-track-area {
  303. width: 100%;
  304. height: 100%;
  305. position: relative;
  306. }
  307. .slider-bg {
  308. position: absolute;
  309. top: 50%;
  310. left: 0;
  311. right: 0;
  312. height: 8rpx;
  313. background-color: #F0F2F5;
  314. transform: translateY(-50%);
  315. border-radius: 4rpx;
  316. }
  317. .slider-active {
  318. position: absolute;
  319. top: 50%;
  320. height: 8rpx;
  321. background-color: #1F6CFF;
  322. transform: translateY(-50%);
  323. border-radius: 4rpx;
  324. }
  325. .slider-thumb {
  326. width: 40rpx;
  327. height: 40rpx;
  328. background-color: #FFFFFF;
  329. border-radius: 50%;
  330. border: 4rpx solid #1F6CFF;
  331. box-shadow: 0 2rpx 6rpx rgba(31, 108, 255, 0.2);
  332. top: 50%;
  333. margin-top: -20rpx;
  334. box-sizing: border-box;
  335. }
  336. .bottom-bar {
  337. position: fixed;
  338. left: 0;
  339. right: 0;
  340. bottom: 0;
  341. height: 110rpx;
  342. background-color: #FFFFFF;
  343. box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.05);
  344. display: flex;
  345. align-items: center;
  346. padding: 0 40rpx;
  347. padding-bottom: env(safe-area-inset-bottom);
  348. gap: 30rpx;
  349. z-index: 100;
  350. .btn {
  351. flex: 1;
  352. display: flex;
  353. align-items: center;
  354. justify-content: center;
  355. font-size: 28rpx;
  356. height: 72rpx;
  357. border-radius: 100rpx;
  358. font-weight: 500;
  359. }
  360. .reset-btn {
  361. background-color: #FFFFFF;
  362. color: #666666;
  363. border: 2rpx solid #E4E7ED;
  364. box-sizing: border-box;
  365. }
  366. .confirm-btn {
  367. background-color: #1F6CFF;
  368. color: #FFFFFF;
  369. }
  370. }
  371. </style>