Guest User

Untitled

a guest
Dec 29th, 2021
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.     <div class="bg-primary-600">
  3.         <HRLayout :isMenuVisible="false">
  4.             <template v-slot:header>
  5.                 <div class="flex justify-between py-6 px-4 items-center">  
  6.                     <GoToHome v-slot="{ navigate }">
  7.                         <button
  8.                             class="p-2 text-gray-700 bg-white rounded-xl"
  9.                             @click="navigate"
  10.                         >
  11.                             <Icon name="left" class="w-5 h-5" />
  12.                         </button>
  13.                     </GoToHome>
  14.                     <Avatar
  15.                         class="w-12 h-12 rounded-full text-lg font-medium bg-gray-400"
  16.                         :username="userFullName"
  17.                         :src="user.imageProfileURL"
  18.                     />
  19.                 </div>    
  20.             </template>
  21.             <template v-slot:content>
  22.                 <Loader v-if="loading" class="m-auto" />
  23.                 <div v-else class="w-full h-full rounded-t-xl">
  24.                     <div class="mx-3 h-full">
  25.                         <div class="pt-6 flex items-center justify-between">
  26.                             <div class="font-bold text-3xl text-hr-secondary">Evaluación</div>
  27.                             {{ answers }}
  28.                         </div>
  29.                         <div class="bg-white p-5 rounded-xl mt-5 shadow-lg">
  30.                             <p class="text-hr-secondary font-bold text-lg mb-2">{{ evaluation.title }}</p>
  31.                             <p class="text-hr-secondary text-md">{{ evaluation.description }}</p>
  32.                         </div>
  33.                         <div class="bg-white rounded-xl p-5 mt-8 shadow-lg overflow-hidden">
  34.                             <div
  35.                                 v-if="!finished"
  36.                                 class="flex transition-all duration-300"
  37.                                 :style="{ 'transform': `translateX(${-questionIndex * 100}%)` }"
  38.                             >
  39.                                 <QuestionItem
  40.                                     v-for="(question, index) in questions"
  41.                                     :key="index"
  42.                                     :question="question"
  43.                                     :index="questionIndex"
  44.                                     v-model="answers"
  45.                                     class="flex-none w-full"
  46.                                 />
  47.  
  48.                             </div>
  49.                             <div v-if="finished" class="p-8 text-center">
  50.                                 <p class="text-xl text-hr-secondary font-bold">Respuestas enviadas</p>
  51.                                 <p class="text-xl text-hr-secondary font-bold">Gracias!</p>
  52.                                 <GoToHome v-slot="{ navigate }">
  53.                                     <button
  54.                                         class="p-2 text-white bg-hr-secondary rounded-xl text-sm px-3 mt-4"
  55.                                         @click="closeEvaluation(navigate)"
  56.                                     >
  57.                                         Salir
  58.                                     </button>
  59.                                 </GoToHome>
  60.                             </div>
  61.                            
  62.                             <div class="flex justify-between mt-8">
  63.                                 <button
  64.                                     v-if="hasPrevQuestion && !finished"
  65.                                     class="border border-hr-secondary text-sm text-hr-secondary font-medium px-4 py-2 rounded-xl"
  66.                                     @click="prevQuestion"
  67.                                 >
  68.                                     Atrás
  69.                                 </button>
  70.                                 <button
  71.                                     v-if="hasNextQuestion && !finished"
  72.                                     class="border border-hr-secondary text-sm text-hr-secondary font-medium px-4 py-2 rounded-xl"
  73.                                     @click="nextQuestion"
  74.                                 >
  75.                                     Siguiente
  76.                                 </button>
  77.                                 <button
  78.                                     v-if="isLastQuestion && !finished"
  79.                                     v-tap @tap="sendAnswers"
  80.                                     class="bg-hr-secondary text-sm text-white font-medium px-4 py-2 rounded-xl"
  81.                                 >
  82.                                     Enviar
  83.                                 </button>
  84.                             </div>                  
  85.                         </div>
  86.                     </div>
  87.                     <ProgressBar v-if="!finished" class="mx-5" :totalQuestions="totalQuestions" :index="questionIndex" :progress="progress" />    
  88.                 </div>
  89.             </template>  
  90.         </HRLayout>  
  91.     </div>
  92. </template>
  93.  
  94. <script>
  95.     import HRLayout from '@/hr/layouts/main';
  96.     import Loader from '@/hr/components/loader';
  97.     import { getters } from "@/store";
  98.     import { Evaluation } from "@/api/models";
  99.     import { getFullName } from "@/utils/employees.js";
  100.     import GoToHome from '@/components/go-to-home';
  101.     import Avatar from "@/components/base/avatar";
  102.     import QuestionItem from "./QuestionItem"
  103.     import ProgressBar from './ProgressBar';
  104.  
  105.     export default {
  106.         name: 'Evaluation',
  107.         components: {
  108.             Loader,
  109.             GoToHome,
  110.             Avatar,
  111.             ProgressBar,
  112.             HRLayout,
  113.             QuestionItem
  114.         },
  115.         data() {
  116.             return {
  117.                 questionIndex: 0,
  118.                 evaluation: {},
  119.                 finished: false,
  120.                 loading: false,
  121.                 answers: [],
  122.             }
  123.         },
  124.         computed: {
  125.             user() {
  126.                 return getters.employee;
  127.             },
  128.             userFullName() {
  129.                 return getFullName(this.user);
  130.             },
  131.             questions() {
  132.                 return this.evaluation?.form?.questions;
  133.             },
  134.             activeQuestion() {
  135.                 return this.questions[this.questionIndex];
  136.             },
  137.             hasPrevQuestion() {
  138.                 return this.questionIndex > 0;
  139.             },
  140.             hasNextQuestion() {
  141.                  return this.questions !== undefined && this.questionIndex < this.questions.length - 1;
  142.             },
  143.             totalQuestions() {
  144.                 if(this.questions !== undefined) {
  145.                     return this.questions.length;
  146.                 }
  147.             },
  148.             isLastQuestion() {
  149.                 return (this.questionIndex + 1) === this.totalQuestions;
  150.             },
  151.             progress() {
  152.                 console.log("ANSWERS", this.answers)
  153.                 if(this.questions !== undefined) {
  154.                     return (this.questionIndex + 1) / this.questions.length * 100
  155.                 }
  156.             }
  157.         },
  158.         methods: {
  159.             async getEvaluations() {
  160.                 await Evaluation.all();
  161.                 //await Evaluation.create({employeeId: "95194a23-9e04-4487-af3f-52cf10002d27"});
  162.                 try {
  163.                     this.loading = true;
  164.                     const { evaluation } = await Evaluation.find(this.$route.params.id);
  165.                     this.evaluation = evaluation;
  166.                     this.loading = false;
  167.                 } catch (error) {
  168.                     console.log(error);
  169.                 }
  170.             },
  171.             async sendAnswers() {
  172.                 try {
  173.                      await Evaluation.create(
  174.                         {
  175.                             answers: [
  176.                                 {
  177.                                     questionId: "6a9ad778-aacf-4e60-9610-37a767700b9f",
  178.                                     questionOptionIds:[
  179.                                         "1bc35f6c-900a-4764-84ee-23531e46e638",
  180.                                     ],
  181.                                     answer: null
  182.                                 },
  183.                             ]
  184.                         }, {param: this.$route.params.id },);
  185.                 } catch (err) {
  186.                     console.log(err);
  187.                 }
  188.  
  189.                 this.finished = true;
  190.             },
  191.             prevQuestion() {
  192.                 if (this.hasPrevQuestion) {
  193.                     this.questionIndex--;
  194.                 } else {
  195.                     this.questionIndex = 0;
  196.                 }
  197.             },
  198.             nextQuestion() {
  199.                 if (this.hasNextQuestion) {
  200.                     this.questionIndex++;
  201.                 } else if (this.questions){
  202.                     this.questionIndex = this.questions.length - 1;
  203.                 }
  204.             },
  205.             closeEvaluation(callback) {
  206.                 callback();
  207.                 this.finished = false;
  208.                 this.questionIndex = 0;
  209.             }
  210.         },
  211.         mounted() {
  212.             this.getEvaluations();
  213.         }  
  214.     }
  215. </script>
  216.  
Advertisement
Add Comment
Please, Sign In to add comment