Centers.vue 36.9 KB
Newer Older
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1 2 3 4 5 6 7
<template>
  <div style="padding: 8px">
    <div
      v-if="init"
    >
      <v-data-table
        :headers="headers"
8 9 10 11 12 13 14 15
        :items="centers"
        :loading="loadingCentersData"
        :footer-props="{
          'disable-items-per-page': true,
          'items-per-page-text': 'Centros por página'
        }"
        sort-by="name"
        :server-items-length="totalCentersItems"
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
16
        class="elevation-1"
17 18
        loading-text="Cargando Centros..."
        @pagination="paginateCenters"
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
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
      >
        <template v-slot:top>
          <v-toolbar
            flat
          >
            <v-toolbar-title>Centros de aislamiento</v-toolbar-title>
            <v-divider
              class="mx-4"
              inset
              vertical
            />
            <v-spacer />
            <v-dialog
              v-model="dialog"
              max-width="500px"
            >
              <template v-slot:activator="{ on, attrs }">
                <v-btn
                  color="success"
                  dark
                  class="mb-2"
                  v-bind="attrs"
                  v-on="on"
                >
                  <v-icon>mdi-plus</v-icon>Añadir Centro
                </v-btn>
              </template>
              <v-card>
                <v-card-title class="fix-title">
                  <span class="text-h5">{{ formTitle }}</span>
                </v-card-title>

                <v-card-text>
                  <v-container>
                    <v-row>
                      <v-col
                        cols="12"
                        sm="6"
                        md="4"
                      >
                        <v-text-field
60
                          v-model="editedItem.nombre_centro"
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
61 62
                          label="Nombre"
                        />
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
63
                      </v-col>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
64
                      <v-col
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
65 66 67 68 69 70 71 72 73 74 75 76 77
                        cols="12"
                        sm="6"
                        md="4"
                      >
                        <v-autocomplete
                          v-model="editedItem.provincia"
                          :items="provinces"
                          color="white"
                          item-text="nombre"
                          label="Provincia"
                          item-value="id"
                          @change="loadMunicipalitiesData(editedItem.provincia)"
                        />
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
78 79 80 81 82 83 84
                      </v-col>
                      <v-col
                        cols="12"
                        sm="6"
                        md="4"
                      >
                        <v-autocomplete
85
                          v-model="editedItem.municipio"
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
86
                          :items="municipalities"
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
87
                          item-value="nombre"
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
88
                          color="white"
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
89
                          item-text="nombre"
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
90 91 92 93 94 95 96 97 98
                          label="Municipio"
                        />
                      </v-col>
                      <v-col
                        cols="12"
                        sm="6"
                        md="4"
                      >
                        <v-text-field
