بناءً على متطلباتك لجدول فرعي يعرض "السجل الوظيفي" في طلب "التحقق من التعليمات"، يمكنني مساعدتك في تعديل الكود الحالي لإضافة هذه الميزة. فيما يلي خطة لتعديل الكود ليتناسب مع الجدول الفرعي "Employment History":
الخطوات:
-
تعديل البيانات:
سنحتاج إلى إضافة منطق لعرض وإدارة معلومات السجل الوظيفي كما فعلنا مع معلومات التعليم.
-
إضافة الحقول:
الحقول المذكورة في الجدول الفرعي سيتم إنشاؤها واستخدامها بشكل مشابه للحقول الموجودة في المعلومات التعليمية.
-
الواجهة:
تصميم الواجهة لتتناسب مع Tailwind CSS وتتبع النمط الحالي للواجهة.
مثال عن الكود:
<template>
<div dir="ltr" class="p-6 bg-bg min-h-screen">
<div v-if="request.doc" class="max-w-7xl mx-auto bg-bg shadow-md rounded-lg p-6">
<!-- Employment History Section -->
<div class="space-y-4">
<div
v-for="(employment, index) in request.doc.employment_history"
:key="employment.id"
class="border border-light_gray rounded-md"
>
<div class="flex justify-between items-center px-4 py-2 bg-more_lighter_gray hover:bg-bg rounded-t-md">
<button :id="'employment-section-button-' + employment.id" @click="toggleSection(employment.id)" :aria-expanded="isOpen(employment.id)" :aria-controls="'employment-section-content-' + employment.id" class="flex items-center space-x-2 focus:outline-none">
<span class="text-dark_gray">{{ employment.company || 'New Employment Record' }}</span>
<svg :class="{'transform rotate-180': isOpen(employment.id)}" class="w-5 h-5 transition-transform duration-200" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path>
</svg>
</button>
<button @click="confirmRemoveEmployment(employment.id)" class="bg-warn hover:bg-warn_hover text-white px-2 py-1 rounded-md">
Delete
</button>
</div>
<transition name="accordion">
<div v-show="isOpen(employment.id)" class="p-4 space-y-4" :id="'employment-section-content-' + employment.id" role="region" :aria-labelledby="'employment-section-button-' + employment.id">
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label class="block text-dark_gray">Company</label>
<input v-model="employment.company" placeholder="Company" class="w-full px-3 py-2 border-light_gray rounded-md focus:outline-none focus:ring-2 focus:ring-primary">
</div>
<div>
<label class="block text-dark_gray">Country</label>
<select v-model="employment.country" @change="employment.selectedCity = ''" class="w-full px-3 py-2 border-light_gray rounded-md focus:outline-none focus:ring-2 focus:ring-primary">
<option value="">Select Country</option>
<option v-for="country in optionCountry" :key="country.value" :value="country.value">{{ country.label }}</option>
</select>
</div>
<!-- Add other fields similarly -->
</div>
</div>
</transition>
</div>
</div>
<!-- Buttons for adding records -->
<div class="flex justify-center items-center mt-6 space-x-4">
<button @click="addEmployment" class="bg-primary hover:bg-primary_hover text-white px-4 py-2 rounded-md">
Add Employment Record
</button>
<button @click="saveRequest" :disabled="isSaving" class="bg-secondary hover:bg-secondary_hover text-white px-4 py-2 rounded-md">
<span v-if="!isSaving">Save Request</span>
<span v-else>Saving...</span>
</button>
</div>
</div>
<div v-else class="flex justify-center items-center h-full">
<p class="text-dark_gray">Loading...</p>
</div>
</div>
</template>
<script setup>
import { createDocumentResource, ErrorMessage } from 'frappe-ui'
import { ref, watch, reactive, nextTick, computed } from 'vue'
import { location } from '../data/useAddressLogic'
// Initialize states
const request = createDocumentResource({
doctype: 'Verification Instructions Request',
name: 'VIR-2024-26-09-000007',
})
const optionCountry = computed(() => {
return location.data.filter(loc => loc.location_type === 'Country').map(loc => ({ label: loc.location_name, value: loc.location_name }))
})
const openSections = reactive({})
// Functionality for toggling and managing sections
const toggleSection = (id) => {
openSections[id] = !openSections[id]
}
const isOpen = (id) => {
return openSections[id]
}
const errors = ref([])
const addEmployment = () => {
const newEmployment = {
company: '',
country: '',
// Initialize other fields similarly
}
request.doc.employment_history.push(newEmployment)
nextTick(() => {
openSections[newEmployment.id] = true
})
}
const confirmRemoveEmployment = (id) => {
if (confirm('Are you sure you want to delete this employment record?')) {
removeEmployment(id)
}
}
const removeEmployment = (id) => {
const index = request.doc.employment_history.findIndex(emp => emp.id === id)
if (index !== -1) {
request.doc.employment_history.splice(index, 1)
delete openSections[id]
}
}
const isSaving = ref(false)
const saveRequest = async () => {
errors.value = [] // Reset errors
// Validate input
if (errors.value.length > 0) {
return
}
isSaving.value = true
try {
await request.setValue.submit({
employment_history: request.doc.employment_history,
})
} catch (error) {
errors.value.push(`An error occurred while saving the request: ${error.message}`)
} finally {
isSaving.value = false
}
}
</script>
<style scoped>
.accordion-enter-active, .accordion-leave-active {
transition: max-height 0.3s ease;
}
.accordion-enter-from, .accordion-leave-to {
max-height: 0;
overflow: hidden;
}
</style>
الشروحات:
- التفاعل مع البيانات: يعتمد على تعريف كائن
request لإدارة البيانات الخاصة بالدوك تايب والجدول الفرعي لسجل التوظيف.
- UI: تصميم الواجهة باستخدام Tailwind CSS.
- رفع الخاصة بسجل التوظيف: يمكنك استخدام نفس المنطق لإدارة السجل الوظيفي مثل قسم المعلومات التعليمية.
- إضافة الوظائف: لتفعيل زر إضافة السجل واحتمالات الحذف بالإضافة إلى الحفظ والوصول إلى البيانات.
يمكنك تخصيص هذه القالب ليتناسب مع احتياجاتك الخاصة ويوفر تجربة مستخدم متكاملة. لا تتردد في طرح أي استفسارات لتمديد التعديلات وصف ما تحتاجه!