Collection.js 1.9 KB

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