64 lines
1.6 KiB
TypeScript
64 lines
1.6 KiB
TypeScript
import { dialog } from 'stores/utils';
|
|
import { defineStore } from 'pinia';
|
|
import { useI18n } from 'vue-i18n';
|
|
import { ref } from 'vue';
|
|
import { DebitNotePayload } from 'src/stores/debit-note';
|
|
import { PayCondition } from 'src/stores/quotations';
|
|
|
|
// NOTE: Import types
|
|
|
|
// NOTE: Import stores
|
|
|
|
const DEFAULT_DATA: DebitNotePayload = {
|
|
productServiceList: [],
|
|
debitNoteQuotationId: '',
|
|
worker: [],
|
|
payBillDate: new Date(),
|
|
paySplitCount: 0,
|
|
payCondition: PayCondition.Full,
|
|
dueDate: new Date(Date.now() + 86400000),
|
|
discount: 0,
|
|
status: 'CREATED',
|
|
remark: '#[quotation-labor]<br/><br/>#[quotation-payment]',
|
|
quotationId: '',
|
|
agentPrice: false,
|
|
};
|
|
|
|
export const useDebitNoteForm = defineStore('form-debit-note', () => {
|
|
const { t } = useI18n();
|
|
|
|
let resetFormData = structuredClone(DEFAULT_DATA);
|
|
|
|
const currentFormData = ref<DebitNotePayload>(structuredClone(resetFormData));
|
|
|
|
const currentFormState = ref<{
|
|
mode: null | 'info' | 'create' | 'edit';
|
|
}>({
|
|
mode: null,
|
|
});
|
|
|
|
function isFormDataDifferent() {
|
|
const { ...resetData } = resetFormData;
|
|
const { ...currData } = currentFormData.value;
|
|
|
|
return JSON.stringify(resetData) !== JSON.stringify(currData);
|
|
}
|
|
|
|
function resetForm(clean = false) {
|
|
if (clean) {
|
|
currentFormData.value = structuredClone(DEFAULT_DATA);
|
|
resetFormData = structuredClone(DEFAULT_DATA);
|
|
return;
|
|
}
|
|
|
|
currentFormData.value = structuredClone(resetFormData);
|
|
|
|
currentFormState.value.mode = 'info';
|
|
}
|
|
|
|
return {
|
|
currentFormData,
|
|
isFormDataDifferent,
|
|
resetForm,
|
|
};
|
|
});
|