import { defineStore } from "pinia"; import { request } from "../api"; export const useCollectStore = defineStore({ id: "collect", state: () => { return { lists: [], entity: {}, files: [], currentLevel: null, pagination: { dictLevel: "", endTime: "", pageNum: 0, pageSize: 20, searchKey: "", startTime: "", }, }; }, getters: {}, actions: { async fetch() { const { data, status } = await request.post("/show/goods/pageList", { ...this.pagination, }); if (data.code === 0) { const { records, total, current, page } = data.data; this.lists = records; this.pagination.total = total; this.pagination.current = current; this.pagination.page = page; } }, async getCollectList(page, level) { this.pagination.pageNum = page || 1; this.pagination.dictLevel = level === 0 ? "" : level; this.currentLevel = level; await this.fetch(); }, async getDetail(id) { const { data, status } = await request.get(`show/goods/detail/${id}`); if (data.code === 0) { const { entity, file } = data.data; this.entity = entity; this.files = file; } else { this.entity = {}; this.files = []; } }, async search(searchKey, level) { this.pagination.searchKey = searchKey; this.pagination.pageNum = 1; this.pagination.dictLevel = level === 0 ? "" : level; await this.fetch(); }, async clearSearch() { this.pagination.searchKey = ""; // await this.fetch(); }, }, });