Collection.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { defineStore } from 'pinia'
  2. import { reactive, ref } from 'vue'
  3. import { createCollection, deleteCollection, updateCollection, retrievalCollection } from '@/api/collection'
  4. import { formatDate } from '@/utils/formatDate'
  5. export const collectionOperate = defineStore('payment', () => {
  6. // 定义数据
  7. const paymentList = reactive([])
  8. const paymentTotal = ref(0)
  9. // 定义修改数据的方法
  10. const getPaymentList = (data) => {
  11. retrievalCollection(data).then(res => {
  12. if (res.code === 0) {
  13. const list = res.data.list
  14. list.forEach(item => {
  15. item.collectionTime = formatDate(item.collectionTime)
  16. console.log(item.collectionTime)
  17. })
  18. paymentList.length = 0
  19. paymentList.push(...list)
  20. }
  21. })
  22. }
  23. const postCollection = (data) => {
  24. createCollection(data).then(res => {
  25. if (res.code === 0) {
  26. console.log(res.data)
  27. }
  28. })
  29. }
  30. const putCollection = (data) => {
  31. updateCollection(data).then(res => {
  32. if (res.code === 0) {
  33. console.log(res.data)
  34. }
  35. })
  36. }
  37. const delCollection = (data) => {
  38. deleteCollection(data).then(res => {
  39. if (res.code === 0) {
  40. console.log(res.data)
  41. }
  42. })
  43. }
  44. const changePaymentList = (list) => {
  45. list.forEach(item => {
  46. item.collectionTime = formatDate(item.collectionTime)
  47. })
  48. paymentList.length = 0
  49. paymentList.push(...list)
  50. }
  51. const changePaymentTotal = (total) => {
  52. paymentTotal.value = total
  53. }
  54. return {
  55. paymentList,
  56. paymentTotal,
  57. getPaymentList,
  58. postCollection,
  59. putCollection,
  60. delCollection,
  61. changePaymentList,
  62. changePaymentTotal
  63. }
  64. })