Fix product performance grouped JSON build
This commit is contained in:
@@ -176,7 +176,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { computed, nextTick, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { useQuasar } from 'quasar'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { usePermission } from 'src/composables/usePermission'
|
||||
@@ -262,6 +262,34 @@ const columns = [
|
||||
]
|
||||
|
||||
const columnFilters = reactive({})
|
||||
const LIST_STATE_STORAGE_KEY = 'bssapp:production-product-costing:no-cost-list-state:v1'
|
||||
|
||||
function persistListState () {
|
||||
try {
|
||||
sessionStorage.setItem(LIST_STATE_STORAGE_KEY, JSON.stringify({
|
||||
filters: {
|
||||
search: String(filters.search || ''),
|
||||
fromDate: String(filters.fromDate || '')
|
||||
},
|
||||
columnFilters: JSON.parse(JSON.stringify(columnFilters)),
|
||||
scrollY: Number(window.scrollY || 0)
|
||||
}))
|
||||
} catch {}
|
||||
}
|
||||
|
||||
function restoreListState () {
|
||||
try {
|
||||
const raw = sessionStorage.getItem(LIST_STATE_STORAGE_KEY)
|
||||
if (!raw) return 0
|
||||
const saved = JSON.parse(raw)
|
||||
filters.search = String(saved?.filters?.search || '')
|
||||
filters.fromDate = String(saved?.filters?.fromDate || '2025-06-01')
|
||||
Object.assign(columnFilters, saved?.columnFilters && typeof saved.columnFilters === 'object' ? saved.columnFilters : {})
|
||||
return Number(saved?.scrollY || 0)
|
||||
} catch {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
function getColumnFilter (name) {
|
||||
if (!columnFilters[name]) {
|
||||
@@ -384,9 +412,11 @@ function clearAllColumnFilters () {
|
||||
}
|
||||
|
||||
let searchTimer = null
|
||||
let filterWatchEnabled = false
|
||||
watch(
|
||||
() => filters.search,
|
||||
() => {
|
||||
if (!filterWatchEnabled) return
|
||||
clearTimeout(searchTimer)
|
||||
searchTimer = setTimeout(() => {
|
||||
fetchRows()
|
||||
@@ -397,6 +427,7 @@ watch(
|
||||
watch(
|
||||
() => filters.fromDate,
|
||||
() => {
|
||||
if (!filterWatchEnabled) return
|
||||
fetchRows()
|
||||
}
|
||||
)
|
||||
@@ -449,6 +480,8 @@ function openRow (row) {
|
||||
recipe_code: recipeCode
|
||||
})
|
||||
|
||||
persistListState()
|
||||
|
||||
router.push({
|
||||
name: 'production-product-costing-has-cost-detail',
|
||||
query: {
|
||||
@@ -460,9 +493,16 @@ function openRow (row) {
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
if (!canReadOrder.value) return
|
||||
fetchRows()
|
||||
const savedScrollY = restoreListState()
|
||||
await nextTick()
|
||||
filterWatchEnabled = true
|
||||
await fetchRows()
|
||||
if (savedScrollY > 0) {
|
||||
await nextTick()
|
||||
window.scrollTo({ top: savedScrollY, behavior: 'auto' })
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user