refactor(CheckoutView): use salix for createOrder
gitea/hedera-web/pipeline/pr-beta This commit looks good
Details
gitea/hedera-web/pipeline/pr-beta This commit looks good
Details
This commit is contained in:
parent
410bf86913
commit
f5e17900d7
|
@ -8,6 +8,7 @@ import VnSelect from 'src/components/common/VnSelect.vue';
|
|||
import { formatDateTitle, formatDate } from 'src/lib/filters.js';
|
||||
import useNotify from 'src/composables/useNotify.js';
|
||||
import { onUserId } from 'src/utils/onUserId';
|
||||
import { useUserStore } from 'stores/user';
|
||||
import { useAppStore } from 'stores/app';
|
||||
import { storeToRefs } from 'pinia';
|
||||
|
||||
|
@ -18,6 +19,7 @@ const route = useRoute();
|
|||
const router = useRouter();
|
||||
const { notify } = useNotify();
|
||||
const appStore = useAppStore();
|
||||
const userStore = useUserStore();
|
||||
const { localeDates, isMobile } = storeToRefs(appStore);
|
||||
|
||||
const stepperRef = ref(null);
|
||||
|
@ -299,30 +301,43 @@ const onPreviousStep = async stepIndex => {
|
|||
|
||||
const submit = async () => {
|
||||
loading.value = true;
|
||||
let query =
|
||||
'CALL myOrder_create(@orderId, #date, #method, #agency, #address); SELECT @orderId;';
|
||||
if (id) {
|
||||
orderForm.value.id = id;
|
||||
query =
|
||||
'CALL myOrder_configure(#id, #date, #method, #agency, #address)';
|
||||
|
||||
const userId = userStore?.user?.id;
|
||||
|
||||
if (!userId) {
|
||||
throw 'no user id';
|
||||
}
|
||||
|
||||
let resultSet;
|
||||
try {
|
||||
const { date, ...restOfForm } = orderForm.value;
|
||||
const _date = new Date(date);
|
||||
resultSet = await jApi.execQuery(query, { ...restOfForm, date: _date });
|
||||
if (id) {
|
||||
notify(t('orderUpdated'), 'positive');
|
||||
if (route.query.continue === 'catalog') {
|
||||
router.push({ name: 'catalog' });
|
||||
} else {
|
||||
router.push({ name: 'basket', params: { id } });
|
||||
}
|
||||
|
||||
if (!id) {
|
||||
const response = await api.post(
|
||||
'Orders',
|
||||
{
|
||||
sourceApp: 'WEB',
|
||||
landed: new Date(date),
|
||||
clientFk: userId,
|
||||
companyFk: 442, // SELECT defaultCompanyFk FROM orderConfig; (wtf)
|
||||
addressFk: orderForm.value.address,
|
||||
agencyModeFk: orderForm.value.agency,
|
||||
configured: new Date(),
|
||||
},
|
||||
);
|
||||
const orderId = response.data.id;
|
||||
appStore.loadIntoBasket(orderId);
|
||||
router.push({ name: 'catalog' });
|
||||
} else {
|
||||
const orderId = resultSet.results[1].data[0]['@orderId'];
|
||||
appStore.loadIntoBasket(orderId);
|
||||
orderForm.value.id = id;
|
||||
let query = 'CALL myOrder_configure(#id, #date, #method, #agency, #address)';
|
||||
let resultSet = await jApi.execQuery(query, { ...restOfForm, date: _date });
|
||||
notify(t('orderUpdated'), 'positive');
|
||||
if (route.query.continue === 'catalog') {
|
||||
router.push({ name: 'catalog' });
|
||||
} else {
|
||||
router.push({ name: 'basket', params: { id } });
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error submitting order:', error);
|
||||
|
|
Loading…
Reference in New Issue