2026-01-24 17:45:54 +03:30
|
|
|
<template>
|
|
|
|
|
<div>
|
|
|
|
|
<BasicMainCard>
|
2026-06-13 12:42:10 +03:30
|
|
|
<div class="flex h-full w-full">
|
2026-01-24 17:45:54 +03:30
|
|
|
<tbl
|
|
|
|
|
ref="table"
|
2026-06-13 12:42:10 +03:30
|
|
|
class="h-full w-full"
|
|
|
|
|
:syncing="syncing"
|
2026-01-24 17:45:54 +03:30
|
|
|
@add="add"
|
2026-06-13 12:42:10 +03:30
|
|
|
@detail="openDetail"
|
|
|
|
|
@sync="handleSync"
|
2026-01-24 17:45:54 +03:30
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</BasicMainCard>
|
|
|
|
|
|
2026-06-13 12:42:10 +03:30
|
|
|
<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" />
|
2026-01-24 17:45:54 +03:30
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2026-06-13 12:42:10 +03:30
|
|
|
import { inputRules } from '@/utils/inputRules'
|
|
|
|
|
import { computed, ref } from 'vue'
|
2026-01-24 17:45:54 +03:30
|
|
|
import tbl from './components/table.vue'
|
|
|
|
|
import type { FormInstance } from 'ant-design-vue'
|
|
|
|
|
import { message } from 'ant-design-vue/es'
|
|
|
|
|
import type { Price } from '@/model/price'
|
2026-06-13 12:42:10 +03:30
|
|
|
import { createPrice, runPriceSync } from '@/api/price'
|
2026-01-24 17:45:54 +03:30
|
|
|
import { usePrice } from '@core/utils/usePrice'
|
2026-06-13 12:42:10 +03:30
|
|
|
import { isStoreApp } from '@/utils/config'
|
|
|
|
|
import PriceSyncDetailModal from './components/PriceSyncDetailModal.vue'
|
|
|
|
|
import type { PriceSyncLog } from '@/model/priceSyncLog'
|
2026-01-24 17:45:54 +03:30
|
|
|
|
2026-06-13 12:42:10 +03:30
|
|
|
const loading = ref(false)
|
|
|
|
|
const syncing = ref(false)
|
|
|
|
|
const table = ref<null | { fetch: () => void }>(null)
|
|
|
|
|
const refreshTable = () => table.value?.fetch()
|
2026-01-24 17:45:54 +03:30
|
|
|
|
2026-06-13 12:42:10 +03:30
|
|
|
const isStore = computed(() => isStoreApp())
|
2026-01-24 17:45:54 +03:30
|
|
|
|
|
|
|
|
const form = ref<Price>({})
|
|
|
|
|
const formRef = ref<FormInstance>()
|
2026-06-13 12:42:10 +03:30
|
|
|
const addPriceVisible = ref(false)
|
|
|
|
|
const priceConfirmVisible = ref(false)
|
|
|
|
|
const detailVisible = ref(false)
|
|
|
|
|
const selectedLogId = ref<number | null>(null)
|
2026-01-24 17:45:54 +03:30
|
|
|
|
2026-06-13 12:42:10 +03:30
|
|
|
function openDetail(record: PriceSyncLog) {
|
|
|
|
|
selectedLogId.value = record.id
|
|
|
|
|
detailVisible.value = true
|
2026-01-24 17:45:54 +03:30
|
|
|
}
|
|
|
|
|
|
2026-06-13 12:42:10 +03:30
|
|
|
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
|
|
|
|
|
}
|
2026-01-24 17:45:54 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function add() {
|
|
|
|
|
addPriceVisible.value = true
|
|
|
|
|
form.value = {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function confirmPrice() {
|
|
|
|
|
formRef.value?.validateFields().then(async () => {
|
|
|
|
|
priceConfirmVisible.value = true
|
|
|
|
|
})
|
|
|
|
|
}
|
2026-06-13 12:42:10 +03:30
|
|
|
|
2026-01-24 17:45:54 +03:30
|
|
|
async function ok() {
|
|
|
|
|
loading.value = true
|
|
|
|
|
try {
|
|
|
|
|
await createPrice(form.value)
|
|
|
|
|
refreshTable()
|
|
|
|
|
priceConfirmVisible.value = false
|
|
|
|
|
addPriceVisible.value = false
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e)
|
|
|
|
|
} finally {
|
|
|
|
|
loading.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped></style>
|