fix(user): keep the chosen alert product and split convert weight across both wires

Alerts store the selected product instead of falling back to gold, and the convert sliders turn the chosen asset amount into complementary 1.5 and 2.5 rings.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-02 18:20:13 +03:30
co-authored by Cursor
parent a19f3072f0
commit 47d4fb44df
8 changed files with 171 additions and 85 deletions
@@ -116,6 +116,7 @@ import BasicInfoItem from '@/components/BasicPacks/BasicInfoItem.vue'
import DialogVant from '@/components/DialogVant.vue'
import { deletePriceTrigger, updatePriceTrigger } from '@/api/triggerPrice'
import { loading } from '@/utils'
import { usePriceTriggerPageContext } from '../composables/usePriceTriggerPage'
const infoVisible = ref(false)
const isActive = ref(false)
@@ -132,7 +133,17 @@ const props = withDefaults(
const emits = defineEmits(['edit', 'refresh'])
const productTitle = computed(() => props.item.product?.title || 'طلا')
const { products } = usePriceTriggerPageContext()
const productTitle = computed(() => {
const nested = props.item.product?.title?.trim()
if (nested) {
return nested
}
const id = Number(props.item.product_id ?? props.item.product?.id)
const match = products.value.find((product) => Number(product.id) === id)
return match?.title?.trim() || '—'
})
onMounted(() => {
isActive.value = props.item.is_active
@@ -10,7 +10,7 @@
<a-form-item :rules="[required()]" label="محصول" name="product_id">
<BasicSelect
v-model:value="form.product_id"
:items="products"
:items="productOptions"
key-name="id"
placeholder="کاتد مس، مفتول مس و..."
size="large"
@@ -62,7 +62,7 @@ const {
editId,
loading,
typeItems,
products,
productOptions,
ok,
} = usePriceTriggerPageContext()
</script>
@@ -1,4 +1,4 @@
import { inject, onMounted, provide, reactive, ref, type InjectionKey, type Ref } from 'vue'
import { computed, inject, onMounted, provide, reactive, ref, type ComputedRef, type InjectionKey, type Ref } from 'vue'
import { cloneDeep } from 'lodash'
import { type FormInstance, message } from 'ant-design-vue'
import { createPriceTrigger, getPriceTriggers, updatePriceTrigger } from '@/api/triggerPrice'
@@ -18,9 +18,24 @@ function emptyForm(): PriceTrigger {
}
}
export function resolveProductId(value: unknown): number | undefined {
if (typeof value === 'number' && Number.isFinite(value) && value > 0) {
return value
}
if (typeof value === 'string' && value.trim()) {
const id = Number(value)
return Number.isFinite(id) && id > 0 ? id : undefined
}
if (value && typeof value === 'object' && 'id' in value) {
return resolveProductId((value as { id?: unknown }).id)
}
return undefined
}
export interface PriceTriggerPageContext {
items: Ref<PriceTrigger[]>
products: Ref<Product[]>
productOptions: ComputedRef<Array<{ id: number; title: string }>>
addTriggerVisible: Ref<boolean>
editId: Ref<number | undefined>
form: Ref<PriceTrigger>
@@ -41,6 +56,14 @@ export const PRICE_TRIGGER_PAGE_CONTEXT_KEY: InjectionKey<PriceTriggerPageContex
export function usePriceTriggerPage() {
const items = ref<PriceTrigger[]>([])
const products = ref<Product[]>([])
const productOptions = computed(() =>
products.value
.map((product) => ({
id: Number(product.id),
title: String(product.title ?? '').trim(),
}))
.filter((product) => Number.isFinite(product.id) && product.id > 0 && product.title),
)
const addTriggerVisible = ref(false)
const editId = ref<number | undefined>(undefined)
const formRef = ref<FormInstance>()
@@ -72,7 +95,7 @@ export function usePriceTriggerPage() {
function openEdit(val: PriceTrigger) {
form.value = cloneDeep({
...val,
product_id: val.product_id ?? val.product?.id,
product_id: resolveProductId(val.product_id ?? val.product?.id),
})
editId.value = form.value.id
addTriggerVisible.value = true
@@ -91,21 +114,30 @@ export function usePriceTriggerPage() {
async function loadProducts() {
try {
products.value = ((await getProducts()) as Product[]) ?? []
const list = await getProducts()
products.value = Array.isArray(list) ? list : []
} catch (e) {
console.log(e)
}
}
async function ok() {
const productId = resolveProductId(form.value.product_id)
form.value.product_id = productId
await formRef.value?.validateFields().then(async () => {
try {
loading.value = true
form.value.action = 'sms'
const payload: PriceTrigger = {
product_id: productId,
price_condition: form.value.price_condition,
is_active: form.value.is_active,
action: 'sms',
target_price: form.value.target_price,
}
if (editId.value) {
await updatePriceTrigger(editId.value, form.value)
await updatePriceTrigger(editId.value, payload)
} else {
await createPriceTrigger(form.value)
await createPriceTrigger(payload)
}
message.success('هشدار با موفقیت ایجاد شد')
await initItems()
@@ -126,6 +158,7 @@ export function usePriceTriggerPage() {
const context: PriceTriggerPageContext = {
items,
products,
productOptions,
addTriggerVisible,
editId,
form,
+2 -2
View File
@@ -1,7 +1,7 @@
<template>
<div class="price-trigger-page-root">
<DesktopPriceTriggerView v-show="isDesktop" />
<MobilePriceTriggerView v-show="!isDesktop" />
<DesktopPriceTriggerView v-if="isDesktop" />
<MobilePriceTriggerView v-else />
<BasicActionSheet v-if="!isDesktop" v-model:show="addTriggerVisible" teleport="body">
<div class="font-bold text-lg mb-2">هشدار قیمت</div>