"src/views/sections/src/views/sections/Centers.vue" did not exist on "ccda68dc8c6a383ff8f9a4a041d2f2f4ee63baa5"
Centers.vue 38.5 KB
Newer Older
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1 2
<template>
  <div style="padding: 8px">
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
3
    <div v-if="init">
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
4 5
      <v-data-table
        :headers="headers"
6 7 8 9 10 11 12 13
        :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
14
        class="elevation-1"
15 16
        loading-text="Cargando Centros..."
        @pagination="paginateCenters"
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
17 18
      >
        <template v-slot:top>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
19
          <v-toolbar flat>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
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
            <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
56
                          v-model="editedItem.nombre_centro"
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
57 58
                          label="Nombre"
                        />
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
59
                      </v-col>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
60
                      <v-col
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
61 62 63 64 65 66 67 68 69 70 71 72 73
                        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
74 75 76 77 78 79 80
                      </v-col>
                      <v-col
                        cols="12"
                        sm="6"
                        md="4"
                      >
                        <v-autocomplete
81
                          v-model="editedItem.municipio"
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
82
                          :items="municipalities"
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
83
                          item-value="nombre"
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
84
                          color="white"
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
85
                          item-text="nombre"
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
86 87 88 89 90 91 92 93 94
                          label="Municipio"
                        />
                      </v-col>
                      <v-col
                        cols="12"
                        sm="6"
                        md="4"
                      >
                        <v-text-field
95
                          v-model="editedItem.organismo"
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
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 149 150 151 152 153 154 155 156 157
                          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>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
158 159 160
                <v-card-title
                  class="text-h5"
                >
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
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
                  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>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
231
    <div v-else-if="area">
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
232 233 234 235 236
      <v-card>
        <v-btn
          style="margin: 12px"
          @click="init= true"
        >
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
237
          <v-icon>mdi-arrow-left</v-icon>Atras
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
238 239
        </v-btn>
        <v-card-title>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
240
          <v-icon large>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
241 242 243
            mdi-hospital-building
          </v-icon>
          <v-card-title class="text-h5">
244
            {{ editedItem.nombre_centro }} / {{ editedItem.organismo }}
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
245 246
          </v-card-title>
        </v-card-title>
247
        <v-card-subtitle>{{ editedItem.municipio }}</v-card-subtitle>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
248 249 250 251 252 253 254 255 256 257
        <v-card-text>
          <info-box
            :stats="myStats"
            :more="false"
          />
          <v-data-table
            v-if="area"
            style="margin: 8px"
            :headers="areaHeaders"
            :items="areas"
258 259 260 261 262 263 264
            :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
265
            class="elevation-1"
266 267
            loading-text="Cargando Areas..."
            @pagination="paginateAreas"
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
268 269
          >
            <template v-slot:top>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
270
              <v-toolbar flat>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
271 272 273 274 275 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
                <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
307
                              v-model="editedAreaItem.nombre"
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
308 309 310 311 312 313 314 315 316
                              label="Nombre"
                            />
                          </v-col>
                          <v-col
                            cols="12"
                            sm="6"
                            md="4"
                          >
                            <v-autocomplete
317
                              v-model="editedAreaItem.categoria"
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
318 319 320 321 322 323 324 325 326 327 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
                              :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>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
383 384 385
                    <v-card-title
                      class="text-h5"
                    >
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
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
                      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
432
              <v-tooltip bottom>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
433 434 435 436 437 438 439 440 441 442 443
                <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
444
              </v-tooltip>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
445 446 447 448 449 450 451 452 453 454 455 456 457
            </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>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
458
    <div v-else-if="room">
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
459 460 461 462 463
      <v-card>
        <v-btn
          style="margin: 12px"
          @click="area = true"
        >
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
464
          <v-icon>mdi-arrow-left</v-icon>Atras
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
465 466
        </v-btn>
        <v-card-title>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
467
          <v-icon large>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
468 469 470
            mdi-hospital-building
          </v-icon>
          <v-card-title class="text-h5">