99
                          v-model="editedItem.organismo"
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
                          label="Organismo"
                        />
                      </v-col>
                    </v-row>
                  </v-container>
                </v-card-text>

                <v-card-actions>
                  <v-spacer />
                  <v-btn
                    color="blue darken-1"
                    text
                    @click="close"
                  >
                    Cancelar
                  </v-btn>
                  <v-btn
                    color="blue darken-1"
                    text
                    @click="save"
                  >
                    Guardar
                  </v-btn>
                </v-card-actions>
              </v-card>
            </v-dialog>
            <v-dialog
              v-model="dialogDelete"
              max-width="500px"
            >
              <v-card>
                <v-card-title
                  class="text-h5"
                  style="word-break: normal"
                >
                  ¿Está seguro que desea eliminar el elemento?
                </v-card-title>
                <v-card-actions>
                  <v-spacer />
                  <v-btn
                    color="blue darken-1"
                    text
                    @click="closeDelete"
                  >
                    Cancel
                  </v-btn>
                  <v-btn
                    color="blue darken-1"
                    text
                    @click="deleteItemConfirm"
                  >
                    OK
                  </v-btn>
                  <v-spacer />
                </v-card-actions>
              </v-card>
            </v-dialog>
            <v-dialog
              v-model="dialogDeleteUnavailable"
              max-width="500px"
            >
              <v-card>
                <v-card-title class="text-h5">
                  Este Centro no se puede eliminar porque tiene camas en uso!!!!
                </v-card-title>
                <v-card-actions>
                  <v-spacer />
                  <v-btn
                    color="blue darken-1"
                    text
                    @click="closeDeleteU"
                  >
                    OK
                  </v-btn>
                  <v-spacer />
                </v-card-actions>
              </v-card>
            </v-dialog>
          </v-toolbar>
        </template>
        <template v-slot:item.actions="{ item }">
          <v-tooltip bottom>
            <template v-slot:activator="{ on, attrs }">
              <v-icon
                class="mr-2"
                color="orange"
                v-bind="attrs"
                v-on="on"
                @click="editItem(item)"
              >
                mdi-pencil
              </v-icon>
            </template>
            <span>Editar</span>
          </v-tooltip>
          <v-tooltip bottom>
            <template v-slot:activator="{ on, attrs }">
              <v-icon
                class="mr-2"
                color="error"
                v-bind="attrs"
                v-on="on"
                @click="deleteItem(item)"
              >
                mdi-delete
              </v-icon>
            </template>
            <span>Eliminar</span>
          </v-tooltip>
          <v-tooltip bottom>
            <template v-slot:activator="{ on, attrs }">
              <v-icon
                color="info"
                v-bind="attrs"
                v-on="on"
                @click="detailsItem(item)"
              >
                mdi-dots-horizontal-circle
              </v-icon>
            </template>
            <span>Detalles</span>
          </v-tooltip>
        </template>
        <template v-slot:no-data>
          <v-btn
            color="primary"
            @click="initialize"
          >
            Reset
          </v-btn>
        </template>
      </v-data-table>
    </div>
    <div
      v-else-if="area"
    >
      <v-card>
        <v-btn
          style="margin: 12px"
          @click="init= true"
        >
          <v-icon>
            mdi-arrow-left
          </v-icon> Atras
        </v-btn>
        <v-card-title>
          <v-icon
            large
          >
            mdi-hospital-building
          </v-icon>
          <v-card-title class="text-h5">
252
            {{ editedItem.nombre_centro }} / {{ editedItem.organismo }}
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
253 254
          </v-card-title>
        </v-card-title>
255
        <v-card-subtitle>{{ editedItem.municipio }}</v-card-subtitle>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
256 257 258 259 260 261 262 263 264 265
        <v-card-text>
          <info-box
            :stats="myStats"
            :more="false"
          />
          <v-data-table
            v-if="area"
            style="margin: 8px"
            :headers="areaHeaders"
            :items="areas"
266 267 268 269 270 271 272
            :loading="loadingAreasData"
            :footer-props="{
              'disable-items-per-page': true,
              'items-per-page-text': 'Areas por página'
            }"
            sort-by="nombre"
            :server-items-length="totalAreasItems"
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
273
            class="elevation-1"
274 275
            loading-text="Cargando Areas..."
            @pagination="paginateAreas"
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
          >
            <template v-slot:top>
              <v-toolbar
                flat
              >
                <v-toolbar-title>Areas</v-toolbar-title>
                <v-divider
                  class="mx-4"
                  inset
                  vertical
                />
                <v-spacer />
                <v-dialog
                  v-model="areaDialog"
                  max-width="500px"
                >
                  <template v-slot:activator="{ on, attrs }">
                    <v-btn
                      color="success"
                      dark
                      class="mb-2"
                      v-bind="attrs"
                      v-on="on"
                    >
                      <v-icon>mdi-plus</v-icon>Añadir Area
                    </v-btn>
                  </template>
                  <v-card>
                    <v-card-title class="fix-title">
                      <span class="text-h5">{{ areaFormTitle }}</span>
                    </v-card-title>

                    <v-card-text>
                      <v-container>
                        <v-row>
                          <v-col
                            cols="12"
                            sm="6"
                            md="4"
                          >
                            <v-text-field
317
                              v-model="editedAreaItem.nombre"
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
318 319 320 321 322 323 324 325 326
                              label="Nombre"
                            />
                          </v-col>
                          <v-col
                            cols="12"
                            sm="6"
                            md="4"
                          >
                            <v-autocomplete
