Compare commits
4
Commits
54c43fab63
...
ghatre
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a9922b33ef | ||
|
|
9ba2d3ec96 | ||
|
|
1905408993 | ||
|
|
4a9cb2a944 |
Vendored
+1
-4
@@ -7,6 +7,7 @@ export {}
|
||||
|
||||
declare module 'vue' {
|
||||
export interface GlobalComponents {
|
||||
ABadge: typeof import('ant-design-vue/es')['Badge']
|
||||
AButton: typeof import('ant-design-vue/es')['Button']
|
||||
AConfigProvider: typeof import('ant-design-vue/es')['ConfigProvider']
|
||||
ADivider: typeof import('ant-design-vue/es')['Divider']
|
||||
@@ -15,16 +16,13 @@ declare module 'vue' {
|
||||
AInput: typeof import('ant-design-vue/es')['Input']
|
||||
AInputPassword: typeof import('ant-design-vue/es')['InputPassword']
|
||||
AModal: typeof import('ant-design-vue/es')['Modal']
|
||||
ARadio: typeof import('ant-design-vue/es')['Radio']
|
||||
ARadioButton: typeof import('ant-design-vue/es')['RadioButton']
|
||||
ARadioGroup: typeof import('ant-design-vue/es')['RadioGroup']
|
||||
ASelect: typeof import('ant-design-vue/es')['Select']
|
||||
ASelectOption: typeof import('ant-design-vue/es')['SelectOption']
|
||||
ASlider: typeof import('ant-design-vue/es')['Slider']
|
||||
ASpin: typeof import('ant-design-vue/es')['Spin']
|
||||
ASwitch: typeof import('ant-design-vue/es')['Switch']
|
||||
ATag: typeof import('ant-design-vue/es')['Tag']
|
||||
ATextarea: typeof import('ant-design-vue/es')['Textarea']
|
||||
ATooltip: typeof import('ant-design-vue/es')['Tooltip']
|
||||
BaseDatePicker: typeof import('./src/components/BasicPacks/BaseDatePicker/src/BaseDatePicker.vue')['default']
|
||||
Basic: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/basic.vue')['default']
|
||||
@@ -68,6 +66,5 @@ declare module 'vue' {
|
||||
TransactionSkeleton: typeof import('./src/components/TransactionSkeleton.vue')['default']
|
||||
VanActionSheet: typeof import('vant/es')['ActionSheet']
|
||||
VanDialog: typeof import('vant/es')['Dialog']
|
||||
VanField: typeof import('vant/es')['Field']
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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})
|
||||
+15
-10
@@ -20,16 +20,16 @@ const router = createRouter({
|
||||
redirect: {name: 'buyProduct'},
|
||||
component: () => import('../views/base/index.vue'),
|
||||
children: [
|
||||
{
|
||||
path: 'home',
|
||||
name: 'home',
|
||||
component: () => import('../views/base/home/index.vue')
|
||||
},
|
||||
{
|
||||
path: 'gold',
|
||||
name: 'gold',
|
||||
component: () => import('@/views/base/gold/index.vue')
|
||||
},
|
||||
// {
|
||||
// path: 'home',
|
||||
// name: 'home',
|
||||
// component: () => import('../views/base/home/index.vue')
|
||||
// },
|
||||
// {
|
||||
// path: 'gold',
|
||||
// name: 'gold',
|
||||
// component: () => import('@/views/base/gold/index.vue')
|
||||
// },
|
||||
{
|
||||
path: 'buyProduct',
|
||||
name: 'buyProduct',
|
||||
@@ -45,6 +45,11 @@ const router = createRouter({
|
||||
name: 'transactions',
|
||||
component: () => import('@/views/base/transactions/index.vue')
|
||||
},
|
||||
{
|
||||
path: 'giftCard',
|
||||
name: 'giftCard',
|
||||
component: () => import('@/views/base/giftCard/index.vue')
|
||||
},
|
||||
{
|
||||
path: 'wallet',
|
||||
name: 'wallet',
|
||||
|
||||
+58
-1
@@ -2,6 +2,8 @@ import { computed, ref } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
import type { CartItem } from '@/models/cart'
|
||||
import type { Product } from '@/models/products'
|
||||
import type { Price } from '@/models/home'
|
||||
import { getProducts } from '@/api/products'
|
||||
|
||||
const CART_STORAGE_KEY = 'ghatre_cart'
|
||||
|
||||
@@ -93,6 +95,58 @@ export const useCartStore = defineStore('cart', () => {
|
||||
return cartItems.value.length
|
||||
})
|
||||
|
||||
function syncProductsFromServer(serverProducts: Product[]): number {
|
||||
const productMap = new Map(serverProducts.map(p => [p.id, p]))
|
||||
const beforeCount = cartItems.value.length
|
||||
|
||||
cartItems.value = cartItems.value
|
||||
.filter(item => productMap.has(item.product.id))
|
||||
.map(item => ({
|
||||
...item,
|
||||
product: { ...productMap.get(item.product.id)! }
|
||||
}))
|
||||
|
||||
if (cartItems.value.length > 0 || beforeCount > 0) {
|
||||
saveCartToStorage()
|
||||
}
|
||||
|
||||
return beforeCount - cartItems.value.length
|
||||
}
|
||||
|
||||
function recalculateCartPrices(lastPrice: Price) {
|
||||
if (!lastPrice || cartItems.value.length === 0) return
|
||||
|
||||
cartItems.value.forEach((item) => {
|
||||
const product = item.product
|
||||
let newPrice = 0
|
||||
|
||||
if (product.group_type == 'آبشده') {
|
||||
newPrice = lastPrice.price_last ?? 0
|
||||
} else {
|
||||
newPrice = product.amount * (lastPrice.price_last ?? 0)
|
||||
}
|
||||
|
||||
product.price = newPrice
|
||||
product.sellPrice = product.amount * (lastPrice.sell ?? 0)
|
||||
item.price = newPrice + (product.cash_fee_buy ?? 0)
|
||||
item.totalPrice = parseInt(String(item.price * item.quantity))
|
||||
})
|
||||
|
||||
saveCartToStorage()
|
||||
}
|
||||
|
||||
async function refreshCartFromServer(): Promise<number> {
|
||||
if (cartItems.value.length === 0) return 0
|
||||
|
||||
try {
|
||||
const serverProducts: Product[] = await getProducts()
|
||||
return syncProductsFromServer(serverProducts)
|
||||
} catch (e) {
|
||||
console.error('Error refreshing cart from server:', e)
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
cartItems,
|
||||
addToCart,
|
||||
@@ -102,7 +156,10 @@ export const useCartStore = defineStore('cart', () => {
|
||||
totalPrice,
|
||||
itemCount,
|
||||
loadCartFromStorage,
|
||||
saveCartToStorage
|
||||
saveCartToStorage,
|
||||
syncProductsFromServer,
|
||||
recalculateCartPrices,
|
||||
refreshCartFromServer
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -50,9 +50,9 @@ _axios.interceptors.response.use(
|
||||
return response.data
|
||||
},
|
||||
async function (error) {
|
||||
// console.log('this is axios error', error)
|
||||
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)
|
||||
}
|
||||
|
||||
//console.log('this is error on interceptors.response', error.config.meta)
|
||||
|
||||
+178
-134
@@ -14,95 +14,129 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<GoldLoading v-model:show="infoVisible" title="" />
|
||||
<div class="px-5 pt-26 pb-30">
|
||||
<GoldLoading v-model:show="infoVisible" title=""/>
|
||||
<div class="px-5 pt-26 pb-30" :class="loading ? 'h-[60vh]' : ''">
|
||||
<template v-if="loading">
|
||||
<TransactionSkeleton v-for="i in 3" :key="i" class="mt-4" />
|
||||
</template>
|
||||
<template v-else>
|
||||
<!-- Empty Cart Message -->
|
||||
<div v-if="cartStore.itemCount === 0" class="flex flex-col items-center justify-center h-[60vh]">
|
||||
<div class="text-gray-500 text-lg font-semibold mb-4">سبد خرید شما خالی است</div>
|
||||
<BasicButton type="primary" @click="$router.push({ name: 'buyProduct' })">
|
||||
مشاهده محصولات
|
||||
</BasicButton>
|
||||
</div>
|
||||
<div class="text-gray-500 text-lg font-semibold mb-4">سبد خرید شما خالی است</div>
|
||||
<BasicButton type="primary" @click="$router.push({ name: 'buyProduct' })">
|
||||
مشاهده محصولات
|
||||
</BasicButton>
|
||||
</div>
|
||||
|
||||
<!-- Cart Items -->
|
||||
<div v-else>
|
||||
<div class="space-y-4 mb-20">
|
||||
<div
|
||||
<!-- Cart Items -->
|
||||
<div v-else>
|
||||
<div class="space-y-4 mb-20">
|
||||
<div
|
||||
v-for="item in cartStore.cartItems"
|
||||
:key="item.id"
|
||||
class="bg-white rounded-lg border border-gray-200 p-4 shadow-sm"
|
||||
>
|
||||
<div class="flex gap-4">
|
||||
<!-- Product Image -->
|
||||
<div class="bg-gray-100 rounded-lg flex justify-center items-center p-1 min-w-[80px] h-[80px]">
|
||||
<img
|
||||
>
|
||||
<div class="flex gap-4">
|
||||
<!-- Product Image -->
|
||||
<div class="bg-gray-100 rounded-lg flex justify-center items-center p-1 min-w-[80px] h-[80px]">
|
||||
<img
|
||||
:src="getProductImage(item.product)"
|
||||
class="max-w-full max-h-full object-contain"
|
||||
alt=""
|
||||
/>
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Product Info -->
|
||||
<div class="flex-1 flex flex-col justify-between">
|
||||
<div>
|
||||
<div class="text-base font-semibold mb-1">{{ item.product.title }}</div>
|
||||
<!-- <div class="text-xs text-gray-500 mb-2">-->
|
||||
<!-- {{ getProductAmount(item.product.amount) }}-->
|
||||
<!-- </div>-->
|
||||
<div class="text-xs text-gray-500 mb-2">
|
||||
روش پرداخت: {{ item.method === 'cash' ? 'نقدی' : 'طلایی' }}
|
||||
<span v-if="item.method === 'cash' && item.gateway" class="mr-2">(با درگاه)</span>
|
||||
</div>
|
||||
<div class="text-xs text-gray-500">
|
||||
تعداد: {{ item.quantity }} عدد
|
||||
<span v-if="item.goldVazn" class="mr-2">| وزن: {{ formatWeight(item.goldVazn) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Product Info -->
|
||||
<div class="flex-1 flex flex-col justify-between">
|
||||
<div>
|
||||
<div class="text-base font-semibold mb-1">{{ item.product.title }}</div>
|
||||
<!-- <div class="text-xs text-gray-500 mb-2">-->
|
||||
<!-- {{ getProductAmount(item.product.amount) }}-->
|
||||
<!-- </div>-->
|
||||
<div class="text-xs text-gray-500 mb-2">
|
||||
روش پرداخت: {{ item.method === 'cash' ? 'نقدی' : 'طلایی' }}
|
||||
<span v-if="item.method === 'cash' && item.gateway" class="mr-2">(با درگاه)</span>
|
||||
</div>
|
||||
<div class="text-xs text-gray-500">
|
||||
تعداد: {{ item.quantity }} عدد
|
||||
<span v-if="item.goldVazn" class="mr-2">| وزن: {{ formatWeight(item.goldVazn) }}</span>
|
||||
</div>
|
||||
<div class="flex items-center justify-between mt-2">
|
||||
<div class="text-primary font-bold">
|
||||
{{ usePrice(item.totalPrice) }}
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-between mt-2">
|
||||
<div class="text-primary font-bold">
|
||||
{{ usePrice(item.totalPrice) }}
|
||||
</div>
|
||||
<BasicIcon
|
||||
<BasicIcon
|
||||
icon="vuesax-linear:trash"
|
||||
class="text-red-500 cursor-pointer"
|
||||
@click.stop="handleRemoveItem(item.id)"
|
||||
/>
|
||||
</div>
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Total and Checkout -->
|
||||
<div class="fixed bottom-20 left-0 right-0 bg-white border-t border-gray-200 p-4 shadow-lg z-1">
|
||||
<!-- Total and Checkout -->
|
||||
<div class=" flex justify-center fixed bottom-20 left-0 right-0 z-1">
|
||||
<div class="md:w-[426px] w-full bg-white border-t border-gray-200 p-4 shadow-lg">
|
||||
<div class="flex justify-between items-center mb-4">
|
||||
<div class="text-lg font-semibold">مجموع:</div>
|
||||
<div class="text-primary font-bold text-xl">
|
||||
<div class="flex flex-col gap-2 ">
|
||||
<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) }}
|
||||
</div>
|
||||
<div v-else
|
||||
class="!text-primary font-bold text-xs underline-solid underline cursor-pointer"
|
||||
@click="showDiscountModal=true">
|
||||
کد تخفیف دارم
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<BasicButton
|
||||
class="w-full py-3"
|
||||
type="primary"
|
||||
size="large"
|
||||
@click="handleCheckout"
|
||||
class="w-full py-3"
|
||||
type="primary"
|
||||
size="large"
|
||||
@click="handleCheckout"
|
||||
>
|
||||
تسویه حساب
|
||||
</BasicButton>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</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 class="font-bold text-xs mt-3">
|
||||
*حساس به حروف بزرگ و کوچک
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</AModal>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, onUnmounted, watch, computed } from 'vue'
|
||||
import { useCartStore } from '@/store/cartStore'
|
||||
import { usePrice, usePriceWithoutType } from '@/utils/usePrice'
|
||||
import {ref, onMounted, onUnmounted, watch, computed} from 'vue'
|
||||
import {useCartStore} from '@/store/cartStore'
|
||||
import {usePrice, usePriceWithoutType} from '@/utils/usePrice'
|
||||
import BasicButton from '@/components/BasicPacks/BasicButton.vue'
|
||||
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import {message, Modal} from 'ant-design-vue'
|
||||
import img from '@/assets/img/user_ly1.svg'
|
||||
import {
|
||||
getLastPrices,
|
||||
@@ -110,12 +144,12 @@ import {
|
||||
stopPriceInterval,
|
||||
setIntervalGetLastPrice
|
||||
} from '@/utils/price'
|
||||
import { checkoutCart } from '@/api/card'
|
||||
import {checkoutCart} from '@/api/card'
|
||||
import router from '@/router'
|
||||
import { useWalletStore } from '@/store/walletStore'
|
||||
import { useFundUserStore } from '@/store/fundStore'
|
||||
import type { Price } from '@/models/home'
|
||||
import type { Order } from '@/models/order'
|
||||
import {useWalletStore} from '@/store/walletStore'
|
||||
import {useFundUserStore} from '@/store/fundStore'
|
||||
import type {Price} from '@/models/home'
|
||||
import type {Order} from '@/models/order'
|
||||
|
||||
// Image imports
|
||||
import defaultImg from '@/assets/img/defaultAbshodeh.svg'
|
||||
@@ -124,53 +158,62 @@ import mokaabImg from '@/assets/img/mokaabImg.svg'
|
||||
import sekkeImg from '@/assets/img/sekkeImg.svg'
|
||||
import parsianImg from '@/assets/img/parsianImg.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 TransactionSkeleton from '@/components/TransactionSkeleton.vue'
|
||||
import {registerCodeDiscount} from "@/api/giftCard";
|
||||
|
||||
const cartStore = useCartStore()
|
||||
const walletStore = useWalletStore()
|
||||
const fundStore = useFundUserStore()
|
||||
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)
|
||||
|
||||
// Watch for price updates and update cart items
|
||||
watch(lastPrice, () => {
|
||||
if (lastPrice.value && cartStore.cartItems.length > 0) {
|
||||
cartStore.cartItems.forEach((item) => {
|
||||
const product = item.product
|
||||
let newPrice = 0
|
||||
|
||||
if (product.group_type == 'آبشده') {
|
||||
newPrice = lastPrice.value?.price_last ?? 0
|
||||
} else {
|
||||
newPrice = product.amount * (lastPrice.value?.price_last ?? 0)
|
||||
}
|
||||
|
||||
// Update product price
|
||||
product.price = newPrice
|
||||
product.sellPrice = product.amount * (lastPrice.value?.sell ?? 0)
|
||||
|
||||
// Update item price and total price
|
||||
item.price = newPrice + (product.cash_fee_buy ?? 0)
|
||||
item.totalPrice = parseInt(item.price * item.quantity)
|
||||
})
|
||||
|
||||
// Save updated prices to storage
|
||||
cartStore.saveCartToStorage()
|
||||
if (lastPrice.value) {
|
||||
cartStore.recalculateCartPrices(lastPrice.value)
|
||||
}
|
||||
}, { deep: true, immediate: false })
|
||||
}, {deep: true, immediate: false})
|
||||
|
||||
// Computed total price that updates with price changes
|
||||
const totalPrice = computed(() => {
|
||||
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) {
|
||||
// Check if product has file field from server with src property
|
||||
if (product?.file?.src) {
|
||||
return product.file.src
|
||||
}
|
||||
|
||||
|
||||
// Fallback to local images based on group_type if file is empty or doesn't exist
|
||||
const type = product?.group_type
|
||||
switch (type) {
|
||||
@@ -238,62 +281,65 @@ async function handleCheckout() {
|
||||
// Check if user is logged in
|
||||
if (!getToken()) {
|
||||
message.warning('برای تسویه حساب، لطفا ابتدا وارد حساب کاربری خود شوید')
|
||||
await router.push({ name: 'login' })
|
||||
await router.push({name: 'login'})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if (cartStore.itemCount === 0) {
|
||||
message.warning('سبد خرید شما خالی است')
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if (!lastPrice.value) {
|
||||
message.error('لطفا منتظر بمانید تا قیمتها بارگذاری شوند')
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// Check wallet balance for cash method items (without gateway)
|
||||
const cashItemsTotal = cartStore.cartItems
|
||||
.filter(item => item.method === 'cash' && !item.gateway)
|
||||
.reduce((sum, item) => parseInt(sum + item.totalPrice), 0)
|
||||
|
||||
let cashItemsTotal = cartStore.cartItems
|
||||
.filter(item => item.method === 'cash' && !item.gateway)
|
||||
.reduce((sum, item) => parseInt(sum + item.totalPrice), 0)
|
||||
|
||||
if (cashItemsTotal > 0) {
|
||||
// Ensure wallet info is loaded
|
||||
if (discountInfo.value?.amount && discountInfo.value?.amount>0){
|
||||
cashItemsTotal=cashItemsTotal-cashItemsTotal*discountInfo.value?.amount
|
||||
}
|
||||
if (!walletStore.walletInfo) {
|
||||
await walletStore.getMyWallet()
|
||||
}
|
||||
|
||||
|
||||
if (!walletStore.walletInfo?.cash || cashItemsTotal > walletStore.walletInfo.cash) {
|
||||
message.error('موجودی کیف پول شما ناکافی است')
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check gold balance for gold method items
|
||||
const goldItemsTotal = cartStore.cartItems
|
||||
.filter(item => item.method === 'gold')
|
||||
.reduce((sum, item) => {
|
||||
// Calculate total gold weight needed
|
||||
const goldWeight = item.goldVazn ? item.goldVazn * item.quantity : 0
|
||||
return sum + goldWeight
|
||||
}, 0)
|
||||
|
||||
.filter(item => item.method === 'gold')
|
||||
.reduce((sum, item) => {
|
||||
// Calculate total gold weight needed
|
||||
const goldWeight = item.goldVazn ? item.goldVazn * item.quantity : 0
|
||||
return sum + goldWeight
|
||||
}, 0)
|
||||
|
||||
if (goldItemsTotal > 0) {
|
||||
// Ensure wallet info is loaded
|
||||
if (!walletStore.walletInfo) {
|
||||
await walletStore.getMyWallet()
|
||||
}
|
||||
|
||||
|
||||
if (!walletStore.walletInfo?.gold || goldItemsTotal > walletStore.walletInfo.gold) {
|
||||
message.error('موجودی کیف طلا شما ناکافی است')
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
loading.value = true
|
||||
infoVisible.value = true
|
||||
|
||||
|
||||
// Prepare orders array with same structure as createOrder for each product
|
||||
const orders: Order[] = cartStore.cartItems.map(item => {
|
||||
const product = item.product
|
||||
@@ -304,7 +350,7 @@ async function handleCheckout() {
|
||||
} else {
|
||||
productPrice = (product.amount ?? 0) * (lastPrice.value?.price_last ?? 0)
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
direction: 1, // 1 for buy (cart items are always buy orders)
|
||||
price: productPrice,
|
||||
@@ -312,13 +358,14 @@ async function handleCheckout() {
|
||||
gateway: item.gateway,
|
||||
product_id: product.id,
|
||||
method: item.method,
|
||||
number: item.quantity
|
||||
number: item.quantity,
|
||||
discount_code:discountInfo.value?.code
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
// Call checkoutCart API with orders array
|
||||
const data = await checkoutCart(orders)
|
||||
|
||||
|
||||
// Check for returnUrl (gateway payment)
|
||||
let returnUrl = null
|
||||
if (Array.isArray(data)) {
|
||||
@@ -329,17 +376,17 @@ async function handleCheckout() {
|
||||
} else if (data?.returnUrl) {
|
||||
returnUrl = data.returnUrl
|
||||
}
|
||||
|
||||
|
||||
// If returnUrl exists, redirect to gateway and stop execution
|
||||
if (returnUrl) {
|
||||
window.location.href = returnUrl
|
||||
return // Stop execution here
|
||||
}
|
||||
|
||||
|
||||
// If no gateway, continue with normal flow
|
||||
await walletStore.getMyWallet()
|
||||
cartStore.clearCart()
|
||||
await router.push({ name: 'transactions' })
|
||||
await router.push({name: 'transactions'})
|
||||
message.success('سفارشات شما با موفقیت ثبت شد')
|
||||
await fundStore.getMyFund()
|
||||
} catch (e: any) {
|
||||
@@ -355,40 +402,37 @@ async function initPrice() {
|
||||
try {
|
||||
await getLastPrices()
|
||||
await setIntervalGetLastPrice()
|
||||
|
||||
// Update prices for all cart items
|
||||
if (lastPrice.value && cartStore.cartItems.length > 0) {
|
||||
cartStore.cartItems.forEach((item) => {
|
||||
const product = item.product
|
||||
let newPrice = 0
|
||||
|
||||
if (product.group_type == 'آبشده') {
|
||||
newPrice = lastPrice.value?.price_last ?? 0
|
||||
} else {
|
||||
newPrice = product.amount * (lastPrice.value?.price_last ?? 0)
|
||||
}
|
||||
|
||||
// Update product price
|
||||
product.price = newPrice
|
||||
product.sellPrice = product.amount * (lastPrice.value?.sell ?? 0)
|
||||
|
||||
// Update item price and total price
|
||||
item.price = newPrice + (product.cash_fee_buy ?? 0)
|
||||
item.totalPrice =parseInt(item.price * item.quantity)
|
||||
})
|
||||
|
||||
// Save updated prices to storage
|
||||
cartStore.saveCartToStorage()
|
||||
if (lastPrice.value) {
|
||||
cartStore.recalculateCartPrices(lastPrice.value)
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshCart() {
|
||||
const removedCount = await cartStore.refreshCartFromServer()
|
||||
if (removedCount > 0) {
|
||||
message.warning(`${removedCount} محصول از سبد خرید حذف شد (دیگر در دسترس نیست)`)
|
||||
}
|
||||
if (lastPrice.value) {
|
||||
cartStore.recalculateCartPrices(lastPrice.value)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
// Load cart from storage if needed
|
||||
cartStore.loadCartFromStorage()
|
||||
await initPrice()
|
||||
loading.value = true
|
||||
try {
|
||||
await initPrice()
|
||||
await refreshCart()
|
||||
const refreshCartInfo=setInterval(async () => {
|
||||
await refreshCart()
|
||||
// await getUpPrice()
|
||||
}, 10000)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
<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-1">
|
||||
کد کارت هدیه خود را در فیلد بالا وارد کنید و سپس دکمه ثبت را بزنید.
|
||||
</div>
|
||||
<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>
|
||||
@@ -57,6 +57,13 @@
|
||||
<div>لیست دریافتی ها</div>
|
||||
</div>
|
||||
</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"
|
||||
@click="$router.push({name: 'about'}); popVisible = false">
|
||||
<div class="flex gap-2 items-center">
|
||||
@@ -137,7 +144,9 @@
|
||||
<!-- <div class="text-xs mt-1 font-bold">دریافت فیزیکی</div>-->
|
||||
<!-- </div>-->
|
||||
<div :class="setNavColor('cart')" class="tab" @click="setRoute('cart')">
|
||||
<Icon icon="vuesax-linear:shopping-cart" />
|
||||
<a-badge :count="cartStore.itemCount">
|
||||
<Icon icon="vuesax-linear:shopping-cart" />
|
||||
</a-badge>
|
||||
<div class="text-xs mt-1 font-bold">سبد خرید</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -173,7 +182,9 @@
|
||||
<div class="text-xs mt-1 font-bold">خرید محصول</div>
|
||||
</div>-->
|
||||
<div :class="setNavColor('cart')" class="tab" @click="setRoute('cart')">
|
||||
<Icon icon="vuesax-linear:shopping-cart" />
|
||||
<a-badge :count="cartStore.itemCount">
|
||||
<Icon icon="vuesax-linear:shopping-cart" />
|
||||
</a-badge>
|
||||
<div class="text-xs mt-1 font-bold">سبد خرید</div>
|
||||
</div>
|
||||
<div :class="setNavColor('login')" class="tab" @click="setRoute('login')">
|
||||
@@ -198,11 +209,14 @@ import BasicButton from '@/components/BasicPacks/BasicButton.vue'
|
||||
import type { Transaction } from '@/models/transaction'
|
||||
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
|
||||
import {isToken} from "@/utils";
|
||||
import { useCartStore } from '@/store/cartStore'
|
||||
|
||||
const currentRoute = computed(() => router.currentRoute.value.name)
|
||||
const cartStore = useCartStore()
|
||||
|
||||
const popVisible = ref(false)
|
||||
|
||||
const currentRoute = computed(() => router.currentRoute.value.name)
|
||||
|
||||
function setNavColor(val: string) {
|
||||
if (currentRoute.value === val) {
|
||||
return 'text-primary'
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
class="text-gray-500 text-xs number-ltr">{{ item.gold }}
|
||||
<div>{{item.unit}}</div>
|
||||
</div>
|
||||
<div class="text-gray-500 flex gap-1 text-xs items-center number-ltr">
|
||||
<div v-if="!isShopProduct" class="text-gray-500 flex gap-1 text-xs items-center number-ltr">
|
||||
<div :class="item.cash > 0 ? 'text-green-600':'text-red-600'" class="text-base">
|
||||
{{ usePriceWithoutType(item.cash?? 0) }}
|
||||
</div>
|
||||
@@ -25,7 +25,27 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="isGold" class="flex w-full justify-between mt-2">
|
||||
<template v-if="isShopProduct">
|
||||
<div class="flex w-full justify-between mt-2">
|
||||
<div class="text-gray-500">تعداد:</div>
|
||||
<div class="text-gray-500 text-xs number-ltr">{{ item?.gold ?? 0 }}</div>
|
||||
</div>
|
||||
<div class="flex w-full justify-between mt-2">
|
||||
<div class="text-gray-500">قیمت کل:</div>
|
||||
<div class="text-gray-500 flex gap-1 text-xs items-center number-ltr">
|
||||
<div class="text-base">{{ usePriceWithoutType(item.order?.total_price ?? 0) }}</div>
|
||||
ریال
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex w-full justify-between mt-2">
|
||||
<div class="text-gray-500">قیمت واحد:</div>
|
||||
<div class="text-gray-500 flex gap-1 text-xs items-center number-ltr">
|
||||
<div class="text-base">{{ usePriceWithoutType(item.order?.price ?? 0) }}</div>
|
||||
ریال
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<div v-else-if="isGold" class="flex w-full justify-between mt-2">
|
||||
<div class="text-gray-500">قیمت معامله:</div>
|
||||
<div class="text-gray-500 flex gap-1 text-xs items-center">
|
||||
<!-- <div class="text-base">{{ typeof parseInt((Math.abs(item.cash) / Math.abs(item.gold)).toFixed(0)) }}</div>-->
|
||||
@@ -60,20 +80,44 @@
|
||||
ریال
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="item.order" class="flex justify-between mb-3">
|
||||
<div class="text-primary">قیمت هر گرم طلا حین معامله:</div>
|
||||
<div class="flex text-xs items-center number-ltr">
|
||||
<div class="text-base ml-1">{{ usePriceWithoutType(item.order?.price?? 0) }}</div>
|
||||
ریال
|
||||
<template v-if="isShopProduct">
|
||||
<div class="flex justify-between mb-3">
|
||||
<div class="text-primary">تعداد:</div>
|
||||
<div class="flex text-xs items-center number-ltr">
|
||||
<div class="text-base ml-1">{{ item.order?.number ?? 0 }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-between mb-3">
|
||||
<div class="text-primary">مقدار {{item.wallet?.product? item.wallet.product.title: 'آبشده' }} مبادله شده:</div>
|
||||
<div :class="item.gold >= 0? 'text-green-600' : 'text-red-600'" class="flex text-xs items-center number-ltr">
|
||||
<div class="text-base ml-1">{{ item.gold }}</div>
|
||||
{{item.unit}}
|
||||
<div class="flex justify-between mb-3">
|
||||
<div class="text-primary">قیمت کل:</div>
|
||||
<div class="flex text-xs items-center number-ltr">
|
||||
<div class="text-base ml-1">{{ usePriceWithoutType(item.order?.total_price ?? 0) }}</div>
|
||||
ریال
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-between mb-3">
|
||||
<div class="text-primary">قیمت واحد:</div>
|
||||
<div class="flex text-xs items-center number-ltr">
|
||||
<div class="text-base ml-1">{{ usePriceWithoutType(item.order?.price ?? 0) }}</div>
|
||||
ریال
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div v-if="item.order" class="flex justify-between mb-3">
|
||||
<div class="text-primary">قیمت هر گرم طلا حین معامله:</div>
|
||||
<div class="flex text-xs items-center number-ltr">
|
||||
<div class="text-base ml-1">{{ usePriceWithoutType(item.order?.price?? 0) }}</div>
|
||||
ریال
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-between mb-3">
|
||||
<div class="text-primary">مقدار {{item.wallet?.product? item.wallet.product.title: 'آبشده' }} مبادله شده:</div>
|
||||
<div :class="item.gold >= 0? 'text-green-600' : 'text-red-600'" class="flex text-xs items-center number-ltr">
|
||||
<div class="text-base ml-1">{{ item.gold }}</div>
|
||||
{{item.unit}}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<div class="flex justify-between mb-3">
|
||||
<div class="text-primary">موجودی کیف پول:</div>
|
||||
<div :class="item.cash > 0? 'text-green-600' : 'text-red-600'" class="flex text-xs items-center number-ltr">
|
||||
@@ -156,6 +200,7 @@ interface Prop {
|
||||
const props = withDefaults(defineProps<Prop>(), {})
|
||||
const isUp = computed(() => props.item.type === 3 || props.item.type === 1 || props.item.type === 8 || props.item.type === 9)
|
||||
const isGold = computed(() => props.item.type === 1 || props.item.type === 2 || props.item.type === 10)
|
||||
const isShopProduct = computed(() => !!props.item?.product_id)
|
||||
/*const title = computed(() => {
|
||||
if (isUp.value) {
|
||||
if (isGold.value) {
|
||||
|
||||
Reference in New Issue
Block a user