1405/01/20-add giftcard & discount

This commit is contained in:
2026-04-09 13:58:37 +03:30
parent 8919374055
commit 4a9cb2a944
6 changed files with 251 additions and 100 deletions
+6
View File
@@ -0,0 +1,6 @@
import useAxios from "@/utils/useAxios";
//customer
export const registerCodeGiftCard = async (code: string) => await useAxios.post(`/customer/giftcard/use`, {code:code})
export const registerCodeDiscount = async (code: string) => await useAxios.post(`customer/validateDiscount`, {code:code})
+5
View File
@@ -45,6 +45,11 @@ const router = createRouter({
name: 'transactions', name: 'transactions',
component: () => import('@/views/base/transactions/index.vue') component: () => import('@/views/base/transactions/index.vue')
}, },
{
path: 'giftCard',
name: 'giftCard',
component: () => import('@/views/base/giftCard/index.vue')
},
{ {
path: 'wallet', path: 'wallet',
name: 'wallet', name: 'wallet',
+1 -1
View File
@@ -50,8 +50,8 @@ _axios.interceptors.response.use(
return response.data return response.data
}, },
async function (error) { async function (error) {
// console.log('this is axios error', error)
if (error.response.data && error.response.data.message) { if (error.response.data && error.response.data.message) {
checkStatus(error.response.data.message, error.response.status, error.config) checkStatus(error.response.data.message, error.response.status, error.config)
} }
+57 -2
View File
@@ -78,9 +78,24 @@
<div class="fixed bottom-20 left-0 right-0 bg-white border-t border-gray-200 p-4 shadow-lg z-1"> <div class="fixed bottom-20 left-0 right-0 bg-white border-t border-gray-200 p-4 shadow-lg z-1">
<div class="flex justify-between items-center mb-4"> <div class="flex justify-between items-center mb-4">
<div class="text-lg font-semibold">مجموع:</div> <div class="text-lg font-semibold">مجموع:</div>
<div class="flex flex-col gap-2 ">
<div class="text-primary font-bold text-xl"> <div class="text-primary font-bold text-xl">
{{ usePrice(displaytotalPrice) }}
</div>
</div>
<div class="!text-primary font-bold text-xs line-through cursor-pointer "
v-if="discountInfo?.amount>0"
@click="showDiscountModal=true">
{{ usePrice(totalPrice) }} {{ usePrice(totalPrice) }}
</div> </div>
<div v-else
class="!text-primary font-bold text-xs underline-solid underline cursor-pointer"
@click="showDiscountModal=true">
کد تخفیف دارم
</div>
</div> </div>
<BasicButton <BasicButton
class="w-full py-3" class="w-full py-3"
@@ -94,6 +109,14 @@
</div> </div>
</div> </div>
</div> </div>
<AModal v-model:visible="showDiscountModal" ok-text="اعمال کد تخفیف" cancel-text="انصراف" @ok="submitDiscount"
@cancel="showDiscountModal=false">
<div class="p-5">
<div>کد تخفیف</div>
<AInput v-model:value="discountCode"></AInput>
</div>
</AModal>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
@@ -126,11 +149,17 @@ import parsianImg from '@/assets/img/parsianImg.svg'
import venusImg from '@/assets/img/venousImg.svg' import venusImg from '@/assets/img/venousImg.svg'
import {loading, getToken} from '@/utils' import {loading, getToken} from '@/utils'
import GoldLoading from '@/components/GoldLoading.vue' import GoldLoading from '@/components/GoldLoading.vue'
import {registerCodeDiscount} from "@/api/giftCard";
const cartStore = useCartStore() const cartStore = useCartStore()
const walletStore = useWalletStore() const walletStore = useWalletStore()
const fundStore = useFundUserStore() const fundStore = useFundUserStore()
const infoVisible = ref(false) const infoVisible = ref(false)
const showDiscountModal = ref(false)
const discountCode = ref<string>('')
const discountInfo = ref()
let totalPriceWithDiscount = 0
const price = computed((): Price => <Price>lastPrice.value ?? 0) const price = computed((): Price => <Price>lastPrice.value ?? 0)
// Watch for price updates and update cart items // Watch for price updates and update cart items
@@ -164,6 +193,28 @@ watch(lastPrice, () => {
const totalPrice = computed(() => { const totalPrice = computed(() => {
return parseInt(cartStore.cartItems.reduce((sum, item) => sum + item.totalPrice, 0)) return parseInt(cartStore.cartItems.reduce((sum, item) => sum + item.totalPrice, 0))
}) })
const displaytotalPrice = computed(() => {
if (discountInfo.value?.amount > 0) {
return (totalPrice.value - (totalPrice.value * discountInfo.value?.amount)).toFixed(0)
} else
return totalPrice.value
})
async function submitDiscount() {
try {
loading.value = true
const temp = await registerCodeDiscount(discountCode.value)
discountInfo.value = temp.giftcard
message.success('کد تخفیف با موفقیت اعمال شد')
showDiscountModal.value = false
} catch (e) {
} finally {
loading.value = false
}
}
function getProductImage(product: any) { function getProductImage(product: any) {
// Check if product has file field from server with src property // Check if product has file field from server with src property
@@ -253,12 +304,15 @@ async function handleCheckout() {
} }
// Check wallet balance for cash method items (without gateway) // Check wallet balance for cash method items (without gateway)
const cashItemsTotal = cartStore.cartItems let cashItemsTotal = cartStore.cartItems
.filter(item => item.method === 'cash' && !item.gateway) .filter(item => item.method === 'cash' && !item.gateway)
.reduce((sum, item) => parseInt(sum + item.totalPrice), 0) .reduce((sum, item) => parseInt(sum + item.totalPrice), 0)
if (cashItemsTotal > 0) { if (cashItemsTotal > 0) {
// Ensure wallet info is loaded // Ensure wallet info is loaded
if (discountInfo.value.amount>0){
cashItemsTotal=cashItemsTotal-cashItemsTotal*discountInfo.value.amount
}
if (!walletStore.walletInfo) { if (!walletStore.walletInfo) {
await walletStore.getMyWallet() await walletStore.getMyWallet()
} }
@@ -312,7 +366,8 @@ async function handleCheckout() {
gateway: item.gateway, gateway: item.gateway,
product_id: product.id, product_id: product.id,
method: item.method, method: item.method,
number: item.quantity number: item.quantity,
discount_code:discountInfo.value.code
} }
}) })
+78
View File
@@ -0,0 +1,78 @@
<template>
<div>
<div class="bg-white py-3 px-3 text-black font-bold drop-shadow z-[1999] wrap-fix">کارت هدیه</div>
<div class="px-5 pt-26 pb-2">
<a-form :model="form" class="!mt-5" name="basic" @finish="registerGiftCard">
<div class="border-gray-200 border-1 rounded-xl p-5 trans h-40 relative">
<bg_main />
<div class="z-100 relative">
<a-form-item :rules="[required()]" label="کد کارت هدیه" name="code">
<BasicInput
v-model:value="form.code"
place-holder="کد کارت هدیه را وارد کنید"
size="large"
type="text"
/>
</a-form-item>
<div class="font-bold text-xs mt-3">
کد کارت هدیه خود را در فیلد بالا وارد کنید و سپس دکمه ثبت را بزنید.
</div>
</div>
</div>
<a-form-item>
<BasicButton
:disabled="disableButton"
class="w-full py-2 mt-5"
html-type="submit"
type="primary"
>
<div>
<a-spin v-if="loading" size="small" />
<div v-else>ثبت کد</div>
</div>
</BasicButton>
</a-form-item>
</a-form>
</div>
</div>
</template>
<script lang="ts" setup>
import { computed, ref } from 'vue'
import { loading } from '@/utils'
import BasicButton from '@/components/BasicPacks/BasicButton.vue'
import Bg_main from '@/components/bg_main.vue'
import { registerCodeGiftCard } from '@/api/giftCard'
import { message } from 'ant-design-vue'
import BasicInput from '@/components/BasicPacks/BasicInput.vue'
import { required } from '@/utils/inputRules'
const form = ref<{ code: string }>({
code: ''
})
const disableButton = computed(() => {
if (!loading.value) {
return !form.value.code || form.value.code.trim().length === 0
} else {
return true
}
})
async function registerGiftCard() {
try {
loading.value = true
await registerCodeGiftCard(form.value.code)
message.success('کد کارت هدیه با موفقیت ثبت شد')
form.value.code = ''
} catch (e: any) {
// message.error(e?.response?.data?.message || 'خطا در ثبت کد کارت هدیه')
} finally {
loading.value = false
}
}
</script>
<style scoped>
</style>
+7
View File
@@ -57,6 +57,13 @@
<div>لیست دریافتی ها</div> <div>لیست دریافتی ها</div>
</div> </div>
</BasicButton> </BasicButton>
<BasicButton v-if="isToken()" icon-size="16" class="!font-bold w-15rem"
@click="$router.push({name: 'giftCard'}); popVisible = false">
<div class="flex gap-2 items-center">
<BasicIcon icon="vuesax-linear:gift" size="16" class="absolute right-2" />
<div>ثبت کارت هدیه</div>
</div>
</BasicButton>
<BasicButton icon-size="16" class="!font-bold w-15rem" <BasicButton icon-size="16" class="!font-bold w-15rem"
@click="$router.push({name: 'about'}); popVisible = false"> @click="$router.push({name: 'about'}); popVisible = false">
<div class="flex gap-2 items-center"> <div class="flex gap-2 items-center">