26/8/1404

This commit is contained in:
2025-11-17 15:03:25 +03:30
parent 23ae6c144c
commit 28506f65ea
9 changed files with 132 additions and 33 deletions
@@ -5,10 +5,16 @@
@click="localValue = props.selfIndex"
>
<div class="p-3 flex flex-col items-center">
<div class="flex justify-between w-full">
<div class="flex w-full">
<div class="text-white font-bold text-lg w-full">{{ props.title }}</div>
<div
class="text-white px-2 flex justify-center items-center rounded-lg w-5rem"
@click.stop="deleteConfirmVisible = true"
class="text-white w-full ml-2 flex justify-center bg-red-600 items-center rounded-lg"
>
حذف کارت
</div>
<div
class="text-white w-full flex justify-center items-center rounded-lg"
:class="active ? 'bg-green-600' : 'bg-red-600'"
>
{{ active ? 'فعال' : 'غیر فعال' }}
@@ -19,18 +25,45 @@
class="mt-[1.5vh] text-white w-full text-center text-xl font-bold"
dir="ltr"
>
{{ useCardNumber(props.cardNumber) }}
{{ formattedCardNumber }}
</div>
<div v-if="props.shaba" class="mt-3 text-white text-lg">
{{ useShabaNumber(props.shaba) }}
{{ formattedShabaNumber }}
</div>
</div>
</div>
<DialogVant
v-model:show="deleteConfirmVisible"
teleport="body"
:closeOnClickOverlay="false"
:timeOut="-1"
>
<template #title>
<div class="flex flex-col items-center">
<div class="p-5 text-sm">
آیا از حذف کارت مطمئن هستید؟
</div>
</div>
</template>
<template #button>
<div class="text-center text-red flex items-center justify-center" @click="removeCard()">
<a-spin :spinning="deleteLoading" size="small">
تایید
</a-spin>
</div>
<div class="text-center" @click="deleteConfirmVisible = false">
انصراف
</div>
</template>
</DialogVant>
</template>
<script lang="ts" setup>
import { computed } from 'vue'
import { computed, ref } from 'vue'
import { useCardNumber, useShabaNumber } from '@/utils/useCardNumber'
import { deleteCard } from '@/api/transfer'
import DialogVant from '@/components/DialogVant.vue'
interface Prop {
sliderIndex: number
@@ -40,20 +73,29 @@ interface Prop {
shaba?: string
color?: string
active?: boolean
id?: number | string
}
const props = defineProps<Prop>()
const emits = defineEmits(['update:sliderIndex', 'deleted'])
const deleteConfirmVisible = ref(false)
const deleteLoading = ref(false)
const localValue = computed({
get() {
return props.sliderIndex
},
set(value) {
emits('update:sliderIndex', value)
}
})
const props = defineProps<Prop>()
const emits = defineEmits(['update:sliderIndex'])
const formattedCardNumber = computed(() =>
props.cardNumber ? useCardNumber(props.cardNumber) : ''
)
const formattedShabaNumber = computed(() =>
props.shaba ? useShabaNumber(props.shaba) : ''
)
function findPositionStyle(pos: number) {
// console.log(localValue.value)
@@ -142,6 +184,28 @@ function topDetail(isAfterIndex: boolean, pos: number) {
function checkTopLimit(val: number) {
return val > 100 || val < 0
}
async function removeCard(id?: number | string) {
const rawId = id ?? props.id
const cardId = rawId != null ? Number(rawId) : null
if (cardId === null || Number.isNaN(cardId)) {
console.warn('cardId is missing or invalid', rawId)
return
}
try {
deleteLoading.value = true
await deleteCard(cardId)
deleteConfirmVisible.value = false
emits('deleted')
} catch (error) {
console.error('Failed to delete card', error)
} finally {
deleteLoading.value = false
}
}
</script>
<style lang="sass" scoped>
@@ -4,7 +4,9 @@
<div ref="el" class="w-full flex flex-col relative h-full test">
<CardItem v-for="(item,i) in props?.items" :key="i" v-model:sliderIndex="index" :card-number="item?.cart_number"
:color="colors[i%3]"
:self-index="i" :shaba="item?.shaba_number" :title="item?.bank_name" :active="item.sts === 2"/>
:self-index="i" :shaba="item?.shaba_number" :title="item?.bank_name" :active="item.sts === 2"
:id="item?.id ?? item?.card_id"
@deleted="handleCardDeleted"/>
<div class="absolute bottom-15vh right-0 left-0 z-100 flex justify-center items-center opacity-70">
<div class="flex gap-1 bg-gray-500 px-2 py-1 rounded-lg">
<Transition name="slide-up" mode="out-in" v-for="i in items.length" :key="i">
@@ -35,7 +37,7 @@ interface Prop {
}
const props = defineProps<Prop>()
const emits = defineEmits(['update:id'])
const emits = defineEmits(['update:id', 'refresh'])
const localValue = computed({
get() {
@@ -101,6 +103,10 @@ watch(index, (n: number)=> {
localValue.value = props.items[n]?.id
})
function handleCardDeleted() {
emits('refresh')
}
/*
const items = [
{
+1
View File
@@ -119,6 +119,7 @@
v-if="cardItems.length > 0"
:items="cardItems"
v-model:id="form.card_id"
@refresh="getCards"
class="card-slider-wrap mt-[2vh] px-3 fixed bottom-10 right-0 left-0"
style="touch-action: none"
/>