327
                              v-model="editedAreaItem.categoria"
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
                              :items="categories"
                              color="white"
                              item-text="name"
                              label="Categoria"
                            />
                          </v-col>
                        </v-row>
                      </v-container>
                    </v-card-text>

                    <v-card-actions>
                      <v-spacer />
                      <v-btn
                        color="blue darken-1"
                        text
                        @click="closeArea"
                      >
                        Cancelar
                      </v-btn>
                      <v-btn
                        color="blue darken-1"
                        text
                        @click="saveArea"
                      >
                        Guardar
                      </v-btn>
                    </v-card-actions>
                  </v-card>
                </v-dialog>
                <v-dialog
                  v-model="dialogAreaDelete"
                  max-width="500px"
                >
                  <v-card>
                    <v-card-title
                      class="text-h5"
                      style="word-break: normal"
                    >
                      ¿Está seguro que desea eliminar el elemento?
                    </v-card-title>
                    <v-card-actions>
                      <v-spacer />
                      <v-btn
                        color="blue darken-1"
                        text
                        @click="closeAreaDelete"
                      >
                        Cancel
                      </v-btn>
                      <v-btn
                        color="blue darken-1"
                        text
                        @click="deleteAreaItemConfirm"
                      >
                        OK
                      </v-btn>
                      <v-spacer />
                    </v-card-actions>
                  </v-card>
                </v-dialog>
                <v-dialog
                  v-model="dialogAreaDeleteUnavailable"
                  max-width="500px"
                >
                  <v-card>
                    <v-card-title class="text-h5">
                      Esta Area no se puede eliminar porque tiene camas en uso!!!!
                    </v-card-title>
                    <v-card-actions>
                      <v-spacer />
                      <v-btn
                        color="blue darken-1"
                        text
                        @click="closeAreaDeleteU"
                      >
                        OK
                      </v-btn>
                      <v-spacer />
                    </v-card-actions>
                  </v-card>
                </v-dialog>
              </v-toolbar>
            </template>
            <template v-slot:item.actions="{ item }">
              <v-tooltip bottom>
                <template v-slot:activator="{ on, attrs }">
                  <v-icon
                    class="mr-2"
                    color="orange"
                    v-bind="attrs"
                    v-on="on"
                    @click="editAreaItem(item)"
                  >
                    mdi-pencil
                  </v-icon>
                </template>
                <span>Editar</span>
              </v-tooltip>
              <v-tooltip bottom>
                <template v-slot:activator="{ on, attrs }">
                  <v-icon
                    class="mr-2"
                    color="error"
                    v-bind="attrs"
                    v-on="on"
                    @click="deleteAreaItem(item)"
                  >
                    mdi-delete
                  </v-icon>
                </template>
                <span>Eliminar</span>
              </v-tooltip>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
440
              <!-- <v-tooltip bottom>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
441 442 443 444 445 446 447 448 449 450 451
                <template v-slot:activator="{ on, attrs }">
                  <v-icon
                    color="info"
                    v-bind="attrs"
                    v-on="on"
                    @click="detailsAreaItem(item)"
                  >
                    mdi-dots-horizontal-circle
                  </v-icon>
                </template>
                <span>Detalles</span>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
452
              </v-tooltip> -->
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
            </template>
            <template v-slot:no-data>
              <v-btn
                color="primary"
                @click="initialize"
              >
                Reset
              </v-btn>
            </template>
          </v-data-table>
        </v-card-text>
      </v-card>
    </div>
    <div
      v-else-if="room"
    >
      <v-card>
        <v-btn
          style="margin: 12px"
          @click="area = true"
        >
          <v-icon>
            mdi-arrow-left
          </v-icon> Atras
        </v-btn>
        <v-card-title>
          <v-icon
            large
          >
            mdi-hospital-building
          </v-icon>
          <v-card-title class="text-h5">
485
            {{ editedItem.nombre_centro }} / {{ editedItem.organismo }}
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
486 487
          </v-card-title>
        </v-card-title>
488
        <v-card-subtitle>{{ editedItem.municipio }}</v-card-subtitle>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
489 490 491 492 493
        <v-card-text>
          <v-card>
            <v-card-title>
              <v-icon>
                mdi-domain
494
              </v-icon>{{ editedAreaItem.nombre }}
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
495
            </v-card-title>
