product modal changes
This commit is contained in:
@@ -300,7 +300,7 @@ import { isSwitchOn } from '@/pages/menuPages/configuration/settingTypes'
|
||||
import type { last } from '@/model/price'
|
||||
import type { MethodePrices } from '@/model/product'
|
||||
import { usePrice } from '@core/utils/usePrice'
|
||||
import { isMeltedTradeGroup } from '@/utils/productCategories'
|
||||
import { usesMeltedPriceEditor } from '@/utils/productCategories'
|
||||
import { computeProductEditorPricePreview } from '@/utils/productEditorPrice'
|
||||
import { resolveTradeWeightUnit, weightFieldLabelForUnit } from '@/utils/weightUnit'
|
||||
import dayjs from 'dayjs'
|
||||
@@ -330,7 +330,7 @@ const props = defineProps<{
|
||||
const isStore = ref(Boolean(props.isStore))
|
||||
|
||||
const tradeWeightUnit = ref('گرم')
|
||||
const isMeltedCategory = computed(() => isMeltedTradeGroup(props.form.group_type))
|
||||
const isMeltedCategory = computed(() => usesMeltedPriceEditor(props.form))
|
||||
|
||||
const showUnitField = computed(() => isMeltedCategory.value || props.weightOption === '1')
|
||||
|
||||
|
||||
@@ -91,7 +91,8 @@ import {
|
||||
import { normalizeProductOrderLimitForm, validateProductOrderLimitForm } from '@/utils/productOrderLimit'
|
||||
import {
|
||||
isMeltedTradeGroup,
|
||||
resolveMeltedPriceSource
|
||||
resolveMeltedPriceSource,
|
||||
usesMeltedPriceEditor,
|
||||
} from '@/utils/productCategories'
|
||||
import { syncAndLoadCategories } from '@/utils/categorySelect'
|
||||
import { getConfiguration } from '@/api/configuration'
|
||||
@@ -309,8 +310,16 @@ async function edit(record: Product) {
|
||||
|
||||
methodOption.value = productData.reading_method ? '2' : '1'
|
||||
meltedPriceOption.value = resolveMeltedPriceSource(productData)
|
||||
if (isMeltedTradeGroup(productData.group_type)) {
|
||||
if (usesMeltedPriceEditor(productData)) {
|
||||
methodOption.value = '1'
|
||||
if (
|
||||
!isMeltedTradeGroup(productData.group_type)
|
||||
&& !productData.reading_method
|
||||
&& Number(productData.direct_price) !== 1
|
||||
&& Number(productData.price) > 0
|
||||
) {
|
||||
meltedPriceOption.value = 'fixed'
|
||||
}
|
||||
}
|
||||
weightOption.value = Number(productData.amount) > 0 ? '1' : '2'
|
||||
if (weightOption.value === '2' && !isMeltedTradeGroup(productData.group_type)) {
|
||||
@@ -438,10 +447,12 @@ async function saveProduct() {
|
||||
loading.value = false
|
||||
return
|
||||
}
|
||||
if (isMeltedTradeGroup(payload.group_type)) {
|
||||
payload.amount = 1
|
||||
if (!editId) {
|
||||
payload.trade_by_quantity = true
|
||||
if (usesMeltedPriceEditor(payload)) {
|
||||
if (isMeltedTradeGroup(payload.group_type)) {
|
||||
payload.amount = 1
|
||||
if (!editId) {
|
||||
payload.trade_by_quantity = true
|
||||
}
|
||||
}
|
||||
payload.direct_price = meltedPriceOption.value === 'fixed' ? 1 : 0
|
||||
payload.cash_fee_buy = payload.cash_fee_buy ?? 0
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { isMeltedTradeGroup } from '@/utils/productCategories'
|
||||
import { isMeltedTradeGroup, usesMeltedPriceEditor } from '@/utils/productCategories'
|
||||
|
||||
function isBlank(value: unknown) {
|
||||
return value === undefined || value === null || value === ''
|
||||
@@ -22,7 +22,7 @@ export function validateProductSubmitInput(input: {
|
||||
}): string | null {
|
||||
const { form, methodOption, weightOption, meltedPriceOption, isEdit } = input
|
||||
const groupType = String(form.group_type ?? '')
|
||||
const melted = isMeltedTradeGroup(groupType)
|
||||
const melted = usesMeltedPriceEditor(form)
|
||||
|
||||
if (!String(form.title ?? '').trim()) {
|
||||
return 'عنوان محصول الزامی است'
|
||||
|
||||
@@ -27,6 +27,22 @@ export function isMeltedTradeGroup(groupType?: string | null) {
|
||||
return group === PRODUCT_CATEGORY_ABSHODE || group === LEGACY_GROUP_KATOD
|
||||
}
|
||||
|
||||
/** ادیتور قیمت آبشدهای — کاتد/آبشده یا معامله مقداری (trade_by_quantity) */
|
||||
export function usesMeltedPriceEditor(input?: {
|
||||
group_type?: string | null
|
||||
trade_by_quantity?: boolean | number | null
|
||||
} | null) {
|
||||
if (!input) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (isMeltedTradeGroup(input.group_type)) {
|
||||
return true
|
||||
}
|
||||
|
||||
return input.trade_by_quantity === true || Number(input.trade_by_quantity) === 1
|
||||
}
|
||||
|
||||
export type MeltedPriceSource = 'app' | 'fixed' | 'reference'
|
||||
|
||||
export function resolveMeltedPriceSource(product?: {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { last } from '@/model/price'
|
||||
import type { MethodePrices } from '@/model/product'
|
||||
import type { MeltedPriceSource } from '@/utils/productCategories'
|
||||
import { isMeltedTradeGroup } from '@/utils/productCategories'
|
||||
import { usesMeltedPriceEditor } from '@/utils/productCategories'
|
||||
|
||||
const GOLD_DOT_REFERENCE_NAME = 'گلد دات ای از آبشده - رسمی - نقد فردا'
|
||||
|
||||
@@ -105,7 +105,7 @@ export function computeProductEditorPricePreview(input: {
|
||||
appLastPrice?: (Partial<last> & { price?: number; last_historical?: number }) | null
|
||||
}): ProductEditorPricePreview {
|
||||
const offsetPercent = Number(input.form.price_offset_percent ?? 0)
|
||||
const melted = isMeltedTradeGroup(input.form.group_type)
|
||||
const melted = usesMeltedPriceEditor(input.form)
|
||||
|
||||
if (melted) {
|
||||
if (input.meltedPriceOption === 'fixed') {
|
||||
|
||||
Reference in New Issue
Block a user