screen.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. <template>
  2. <view class="flex flex-direction" style="height: 100vh;">
  3. <navBar title="筛选" color="#000" />
  4. <!-- 列表 -->
  5. <view class="list flex justify-between">
  6. <scroll-view scroll-y="true" @scroll="scrolls" scroll-with-animation="true"
  7. :scroll-into-view="'bottomView' + current" style="width: 100%; height: 100%;">
  8. <block v-if="type">
  9. <view class="list-r-item" :id="'bottomView' + index" v-if="list.length > 0 && index != 3"
  10. v-for="(item, index) in list" :key="index">
  11. <view class="list-r-item-title">
  12. {{ item.name }}
  13. </view>
  14. <view class="list-r-item-childs flex justify-around align-center flex-wrap">
  15. <view class="list-r-item-childs-i flex justify-center align-center"
  16. v-for="(ite, ind) in item.list" :class="ite.select == true ? 'activeRight' : ''"
  17. @click="selectHyList(index, item.name, ite, ind)" :key="ind">
  18. {{ ite.value }}
  19. </view>
  20. <view class="list-r-item-childs-i flex justify-center align-center"
  21. style="height: 0; padding: 0">
  22. </view>
  23. </view>
  24. </view>
  25. </block>
  26. <block v-else>
  27. <view class="list-r-item" :id="'bottomView' + index" v-if="list.length > 0"
  28. v-for="(item, index) in list" :key="index">
  29. <view class="list-r-item-title">
  30. {{ item.name }}
  31. </view>
  32. <view class="list-r-item-childs flex justify-around align-center flex-wrap">
  33. <view class="list-r-item-childs-i flex justify-center align-center"
  34. v-for="(ite, ind) in item.list" :class="ite.select == true ? 'activeRight' : ''"
  35. @click="selectHyList(index, item.name, ite, ind)" :key="ind">
  36. {{ ite.value }}
  37. </view>
  38. <view class="list-r-item-childs-i flex justify-center align-center"
  39. style="height: 0; padding: 0">
  40. </view>
  41. </view>
  42. </view>
  43. </block>
  44. <empty v-if="list.length == 0" />
  45. </scroll-view>
  46. </view>
  47. <!-- 底部按钮 -->
  48. <view class="bottom flex justify-center">
  49. <view class="bottom-box flex justify-between">
  50. <view @click="cleanSe()" class="bottom-box-left flex justify-center align-center">
  51. 清除
  52. </view>
  53. <view @click="submitSe()" class="bottom-box-right flex justify-center align-center">
  54. 确定
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. import empty from "../../components/empty.vue";
  62. import navBar from "@/components/nav-bar/index.vue";
  63. export default {
  64. components: {
  65. empty,
  66. navBar
  67. },
  68. data() {
  69. return {
  70. current: 0,
  71. currents: 0,
  72. list: [],
  73. top_list: [],
  74. selectArr: [],
  75. type: "",
  76. isBrowse: false, //是否是从用户浏览记录里过来的
  77. isCompyBrowse: false, //是否是从企业浏览记录过来的
  78. isCompyHistory: false, //是否是从企业的投递记录过来的
  79. storageKey: 'filter', // 首页 filter,搜索页 filterSearch
  80. };
  81. },
  82. onLoad(option) {
  83. if (option.type) {
  84. this.type = option.type;
  85. this.storageKey = option.type == 1 ? 'filterSearch' : 'filter'
  86. }
  87. if (option.isBrowse) {
  88. this.isBrowse = true;
  89. } else {
  90. this.isBrowse = false;
  91. }
  92. if (option.isCompyBrowse) {
  93. this.isCompyBrowse = true;
  94. } else {
  95. this.isCompyBrowse = false;
  96. }
  97. if (option.isCompyHistory) {
  98. this.isCompyHistory = true;
  99. } else {
  100. this.isCompyHistory = false;
  101. }
  102. this.getSchools();
  103. },
  104. methods: {
  105. /**
  106. * 清空筛选条件并清空缓存
  107. */
  108. cleanSe() {
  109. this.list.map((item) => {
  110. item.list.map((ite) => {
  111. ite.select = false;
  112. });
  113. });
  114. if (this.isBrowse) {
  115. uni.removeStorageSync("browse");
  116. } else if (this.isCompyBrowse) {
  117. uni.removeStorageSync("isCompyBrowse");
  118. } else if (this.isCompyHistory) {
  119. uni.removeStorageSync("isCompyHistory");
  120. } else {
  121. uni.removeStorageSync(this.storageKey);
  122. }
  123. },
  124. /**
  125. * 处理选中的条件
  126. */
  127. submitSe() {
  128. let arr = JSON.parse(JSON.stringify(this.list));
  129. arr =
  130. arr &&
  131. arr.map((item) => {
  132. item.list =
  133. item.list &&
  134. item.list.filter((val) => {
  135. if (val.select) return val;
  136. });
  137. if (item.list.length > 0) {
  138. return item;
  139. }
  140. });
  141. arr = arr.filter((val) => {
  142. if (val) return val;
  143. });
  144. if (this.isBrowse) {
  145. uni.setStorageSync("browse", arr);
  146. } else if (this.isCompyBrowse) {
  147. uni.setStorageSync("isCompyBrowse", arr);
  148. } else if (this.isCompyHistory) {
  149. uni.setStorageSync("isCompyHistory", arr);
  150. } else {
  151. uni.setStorageSync(this.storageKey, arr);
  152. }
  153. uni.$emit('updateScreenFilterRecord')
  154. uni.navigateBack();
  155. },
  156. /**
  157. * @param {Object} index 外层下标
  158. * @param {Object} name 外层名称
  159. * @param {Object} info 内层对象
  160. * @param {Object} ind 内层下标
  161. * 选择右侧的筛选
  162. * 学历、薪资、经验单选,其余可以多选
  163. */
  164. selectHyList(index, name, info, ind) {
  165. // 定义需要单选的类型
  166. // const singleSelectTypes = ['学历要求', '薪资范围(单选)', '经验要求'];
  167. const singleSelectTypes = ['薪资范围(单选)'];
  168. if (singleSelectTypes.includes(name)) {
  169. // 单选逻辑:先取消当前分类下所有选项的选中状态,再选中当前点击的选项
  170. this.list[index].list.forEach(item => {
  171. item.select = false;
  172. });
  173. info.select = true;
  174. } else {
  175. // 其余多选逻辑保持不变
  176. if (info.value == "不限") {
  177. this.list[index].list.forEach(item => {
  178. item.select = false;
  179. });
  180. info.select = true;
  181. } else {
  182. this.list[index].list.forEach(item => {
  183. if (item.value == "不限") {
  184. item.select = false;
  185. }
  186. });
  187. info.select = !info.select;
  188. }
  189. }
  190. this.$forceUpdate();
  191. },
  192. /**
  193. * @param {Object} index
  194. * 点击切换分类
  195. */
  196. change_click_index(index) {
  197. this.current = index;
  198. //解决最后一个 ***来回*** 问题
  199. uni.setStorageSync("resolve", "last");
  200. setTimeout(() => {
  201. uni.removeStorageSync("resolve");
  202. }, 400);
  203. },
  204. scrolls(e) {
  205. if (!uni.getStorageSync("resolve")) {
  206. // this.get_node_details(e);
  207. }
  208. },
  209. /**
  210. * @param {Object} options
  211. * 获取节点信息
  212. */
  213. get_node_details(options) {
  214. const query = uni.createSelectorQuery().in(this);
  215. query
  216. .selectAll(".list-r-item")
  217. .boundingClientRect((data) => {
  218. this.top_list = data.map((item) => {
  219. return Math.ceil(item.top);
  220. });
  221. this.async_detail_msg(options);
  222. })
  223. .exec();
  224. },
  225. /**
  226. * @param {Object} options
  227. * 设置滚动的位置
  228. */
  229. async_detail_msg(options) {
  230. let top_page = options.detail.scrollTop + this.top_list[0];
  231. for (let i = 0; i < this.top_list.length; i++) {
  232. let node1 = this.top_list[i];
  233. let node2 = this.top_list[i + 1];
  234. if (node2 && top_page >= node1 && top_page < node2) {
  235. this.current = i;
  236. break;
  237. } else if (node2 && top_page === node2) {
  238. this.current = i + 1;
  239. break;
  240. }
  241. }
  242. },
  243. /**
  244. * 获取学历列表
  245. */
  246. getSchools() {
  247. this.$Request
  248. .get("/app/dict/list", {
  249. type: "学历",
  250. })
  251. .then((res) => {
  252. if (res.code == 0) {
  253. let list = [{
  254. value: "不限",
  255. }, ];
  256. let obj = {
  257. name: "学历要求",
  258. list: [...list, ...res.data],
  259. };
  260. this.getMoney(obj);
  261. }
  262. });
  263. },
  264. /**
  265. * 获取薪资 列表
  266. */
  267. getMoney(obj1) {
  268. this.$Request
  269. .get("/app/dict/list", {
  270. type: "薪资 ",
  271. })
  272. .then((res) => {
  273. if (res.code == 0) {
  274. let list = [{
  275. value: "不限",
  276. }, ];
  277. let obj = {
  278. name: "薪资范围(单选)",
  279. list: [...list, ...res.data],
  280. };
  281. this.getJy(obj1, obj);
  282. }
  283. });
  284. },
  285. /**
  286. * 获取工作经验列表
  287. */
  288. getJy(obj1, obj2) {
  289. this.$Request
  290. .get("/app/dict/list", {
  291. type: "工作经验 ",
  292. })
  293. .then((res) => {
  294. if (res.code == 0) {
  295. let list = [{
  296. value: "不限",
  297. }, ];
  298. let obj = {
  299. name: "经验要求",
  300. list: [...list, ...res.data],
  301. };
  302. this.getGm(obj1, obj2, obj);
  303. }
  304. });
  305. },
  306. /**
  307. * 获取公司规模列表
  308. */
  309. getGm(obj1, obj2, obj3) {
  310. this.$Request
  311. .get("/app/dict/list", {
  312. type: "公司规模 ",
  313. })
  314. .then((res) => {
  315. if (res.code == 0) {
  316. let list = [{
  317. value: "不限",
  318. }, ];
  319. let obj = {
  320. name: "公司规模",
  321. list: [...list, ...res.data],
  322. };
  323. this.getIndustryList(obj1, obj2, obj3, obj);
  324. }
  325. });
  326. },
  327. /**
  328. * 获取行业列表
  329. */
  330. getIndustryList(obj1, obj2, obj3, obj4) {
  331. this.$Request.get("/app/industry/getIndustryList").then((res) => {
  332. if (res.code == 0) {
  333. let list = [{
  334. value: "不限",
  335. }, ];
  336. let arrAy = [];
  337. res.data.map((item) => {
  338. arrAy = [...arrAy, ...item.childrenList];
  339. });
  340. let arrs = JSON.parse(JSON.stringify(arrAy).replace(/industryName/g, "value"));
  341. let obj = {
  342. name: "行业",
  343. list: [...list, ...arrs],
  344. };
  345. let arr = [];
  346. arr[0] = obj1;
  347. arr[1] = obj2;
  348. arr[2] = obj3;
  349. arr[3] = obj4;
  350. //arr[4] = obj;
  351. arr.map((item) => {
  352. item.list.map((ite) => {
  353. ite.select = false;
  354. });
  355. });
  356. this.list = arr;
  357. // 从缓存加载选中状态
  358. const storageKeys = [{
  359. key: this.storageKey,
  360. condition: !this.isBrowse && !this.isCompyBrowse && !this.isCompyHistory
  361. },
  362. {
  363. key: 'browse',
  364. condition: this.isBrowse
  365. },
  366. {
  367. key: 'isCompyBrowse',
  368. condition: this.isCompyBrowse
  369. },
  370. {
  371. key: 'isCompyHistory',
  372. condition: this.isCompyHistory
  373. }
  374. ];
  375. for (const {
  376. key,
  377. condition
  378. }
  379. of storageKeys) {
  380. if (condition && uni.getStorageSync(key)) {
  381. const storedData = uni.getStorageSync(key);
  382. const selectedValues = [];
  383. const selectedValuesList = [];
  384. storedData.forEach(item => {
  385. let obj = {
  386. name: item.name,
  387. list: []
  388. }
  389. item.list.forEach(ite => {
  390. selectedValues.push(ite.value);
  391. obj.list.push(ite.value)
  392. });
  393. selectedValuesList.push(obj)
  394. });
  395. console.log(selectedValuesList)
  396. this.list.forEach(item => {
  397. item.list.forEach(ite => {
  398. // if (selectedValues.includes(ite.value)) {
  399. // ite.select = true;
  400. // }
  401. const selectList = []
  402. const obj = selectedValuesList.find(data => data.name == item.name)
  403. if (obj && obj.list?.includes(ite.value)) {
  404. ite.select = true;
  405. }
  406. });
  407. });
  408. break;
  409. }
  410. }
  411. }
  412. });
  413. },
  414. },
  415. };
  416. </script>
  417. <style lang="scss">
  418. /* 样式保持不变 */
  419. page {
  420. background-color: #ffffff;
  421. }
  422. .activeRight {
  423. color: rgba(1, 107, 246, 1) !important;
  424. background-color: rgba(153, 196, 250, 0.4) !important;
  425. border-radius: 18rpx !important;
  426. border: 0.5px solid rgba(1, 107, 246, 1);
  427. }
  428. .active {
  429. border-left: 8rpx solid #016bf6 !important;
  430. color: #016bf6 !important;
  431. }
  432. .list {
  433. width: 100%;
  434. flex: 1;
  435. overflow: hidden;
  436. .list-l {
  437. width: 30%;
  438. height: 100%;
  439. .list-l-item {
  440. margin-top: 40rpx;
  441. font-size: 28rpx;
  442. color: #121212;
  443. padding-left: 20rpx;
  444. border-left: 8rpx solid #ffffff;
  445. }
  446. }
  447. .list-r-item {
  448. width: 100%;
  449. margin-top: 40rpx;
  450. .list-r-item-title {
  451. width: 100%;
  452. color: #121212;
  453. font-size: 32rpx;
  454. font-weight: bold;
  455. padding-left: 30rpx;
  456. }
  457. .list-r-item-childs {
  458. width: 100%;
  459. .list-r-item-childs-i {
  460. width: calc((100% - 120rpx) / 2);
  461. margin-top: 20rpx;
  462. padding-top: 16rpx;
  463. padding-bottom: 16rpx;
  464. padding-left: 16rpx;
  465. padding-right: 16rpx;
  466. font-size: 26rpx;
  467. color: #121212;
  468. background: rgba(245, 248, 254, 1);
  469. text-align: center;
  470. border-radius: 18rpx;
  471. }
  472. }
  473. }
  474. }
  475. .bottom {
  476. width: 100%;
  477. background-color: #ffffff;
  478. .bottom-box {
  479. width: 686rpx;
  480. height: 80rpx;
  481. margin: 20rpx 0 40rpx;
  482. .bottom-box-left {
  483. width: 40%;
  484. height: 80rpx;
  485. color: #ffffff;
  486. border-radius: 999rpx;
  487. background: rgba(153, 196, 250, 1);
  488. }
  489. .bottom-box-right {
  490. width: 57%;
  491. height: 80rpx;
  492. border-radius: 999rpx;
  493. background: var(--线性渐变,
  494. linear-gradient(90deg, rgba(13, 39, 247, 1), rgba(19, 193, 234, 1) 100%));
  495. color: #ffffff;
  496. }
  497. }
  498. }
  499. </style>