Files
boursecu_admin/src/pages/menuPages/configuration/components/TextConfigs.vue
T

135 lines
3.5 KiB
Vue
Raw Normal View History

<template>
2026-05-25 10:49:08 +03:30
<div class="mb-2 justify-between items-center border-1 border-gray-300 border-solid rounded-lg p-3">
<div>
<div class="flex justify-between">
<div>{{ item.title_fa ?? item.name ?? '-' }}</div>
<div>
<a-switch
checked-children="فعال"
un-checked-children="غیرفعال"
v-model:checked="isActive"
@change="ok"
/>
</div>
</div>
</div>
<div v-if="!item.list?.length" class="flex justify-between items-center mt-2">
<div class="text-xs">کلید: {{ item.key }}</div>
<div class="flex">
<a-switch
checked-children="نمایش"
un-checked-children="عدم نمایش"
v-model:checked="isVisible"
@change="ok"
/>
</div>
</div>
<div v-else class="text-xs mt-2">کلید: {{ item.key }}</div>
<div class="flex justify-between gap-1 mt-2">
<BasicSelect
v-if="item.list && item.list.length > 0"
class="w-full"
value-name="value"
key-name="lable"
v-model:value="configValue"
:items="itemListLocal"
@change="ok"
/>
<BasicInput
v-else
class="flex-1"
type="text"
place-holder="مقدار"
v-model:value="configValue"
@input="isChanged = true"
/>
<div v-if="item.list && item.list.length === 0 && isChanged" class="flex items-center">
<BaseIcon
icon="vuesax-linear:tick-circle"
class="mr-2 items-center cursor-pointer"
color="green"
size="24"
@click="ok()"
/>
<BaseIcon
2026-05-25 10:49:08 +03:30
icon="vuesax-linear:close-circle"
class="mr-2 items-center cursor-pointer"
color="red"
@click="cancelFn"
size="24"
/>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { loading } from '@/utils'
import { setConfiguration } from '@/api/configuration'
import { message } from 'ant-design-vue'
2026-05-25 10:49:08 +03:30
import type { itemConfig } from '@/model/configuration'
interface Prop {
item: itemConfig
}
const props = defineProps<Prop>()
2026-05-25 10:49:08 +03:30
const configValue = ref<string>('')
const isActive = ref<boolean>(false)
const isVisible = ref<boolean>(false)
const isChanged = ref<boolean>(false)
const itemListLocal = computed(() => {
if (!props.item.list) return []
return props.item.list.map((x) => ({
lable: x,
value: x
}))
})
2026-05-25 10:49:08 +03:30
function isTruthyFlag(val?: string) {
return val === 'true' || val === '1'
}
2026-05-25 10:49:08 +03:30
function cancelFn() {
configValue.value = props.item.value
isChanged.value = false
}
function buildPayload() {
const hasSelectOptions = props.item.list && props.item.list.length > 0
return {
id: props.item.id,
key: props.item.key,
2026-05-25 10:49:08 +03:30
value: configValue.value,
title_fa: props.item.title_fa ?? props.item.name,
type: props.item.type,
description: hasSelectOptions
? props.item.description
: isVisible.value
? 'true'
: 'false',
is_active: isActive.value
}
2026-05-25 10:49:08 +03:30
}
async function ok() {
try {
loading.value = true
2026-05-25 10:49:08 +03:30
await setConfiguration(buildPayload())
message.success('تغییر با موفقیت انجام شد')
2026-05-25 10:49:08 +03:30
isChanged.value = false
} catch (e) {
console.error(e)
} finally {
loading.value = false
}
}
onMounted(() => {
2026-05-25 10:49:08 +03:30
configValue.value = props.item.value
isActive.value = props.item.is_active === true
isVisible.value = isTruthyFlag(props.item.description) || props.item.description == null
})
</script>