import { defineStore } from 'pinia' import { reactive, ref } from 'vue' import { createCollection, deleteCollection, updateCollection, retrievalCollection } from '@/api/collection' import { formatDate } from '@/utils/formatDate' export const collectionOperate = defineStore('payment', () => { // 定义数据 const paymentList = reactive([]) const paymentTotal = ref(0) // 定义修改数据的方法 const getPaymentList = (data) => { retrievalCollection(data).then(res => { if (res.code === 0) { const list = res.data.list list.forEach(item => { item.collectionTime = formatDate(item.collectionTime) console.log(item.collectionTime) }) paymentList.length = 0 paymentList.push(...list) } }) } const postCollection = (data) => { createCollection(data).then(res => { if (res.code === 0) { console.log(res.data) } }) } const putCollection = (data) => { updateCollection(data).then(res => { if (res.code === 0) { console.log(res.data) } }) } const delCollection = (data) => { deleteCollection(data).then(res => { if (res.code === 0) { console.log(res.data) } }) } const changePaymentList = (list) => { list.forEach(item => { item.collectionTime = formatDate(item.collectionTime) }) paymentList.length = 0 paymentList.push(...list) } const changePaymentTotal = (total) => { paymentTotal.value = total } return { paymentList, paymentTotal, getPaymentList, postCollection, putCollection, delCollection, changePaymentList, changePaymentTotal } })