Advertisement
Guest User

Untitled

a guest
Dec 29th, 2021
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.     <div class="px-6">
  3.         <p class="text-lg text-hr-secondary font-medium">
  4.             {{ index + 1 }}. {{ question.name }}
  5.             <span v-if="question.required" class="text-red-500">*</span>
  6.             {{ questionValue }}
  7.         </p>
  8.         <div v-if="question.type === 'stars'">
  9.             <div class="mt-8">
  10.                 <div class="flex justify-center mx-10">
  11.                     <star-rating
  12.                         :rounded-corners="true"
  13.                         :show-rating="false"
  14.                         @rating-selected="setRating"
  15.                         :star-size="35"
  16.                         active-color="#55E5BD"
  17.                         :padding="5"
  18.                     />
  19.                 </div>
  20.                 <div class="flex justify-between">
  21.                     <p>Poco</p>
  22.                     <p>Mucho</p>
  23.                 </div>
  24.             </div>
  25.         </div>
  26.         <div v-else-if="question.type === 'text'">
  27.             <textarea
  28.                 v-model="questionValue"
  29.                 rows="5"
  30.                 class="w-full mt-8 form-textarea rounded-xl bg-gray-200"
  31.                 placeholder="Escribe tu respuesta"
  32.             ></textarea>            
  33.         </div>
  34.         <div v-else-if="question.type === 'radio'">
  35.             <div class="mt-8">
  36.                 <BaseRadioInput
  37.                     :options="question.options"
  38.                     @input="radioInputOption"
  39.                 />
  40.             </div>
  41.         </div>
  42.         <div v-else-if="question.type === 'check'">
  43.             <BaseCheckBox
  44.                 class="space-y-6 mt-8"
  45.                 :options="question.options"
  46.                 @input="multipleInputOptions"
  47.             />
  48.         </div>
  49.         <div v-else-if="question.type === 'range'">
  50.             <Slider :max="parseInt(question.options[0].option, 10)" @input="rangeInput" />
  51.         </div>
  52.         <div v-else-if="question.type === 'faces'" class="flex justify-evenly">
  53.             <div v-for="(face, index) in feedback" :key="index" class="mt-10">
  54.                 <div class="bg-gray-200 p-2 rounded-xl" v-tap @tap="selectFace(face.label)" :class="[questionValue === face.label && 'bg-primary-300']">
  55.                     <Icon :name="face.icon" class="w-6 h-6" />
  56.                 </div>
  57.             </div>
  58.         </div>
  59.     </div>
  60. </template>
  61.  
  62. <script>
  63. import StarRating from 'vue-star-rating';
  64. import Slider from "@/components/custom/slider";
  65. import BaseCheckBox from "@/components/base/checkbox";
  66. import BaseRadioInput from "@/components/base/radio-input";
  67.  
  68.     const feedback = [
  69.         {
  70.             label: 'awful',
  71.             icon: 'awful-smile'
  72.         },
  73.         {
  74.             label: 'bad',
  75.             icon: 'bad-smile'
  76.         },
  77.         {
  78.             label: 'normal',
  79.             icon: 'normal-smile'
  80.         },
  81.         {
  82.             label: 'fine',
  83.             icon: 'fine-smile'
  84.         },
  85.         {
  86.             label: 'perfect',
  87.             icon: 'perfect-smile'
  88.         }
  89.     ]
  90.  
  91. export default {
  92.     name: "QuestionItem",
  93.     props: {
  94.        
  95.         question: Object,
  96.         index: Number
  97.     },
  98.     components: {
  99.         StarRating,
  100.         Slider,
  101.         BaseCheckBox,
  102.         BaseRadioInput
  103.     },
  104.     data() {
  105.         return {
  106.             feedback,
  107.             rating: 0,
  108.             questionValue: null,
  109.             localAnswers: [],
  110.         }
  111.     },
  112.     watch: {
  113.         questionValue(newValue) {
  114.             this.$emit('input', newValue)
  115.         },
  116.     },
  117.     methods: {
  118.         setRating(rating) {
  119.             this.questionValue = rating;
  120.         },
  121.         selectFace(face) {
  122.             this.questionValue = face;
  123.         },
  124.         multipleInputOptions(options) {
  125.             this.questionValue = options;
  126.         },
  127.         radioInputOption(id) {
  128.             this.questionValue = id;
  129.         },
  130.         rangeInput(number) {
  131.             this.questionValue = number;
  132.         }
  133.     },
  134. }
  135. </script>
  136.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement