fix bug
This commit is contained in:
@@ -0,0 +1,63 @@
|
|||||||
|
import { useSettingsStore } from '@/store/settingsStore'
|
||||||
|
import { lastPrice } from '@/utils/price'
|
||||||
|
|
||||||
|
export interface StoreTradingHours {
|
||||||
|
start: string
|
||||||
|
end: string
|
||||||
|
closePriceEnabled: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseTimeToSeconds(time: string): number {
|
||||||
|
const parts = time.trim().split(':').map(Number)
|
||||||
|
const [hours = 0, minutes = 0, seconds = 0] = parts
|
||||||
|
return hours * 3600 + minutes * 60 + seconds
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatTradingTimeDisplay(time: string): string {
|
||||||
|
const parts = time.trim().split(':')
|
||||||
|
if (parts.length >= 3) {
|
||||||
|
return `${parts[0]}:${parts[1]}:${parts[2]}`
|
||||||
|
}
|
||||||
|
if (parts.length >= 2) {
|
||||||
|
return `${parts[0]}:${parts[1]}:00`
|
||||||
|
}
|
||||||
|
return time
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getStoreTradingHours(): StoreTradingHours {
|
||||||
|
const settings = useSettingsStore()
|
||||||
|
const closeRaw = settings.getSettingByKey('close_price')
|
||||||
|
const closePriceEnabled =
|
||||||
|
closeRaw === true ||
|
||||||
|
closeRaw === 1 ||
|
||||||
|
String(closeRaw ?? 'false').trim().toLowerCase() === 'true'
|
||||||
|
|
||||||
|
return {
|
||||||
|
start: String(settings.getSettingByKey('startDay') ?? '00:00'),
|
||||||
|
end: String(settings.getSettingByKey('endDay') ?? '23:59'),
|
||||||
|
closePriceEnabled,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isStoreClosedBySchedule(now = new Date()): boolean {
|
||||||
|
const { start, end, closePriceEnabled } = getStoreTradingHours()
|
||||||
|
if (!closePriceEnabled) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentSeconds = now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds()
|
||||||
|
const openSeconds = parseTimeToSeconds(start)
|
||||||
|
const closeSeconds = parseTimeToSeconds(end)
|
||||||
|
|
||||||
|
return currentSeconds < openSeconds || currentSeconds > closeSeconds
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isStoreClosed(): boolean {
|
||||||
|
if (lastPrice.value?.closed === true) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return isStoreClosedBySchedule()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const STORE_CLOSED_MESSAGE = 'فروشگاه در حال حاضر بسته است.'
|
||||||
@@ -239,6 +239,7 @@ import {useConfigStore} from "@/store/configStore";
|
|||||||
import { calcFeeInGrams } from '@/utils/serviceFee'
|
import { calcFeeInGrams } from '@/utils/serviceFee'
|
||||||
import { formatCashWalletBalanceText, formatGoldWalletBalanceText } from '@/utils/productDealMethod'
|
import { formatCashWalletBalanceText, formatGoldWalletBalanceText } from '@/utils/productDealMethod'
|
||||||
import { getCashWalletBalance } from '@/utils/productAssets'
|
import { getCashWalletBalance } from '@/utils/productAssets'
|
||||||
|
import { isStoreClosed, STORE_CLOSED_MESSAGE } from '@/utils/storeHours'
|
||||||
|
|
||||||
const infoVisible = ref(false)
|
const infoVisible = ref(false)
|
||||||
const walletStore = useWalletStore()
|
const walletStore = useWalletStore()
|
||||||
@@ -325,6 +326,7 @@ const equivalentPrice = computed(() => usePriceWithoutType(feeInRial.value.toFix
|
|||||||
|
|
||||||
const disableTransaction = computed(() =>
|
const disableTransaction = computed(() =>
|
||||||
loading.value ||
|
loading.value ||
|
||||||
|
isStoreClosed() ||
|
||||||
form.value?.goldValue === undefined ||
|
form.value?.goldValue === undefined ||
|
||||||
form.value?.goldValue === '' ||
|
form.value?.goldValue === '' ||
|
||||||
form.value?.goldCash === '' ||
|
form.value?.goldCash === '' ||
|
||||||
@@ -640,10 +642,18 @@ async function initPrice() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function okConfirm() {
|
function okConfirm() {
|
||||||
|
if (isStoreClosed()) {
|
||||||
|
message.warning(STORE_CLOSED_MESSAGE)
|
||||||
|
return
|
||||||
|
}
|
||||||
confirmAction.value = true
|
confirmAction.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
async function ok() {
|
async function ok() {
|
||||||
|
if (isStoreClosed()) {
|
||||||
|
message.warning(STORE_CLOSED_MESSAGE)
|
||||||
|
return
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
infoVisible.value = true
|
infoVisible.value = true
|
||||||
|
|||||||
@@ -236,6 +236,7 @@ import type { Product } from '@/models/products'
|
|||||||
import { useFundUserStore } from '@/store/fundStore'
|
import { useFundUserStore } from '@/store/fundStore'
|
||||||
import {useConfigStore} from "@/store/configStore";
|
import {useConfigStore} from "@/store/configStore";
|
||||||
import { calcFeeInGrams, loadServiceFeeFromSettings } from '@/utils/serviceFee'
|
import { calcFeeInGrams, loadServiceFeeFromSettings } from '@/utils/serviceFee'
|
||||||
|
import { isStoreClosed, STORE_CLOSED_MESSAGE } from '@/utils/storeHours'
|
||||||
import { formatCashWalletBalanceText, getWeightUnit } from '@/utils/productDealMethod'
|
import { formatCashWalletBalanceText, getWeightUnit } from '@/utils/productDealMethod'
|
||||||
import { formatProductWalletBalanceText, getCashWalletBalance, getProductInventoryQuantity } from '@/utils/productAssets'
|
import { formatProductWalletBalanceText, getCashWalletBalance, getProductInventoryQuantity } from '@/utils/productAssets'
|
||||||
import { useWalletAssets } from '@/composables/useWalletAssets'
|
import { useWalletAssets } from '@/composables/useWalletAssets'
|
||||||
@@ -344,6 +345,7 @@ const priceUnavailable = computed(() => {
|
|||||||
|
|
||||||
const disableTransaction = computed(() =>
|
const disableTransaction = computed(() =>
|
||||||
loading.value ||
|
loading.value ||
|
||||||
|
isStoreClosed() ||
|
||||||
form.value?.goldValue === undefined ||
|
form.value?.goldValue === undefined ||
|
||||||
form.value?.goldValue === '' ||
|
form.value?.goldValue === '' ||
|
||||||
form.value?.goldCash === '' ||
|
form.value?.goldCash === '' ||
|
||||||
@@ -633,6 +635,10 @@ async function initPrice() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function okConfirm() {
|
function okConfirm() {
|
||||||
|
if (isStoreClosed()) {
|
||||||
|
message.warning(STORE_CLOSED_MESSAGE)
|
||||||
|
return
|
||||||
|
}
|
||||||
if (cashValidationMessage.value) {
|
if (cashValidationMessage.value) {
|
||||||
message.warning(cashValidationMessage.value)
|
message.warning(cashValidationMessage.value)
|
||||||
return
|
return
|
||||||
@@ -641,6 +647,10 @@ function okConfirm() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function ok() {
|
async function ok() {
|
||||||
|
if (isStoreClosed()) {
|
||||||
|
message.warning(STORE_CLOSED_MESSAGE)
|
||||||
|
return
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
infoVisible.value = true
|
infoVisible.value = true
|
||||||
|
|||||||
@@ -297,6 +297,7 @@ import {
|
|||||||
} from '@/utils/productOrderLimit'
|
} from '@/utils/productOrderLimit'
|
||||||
import { useWalletAssets } from '@/composables/useWalletAssets'
|
import { useWalletAssets } from '@/composables/useWalletAssets'
|
||||||
import { formatProductWalletBalanceText, getCashWalletBalance, getProductInventoryQuantity } from '@/utils/productAssets'
|
import { formatProductWalletBalanceText, getCashWalletBalance, getProductInventoryQuantity } from '@/utils/productAssets'
|
||||||
|
import { isStoreClosed, STORE_CLOSED_MESSAGE } from '@/utils/storeHours'
|
||||||
|
|
||||||
const typeDeal = computed(() => getProductDealMethodOptions(props?.ProductItem?.group_type, isBuy.value))
|
const typeDeal = computed(() => getProductDealMethodOptions(props?.ProductItem?.group_type, isBuy.value))
|
||||||
|
|
||||||
@@ -438,6 +439,7 @@ const cashValidationMessage = computed(() =>
|
|||||||
|
|
||||||
const disableTransaction = computed(() =>
|
const disableTransaction = computed(() =>
|
||||||
loading.value ||
|
loading.value ||
|
||||||
|
isStoreClosed() ||
|
||||||
form.value?.goldValue === undefined ||
|
form.value?.goldValue === undefined ||
|
||||||
form.value?.goldValue === '' ||
|
form.value?.goldValue === '' ||
|
||||||
form.value?.goldCash === '' ||
|
form.value?.goldCash === '' ||
|
||||||
@@ -795,11 +797,19 @@ async function initPrice() {
|
|||||||
// })
|
// })
|
||||||
|
|
||||||
function okConfirm() {
|
function okConfirm() {
|
||||||
|
if (isStoreClosed()) {
|
||||||
|
message.warning(STORE_CLOSED_MESSAGE)
|
||||||
|
return
|
||||||
|
}
|
||||||
confirmAction.value = true
|
confirmAction.value = true
|
||||||
refInput.value?.validateFields()
|
refInput.value?.validateFields()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function ok() {
|
async function ok() {
|
||||||
|
if (isStoreClosed()) {
|
||||||
|
message.warning(STORE_CLOSED_MESSAGE)
|
||||||
|
return
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
infoVisible.value = true
|
infoVisible.value = true
|
||||||
|
|||||||
@@ -103,7 +103,13 @@ import { isMetalCommodityGroup, isMeltedTradeGroup } from '@/utils/productCatego
|
|||||||
import { isBoursecuDealProductGroup } from '@/utils/productDealMethod'
|
import { isBoursecuDealProductGroup } from '@/utils/productDealMethod'
|
||||||
import { loadServiceFeeFromSettings } from '@/utils/serviceFee'
|
import { loadServiceFeeFromSettings } from '@/utils/serviceFee'
|
||||||
import { loadProductCategoryTabNames } from '@/utils/categoryTabs'
|
import { loadProductCategoryTabNames } from '@/utils/categoryTabs'
|
||||||
import { getLastPrices, startLastPricePolling, stopLastPricePolling } from '@/utils/price'
|
import { getLastPrices, lastPrice, startLastPricePolling, stopLastPricePolling } from '@/utils/price'
|
||||||
|
import {
|
||||||
|
formatTradingTimeDisplay,
|
||||||
|
getStoreTradingHours,
|
||||||
|
isStoreClosed,
|
||||||
|
STORE_CLOSED_MESSAGE
|
||||||
|
} from '@/utils/storeHours'
|
||||||
|
|
||||||
const activekey = ref('طلا' ||'آبشده')
|
const activekey = ref('طلا' ||'آبشده')
|
||||||
const showFilter = ref(false)
|
const showFilter = ref(false)
|
||||||
@@ -114,20 +120,26 @@ const openTime = ref<string>('')
|
|||||||
const isAfterCloseTime = ref<boolean>(false)
|
const isAfterCloseTime = ref<boolean>(false)
|
||||||
const isProductInactive = ref<boolean>(false)
|
const isProductInactive = ref<boolean>(false)
|
||||||
|
|
||||||
watch([openTime, closeTime], ([open, close]) => {
|
watch([openTime, closeTime], () => {
|
||||||
if (!open || !close) return
|
syncStoreClosedState()
|
||||||
const now = new Date()
|
|
||||||
const currentSeconds = now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds()
|
|
||||||
const [oh, om, os] = open.split(':').map(Number)
|
|
||||||
const [ch, cm, cs] = close.split(':').map(Number)
|
|
||||||
const openSeconds = oh * 3600 + om * 60 + os
|
|
||||||
const closeSeconds = ch * 3600 + cm * 60 + cs
|
|
||||||
isAfterCloseTime.value = currentSeconds < openSeconds || currentSeconds > closeSeconds
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function syncStoreClosedState() {
|
||||||
|
if (isStoreClosed()) {
|
||||||
|
showFilter.value = false
|
||||||
|
isAfterCloseTime.value = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function clickProduct(item?: Product) {
|
function clickProduct(item?: Product) {
|
||||||
if (!item?.show) return
|
if (!item?.show) return
|
||||||
|
|
||||||
|
if (isStoreClosed()) {
|
||||||
|
showFilter.value = false
|
||||||
|
isAfterCloseTime.value = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (isProductPriceInactive(item)) {
|
if (isProductPriceInactive(item)) {
|
||||||
showFilter.value = false
|
showFilter.value = false
|
||||||
isProductInactive.value = true
|
isProductInactive.value = true
|
||||||
@@ -144,6 +156,11 @@ function onProductOrdered() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
watch(showFilter, (open) => {
|
watch(showFilter, (open) => {
|
||||||
|
if (open && isStoreClosed()) {
|
||||||
|
showFilter.value = false
|
||||||
|
isAfterCloseTime.value = true
|
||||||
|
return
|
||||||
|
}
|
||||||
if (!open) {
|
if (!open) {
|
||||||
orderSheetKey.value += 1
|
orderSheetKey.value += 1
|
||||||
}
|
}
|
||||||
@@ -212,6 +229,8 @@ async function refreshProducts() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
watch(() => lastPrice.value?.closed, syncStoreClosedState)
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
try {
|
try {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
@@ -219,10 +238,10 @@ onMounted(async () => {
|
|||||||
startLastPricePolling()
|
startLastPricePolling()
|
||||||
items.value = await getProducts()
|
items.value = await getProducts()
|
||||||
|
|
||||||
if (items.value?.length) {
|
const hours = getStoreTradingHours()
|
||||||
closeTime.value = items.value[0].auto_close_at
|
openTime.value = formatTradingTimeDisplay(hours.start)
|
||||||
openTime.value = items.value[0].auto_open_at
|
closeTime.value = formatTradingTimeDisplay(hours.end)
|
||||||
}
|
syncStoreClosedState()
|
||||||
|
|
||||||
await loadCategoryTabs()
|
await loadCategoryTabs()
|
||||||
firstItems.value = items.value
|
firstItems.value = items.value
|
||||||
@@ -239,7 +258,9 @@ onMounted(async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (router.currentRoute.value.query.state) {
|
if (router.currentRoute.value.query.state) {
|
||||||
if (router.currentRoute.value.query.product) {
|
if (isStoreClosed()) {
|
||||||
|
isAfterCloseTime.value = true
|
||||||
|
} else if (router.currentRoute.value.query.product) {
|
||||||
clickProduct(items.value?.find(x => x.title === 'سکه'))
|
clickProduct(items.value?.find(x => x.title === 'سکه'))
|
||||||
} else {
|
} else {
|
||||||
clickProduct(items.value?.find(x => x.title === 'آبشده نقدی'))
|
clickProduct(items.value?.find(x => x.title === 'آبشده نقدی'))
|
||||||
|
|||||||
Reference in New Issue
Block a user