496
            <v-card-subtitle>{{ editedAreaItem.categoria }}</v-card-subtitle>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
            <info-box
              style="margin: 4px"
              :stats="myAreaStats"
              :more="false"
            />
            <v-data-table
              v-if="room"
              style="margin: 14px"
              :headers="roomsHeaders"
              :items="rooms"
              sort-by="calories"
              class="elevation-1"
            >
              <template v-slot:top>
                <v-toolbar
                  flat
                >
                  <v-toolbar-title>Habitaciones</v-toolbar-title>
                  <v-divider
                    class="mx-4"
                    inset
                    vertical
                  />
                  <v-spacer />
                  <v-dialog
                    v-model="roomsDialog"
                    max-width="500px"
                  >
                    <template v-slot:activator="{ on, attrs }">
                      <v-btn
                        color="success"
                        dark
                        class="mb-2"
                        v-bind="attrs"
                        v-on="on"
                      >
                        <v-icon>mdi-plus</v-icon>Añadir Habitación
                      </v-btn>
                    </template>
                    <v-card>
                      <v-card-title class="fix-title">
                        <span class="text-h5">{{ roomsFormTitle }}</span>
                      </v-card-title>

                      <v-card-text>
                        <v-container>
                          <v-row>
                            <v-col
                              cols="12"
                              sm="6"
                              md="4"
                            >
                              <v-text-field
                                v-model="editedRoomItem.number"
                                label="Numero"
                              />
                            </v-col>
                            <v-col
                              cols="12"
                              sm="6"
                              md="4"
                            >
                              <v-text-field
                                v-model="editedRoomItem.capacity"
                                label="Capacidad"
                                type="number"
                              />
                            </v-col>
                          </v-row>
                        </v-container>
                      </v-card-text>

                      <v-card-actions>
                        <v-spacer />
                        <v-btn
                          color="blue darken-1"
                          text
                          @click="closeRoom"
                        >
                          Cancelar
                        </v-btn>
                        <v-btn
                          color="blue darken-1"
                          text
                          @click="saveRoom"
                        >
                          Guardar
                        </v-btn>
                      </v-card-actions>
                    </v-card>
                  </v-dialog>
                  <v-dialog
                    v-model="dialogRoomDelete"
                    max-width="500px"
                  >
                    <v-card>
                      <v-card-title
                        class="text-h5"
                        style="word-break: normal"
                      >
                        ¿Está seguro que desea eliminar el elemento?
                      </v-card-title>
                      <v-card-actions>
                        <v-spacer />
                        <v-btn
                          color="blue darken-1"
                          text
                          @click="closeRoomDelete"
                        >
                          Cancel
                        </v-btn>
                        <v-btn
                          color="blue darken-1"
                          text
                          @click="deleteRoomItemConfirm"
                        >
                          OK
                        </v-btn>
                        <v-spacer />
                      </v-card-actions>
                    </v-card>
                  </v-dialog>
                  <v-dialog
                    v-model="dialogRoomDeleteUnavailable"
                    max-width="500px"
                  >
                    <v-card>
                      <v-card-title class="text-h5">
                        Esta Habitacion no se puede eliminar porque tiene camas en uso!!!!
                      </v-card-title>
                      <v-card-actions>
                        <v-spacer />
                        <v-btn
                          color="blue darken-1"
                          text
                          @click="closeRoomDeleteU"
                        >
                          OK
                        </v-btn>
                        <v-spacer />
                      </v-card-actions>
                    </v-card>
                  </v-dialog>
                </v-toolbar>
              </template>
              <template v-slot:item.actions="{ item }">
                <v-tooltip bottom>
                  <template v-slot:activator="{ on, attrs }">
                    <v-icon
                      class="mr-2"
                      color="orange"
                      v-bind="attrs"
                      v-on="on"
                      @click="editRoomItem(item)"
                    >
                      mdi-pencil
                    </v-icon>
                  </template>
                  <span>Editar</span>
                </v-tooltip>
                <v-tooltip bottom>
                  <template v-slot:activator="{ on, attrs }">
                    <v-icon
                      class="mr-2"
                      color="error"
                      v-bind="attrs"
                      v-on="on"
                      @click="deleteRoomItem(item)"
                    >
                      mdi-delete
                    </v-icon>
                  </template>
                  <span>Eliminar</span>
                </v-tooltip>
              </template>
              <template v-slot:no-data>
                <v-btn
                  color="primary"
                  @click="initialize"
                >
                  Reset
                </v-btn>
              </template>
            </v-data-table>
          </v-card>
        </v-card-text>
      </v-card>
    </div>
  </div>
