fix bugs
This commit is contained in:
@@ -40,8 +40,12 @@ async function handleSync() {
|
||||
syncing.value = true
|
||||
try {
|
||||
const res = await runPriceSync()
|
||||
message.success(res.message || 'انجام شد')
|
||||
refreshTable()
|
||||
if (res.data) {
|
||||
message.success(res.message || 'انجام شد')
|
||||
refreshTable()
|
||||
} else {
|
||||
message.info(res.message || 'قیمت تغییری نکرد')
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
message.error('خطا در بهروزرسانی قیمت')
|
||||
|
||||
@@ -191,7 +191,12 @@
|
||||
<a-form-item v-if="!isMeltedCategory" label="نوع قیمت" name="direct_price" :rules="inputRules()">
|
||||
<BasicSelect v-model:value="form.direct_price" :items="priceItems" valueName="value" keyName="key" />
|
||||
</a-form-item>
|
||||
<a-form-item label="واحد" name="unit" :rules="inputRules()">
|
||||
<a-form-item
|
||||
v-if="isMeltedCategory || weightOption === '1'"
|
||||
label="واحد"
|
||||
name="unit"
|
||||
:rules="showUnitField ? inputRules() : []"
|
||||
>
|
||||
<BasicSelect v-model:value="form.unit" :items="unitItems" valueName="value" keyName="value" />
|
||||
</a-form-item>
|
||||
<a-form-item
|
||||
@@ -292,6 +297,8 @@ const isStore = ref(Boolean(props.isStore))
|
||||
const tradeWeightUnit = ref('گرم')
|
||||
const isMeltedCategory = computed(() => isMeltedTradeGroup(props.form.group_type))
|
||||
|
||||
const showUnitField = computed(() => isMeltedCategory.value || props.weightOption === '1')
|
||||
|
||||
const livePricePreview = computed(() =>
|
||||
computeProductEditorPricePreview({
|
||||
form: props.form,
|
||||
|
||||
@@ -84,6 +84,8 @@ import {
|
||||
resolveMeltedPriceSource
|
||||
} from '@/utils/productCategories'
|
||||
import { syncAndLoadCategories } from '@/utils/categorySelect'
|
||||
import { getConfiguration } from '@/api/configuration'
|
||||
import { resolveTradeWeightUnit } from '@/utils/weightUnit'
|
||||
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
@@ -94,6 +96,7 @@ const refreshTable = () => table.value?.fetch()
|
||||
const methodOption = ref('1')
|
||||
const weightOption = ref('1')
|
||||
const meltedPriceOption = ref('app')
|
||||
const tradeWeightUnit = ref('گرم')
|
||||
const activeKey_ = ref(['0'])
|
||||
const ProductIndexImage = ref<Array<FileList>>([])
|
||||
const addUserVisible = ref(false)
|
||||
@@ -191,6 +194,15 @@ watch(addUserVisible, (visible) => {
|
||||
onMounted(() => {
|
||||
void refreshLivePrices()
|
||||
void loadCategorySelectItems()
|
||||
void (async () => {
|
||||
try {
|
||||
const rows = await getConfiguration()
|
||||
const unitRow = Array.isArray(rows) ? rows.find((row) => row.key === 'unit') : null
|
||||
tradeWeightUnit.value = resolveTradeWeightUnit(unitRow?.value)
|
||||
} catch {
|
||||
tradeWeightUnit.value = 'گرم'
|
||||
}
|
||||
})()
|
||||
})
|
||||
|
||||
async function loadCategorySelectItems() {
|
||||
@@ -289,7 +301,10 @@ async function edit(record: Product) {
|
||||
if (isMeltedTradeGroup(productData.group_type)) {
|
||||
methodOption.value = '1'
|
||||
}
|
||||
weightOption.value = productData.amount && productData.amount !== 1 ? '1' : '2'
|
||||
weightOption.value = Number(productData.amount) > 0 ? '1' : '2'
|
||||
if (weightOption.value === '2' && !isMeltedTradeGroup(productData.group_type)) {
|
||||
productData.unit = undefined
|
||||
}
|
||||
|
||||
const start = productData.auto_open_at
|
||||
? dayjs(productData.auto_open_at, 'HH:mm:ss')
|
||||
@@ -353,6 +368,16 @@ function resetData() {
|
||||
}
|
||||
|
||||
async function ok() {
|
||||
if (!isMeltedTradeGroup(form.value.group_type ?? '')) {
|
||||
if (weightOption.value === '1') {
|
||||
const amount = Number(form.value.amount)
|
||||
if (!Number.isFinite(amount) || amount <= 0) {
|
||||
message.error('لطفاً وزن محصول را وارد کنید')
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await formRef.value?.validateFields()
|
||||
} catch {
|
||||
@@ -392,7 +417,14 @@ async function ok() {
|
||||
delete payload.price
|
||||
payload.price_offset_percent = Number(payload.price_offset_percent ?? 0)
|
||||
}
|
||||
if (weightOption.value === '2') payload.amount = 1
|
||||
if (weightOption.value === '2') {
|
||||
payload.amount = 0
|
||||
if (!isMeltedTradeGroup(payload.group_type)) {
|
||||
payload.unit = tradeWeightUnit.value
|
||||
}
|
||||
} else if (!isMeltedTradeGroup(payload.group_type)) {
|
||||
payload.amount = Number(payload.amount)
|
||||
}
|
||||
|
||||
if (isStoreApp() && !isMeltedTradeGroup(payload.group_type)) {
|
||||
payload.inventory = Math.max(0, Number(payload.inventory ?? 0))
|
||||
@@ -445,5 +477,14 @@ const minusPrice = () => {
|
||||
if (form.value.price) form.value.price = parseInt(String(form.value.price)) - 10000
|
||||
else form.value.price = -10000
|
||||
}
|
||||
|
||||
watch(weightOption, (option) => {
|
||||
if (option === '1' && Number(form.value.amount) <= 0) {
|
||||
form.value.amount = undefined
|
||||
}
|
||||
if (option === '2' && !isMeltedTradeGroup(form.value.group_type ?? '')) {
|
||||
form.value.unit = undefined
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user