feat(admin): let price alerts pick a product
Show the product on the form and table so each alert is tied to one item. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -11,6 +11,16 @@
|
||||
/>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="محصول" name="product_id" :rules="inputRules()">
|
||||
<BasicSelect
|
||||
v-model:value="form.product_id"
|
||||
:items="productItems"
|
||||
key-name="id"
|
||||
value-name="label"
|
||||
placeholder="آبشده، سکه، نقره و ..."
|
||||
/>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="شرط قیمت" name="price_condition" :rules="inputRules()">
|
||||
<BasicSelect
|
||||
v-model:value="form.price_condition"
|
||||
@@ -48,6 +58,7 @@ import { inputRules, inputRulesNumber } from '@/utils/inputRules'
|
||||
defineProps<{
|
||||
form: Partial<PriceTriggers>
|
||||
customerItems: Array<{ id: number; label: string }>
|
||||
productItems: Array<{ id: number; label: string }>
|
||||
editId?: number
|
||||
}>()
|
||||
|
||||
|
||||
@@ -39,6 +39,15 @@ export const cols: BaseTableColumn[] = [
|
||||
return name ? `${name} (${record.customer_id})` : String(record.customer_id ?? '-')
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'محصول',
|
||||
dataIndex: 'product',
|
||||
key: 'product',
|
||||
type: 'Text',
|
||||
customRender: ({ record }) => {
|
||||
return record.product?.title || (record.product_id ? `محصول ${record.product_id}` : 'طلا')
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'کد مشتری',
|
||||
dataIndex: 'customer_id',
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
ref="editorRef"
|
||||
:form="form"
|
||||
:customer-items="customerItems"
|
||||
:product-items="productItems"
|
||||
:edit-id="editId"
|
||||
/>
|
||||
</BasicActionSheet>
|
||||
@@ -38,6 +39,7 @@ import PriceTriggerEditorFormBody from './components/PriceTriggerEditorFormBody.
|
||||
import type { PriceTriggers } from '@/model/priceTriggers'
|
||||
import type { Customer } from '@/model/customer'
|
||||
import { getCustomersList } from '@/api/customer'
|
||||
import { getCustomersList as getProductsList } from '@/api/product'
|
||||
import {
|
||||
createPriceTrigger,
|
||||
deletePriceTrigger,
|
||||
@@ -57,9 +59,11 @@ const loading = ref(false)
|
||||
const editorVisible = ref(false)
|
||||
const editId = ref<number | undefined>()
|
||||
const customers = ref<Customer[]>([])
|
||||
const products = ref<Array<{ id: number; title?: string }>>([])
|
||||
|
||||
const defaultForm = (): Partial<PriceTriggers> => ({
|
||||
customer_id: undefined,
|
||||
product_id: undefined,
|
||||
target_price: undefined,
|
||||
price_condition: '>',
|
||||
action: 'sms',
|
||||
@@ -77,6 +81,13 @@ const customerItems = computed(() =>
|
||||
}))
|
||||
)
|
||||
|
||||
const productItems = computed(() =>
|
||||
products.value.map((p) => ({
|
||||
id: p.id,
|
||||
label: p.title || String(p.id),
|
||||
}))
|
||||
)
|
||||
|
||||
function refreshTable() {
|
||||
tableRef.value?.fetch()
|
||||
}
|
||||
@@ -96,6 +107,7 @@ function openEdit(record: PriceTriggers) {
|
||||
editId.value = record.id
|
||||
form.value = cloneDeep({
|
||||
customer_id: record.customer_id,
|
||||
product_id: record.product_id ?? record.product?.id,
|
||||
target_price: record.target_price,
|
||||
price_condition: record.price_condition,
|
||||
action: record.action,
|
||||
@@ -111,6 +123,7 @@ async function submitForm() {
|
||||
|
||||
const payload = {
|
||||
customer_id: Number(form.value.customer_id),
|
||||
product_id: Number(form.value.product_id),
|
||||
target_price: Number(form.value.target_price),
|
||||
price_condition: form.value.price_condition,
|
||||
action: form.value.action,
|
||||
@@ -156,6 +169,7 @@ function deleteItem(id: number) {
|
||||
onMounted(async () => {
|
||||
try {
|
||||
customers.value = (await getCustomersList()) ?? []
|
||||
products.value = ((await getProductsList()) as Array<{ id: number; title?: string }>) ?? []
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user