This commit is contained in:
2026-06-13 12:42:10 +03:30
parent 164dbbfe53
commit 7050d041c4
7 changed files with 348 additions and 233 deletions
+11
View File
@@ -4,11 +4,22 @@ import type { last, Price } from "@/model/price";
import type { TableInput } from '@core/type/baseTable'
import type { MethodePrices } from "@/model/product";
import type { PriceSyncLog } from '@/model/priceSyncLog'
export const createPrice = async (obj: Price) => await useAxios.post<AddId>(`/admin/price`, obj)
export const getPriceTable = async (params: TableInput) =>
await useAxios.post<Array<Price>>('/admin/price/table', params)
export const getPriceSyncLogTable = async (params: TableInput) =>
await useAxios.post<Array<PriceSyncLog>>('/admin/price-sync-logs/table', params)
export const getPriceSyncLogDetail = async (id: number) =>
await useAxios.get<PriceSyncLog>(`/admin/price-sync-logs/${id}`)
export const runPriceSync = async () =>
await useAxios.post<{ message: string; data: PriceSyncLog | null }>('/admin/price-sync/run')
export const getLastPrice = async () => await useAxios.get<last>(`/api/price/last`)
export const methodePrices = async () => await useAxios.get<MethodePrices[]>('/admin/p')
+23
View File
@@ -0,0 +1,23 @@
export interface PriceSyncLogItem {
id: number
log_id: number
product_id?: number | null
product_title?: string | null
reading_method?: string | null
source_name?: string | null
base_price: number
base_profit: number
offset_percent: number
stored_price: number
previous_price: number
}
export interface PriceSyncLog {
id: number
source: string
source_url?: string | null
liquid_gold_price: number
products_updated: number
created_at: string
items?: PriceSyncLogItem[]
}
@@ -0,0 +1,112 @@
<template>
<BasicActionSheet
v-model:visible="visible"
title="جزئیات همگام‌سازی قیمت"
modal-width="52rem"
:showButton="false"
:showCancel="true"
:showOk="false"
cancelText="بستن"
@cancel="visible = false"
@close="visible = false"
>
<a-spin :spinning="loading">
<div v-if="log" class="flex flex-col gap-4">
<div class="grid grid-cols-1 gap-2 text-sm md:grid-cols-2">
<div><span class="text-gray-500">منبع:</span> {{ sourceLabel(log.source) }}</div>
<div><span class="text-gray-500">آدرس:</span> {{ log.source_url || '—' }}</div>
<div>
<span class="text-gray-500">قیمت مرجع آبشده:</span>
{{ log.liquid_gold_price > 0 ? usePrice(log.liquid_gold_price, true, 'ریال') : '—' }}
</div>
<div><span class="text-gray-500">تعداد محصول:</span> {{ log.products_updated }}</div>
</div>
<a-table
:columns="itemColumns"
:data-source="log.items ?? []"
:pagination="false"
row-key="id"
size="small"
:scroll="{ x: 900 }"
/>
</div>
</a-spin>
</BasicActionSheet>
</template>
<script setup lang="ts">
import type { TableColumnType } from 'ant-design-vue'
import { ref, watch } from 'vue'
import { getPriceSyncLogDetail } from '@/api/price'
import type { PriceSyncLog } from '@/model/priceSyncLog'
import BasicActionSheet from '@/components/BasicActionSheet.vue'
import { usePrice } from '@core/utils/usePrice'
const visible = defineModel<boolean>('visible', { default: false })
const props = defineProps<{ logId?: number | null }>()
const loading = ref(false)
const log = ref<PriceSyncLog | null>(null)
const SOURCE_LABELS: Record<string, string> = {
zaarbox: 'تابلو Zaarbox',
legacy: 'فید قدیمی'
}
function sourceLabel(source?: string) {
return SOURCE_LABELS[source ?? ''] ?? source ?? '—'
}
const itemColumns: TableColumnType[] = [
{ title: 'محصول', dataIndex: 'product_title', key: 'product_title', width: 140 },
{ title: 'کلید مرجع', dataIndex: 'reading_method', key: 'reading_method', width: 120 },
{ title: 'نام در فید', dataIndex: 'source_name', key: 'source_name', width: 120 },
{
title: 'قیمت پایه فید',
key: 'base_price',
customRender: ({ record }) => usePrice(record.base_price ?? 0, true, '')
},
{
title: 'سود فید',
key: 'base_profit',
customRender: ({ record }) => usePrice(record.base_profit ?? 0, true, '')
},
{
title: 'تعدیل ٪',
dataIndex: 'offset_percent',
key: 'offset_percent'
},
{
title: 'قیمت قبلی',
key: 'previous_price',
customRender: ({ record }) => usePrice(record.previous_price ?? 0, true, '')
},
{
title: 'قیمت ذخیره‌شده',
key: 'stored_price',
customRender: ({ record }) => usePrice(record.stored_price ?? 0, true, '')
}
]
async function loadDetail(id: number) {
loading.value = true
try {
log.value = await getPriceSyncLogDetail(id)
} catch (e) {
console.error(e)
log.value = null
} finally {
loading.value = false
}
}
watch(
() => [visible.value, props.logId] as const,
([open, id]) => {
if (open && id) {
void loadDetail(id)
}
}
)
</script>
@@ -1,8 +1,25 @@
<template>
<div class="h-full min-h-0 min-w-0 max-w-full overflow-hidden">
<BasicShowContext title="تاریخچه قیمت">
<BasicShowContext :title="isStore ? 'تاریخچه همگام‌سازی قیمت' : 'تاریخچه قیمت'">
<template #extra>
<BaseButton type="primary" size="small" class="flex shrink-0 md:hidden" @click="emits('add')">
<BaseButton
v-if="isStore"
type="primary"
size="small"
class="flex shrink-0 md:hidden"
:loading="syncing"
@click="emits('sync')"
>
<div>به‌روزرسانی قیمت</div>
<BaseIcon icon="vuesax-linear:refresh" Size="16px" />
</BaseButton>
<BaseButton
v-else
type="primary"
size="small"
class="flex shrink-0 md:hidden"
@click="emits('add')"
>
<div>قیمت گذاری</div>
<BaseIcon icon="vuesax-linear:dollar-circle" Size="16px" />
</BaseButton>
@@ -10,25 +27,37 @@
<div class="flex h-full min-h-0 flex-col">
<BaseTable v-if="!isMobile" class="h-full min-h-0 min-w-0" v-bind="tblProps" @register="submit" ref="tbl">
<template #extraHeader>
<BaseButton type="primary" size="small" class="flex" @click="emits('add')">
<div>قیمت گذاری</div>
<BaseIcon icon="vuesax-linear:dollar-circle" Size="16px" />
</BaseButton>
</template>
<template #action="{ column, record }">
<div class="gap-2 flex justify-center">
<a-tooltip placement="bottom" class="cursor-pointer" @click="emits('info', record)">
<template #title>
<span>مشخصات</span>
</template>
<Icon icon="vuesax-linear:stickynote" color="#10913A" />
</a-tooltip>
</div>
</template>
</BaseTable>
<template #extraHeader>
<BaseButton
v-if="isStore"
type="primary"
size="small"
class="flex"
:loading="syncing"
@click="emits('sync')"
>
<div>به‌روزرسانی قیمت</div>
<BaseIcon icon="vuesax-linear:refresh" Size="16px" />
</BaseButton>
<BaseButton v-else type="primary" size="small" class="flex" @click="emits('add')">
<div>قیمت گذاری</div>
<BaseIcon icon="vuesax-linear:dollar-circle" Size="16px" />
</BaseButton>
</template>
<template #action="{ record }">
<div class="flex justify-center gap-2">
<a-tooltip placement="bottom" class="cursor-pointer" @click="emits('detail', record)">
<template #title>
<span>جزئیات محصولات</span>
</template>
<Icon icon="vuesax-linear:stickynote" color="#10913A" />
</a-tooltip>
</div>
</template>
</BaseTable>
<PriceMobileCardList v-else ref="mobileListRef" class="min-h-0 flex-1" />
<PriceMobileCardList v-else-if="!isStore" ref="mobileListRef" class="min-h-0 flex-1" />
<div v-else class="p-4 text-center text-gray-500">در موبایل از نسخه دسکتاپ استفاده کنید</div>
</div>
</BasicShowContext>
</div>
@@ -39,24 +68,29 @@ import type { TableInput } from '@core/type/baseTable'
import useBaseTable from '@core/components/BaseTableOld/hooks/useBaseTable'
import Icon from '@core/components/BaseIcon/src/Icon.vue'
import { cols } from '../hooks/priceColumns'
import { storePriceColumns } from '../hooks/storePriceColumns'
import { usePrefix } from '@core/composable/usePrefix'
import { getPriceTable } from '@/api/price'
import { getPriceSyncLogTable, getPriceTable } from '@/api/price'
import { isStoreApp } from '@/utils/config'
import PriceMobileCardList from './PriceMobileCardList.vue'
import { isMobile } from '@core/utils/is'
import { computed } from 'vue'
const props = defineProps<{ syncing?: boolean }>()
const [submit, reload] = useBaseTable()
const mobileListRef = ref<null | { fetch: () => Promise<void> }>(null)
const emits = defineEmits(['delete', 'edit', 'add', 'info'])
const emits = defineEmits(['delete', 'edit', 'add', 'info', 'detail', 'sync'])
const isStore = computed(() => isStoreApp())
const { prefixCls } = usePrefix('pophoverstatus')
const tblProps = ref<any>({
columns: cols,
api: (params: TableInput) => {
return getPriceTable(params)
}
})
const tblProps = computed(() => ({
columns: isStore.value ? storePriceColumns : cols,
api: (params: TableInput) =>
isStore.value ? getPriceSyncLogTable(params) : getPriceTable(params)
}))
async function fetch() {
await Promise.allSettled([reload(), mobileListRef.value?.fetch?.() as Promise<void>])
@@ -0,0 +1,63 @@
import type { BaseTableColumn } from '@core/type/baseTable'
import { toJalaliNoTime, toTime } from '@core/utils/useDataTime'
import { usePrice } from '@core/utils/usePrice'
const SOURCE_LABELS: Record<string, string> = {
zaarbox: 'تابلو Zaarbox',
legacy: 'فید قدیمی'
}
export const storePriceColumns: BaseTableColumn[] = [
{
title: 'ردیف',
dataIndex: 'id',
key: 'row',
filterable: false,
sortable: false,
customRender: (record: any) => record.index + 1
},
{
title: 'منبع قیمت',
dataIndex: 'source',
key: 'source',
type: 'Text',
customRender: ({ record }) => SOURCE_LABELS[record.source] ?? record.source
},
{
title: 'قیمت مرجع آبشده (ریال)',
dataIndex: 'liquid_gold_price',
key: 'liquid_gold_price',
type: 'Text',
customRender: ({ record }) =>
record.liquid_gold_price > 0 ? usePrice(record.liquid_gold_price, true, '') : '—'
},
{
title: 'محصولات به‌روز شده',
dataIndex: 'products_updated',
key: 'products_updated',
type: 'Number'
},
{
title: 'تاریخ',
dataIndex: 'created_at',
key: 'created_at',
type: 'DateTime',
customRender: (record: any) => toJalaliNoTime(record.record.created_at)
},
{
title: 'زمان',
dataIndex: 'created_at',
key: 'time_at',
type: 'DateTime',
customRender: (record: any) => toTime(record.record.created_at)
},
{
title: 'عملیات',
dataIndex: 'action',
key: 'action',
slot: 'action',
fixed: 'right',
filterable: false,
sortable: false
}
]
+70 -205
View File
@@ -1,245 +1,112 @@
<template>
<div>
<BasicMainCard>
<div class="flex w-full h-full">
<div class="flex h-full w-full">
<tbl
ref="table"
class="w-full h-full"
@info="info"
@edit="edit"
@delete="deleteItem"
class="h-full w-full"
:syncing="syncing"
@add="add"
@detail="openDetail"
@sync="handleSync"
/>
<!-- <BasicMenu :menu="menu" width="13rem" @onChange="tabSelected" />
<component :is="selectedComponent" class="mr-5" />-->
<!-- <BasicShowContext title="پروژه ها"> <Search /> </BasicShowContext>-->
</div>
</BasicMainCard>
<BasicModal
v-model:visible="priceConfirmVisible"
width="25rem"
@ok="ok"
:confirm-loading="loading"
@close="priceConfirmVisible = false"
>
<div class="flex items-center gap-2 font-bold">
<BaseIcon icon="vuesax-linear:info-circle" color="orange" />
<div>آیا مطمئن به تغییر قیمت می باشید؟</div>
</div>
</BasicModal>
<!-- <BasicInfoModal
v-model:visible="userInfoVisible"
@close="userInfoVisible = false"
:title="infoParams.title"
:date="infoParams.date"
:time="infoParams.time"
:type="infoParams.type"
:name="infoParams.name"
:items="infoParams.items"
/>-->
<template v-if="!isStore">
<BasicModal
v-model:visible="priceConfirmVisible"
width="25rem"
@ok="ok"
:confirm-loading="loading"
@close="priceConfirmVisible = false"
>
<div class="flex items-center gap-2 font-bold">
<BaseIcon icon="vuesax-linear:info-circle" color="orange" />
<div>آیا مطمئن به تغییر قیمت می باشید؟</div>
</div>
</BasicModal>
<BasicModal
v-model:visible="addPriceVisible"
width="25rem"
title="قیمت گذاری"
@ok="confirmPrice"
:loading="loading"
@close="addPriceVisible = false"
>
<a-form :model="form" ref="formRef" autocomplete="off">
<div class="gap-4">
<a-form-item label="قیمت جدید" name="price" :rules="inputRules()">
<BasicInput v-model:value="form.price" type="price" addon-before="ریال" />
</a-form-item>
<div v-show="form.price > 10">معادل {{ usePrice(form.price / 10, true, 'تومان') }}</div>
</div>
</a-form>
</BasicModal>
</template>
<PriceSyncDetailModal v-model:visible="detailVisible" :log-id="selectedLogId" />
</div>
<BasicModal
v-model:visible="addPriceVisible"
width="25rem"
title="قیمت گذاری"
@ok="confirmPrice"
:loading="loading"
@close="addPriceVisible = false"
>
<a-form :model="form" ref="formRef" autocomplete="off">
<div class="gap-4">
<a-form-item label="قیمت جدید" name="price" :rules="inputRules()">
<BasicInput v-model:value="form.price" type="price" addon-before="ریال" />
</a-form-item>
<div v-show="form.price > 10">معادل {{ usePrice(form.price / 10, true, 'تومان') }}</div>
<!-- <a-form-item label="نام چاپی" name="print_name" :rules="inputRules()">
<BasicInput v-model:value="form.print_name" />
</a-form-item>-->
</div>
</a-form>
</BasicModal>
</template>
<script setup lang="ts">
// import BasicInfoModal from '@/components/BasicInfoModal'
import { inputLenRules, inputRules } from '@/utils/inputRules'
import { useStaticApiListsStore } from '@/store/staticApisStore'
import { ref } from 'vue'
import { inputRules } from '@/utils/inputRules'
import { computed, ref } from 'vue'
import tbl from './components/table.vue'
import type { FormInstance } from 'ant-design-vue'
import BasicInfoModal from '@/components/BasicInfoModal/index.vue'
import { message } from 'ant-design-vue/es'
import type { Info } from '@/components/BasicInfoModal/model/Info'
import { toJalaliNoTime, toTime } from '@core/utils/useDataTime'
import { confirmActOnApi, confirmDeleteItem } from '@/utils/confirmModal'
import { cloneDeep } from 'lodash'
import type { Item } from '@/model/Item'
import type { Customer } from '@/model/customer'
import { createCustomer, deleteCustomer, updateCustomer } from '@/api/customer'
import type { Order } from '@/model/order'
import type { Price } from '@/model/price'
import { createPrice } from '@/api/price'
import { createPrice, runPriceSync } from '@/api/price'
import { usePrice } from '@core/utils/usePrice'
import Icon from '@core/components/BaseIcon'
import { isStoreApp } from '@/utils/config'
import PriceSyncDetailModal from './components/PriceSyncDetailModal.vue'
import type { PriceSyncLog } from '@/model/priceSyncLog'
//loading
const loading = ref<boolean>(false)
const loading = ref(false)
const syncing = ref(false)
const table = ref<null | { fetch: () => void }>(null)
const refreshTable = () => table.value?.fetch()
//define store
const store = useStaticApiListsStore()
const isStore = computed(() => isStoreApp())
//define tbl
const table = ref(null)
const refreshTable = () => table?.value?.fetch()
let updateKey = ref<number>(0)
//role confirm items
const confirmItems: Array<Item> = [
{
value: 'بله',
key: true
},
{
value: 'خیر',
key: false
}
]
//form
const form = ref<Price>({})
const formRef = ref<FormInstance>()
const addPriceVisible = ref(false)
const priceConfirmVisible = ref(false)
const detailVisible = ref(false)
const selectedLogId = ref<number | null>(null)
//info
let infoParams = reactive<Info>({})
/*
function info(val: Order) {
infoParams.name = val.customer.name
infoParams.type = val.customer.mobile
infoParams.date = toJalaliNoTime(val.created_at)
infoParams.time = toTime(val.created_at)
infoParams.itemsTitle = 'اطلاعات کاربری'
infoParams.items = [
{
key: 'مقدار (گرم)',
value: val.amount ?? '-'
},
{
key: 'قیمت هر گرم طلا برای مشتری (ریال)',
value: val.price ?? '-'
},
{
key: 'قیمت کل برای مشتری (ریال)',
value: val.total_price ?? '-'
},
{
key: '/قیمت هر گرم طلا بدون سود (ریال)',
value: val.price_original ?? '-'
},
{
key: 'قیمت کل بدون سود (ریال)',
value: val.total_price_original ?? '-'
},
{
key: 'سود هر گرم (ریال)',
value: val.fee ?? '-'
},
{
key: 'سود کل (ریال)',
value: val.total_fee ?? '-'
},
{
key: 'کد کاربری',
value: val.customer.id ?? '-'
},
{
key: 'شماره ملی',
value: val.customer.n_code ?? '-'
},
{
key: 'تاریخ تولد',
value: toJalaliNoTime(val.customer.birth_date) ?? '-'
},
/!* {
key: 'نام فروشگاه',
value: val.customer.shop_name ?? '-'
},*!/
{
key: 'شماره تلفن',
value: val.customer.phone_number ?? '-'
},
{
key: 'نام استان',
value: val.customer.province ?? '-'
},
{
key: 'نام شهر',
value: val.customer.city ?? '-'
}
/!* {
key: 'نام چاپی',
value: val.print_name ?? '-'
}*!/
]
userInfoVisible.value = true
function openDetail(record: PriceSyncLog) {
selectedLogId.value = record.id
detailVisible.value = true
}
*/
//edit
let editId: number | undefined = undefined
/*
async function edit(record: Customer) {
addPriceVisible.value = true
editId = record.id
form.value = cloneDeep(record)
async function handleSync() {
syncing.value = true
try {
const res = await runPriceSync()
message.success(res.message || 'انجام شد')
refreshTable()
} catch (e) {
console.error(e)
message.error('خطا در به‌روزرسانی قیمت')
} finally {
syncing.value = false
}
}
*/
//add
async function add() {
loading.value = true
editId = undefined
// await store.getUsersList()
addPriceVisible.value = true
updateKey.value++
resetData()
loading.value = false
}
//reset data
const resetData = () => {
formRef.value?.resetFields()
form.value = {}
}
//delete
// const deleteItem = (id: number) => confirmDeleteItem('کاربر', id, deleteCustomer, refreshTable)
//define selects
/*
onMounted(async () => {
loading.value = true
// await getResponsible()
// await getQC()
// await getManager()
loading.value = false
})
*/
//add project modal
const addPriceVisible = ref<boolean>(false)
const priceConfirmVisible = ref<boolean>(false)
//submit user
function confirmPrice() {
formRef.value?.validateFields().then(async () => {
priceConfirmVisible.value = true
})
}
async function ok() {
loading.value = true
try {
@@ -247,10 +114,8 @@ async function ok() {
refreshTable()
priceConfirmVisible.value = false
addPriceVisible.value = false
// await confirmActOnApi('آیا از اعمال قیمت جدید اطمینان دارید؟', form.value, createPrice)
} catch (e) {
console.error(e)
// message.error('خطا در بارگذاری اطلاعات')
} finally {
loading.value = false
}
+7
View File
@@ -10,6 +10,10 @@ import { cloneDeep } from 'lodash'
function applyAppModeMeta(route: RouteRecordRaw, appName: string | null) {
const store = isStoreApp()
if (route.name === 'pricing' && route.meta) {
route.meta.title = store ? 'تاریخچه قیمت' : 'قیمت گذاری'
}
if (!route.children?.length) return
for (const child of route.children) {
@@ -26,6 +30,9 @@ function applyAppModeMeta(route: RouteRecordRaw, appName: string | null) {
if (child.name === 'productsMain_categories' && child.meta) {
child.meta.hideMenu = !store
}
if (child.name === 'pricingMain' && child.meta) {
child.meta.title = store ? 'تاریخچه قیمت' : 'قیمت گذاری'
}
applyAppModeMeta(child, appName)
}
}