Merge remote-tracking branch 'origin/master'
This commit is contained in:
163
ui/src/pages/OrderPriceListUserPriceGroupMapping.vue
Normal file
163
ui/src/pages/OrderPriceListUserPriceGroupMapping.vue
Normal file
@@ -0,0 +1,163 @@
|
||||
<template>
|
||||
<q-page v-if="canUpdateSystem" class="q-pa-md">
|
||||
<div class="row items-center justify-between q-mb-md">
|
||||
<div>
|
||||
<div class="text-h6">Kullanici Fiyat Grubu Eslestirme</div>
|
||||
<div class="text-caption text-grey-7">Fiyat Listesi ekraninda kullanicinin gorebilecegi fiyat gruplarini belirler.</div>
|
||||
</div>
|
||||
<q-btn
|
||||
color="primary"
|
||||
icon="save"
|
||||
label="Degisiklikleri Kaydet"
|
||||
:loading="store.saving"
|
||||
:disable="!hasChanges"
|
||||
@click="saveChanges"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<q-table
|
||||
flat
|
||||
bordered
|
||||
dense
|
||||
row-key="user_id"
|
||||
:loading="store.loading"
|
||||
:rows="store.rows"
|
||||
:columns="columns"
|
||||
:rows-per-page-options="[0]"
|
||||
:pagination="{ rowsPerPage: 0 }"
|
||||
>
|
||||
<template #body-cell-price_groups="props">
|
||||
<q-td :props="props">
|
||||
<q-select
|
||||
:model-value="editableByUser[props.row.user_id] || []"
|
||||
:options="store.priceGroupOptions"
|
||||
option-value="value"
|
||||
option-label="label"
|
||||
emit-value
|
||||
map-options
|
||||
multiple
|
||||
use-chips
|
||||
clearable
|
||||
dense
|
||||
outlined
|
||||
label="Fiyat gruplari"
|
||||
@update:model-value="(val) => updateRowSelection(props.row.user_id, val)"
|
||||
>
|
||||
<template #before-options>
|
||||
<q-item clickable @click="selectAll(props.row.user_id)">
|
||||
<q-item-section>Tumunu Sec</q-item-section>
|
||||
</q-item>
|
||||
<q-item clickable @click="clearAll(props.row.user_id)">
|
||||
<q-item-section>Temizle</q-item-section>
|
||||
</q-item>
|
||||
<q-separator />
|
||||
</template>
|
||||
</q-select>
|
||||
</q-td>
|
||||
</template>
|
||||
</q-table>
|
||||
</q-page>
|
||||
|
||||
<q-page v-else class="q-pa-md flex flex-center">
|
||||
<div class="text-negative text-subtitle1">
|
||||
Bu module erisim yetkiniz yok.
|
||||
</div>
|
||||
</q-page>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useQuasar } from 'quasar'
|
||||
import { usePermission } from 'src/composables/usePermission'
|
||||
import { useOrderPriceListUserPriceGroupStore } from 'src/stores/orderPriceListUserPriceGroupStore'
|
||||
|
||||
const $q = useQuasar()
|
||||
const store = useOrderPriceListUserPriceGroupStore()
|
||||
const { canUpdate } = usePermission()
|
||||
const canUpdateSystem = canUpdate('system')
|
||||
|
||||
const editableByUser = ref({})
|
||||
const originalByUser = ref({})
|
||||
|
||||
const columns = [
|
||||
{ name: 'username', label: 'Kullanici Kodu', field: 'username', align: 'left', sortable: true },
|
||||
{ name: 'full_name', label: 'Ad Soyad', field: 'full_name', align: 'left', sortable: true },
|
||||
{ name: 'email', label: 'E-Posta', field: 'email', align: 'left' },
|
||||
{ name: 'price_groups', label: 'Gorebilecegi Fiyat Gruplari', field: 'price_groups', align: 'left' }
|
||||
]
|
||||
|
||||
const changedUsers = computed(() => {
|
||||
return (store.rows || [])
|
||||
.map((r) => Number(r.user_id || 0))
|
||||
.filter(Boolean)
|
||||
.filter((id) => !isEqualList(normalizeList(editableByUser.value[id] || []), normalizeList(originalByUser.value[id] || [])))
|
||||
})
|
||||
|
||||
const hasChanges = computed(() => changedUsers.value.length > 0)
|
||||
|
||||
function normalizeList (list) {
|
||||
const allowed = new Set((store.priceGroupOptions || []).map((x) => x.value))
|
||||
return Array.from(new Set((Array.isArray(list) ? list : []).map((x) => String(x).trim()).filter((x) => allowed.has(x)))).sort()
|
||||
}
|
||||
|
||||
function isEqualList (a, b) {
|
||||
if (a.length !== b.length) return false
|
||||
for (let i = 0; i < a.length; i += 1) {
|
||||
if (a[i] !== b[i]) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
function initEditableState () {
|
||||
const editable = {}
|
||||
const original = {}
|
||||
for (const row of store.rows || []) {
|
||||
const id = Number(row.user_id || 0)
|
||||
if (!id) continue
|
||||
const selected = normalizeList(row.price_groups || [])
|
||||
editable[id] = [...selected]
|
||||
original[id] = [...selected]
|
||||
}
|
||||
editableByUser.value = editable
|
||||
originalByUser.value = original
|
||||
}
|
||||
|
||||
function updateRowSelection (userId, newValue) {
|
||||
const id = Number(userId || 0)
|
||||
if (!id) return
|
||||
editableByUser.value = { ...editableByUser.value, [id]: normalizeList(newValue) }
|
||||
}
|
||||
|
||||
function selectAll (userId) {
|
||||
updateRowSelection(userId, store.priceGroupOptions.map((x) => x.value))
|
||||
}
|
||||
|
||||
function clearAll (userId) {
|
||||
updateRowSelection(userId, [])
|
||||
}
|
||||
|
||||
async function init () {
|
||||
try {
|
||||
await Promise.all([store.fetchLookups(), store.fetchRows()])
|
||||
initEditableState()
|
||||
} catch (err) {
|
||||
$q.notify({ type: 'negative', message: err?.message || 'Kullanici fiyat grubu eslestirmeleri yuklenemedi' })
|
||||
}
|
||||
}
|
||||
|
||||
async function saveChanges () {
|
||||
if (!hasChanges.value) return
|
||||
try {
|
||||
for (const id of changedUsers.value) {
|
||||
await store.saveUserPriceGroups(id, editableByUser.value[id] || [])
|
||||
}
|
||||
await store.fetchRows()
|
||||
initEditableState()
|
||||
$q.notify({ type: 'positive', message: 'Degisiklikler kaydedildi' })
|
||||
} catch (err) {
|
||||
$q.notify({ type: 'negative', message: err?.message || 'Kayit hatasi' })
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => { init() })
|
||||
</script>
|
||||
Reference in New Issue
Block a user