135 lines
3.5 KiB
Vue
135 lines
3.5 KiB
Vue
<template>
|
|
<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
|
|
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'
|
|
import type { itemConfig } from '@/model/configuration'
|
|
|
|
interface Prop {
|
|
item: itemConfig
|
|
}
|
|
|
|
const props = defineProps<Prop>()
|
|
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
|
|
}))
|
|
})
|
|
|
|
function isTruthyFlag(val?: string) {
|
|
return val === 'true' || val === '1'
|
|
}
|
|
|
|
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,
|
|
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
|
|
}
|
|
}
|
|
|
|
async function ok() {
|
|
try {
|
|
loading.value = true
|
|
await setConfiguration(buildPayload())
|
|
message.success('تغییر با موفقیت انجام شد')
|
|
isChanged.value = false
|
|
} catch (e) {
|
|
console.error(e)
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
onMounted(() => {
|
|
configValue.value = props.item.value
|
|
isActive.value = props.item.is_active === true
|
|
isVisible.value = isTruthyFlag(props.item.description) || props.item.description == null
|
|
})
|
|
</script>
|