| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import { defineStore } from 'pinia';
- import { message } from 'ant-design-vue';
- import { getList, addToCard, addFavorite, delFavorite, getFavoriteList } from '@/api/goods';
- import { goodsList } from '@/utils/mock';
- export const useGoodsStore = defineStore('goods', {
- state: () => ({
- params: {
- pageNum: 1,
- pageSize: 24,
- total: 0,
- categoryId: ''
- },
- list: []
- }),
- actions: {
- resetListData() {
- this.list = [];
- },
- async fetchListData() {
- const res = await getList({
- pageNum: this.params.pageNum,
- pageSize: this.params.pageSize,
- categoryId: this.params.categoryId
- });
- this.list = res.data?.records || [];
- this.params.total = res.data?.total || 0;
- // this.list = goodsList;
- // this.params.total = 120;
- },
- async fetchAllData(params) {
- const res = await getList(params);
- return Promise.resolve(res.data?.records || []);
- // return new Promise(resolve => resolve(goodsList))
- },
- resetParams() {
- this.params.pageNum = 1;
- this.params.total = 0;
- this.params.categoryId = '';
- },
- updateParams(object = {}) {
- Object.keys(object).forEach(key => {
- if (this.params[key] != undefined) {
- this.params[key] = object[key];
- }
- })
- },
- async addToCard(params) {
- await addToCard(params)
- message.success('添加成功')
- },
- async addFavorite(params) {
- await addFavorite(params)
- message.success('添加成功')
- },
- async getFavoriteList(params) {
- return getFavoriteList(params)
- },
- async delFavorite(params) {
- return delFavorite(params).then(() => {
- message.success('删除成功')
- })
- }
- }
- })
|