471
            {{ editedItem.nombre_centro }} / {{ editedItem.organismo }}
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
472 473
          </v-card-title>
        </v-card-title>
474
        <v-card-subtitle>{{ editedItem.municipio }}</v-card-subtitle>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
475 476 477
        <v-card-text>
          <v-card>
            <v-card-title>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
478 479
              <v-icon>mdi-domain</v-icon>
              {{ editedAreaItem.nombre }}
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
480
            </v-card-title>
481
            <v-card-subtitle>{{ editedAreaItem.categoria }}</v-card-subtitle>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
482 483 484 485 486 487 488 489 490 491 492 493 494 495
            <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>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
496
                <v-toolbar flat>
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
                  <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>
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
607 608 609
                      <v-card-title
                        class="text-h5"
                      >
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
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
                        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>
674
  import InfoBox from '@/components/InfoBox.vue'
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
  import {
    getCenters,
    postCenter,
    putCenter,
    deleteCenter,
  } from '@/axios/centers'
  import {
    getAreas,
    postArea,
    putArea,
    deleteArea,
  } from '@/axios/areas'
  import {
    getMunicipalities,
    getProvinces,
    getCategories,
  } from '@/axios/nomenclators'
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
692 693 694
  export default {
    components: { InfoBox },
    data: () => ({
695 696 697 698 699 700 701 702 703 704 705 706
      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
707 708
      myStats: [],
      myAreaStats: [],
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
709 710 711 712 713 714 715 716 717 718 719 720
      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
721 722
      provinces: [],
      municipalities: [],
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
723 724 725 726 727 728 729 730 731 732
      categories: [
        { name: 'Sospechoso', id: 1 },
        { name: 'Positivo', id: 2 },
        { name: 'Contacto', id: 3 },
      ],
      headers: [
        {
          text: 'Nombre',
          align: 'start',
          sortable: true,
733
          value: 'nombre_centro',
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
734
        },
735 736
        { text: 'Municipio', value: 'municipio' },
        { text: 'Organismo', value: 'organismo' },
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
737 738 739 740 741 742 743
        { text: 'Acciones', value: 'actions', sortable: false },
      ],
      areaHeaders: [
        {
          text: 'Nombre',
          align: 'start',
          sortable: true,
744
          value: 'nombre',
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
745
        },
746
        { text: 'Categoria', value: 'categoria' },
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
747 748 749 750 751 752 753 754 755 756 757 758
        { 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 },
      ],
759
      centers: [],
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
760 761 762 763 764 765
      areas: [],
      rooms: [],
      editedIndex: -1,
      editedAreaIndex: -1,
      editedRoomIndex: -1,
      editedItem: {
766
        nombre_centro: '',
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
767
        provincia: '',
768 769
        municipio: '',
        organismo: '',
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
770 771
        cap_total: 0,
        cap_disponible: 0,
772
        id: -1,
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
773 774
      },
      defaultItem: {
775
        nombre_centro: '',
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
776
        provincia: '',
777 778
        municipio: '',
        organismo: '',
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
779 780
        cap_total: 0,
        cap_disponible: 0,
781
        id: -1,
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
782 783
      },
      editedAreaItem: {
784 785
        nombre: '',
        categoria: '',
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
786 787 788 789
        capacity: 0,
        availability: 0,
      },
      defaultAreaItem: {
790 791
        nombre: '',
        categoria: '',
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811
        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 () {
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
812 813 814
        return this.editedRoomIndex === -1
          ? 'Nueva Habitación'
          : 'Editar Habitación'
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836
      },
    },
    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
837
    created () {
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
838 839 840 841
      this.initialize()
      this.getProvincesData()
      this.loadMunicipalitiesData()
    },
842
    async mounted () {
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
843
      this.initialize()
844
      this.loadCentersData()
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
845 846
    },
    methods: {
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867
      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
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888
      async getCategoriesData () {
        try {
          const categoriesResponse = await getCategories()
          this.categories = categoriesResponse.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
889
      async getProvincesData () {
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909
        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,
          })
        }
      },
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931
      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
932
      detailsItem (item) {
933
        this.editedIndex = this.centers.indexOf(item)
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
934
        this.editedItem = Object.assign({}, item)
935
        this.loadAreasData()
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
        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 () {
955
        this.centers = [
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
956
          {
957 958 959
            nombre_centro: 'EIA',
            municipio: 'Santa Clara',
            organismo: 'MINED',
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
960 961 962 963 964 965 966 967
            cap_positivos: 100,
            cap_sospechosos: 67,
            cap_contactos: 67,
            dis_positivos: 80,
            dis_sospechosos: 25,
            dis_contactos: 50,
          },
          {
968 969 970
            nombre_centro: 'UCLV',
            municipio: 'Santa Clara',
            organismo: 'MES',
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
971 972 973 974 975 976 977 978
            cap_positivos: 100,
            cap_sospechosos: 67,
            cap_contactos: 67,
            dis_positivos: 80,
            dis_sospechosos: 25,
            dis_contactos: 50,
          },
          {
979 980 981
            nombre_centro: 'Pedagogico',
            municipio: 'Santa Clara',
            organismo: 'MES',
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
982 983 984 985 986 987 988 989
            cap_positivos: 100,
            cap_sospechosos: 67,
            cap_contactos: 67,
            dis_positivos: 80,
            dis_sospechosos: 25,
            dis_contactos: 50,
          },
          {
990 991 992
            nombre_centro: 'Perez Quintosa',
            municipio: 'Santa Clara',
            organismo: 'MINED',
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032
            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) {
1033
        this.editedIndex = this.centers.indexOf(item)
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047
        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) {
1048
        this.editedIndex = this.centers.indexOf(item)
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065
        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
      },
1066 1067 1068
      async deleteItemConfirm () {
        try {
          await deleteCenter(this.editedItem.id_centro)
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082
          this.$toast.success('Centro eliminado correctamente', {
            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,
          })
1083 1084 1085 1086 1087
          this.loadCentersData()
        } catch (err) {
          console.log(err)
        }
        this.centers.splice(this.editedIndex, 1)
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1088 1089
        this.closeDelete()
      },
1090 1091 1092
      async deleteAreaItemConfirm () {
        try {
          await deleteArea(this.editedAreaItem.id_area)
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
          this.$toast.success('Área eliminada correctamente', {
            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,
          })
1107 1108 1109 1110
          this.loadAreasData()
        } catch (err) {
          console.log(err)
        }
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 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
        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
        })
      },
1160
      async save () {
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1161
        if (this.editedIndex > -1) {
1162 1163 1164
          await putCenter(this.editedItem)
          this.loadCentersData()
          Object.assign(this.centers[this.editedIndex], this.editedItem)
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178
          this.$toast.success('Centro editado correctamente', {
            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
1179
        } else {
1180 1181 1182
          await postCenter(this.editedItem)
          this.loadCentersData()
          this.centers.push(this.editedItem)
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196
          this.$toast.success('Centro insertado correctamente', {
            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
1197 1198 1199
        }
        this.close()
      },
1200
      async saveArea () {
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1201
        if (this.editedAreaIndex > -1) {
1202 1203
          await putArea(this.editedAreaItem)
          this.loadAreasData()
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1204
          Object.assign(this.areas[this.editedAreaIndex], this.editedAreaItem)
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218
          this.$toast.success('Área editada correctamente', {
            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
1219
        } else {
1220 1221
          await postArea(this.editedItem.id_centro, this.editedAreaItem)
          this.loadAreasData()
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1222
          this.areas.push(this.editedAreaItem)
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236
          this.$toast.success('Área insertada correctamente', {
            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
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
        }
        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()
      },
1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264
      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
1265 1266 1267 1268 1269
    },
  }
</script>
<style scoped>
.fix-title {
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1270 1271
  word-break: normal;
}
Yoelvis Gonzalez's avatar
Yoelvis Gonzalez committed
1272
</style>