shop.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { defineStore } from "pinia";
  2. import { SHOP_CART_LIST, SHOP_ORDER_STATUS, CONTENT_FLOAT, SHOP_ADDRESS_LIST } from "@/api";
  3. import { setStorage, getStorage } from '@/utils'
  4. const state = () => ({
  5. cartList: [],
  6. cartNum: 0,
  7. orderStatus: [],
  8. hotLink: [],
  9. addressList: [],
  10. logistics: {},
  11. tabParams: null
  12. })
  13. export const useShopStore = defineStore('shop', {
  14. state,
  15. getters: {
  16. getCartList() {
  17. return this.cartList
  18. },
  19. getCartNum() {
  20. return this.cartNum
  21. },
  22. getOrderStatus() {
  23. return this.orderStatus
  24. },
  25. getHotLink() {
  26. // if (!this.hotLink.length) {
  27. // this.setHotLink();
  28. // }
  29. return this.hotLink || [];
  30. },
  31. getAddressList() {
  32. return this.addressList || [];
  33. },
  34. getLogistics() {
  35. return this.logistics || {}
  36. },
  37. getTabParams() {
  38. return this.tabParams || null
  39. }
  40. },
  41. actions: {
  42. async setCartList(is_free) {
  43. try {
  44. const { data: { list = [], cartCount = 0 } } = await SHOP_CART_LIST(is_free);
  45. this.cartList = list || [];
  46. this.cartNum = cartCount;
  47. } catch (error) { }
  48. },
  49. setCartNum(_num_) {
  50. this.cartNum = _num_
  51. },
  52. async setOrderStatus() {
  53. try {
  54. const res = await SHOP_ORDER_STATUS();
  55. let arr = Object.entries(res.data).map(([key, value]) => ({
  56. status: key,
  57. value: value
  58. }));
  59. this.orderStatus = arr
  60. } catch (error) { }
  61. },
  62. async setHotLink() {
  63. try {
  64. const res = await CONTENT_FLOAT({
  65. type: 'image-text',
  66. posititon: 'search'
  67. })
  68. this.hotLink = res.data
  69. } catch (error) { }
  70. },
  71. async setAddressList() {
  72. try {
  73. const res = await SHOP_ADDRESS_LIST()
  74. this.addressList = res.data
  75. } catch (error) { }
  76. },
  77. setLogistics(data) {
  78. this.logistics = data
  79. },
  80. setTabParams(params) {
  81. this.tabParams = params;
  82. }
  83. }
  84. })