1404/11/19-change rule in input buy product
This commit is contained in:
@@ -169,6 +169,39 @@ const checkNumber = async (_rule: Rule, value: number) => {
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
}
|
||||
const checkNumber2 = async (_rule: Rule, value: number) => {
|
||||
|
||||
|
||||
if (!value) {
|
||||
return Promise.reject('تعداد محصول را مشخص کنید')
|
||||
}
|
||||
if (value % 1 !== 0) {
|
||||
return Promise.reject('استفاده از اعداد اعشاری مجاز نمی باشد')
|
||||
}
|
||||
if (isBuyP) {
|
||||
// Skip wallet balance check if gateway is enabled
|
||||
if (!gatewayP && isToken()) {
|
||||
// if (!walletCash?.walletInfo?.cash && methodP == 'cash') {
|
||||
// return Promise.reject('موجودی کیف پول ناکافی است')
|
||||
// }
|
||||
// if (!walletCash?.walletInfo?.gold && methodP == 'gold') {
|
||||
// return Promise.reject('موجودی کیف طلا ناکافی است')
|
||||
// }
|
||||
// if (priceP * value > walletCash?.walletInfo?.cash && methodP == 'cash')
|
||||
// return Promise.reject('موجودی کیف پول ناکافی است')
|
||||
// if (amountP * value > walletCash?.walletInfo?.gold && methodP == 'gold')
|
||||
// return Promise.reject('موجودی کیف طلا ناکافی است')
|
||||
}
|
||||
return Promise.resolve()
|
||||
} else {
|
||||
if (value > NumP)
|
||||
|
||||
return Promise.reject('موجودی محصول ناکافی است')
|
||||
else
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
}
|
||||
export const justNumber2 = (price: number, method?: string, amount?: number, isBuy?: boolean, gateway?: boolean) => {
|
||||
priceP = price
|
||||
@@ -193,6 +226,17 @@ export const justNumber3 = (price: number, Num?: number, isBuy?: boolean) => {
|
||||
trigger: 'change'
|
||||
}
|
||||
|
||||
}
|
||||
export const justNumber4 = (price: number, Num?: number, isBuy?: boolean) => {
|
||||
priceP = price
|
||||
NumP = Num
|
||||
isBuyP = isBuy
|
||||
return {
|
||||
required: true,
|
||||
validator: checkNumber2,
|
||||
trigger: 'change'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const ruleNumber = () => {
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
>
|
||||
<div class="flex gap-4">
|
||||
<!-- Product Image -->
|
||||
<div class="bg-gray-100 rounded-lg flex justify-center items-center p-3 min-w-[80px] h-[80px]">
|
||||
<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"
|
||||
@@ -152,7 +152,7 @@ watch(lastPrice, () => {
|
||||
|
||||
// Update item price and total price
|
||||
item.price = newPrice + (product.cash_fee_buy ?? 0)
|
||||
item.totalPrice = item.price * item.quantity
|
||||
item.totalPrice = parseInt(item.price * item.quantity)
|
||||
})
|
||||
|
||||
// Save updated prices to storage
|
||||
@@ -162,7 +162,7 @@ watch(lastPrice, () => {
|
||||
|
||||
// Computed total price that updates with price changes
|
||||
const totalPrice = computed(() => {
|
||||
return cartStore.cartItems.reduce((sum, item) => sum + item.totalPrice, 0)
|
||||
return parseInt(cartStore.cartItems.reduce((sum, item) => sum + item.totalPrice, 0))
|
||||
})
|
||||
|
||||
function getProductImage(product: any) {
|
||||
@@ -255,7 +255,7 @@ async function handleCheckout() {
|
||||
// Check wallet balance for cash method items (without gateway)
|
||||
const cashItemsTotal = cartStore.cartItems
|
||||
.filter(item => item.method === 'cash' && !item.gateway)
|
||||
.reduce((sum, item) => sum + item.totalPrice, 0)
|
||||
.reduce((sum, item) => parseInt(sum + item.totalPrice), 0)
|
||||
|
||||
if (cashItemsTotal > 0) {
|
||||
// Ensure wallet info is loaded
|
||||
@@ -374,7 +374,7 @@ async function initPrice() {
|
||||
|
||||
// Update item price and total price
|
||||
item.price = newPrice + (product.cash_fee_buy ?? 0)
|
||||
item.totalPrice = item.price * item.quantity
|
||||
item.totalPrice =parseInt(item.price * item.quantity)
|
||||
})
|
||||
|
||||
// Save updated prices to storage
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item v-if="isBuy" name="goldValue"
|
||||
:rules="[justNumber2(props?.ProductItem?.price , form.method , props?.ProductItem?.amount, true, form.gateway)]">
|
||||
:rules="[justNumber4(props?.ProductItem?.price , form.method , props?.ProductItem?.amount, true, form.gateway)]">
|
||||
<BasicInput v-model:value="form.goldValue" addon-before="تعداد" addon-bg-color="#521620"
|
||||
addon-text-color="white"
|
||||
place-holder="تعداد"
|
||||
@@ -253,7 +253,7 @@ import type { Price } from '@/models/home'
|
||||
import Icon from '@/components/BasicPacks/BasicIcon.vue'
|
||||
import { useUserStore } from '@/store/userStore'
|
||||
import BasicActionSheet from '@/components/BasicPacks/BasicActionSheet.vue'
|
||||
import { justNumber, justNumber2, justNumber3, required, ruleNumber } from '@/utils/inputRules'
|
||||
import {justNumber, justNumber2, justNumber3, justNumber4, required, ruleNumber} from '@/utils/inputRules'
|
||||
import GoldSkeleton from '@/views/base/gold/components/GoldSkeleton.vue'
|
||||
import GoldLoading from '@/components/GoldLoading.vue'
|
||||
// import {update} from 'lodash'
|
||||
@@ -274,10 +274,10 @@ const typeDeal: SelectItem[] = [
|
||||
value: 'نقدی',
|
||||
key: 'cash'
|
||||
},
|
||||
{
|
||||
value: ' طلایی',
|
||||
key: 'gold'
|
||||
}
|
||||
// {
|
||||
// value: ' طلایی',
|
||||
// key: 'gold'
|
||||
// }
|
||||
|
||||
]
|
||||
const infoVisible = ref(false)
|
||||
@@ -558,9 +558,9 @@ const limitedPrice = computed(() => {
|
||||
|
||||
function calculateCash(val: number) {
|
||||
priceErrorVisible.value = false
|
||||
// console.log(val)
|
||||
console.log("val",val,props?.ProductItem)
|
||||
if (price.value) {
|
||||
form.value.goldVazn = parseFloat((val * (( props?.ProductItem?.price) + (props?.ProductItem?.cash_fee_buy)))/lastPrice.value?.buy).toFixed(1)
|
||||
form.value.goldVazn = parseFloat((val * props?.ProductItem?.amount).toFixed(3))
|
||||
console.log(val,props?.ProductItem?.price,props?.ProductItem?.cash_fee_buy,lastPrice.value?.buy)
|
||||
if (isBuy.value) {
|
||||
if (val){
|
||||
@@ -579,7 +579,7 @@ console.log(val,props?.ProductItem?.price,props?.ProductItem?.cash_fee_buy,lastP
|
||||
form.value.goldVazn = 0
|
||||
}
|
||||
}
|
||||
console.log(form.value.goldVazn)
|
||||
console.log('goldVazn',form.value.goldVazn)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<div class="!h-full overflow-y-scroll">
|
||||
<div class="mx-5 pb-30 pt-5" style="color: #1b2b07">
|
||||
<!-- Product Image -->
|
||||
<div class="bg-gray-100 rounded-lg w-full flex justify-center p-8 mb-4">
|
||||
<div class="bg-gray-100 rounded-lg w-full flex justify-center mb-4">
|
||||
<img :src="getProductImage(product)" class="max-w-full h-auto" />
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user