</template>

<script>
689 690 691
  import InfoBox from '@/components/InfoBox.vue'
  import { getCenters, getCenter, postCenter, putCenter, deleteCenter } from '@/axios/centers'
  import { getAreas, getArea, postArea, putArea, deleteArea } from '@/axios/areas'
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
692
  import { getMunicipalities, getProvinces } from '@/axios/nomenclators'
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
693 694 695
  export default {
    components: { InfoBox },
    data: () => ({
696 697 698 699 700 701 702 703 704 705 706 707
      centersFilters: {
        page: 1,
      },
      areasFilters: {
        page: 1,
      },
      centersFirstLoad: true,
      areasFirstLoadL: true,
      loadingAreasData: true,
      loadingCentersData: true,
      totalCentersItems: 0,
      totalAreasItems: 0,
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789
      myStats: [
        {
          bgColor: 'success  ligthen-1',
          iconClass: 'blue lighten-3 white--text',
          icon: 'mdi-bunk-bed-outline',
          title: 'Camas Totales',
          data: '450',
          action: {
            label: 'more',
            link: '',
          },
        },
        {
          bgColor: 'success  ligthen-1',
          iconClass: 'blue lighten-3 white--text',
          icon: 'mdi-bed',
          title: 'Camas Usadas',
          data: '200',
          action: {
            label: 'more',
            link: '',
          },
        },
        {
          bgColor: 'success  ligthen-1',
          iconClass: 'blue lighten-3 white--text',
          icon: 'mdi-bed-empty',
          title: 'Camas Disponibles',
          data: '250',
          action: {
            label: 'more',
            link: '',
          },
        },
      ],
      myAreaStats: [
        {
          bgColor: 'success  ligthen-1',
          iconClass: 'blue lighten-3 white--text',
          icon: 'mdi-bunk-bed-outline',
          title: 'Camas Totales',
          data: '200',
          action: {
            label: 'more',
            link: '',
          },
        },
        {
          bgColor: 'success  ligthen-1',
          iconClass: 'blue lighten-3 white--text',
          icon: 'mdi-bed',
          title: 'Camas Usadas',
          data: '150',
          action: {
            label: 'more',
            link: '',
          },
        },
        {
          bgColor: 'success  ligthen-1',
          iconClass: 'blue lighten-3 white--text',
          icon: 'mdi-bed-empty',
          title: 'Camas Disponibles',
          data: '50',
          action: {
            label: 'more',
            link: '',
          },
        },
      ],
      area: false,
      init: true,
      room: false,
      dialogDeleteUnavailable: false,
      dialogAreaDeleteUnavailable: false,
      dialogRoomDeleteUnavailable: false,
      dialog: false,
      areaDialog: false,
      roomsDialog: false,
      dialogDelete: false,
      dialogAreaDelete: false,
      dialogRoomDelete: false,
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
790 791
      provinces: [],
      municipalities: [],
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
792 793 794 795 796 797 798 799 800 801
      categories: [
        { name: 'Sospechoso', id: 1 },
        { name: 'Positivo', id: 2 },
        { name: 'Contacto', id: 3 },
      ],
      headers: [
        {
          text: 'Nombre',
          align: 'start',
          sortable: true,
802
          value: 'nombre_centro',
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
803
        },
804 805
        { text: 'Municipio', value: 'municipio' },
        { text: 'Organismo', value: 'organismo' },
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
806 807 808 809 810 811 812
        { text: 'Acciones', value: 'actions', sortable: false },
      ],
      areaHeaders: [
        {
          text: 'Nombre',
          align: 'start',
          sortable: true,
813
          value: 'nombre',
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
814
        },
815
        { text: 'Categoria', value: 'categoria' },
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
816 817 818 819 820 821 822 823 824 825 826 827
        { text: 'Acciones', value: 'actions', sortable: false },
      ],
      roomsHeaders: [
        {
          text: 'Numero',
          align: 'start',
          sortable: true,
          value: 'number',
        },
        { text: 'Capacidad', value: 'capacity' },
        { text: 'Acciones', value: 'actions', sortable: false },
      ],
828
      centers: [],
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
829 830 831 832 833 834
      areas: [],
      rooms: [],
      editedIndex: -1,
      editedAreaIndex: -1,
      editedRoomIndex: -1,
      editedItem: {
835
        nombre_centro: '',
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
836
        provincia: '',
837 838
        municipio: '',
        organismo: '',
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
839 840
        cap_total: 0,
        cap_disponible: 0,
841
        id: -1,
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
842 843
      },
      defaultItem: {
844
        nombre_centro: '',
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
845
        provincia: '',
846 847
        municipio: '',
        organismo: '',
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
848 849
        cap_total: 0,
        cap_disponible: 0,
850
        id: -1,
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
851 852
      },
      editedAreaItem: {
853 854
        nombre: '',
        categoria: '',
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
855 856 857 858
        capacity: 0,
        availability: 0,
      },
      defaultAreaItem: {
859 860
        nombre: '',
        categoria: '',
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903
        capacity: 0,
        availability: 0,
      },
      editedRoomItem: {
        number: '',
        capacity: 0,
      },
      defaultRoomItem: {
        number: '',
        capacity: 0,
      },
    }),
    computed: {
      formTitle () {
        return this.editedIndex === -1 ? 'Nuevo Centro' : 'Editar Centro'
      },
      areaFormTitle () {
        return this.editedAreaIndex === -1 ? 'Nueva Area' : 'Editar Area'
      },
      roomsFormTitle () {
        return this.editedRoomIndex === -1 ? 'Nueva Habitación' : 'Editar Habitación'
      },
    },
    watch: {
      dialog (val) {
        val || this.close()
      },
      dialogDelete (val) {
        val || this.closeDelete()
      },
      dialogArea (val) {
        val || this.closeArea()
      },
      dialogAreaDelete (val) {
        val || this.closeAreaDelete()
      },
      dialogRoom (val) {
        val || this.closeRoom()
      },
      dialogRoomDelete (val) {
        val || this.closeRoomDelete()
      },
    },
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
904
    created () {
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
905 906 907 908
      this.initialize()
      this.getProvincesData()
      this.loadMunicipalitiesData()
    },
909
    async mounted () {
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
910
      this.initialize()
911
      this.loadCentersData()
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
912 913
    },
    methods: {
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934
      async loadMunicipalitiesData (id) {
        try {
          const municipalitiesRes = await getMunicipalities(id)
          this.municipalities = municipalitiesRes.data
        } catch (e) {
          this.$toast.error(e.toString(), {
            position: 'bottom-center',
            timeout: 5000,
            closeOnClick: true,
            pauseOnFocusLoss: false,
            pauseOnHover: true,
            draggable: true,
            draggablePercent: 0.6,
            showCloseButtonOnHover: false,
            hideProgressBar: true,
            closeButton: 'button',
            icon: true,
            rtl: false,
          })
        }
      },
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
935
      async getProvincesData () {
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955
        try {
          const provincesResponse = await getProvinces()
          this.provinces = provincesResponse.data
        } catch (e) {
          this.$toast.error(e.toString(), {
            position: 'bottom-center',
            timeout: 5000,
            closeOnClick: true,
            pauseOnFocusLoss: false,
            pauseOnHover: true,
            draggable: true,
            draggablePercent: 0.6,
            showCloseButtonOnHover: false,
            hideProgressBar: true,
            closeButton: 'button',
            icon: true,
            rtl: false,
          })
        }
      },
956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977
      async loadCentersData (page = 1) {
        this.loadingCentersData = true
        try {
          const centersResponse = await getCenters(page)
          this.totalCentersItems = centersResponse.data.meta.total
          this.centers = centersResponse.data.centros
          this.loadingCentersData = false
        } catch (err) {
          console.log(err)
        }
      },
      async loadAreasData (page = 1) {
        this.loadingAreasData = true
        try {
          const areasResponse = await getAreas(this.editedItem.id_centro, page)
          this.totalAreasItems = areasResponse.data.meta.total
          this.areas = areasResponse.data.areas
          this.loadingAreasData = false
        } catch (err) {
          console.log(err)
        }
      },
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
978
      detailsItem (item) {
979
        this.editedIndex = this.centers.indexOf(item)
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
980
        this.editedItem = Object.assign({}, item)
981
        this.loadAreasData()
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
        this.init = false
        this.area = true
      },
      detailsAreaItem (item) {
        this.editedAreaIndex = this.areas.indexOf(item)
        this.editedAreaItem = Object.assign({}, item)
        this.area = false
        this.room = true
      },
      closeDeleteU () {
        this.dialogDeleteUnavailable = false
      },
      closeAreaDeleteU () {
        this.dialogAreaDeleteUnavailable = false
      },
      closeRoomDeleteU () {
        this.dialogRoomDeleteUnavailable = false
      },
      initialize () {
1001
        this.centers = [
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1002
          {
1003 1004 1005
            nombre_centro: 'EIA',
            municipio: 'Santa Clara',
            organismo: 'MINED',
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1006 1007 1008 1009 1010 1011 1012 1013
            cap_positivos: 100,
            cap_sospechosos: 67,
            cap_contactos: 67,
            dis_positivos: 80,
            dis_sospechosos: 25,
            dis_contactos: 50,
          },
          {
1014 1015 1016
            nombre_centro: 'UCLV',
            municipio: 'Santa Clara',
            organismo: 'MES',
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1017 1018 1019 1020 1021 1022 1023 1024
            cap_positivos: 100,
            cap_sospechosos: 67,
            cap_contactos: 67,
            dis_positivos: 80,
            dis_sospechosos: 25,
            dis_contactos: 50,
          },
          {
1025 1026 1027
            nombre_centro: 'Pedagogico',
            municipio: 'Santa Clara',
            organismo: 'MES',
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1028 1029 1030 1031 1032 1033 1034 1035
            cap_positivos: 100,
            cap_sospechosos: 67,
            cap_contactos: 67,
            dis_positivos: 80,
            dis_sospechosos: 25,
            dis_contactos: 50,
          },
          {
1036 1037 1038
            nombre_centro: 'Perez Quintosa',
            municipio: 'Santa Clara',
            organismo: 'MINED',
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
            cap_positivos: 100,
            cap_sospechosos: 67,
            cap_contactos: 67,
            dis_positivos: 80,
            dis_sospechosos: 25,
            dis_contactos: 50,
          },
        ]
        this.areas = [
          {
            name: '900-A',
            category: 'Sospechosos',
            capacity: 45,
            availability: 20,
          },
          {
            name: '900-B',
            category: 'Sospechosos',
            capacity: 45,
            availability: 15,
          },
          {
            name: '900-C',
            category: 'Sospechosos',
            capacity: 53,
            availability: 20,
          },
        ]
        this.rooms = [
          {
            number: 101,
            capacity: 20,
          },
          {
            number: 102,
            capacity: 25,
          },
        ]
      },
      editItem (item) {
1079
        this.editedIndex = this.centers.indexOf(item)
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093
        this.editedItem = Object.assign({}, item)
        this.dialog = true
      },
      editAreaItem (item) {
        this.editedAreaIndex = this.areas.indexOf(item)
        this.editedAreaItem = Object.assign({}, item)
        this.areaDialog = true
      },
      editRoomItem (item) {
        this.editedRoomIndex = this.rooms.indexOf(item)
        this.editedRoomItem = Object.assign({}, item)
        this.roomsDialog = true
      },
      deleteItem (item) {
1094
        this.editedIndex = this.centers.indexOf(item)
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111
        this.editedItem = Object.assign({}, item)
        if (this.editedItem.cap_disponible < this.editedItem.cap_total) {
          this.dialogDeleteUnavailable = true
        } else {
          this.dialogDelete = true
        }
      },
      deleteAreaItem (item) {
        this.editedAreaIndex = this.areas.indexOf(item)
        this.editedAreaItem = Object.assign({}, item)
        this.dialogAreaDelete = true
      },
      deleteRoomItem (item) {
        this.editedRoomIndex = this.rooms.indexOf(item)
        this.editedRoomItem = Object.assign({}, item)
        this.dialogRoomDelete = true
      },
1112 1113 1114 1115 1116 1117 1118 1119
      async deleteItemConfirm () {
        try {
          await deleteCenter(this.editedItem.id_centro)
          this.loadCentersData()
        } catch (err) {
          console.log(err)
        }
        this.centers.splice(this.editedIndex, 1)
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1120 1121
        this.closeDelete()
      },
1122 1123 1124 1125 1126 1127 1128
      async deleteAreaItemConfirm () {
        try {
          await deleteArea(this.editedAreaItem.id_area)
          this.loadAreasData()
        } catch (err) {
          console.log(err)
        }
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177
        this.areas.splice(this.editedAreaIndex, 1)
        this.closeAreaDelete()
      },
      deleteRoomItemConfirm () {
        this.rooms.splice(this.editedRoomIndex, 1)
        this.closeRoomDelete()
      },
      close () {
        this.dialog = false
        this.$nextTick(() => {
          this.editedItem = Object.assign({}, this.defaultItem)
          this.editedIndex = -1
        })
      },
      closeArea () {
        this.areaDialog = false
        this.$nextTick(() => {
          this.editedAreaItem = Object.assign({}, this.defaultAreaItem)
          this.editedAreaIndex = -1
        })
      },
      closeRoom () {
        this.roomsDialog = false
        this.$nextTick(() => {
          this.editedRoomItem = Object.assign({}, this.defaultRoomItem)
          this.editedRoomIndex = -1
        })
      },
      closeDelete () {
        this.dialogDelete = false
        this.$nextTick(() => {
          this.editedItem = Object.assign({}, this.defaultItem)
          this.editedIndex = -1
        })
      },
      closeAreaDelete () {
        this.dialogAreaDelete = false
        this.$nextTick(() => {
          this.editedAreaItem = Object.assign({}, this.defaultAreaItem)
          this.editedAreaIndex = -1
        })
      },
      closeRoomDelete () {
        this.dialogRoomDelete = false
        this.$nextTick(() => {
          this.editedRoomItem = Object.assign({}, this.defaultRoomItem)
          this.editedRoomIndex = -1
        })
      },
1178
      async save () {
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1179
        if (this.editedIndex > -1) {
1180 1181 1182 1183
          await putCenter(this.editedItem)
          this.loadCentersData()
          // TODO: DELETE THIS !!
          Object.assign(this.centers[this.editedIndex], this.editedItem)
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1184
        } else {
1185 1186 1187 1188
          await postCenter(this.editedItem)
          this.loadCentersData()
          // TODO: DELETE THIS !!
          this.centers.push(this.editedItem)
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1189 1190 1191
        }
        this.close()
      },
1192
      async saveArea () {
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1193
        if (this.editedAreaIndex > -1) {
1194 1195
          await putArea(this.editedAreaItem)
          this.loadAreasData()
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1196 1197
          Object.assign(this.areas[this.editedAreaIndex], this.editedAreaItem)
        } else {
1198 1199
          await postArea(this.editedItem.id_centro, this.editedAreaItem)
          this.loadAreasData()
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212
          this.areas.push(this.editedAreaItem)
        }
        this.closeArea()
      },
      saveRoom () {
        console.log(this.editedRoomItem)
        if (this.editedRoomIndex > -1) {
          Object.assign(this.rooms[this.editedRoomIndex], this.editedRoomItem)
        } else {
          this.rooms.push(this.editedRoomItem)
        }
        this.closeRoom()
      },
1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228
      paginateCenters (pageInfo) {
        if (this.centersFirstLoad) {
          this.centersFirstLoad = false
          return
        }
        this.centersFilters.page = pageInfo.page
        this.loadCentersData(pageInfo.page)
      },
      paginateAreas (pageInfo) {
        if (this.areasFirstLoad) {
          this.areasFirstLoad = false
          return
        }
        this.areasFilters.page = pageInfo.page
        this.loadAreasData(pageInfo.page)
      },
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1229 1230 1231 1232 1233 1234 1235 1236
    },
  }
</script>
<style scoped>
.fix-title {
    word-break: normal;
  }
</style>