collect.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { defineStore } from "pinia";
  2. import { request } from "../api";
  3. export const useCollectStore = defineStore({
  4. id: "collect",
  5. state: () => {
  6. return {
  7. lists: [],
  8. entity: {},
  9. files: [],
  10. currentLevel: null,
  11. pagination: {
  12. dictLevel: "",
  13. endTime: "",
  14. pageNum: 0,
  15. pageSize: 20,
  16. searchKey: "",
  17. startTime: "",
  18. },
  19. };
  20. },
  21. getters: {},
  22. actions: {
  23. async fetch() {
  24. const { data, status } = await request.post("/show/goods/pageList", {
  25. ...this.pagination,
  26. });
  27. if (data.code === 0) {
  28. const { records, total, current, page } = data.data;
  29. this.lists = records;
  30. this.pagination.total = total;
  31. this.pagination.current = current;
  32. this.pagination.page = page;
  33. }
  34. },
  35. async getCollectList(page, level) {
  36. this.pagination.pageNum = page || 1;
  37. this.pagination.dictLevel = level === 0 ? "" : level;
  38. this.currentLevel = level;
  39. await this.fetch();
  40. },
  41. async getDetail(id) {
  42. const { data, status } = await request.get(`show/goods/detail/${id}`);
  43. if (data.code === 0) {
  44. const { entity, file } = data.data;
  45. this.entity = entity;
  46. this.files = file;
  47. } else {
  48. this.entity = {};
  49. this.files = [];
  50. }
  51. },
  52. async search(searchKey, level) {
  53. this.pagination.searchKey = searchKey;
  54. this.pagination.pageNum = 1;
  55. this.pagination.dictLevel = level === 0 ? "" : level;
  56. await this.fetch();
  57. },
  58. async clearSearch() {
  59. this.pagination.searchKey = "";
  60. // await this.fetch();
  61. },
  62. },
  63. });