All files / src/components/vote VoteForm.vue

0% Statements 0/57
0% Branches 0/32
0% Functions 0/26
0% Lines 0/57

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148                                                                                                                                                                                                                                                                                                       
<template>
 
  <v-form ref="vot" @submit="voteSend">
    <v-card id="scroll-window-chekbox" :height="heightel" elevation="0">
      <!-- Форма голосования -->
 
      <v-virtual-scroll :items="persons">
        <template v-slot:default="{ item }">
          <v-checkbox :id="item.fio" v-model="vote" :label="item.fio" :value="item.fio" hide-details="true" required/>
        </template>
      </v-virtual-scroll>
    </v-card>
 
    <v-dialog v-model="dialog" max-width="500">
      <!-- <template v-slot:activator>
      </template> -->
      <template v-slot:default>
        <v-card class="justify-center align-center">
          <v-card-title>Вы подтверждаете выбор?</v-card-title>
          <v-card-text>После подтверждения внесение измений станет невозможным.</v-card-text>
          <p>Выбранный кандидат</p>
          <v-card-title v-if="approve_name">{{ approve_name }}</v-card-title>
          <v-card-title v-else>Кандидат не выбран повторите голосование</v-card-title>
          <v-col class="d-flex flex-rows justify-center align-center" cols="12">
            <v-col cols="2">
              <v-btn v-if="approve_name" color="green-darken-1" variant="elevated"
                     @click="voteSend">ДА
              </v-btn>
              <v-btn v-else color="green-darken-1" disabled variant="elevated"
                     @click="voteSend">ДА
              </v-btn>
            </v-col>
            <v-col cols="2">
              <v-btn color="red-darken-1" variant="elevated"
                     @click="dialog = false">НЕТ
              </v-btn>
            </v-col>
          </v-col>
        </v-card>
      </template>
    </v-dialog>
  </v-form>
 
 
</template>
<script scope>
import {computed, ref} from "vue";
import {axiosApiInstance} from "@/utils/axios-api";
import {useAccountStore} from '@/store/AccountStore';
 
export default {
 
  props: {
    type_fetch: {type: String, default: 'best'},
    persons: {
      type: Array,
      default: () => []
    },
    myrealdep: {
      type: Object,
      default: () => {
      }
    }
  },
  setup(props, {emit}) {
    let account_login = useAccountStore();
    // let department_id = useAccountStore().user.id_dict_department;
    // let department_name = useAccountStore().user.department
    // let type_fetch = props.type_fetch;
    const dialog = ref(false)
    let vote = ref();
    // let get_address = ref();
    let send_address = ref();
    // let vote_data = ref([]);
    let approve_name = ref();
    let aproveFalseMessage = ref();
 
    if (props.type_fetch == "thanks") {
 
      send_address = `api/vote/setthanks/`;
    } else if (props.type_fetch == "best") {

      send_address = `api/vote/setbest/`;
    }
 
    // const getVotesData = () => {
    //     clearAxios.get(get_address).then((data) => {
    //         vote_data.value = data.data;
    //     });
    // };
 
 
    const approveCandidate = () => {
      if (vote.value === 'False' || vote.value === '') {
        approve_name.value = false;
 
      } else {
        approve_name.value = vote.value;
 
      }
 
      dialog.value = true
    }
 
    const voteSend = () => {
      console.log(vote.value);
      axiosApiInstance.post(send_address, {
          cand_name_id: vote.value,
          // department_user: props.myrealdep.department,

        },
        {
          headers: {
            'Content-Type': 'application/json'
          }
        }
      ).then(res => {
        dialog.value = false
        window.location.reload()
      });
    };

 
    // getVotesData();
    const vot = ref(null)
    const heightel = computed(() => !!vot.value ? vot.value.clientHeight : 300)
    return {
      vot,
      heightel,
      approveCandidate,
      voteSend,
      // vote_data,
      vote,
      approve_name,
      aproveFalseMessage,
      dialog
    }
  },
 
 
}
</script>
<style>
#scroll-window-chekbox {
  overflow-y: scroll !important;
}
</style>