<script setup lang="ts">
import { ref, onMounted, watch } from "vue";
import { checkPermission } from "@/utils/permissions";
import http from "@/plugins/http";
import config from "@/app.config";
import { useQuasar } from "quasar";

/**
 * import Typฃ
 */
import type { OptionData } from "@/modules/07_insignia/interface/index/Main";
import type { QTableProps, QInput } from "quasar";

/**
 * import Components
 */
import DialogHeader from "@/components/DialogHeader.vue";
import Dialogbody from "@/modules/07_insignia/components/3_result/Dialogbody.vue"; //รับ-คืนเครื่องราชฯ
import DialogForm from "@/modules/07_insignia/components/3_result/DialogForm.vue"; //บันทึกผล
import fileUploadview from "../components/3_result/fileUpload.vue";

/**
 * import Stores
 */
import { useResultDataStore } from "@/modules/07_insignia/storeResult";
import { useCounterMixin } from "@/stores/mixin";

/**
 * use
 */
const $q = useQuasar();
const DataStore = useResultDataStore();
const mixin = useCounterMixin();
const {
  date2Thai,
  dialogConfirm,
  showLoader,
  hideLoader,
  messageError,
  success,
} = mixin;

/**
 * ตัวแปร
 */
const tab = ref<string>("");
const selectRound = ref<string>("");
const selectRoundOption = ref<OptionData[]>([]);
const modal = ref<boolean>(false);
const action = ref<string>("");
const personId = ref<string>();
const profileType = ref<string>("");
const fileResult = ref<any>(null);
const fileinvoice = ref<any>(null);
const loadView = ref<boolean>(false);
const insigniaTypeOption = ref<any>([]);
const insigniaTypeFilter = ref<any>({
  insigniaTypeOption: [],
});
const filterInvoice = ref<any>(DataStore.invoiceTypeop);
const filterEmployee = ref<any>(DataStore.employeeClassOps);
const ModalDialog = ref<boolean>(false);
const dateCheckReceive = ref<any>();
const dateCheckReturn = ref<any>();
const dataModal = ref<any>([]);

/**
 * ข้อมูล Tabla
 */
const columns = ref<QTableProps["columns"]>([
  {
    name: "action",
    align: "left",
    label: "",
    field: "",
  },
  {
    name: "no",
    align: "left",
    label: "ลำดับ",
    field: "no",
    sortable: false,
  },
  {
    name: "status",
    align: "left",
    label: "สถานะ",
    field: "status",
    sortable: true,
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
  {
    name: "citizenId",
    align: "left",
    label: "เลขประจำตัวประชาชน",
    field: "citizenId",
    sortable: true,
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
  {
    name: "name",
    align: "left",
    label: "ชื่อ - นามสกุล",
    field: "name",
    sortable: true,
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
  {
    name: "employeeType",
    align: "left",
    label: "สถานภาพ",
    field: "employeeType",
    sortable: true,
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
  {
    name: "type",
    align: "left",
    label: "เครื่องราชฯ",
    field: "type",
    sortable: true,
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
  {
    name: "dateReceive",
    align: "left",
    label: "วันที่ได้รับพระราชทาน",
    field: "dateReceive",
    sortable: true,
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
  {
    name: "date",
    align: "left",
    label: "วันที่ในราชกิจนุเบกษา",
    field: "date",
    sortable: true,
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
  {
    name: "volumeNo",
    align: "left",
    label: "เล่มที่ในราชกิจนุเบกษา",
    field: "volumeNo",
    sortable: true,
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
  {
    name: "section",
    align: "left",
    label: "ตอนที่ในราชกิจนุเบกษา",
    field: "section",
    sortable: true,
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },

  {
    name: "page",
    align: "left",
    label: "หน้าที่ในราชกิจนุเบกษา",
    field: "page",
    sortable: true,
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
  {
    name: "number",
    align: "left",
    label: "ลำดับที่ในราชกิจจานุเบกษา",
    field: "number",
    sortable: true,
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
  {
    name: "vatnumber",
    align: "left",
    label: "หมายเลขใบกำกับ",
    field: "vatnumber",
    sortable: true,
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
  {
    name: "datepay",
    align: "left",
    label: "วันที่จ่ายใบกำกับฯ",
    field: "datepay",
    sortable: true,
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
  {
    name: "typepay",
    align: "left",
    label: "รูปแบบการจ่าย",
    field: "typepay",
    sortable: true,
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
  {
    name: "address",
    align: "left",
    label: "ที่อยู่ที่จ่าย",
    field: "address",
    sortable: true,
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
]);
const visibleColumns = ref<String[]>([
  "action",
  "no",
  "status",
  "citizenId",
  "name",
  "type",
  "dateReceive",
  "date",
  "employeeType",
  "volumeNo",
  "section",
  "page",
  "number",
  "vatnumber",
  "datepay",
  "typepay",
  "address",
]);
const filterRef = ref<QInput>();
const filter = ref<string>("");

/**
 *function เรียกรอบการเสนอขอพระราชทานเครื่องราช
 */
function fecthRound() {
  showLoader();
  http
    .get(config.API.noteround())
    .then(async (res) => {
      let data = res.data.result;

      if (data.length !== 0) {
        selectRoundOption.value = data.map((e: any) => ({
          name: "รอบการเสนอขอพระราชทานเครื่องราชฯ ปี" + "  " + (e.year + 543),
          id: e.id,
        }));
        selectRound.value = data[0].id;
        await fecthInsignia();
        await fecthInsigniaType();
      } else {
        hideLoader();
      }
    })
    .catch((err) => {
      messageError($q, err);
      hideLoader();
    });
}

/**
 * function เรียกประเภทเครื่องราช
 */
function fecthInsignia() {
  http
    .get(config.API.insigniaOrg)
    .then((res) => {
      let data = res.data.result;
      DataStore.fetchDatainsignia(data);
    })
    .catch((err) => {
      messageError($q, err);
    });
}

/**
 * function เรียกระดับเครื่องราช
 */
function fecthInsigniaType() {
  http(config.API.insigniaTypeOrg)
    .then((res) => {
      let data = res.data.result;
      DataStore.fetchDatainsigniaType(data);
      tab.value = DataStore.insigniaType[0].name;
      loadView.value = true;
    })
    .catch((err) => {
      messageError($q, err);
    });
}

/**
 * function เลือกประเภทเครื่องราช
 */
function selectorInsignia() {
  fecthlistInsignia();
}

/**
 *  function เลือกรอบการเสนอขอ
 * @param round รอบการเสนอขอ
 */
function selectorRound(round: string) {
  if (round) {
    selectRound.value = round;
  }
  fecthlistInsignia();
}

/**
 * callback function จำทำงานเมื่อ tab มีการเปลี่ยนแปลง
 */
watch(tab, () => {
  if (tab.value !== "doc") {
    DataStore.insignia = "";
    fecthlistInsignia();

    insigniaTypeOption.value = DataStore.insigniaOp.filter(
      (e: any) => e.insigniaType == tab.value || e.name == "ทั้งหมด"
    );
    insigniaTypeFilter.value = insigniaTypeOption.value;
  }
});

/**
 * callback function จำทำงานเมื่อ modal มีการเปลี่ยนแปลง
 */
// watch(modal, () => {
//   if (modal.value == false) {
//     fecthlistInsignia();
//   }
// });

/**
 * function เรียกรายชื่อบันทึกผลการได้รับพระราชทานเครื่องราชอิสริยาภรณ์/การจ่ายใบกำกับ
 */
function fecthlistInsignia() {
  showLoader();
  let data = {
    insigniaTypeId: tab.value,
    insigniaNoteId: selectRound.value,
    insigniaId: DataStore.insignia,
  };
  http
    .post(config.API.noteSearch(), data)
    .then((res) => {
      let data = res.data.result;
      DataStore.fetchlistinsignia(data);
    })
    .catch((err) => {
      messageError($q, err);
    })
    .finally(() => {
      hideLoader();
    });
}

/**
 * function uploadFile
 * @param event file
 * @param action  typepreview
 */
function uploadFile(event: any, action: string) {
  if (selectRound.value !== undefined) {
    let id = selectRound.value;
    dialogConfirm($q, () => {
      showLoader();
      const formdata = new FormData();
      formdata.append("file", event);
      http
        .put(config.API.uploadfileInsignia(action, id), formdata)
        .then(async () => {
          await fecthlistInsignia();
          if (action === "receice") {
            fileResult.value = null;
          } else if (action === "invoice") {
            fileinvoice.value = null;
          }

          await success($q, "อัพโหลดไฟล์สำเร็จ");
          modelPerview.value = await false;
        })
        .catch((err) => {
          messageError($q, err);
          hideLoader();
        });
    }),
      "ยืนยันการบันทึกรายการข้อมูล",
      "ต้องการยืนยันรายการข้อมูลนี้หรื้อไม่ ?";
  }
}

/** function closePopup*/
function close() {
  modal.value = false;
  ModalDialog.value = false;
}

/** function openPopup add*/
function addData() {
  modal.value = true;
  action.value = "addData";
}

/** function openPopup edit*/
function editData(data: any) {
  personId.value = data.id;
  profileType.value = data.profileType;
  action.value = "editData";
  modal.value = true;
}

const save = () => {
  console.log("save function");
};

/**
 * ข้อมูล ไฟล์
 */
const modelPerview = ref<boolean>(false);
const rowspreview = ref<any>([]);
const typepreview = ref<string>("");
const fileInsignia = ref<any>(null);

/**
 * function แสดง fileupload
 * @param event  ไฟล
 * @param actionType  ประเภทไฟล์ receice,invoice
 */
function perviewfile(event: any, actionType: string) {
  showLoader();
  typepreview.value = actionType;
  fileInsignia.value = event;
  if (selectRound.value !== undefined) {
    let id = selectRound.value.toString();
    const formdata = new FormData();
    formdata.append("file", event);
    http
      .put(config.API.previewfileInsignia(actionType, id), formdata)
      .then((res) => {
        let data = res.data.result;
        rowspreview.value = data.map((e: any) => ({
          id: e.id,
          citizenId: e.citizenId,
          prefix: e.prefix,
          position: e.position,
          status: DataStore.status(e.status),
          dateReceive: date2Thai(e.dateReceive),
          name: e.fullName,
          type: e.requestInsignia,
          employeeType: DataStore.profileType(e.profileType),
          profileType: e.profileType,
          page: e.page,
          number: e.no,
          vatnumber: e.number,
          datepay: date2Thai(e.datePayment),
          typepay: e.typePayment,
          address: e.address,
        }));
        modelPerview.value = true;
      })
      .catch((err) => {
        messageError($q, err);
      })
      .finally(() => {
        hideLoader();
      });
  }
}

function closeDialogPerview() {
  modelPerview.value = false;
}

const resetFilter = () => {
  filter.value = "";
  filterRef.value!.focus();
};
const pagination = ref({
  sortBy: "name",
  descending: false,
  page: 1,
  rowsPerPage: 10,
});
const paging = ref<boolean>(true);
const paginationLabel = (start: number, end: number, total: number) => {
  if (paging.value == true) return " " + start + "-" + end + " ใน " + total;
  else return start + "-" + end + " ใน " + total;
};

/**
 * function openPopup
 */
function OpenModal(data: any) {
  dataModal.value = data;
  ModalDialog.value = true;
  dateCheckReceive.value = data.dateReceiveInsignia;
  dateCheckReturn.value = data.dateReturnInsignia;
  personId.value = data.id;
}

/**
 * function ค้นหาข้อมูล option
 * @param val คำค้นหา
 * @param update function
 * @param name ชื่อ selec
 */
function filterSelector(val: any, update: Function, name: any) {
  update(() => {
    const needle = val.toLowerCase();
    if (name === "insigniaTypeFilter") {
      DataStore.insignia = null as any;
      insigniaTypeFilter.value = insigniaTypeOption.value.filter(
        (v: any) => v.name.toLowerCase().indexOf(needle) > -1
      );
    } else if (name === "filterInvoice") {
      DataStore.invoiceType = "";
      filterInvoice.value = DataStore.invoiceTypeop.filter(
        (v: any) => v.name.toLowerCase().indexOf(needle) > -1
      );
    } else if (name === "filterEmployee") {
      DataStore.employeeClass = "";
      filterEmployee.value = DataStore.employeeClassOps.filter(
        (v: any) => v.name.toLowerCase().indexOf(needle) > -1
      );
    }
  });
}

/**
 * function clearfilter เครื่องราช
 * @param name ชื่อ selec
 */
function clearInsigniaFilters(name: string) {
  if (name === "insigniaTypeFilter") {
    DataStore.insignia = "";
    insigniaTypeFilter.value = insigniaTypeOption.value;
  } else if (name === "filterInvoice") {
    DataStore.invoiceType = "all";
    filterInvoice.value = DataStore.invoiceTypeop;
  } else if (name === "filterEmployee") {
    DataStore.employeeClass = "all";
    filterEmployee.value = DataStore.employeeClassOps;
  }
}

/** hook*/
onMounted(() => {
  fecthRound();
});
</script>

<template>
  <div class="toptitle text-dark col-12 row items-center">
    บันทึกผลการได้รับพระราชทานเครื่องราชอิสริยาภรณ์/การจ่ายใบกำกับ
  </div>
  <q-card
    flat
    bordered
    class="col-12 q-my-md q-mt-sm rounded-borders"
    v-if="loadView == true"
  >
    <div class="bg-grey-1 col-12 row items-center">
      <div class="q-pl-md q-pr-sm text-weight-medium text-grey-7">รอบ</div>
      <div>
        <q-select
          hide-bottom-space
          borderless
          dense
          lazy-rules
          emit-value
          map-options
          options-dense
          option-label="name"
          option-value="id"
          v-model="selectRound"
          :options="selectRoundOption"
          use-input
          input-debounce="0"
          input-class="text-bold text-grey"
          @update:model-value="selectorRound(selectRound)"
        >
        </q-select>
      </div>
    </div>
    <q-separator />
    <q-tabs
      dense
      v-model="tab"
      align="left"
      class="bg-white text-grey"
      active-color="primary"
      indicator-color="primary"
    >
      <div v-for="item in DataStore.insigniaType">
        <q-tab :name="item.name" :label="item.label" />
      </div>

      <q-tab name="doc" label="เอกสารอ้างอิง" />
    </q-tabs>
    <q-separator />
    <q-tab-panels v-model="tab" animated>
      <q-tab-panel
        v-for="item in DataStore.insigniaType"
        :key="item.name"
        :name="item.name"
        class="q-pa-none"
      >
        <div class="q-pa-md">
          <q-card
            bordered
            class="col-12 q-mb-sm q-pa-sm"
            v-if="checkPermission($route)?.attrIsCreate"
          >
            <div class="row col-12 q-col-gutter-x-xs">
              <div class="col-xs-12 col-sm-6 row no-wrap q-col-gutter-x-xs">
                <q-file
                  dense
                  clearable
                  outlined
                  v-model="fileResult"
                  label="บันทึกผลการได้รับพระราชทานเครื่องราชอิสริยาภรณ์"
                  accept=".xlsx"
                  class="full-width"
                >
                  <template v-slot:prepend>
                    <q-icon name="attach_file" color="primary" />
                  </template>
                  <q-tooltip
                    >อัพโหลดไฟล์บันทึกผลการได้รับพระราชทานเครื่องราชอิสริยาภรณ์</q-tooltip
                  >
                </q-file>
                <div v-if="fileResult !== null">
                  <q-btn
                    size="12px"
                    flat
                    class="bg-teal-1 fit"
                    color="add"
                    icon="mdi-upload"
                    @click="perviewfile(fileResult, 'receice')"
                  >
                    <q-tooltip
                      >อัพโหลดไฟล์บันทึกผลการได้รับพระราชทานเครื่องราชอิสริยาภรณ์</q-tooltip
                    >
                  </q-btn>
                </div>
              </div>
              <div class="col-xs-12 col-sm-6 row no-wrap q-col-gutter-x-xs">
                <q-file
                  dense
                  clearable
                  outlined
                  v-model="fileinvoice"
                  label="บันทึกผลการจ่ายใบกำกับ"
                  accept=".xlsx"
                  class="full-width"
                >
                  <template v-slot:prepend>
                    <q-icon name="attach_file" color="primary" />
                  </template>
                  <q-tooltip>อัพโหลดไฟล์บันทึกผลการจ่ายใบกำกับ</q-tooltip>
                </q-file>
                <div v-if="fileinvoice !== null">
                  <q-btn
                    size="12px"
                    flat
                    color="add"
                    class="bg-teal-1 fit"
                    icon="mdi-upload"
                    @click="perviewfile(fileinvoice, 'invoice')"
                  >
                    <q-tooltip>อัพโหลดไฟล์บันทึกผลการจ่ายใบกำกับ</q-tooltip>
                  </q-btn>
                </div>
              </div>
            </div>
          </q-card>
          <div class="row col-12 q-pb-sm q-col-gutter-xs">
            <q-select
              v-model="DataStore.insignia"
              dense
              outlined
              lazy-rules
              hide-bottom-space
              :label="`${'เครื่องราชฯ'}`"
              emit-value
              map-options
              use-input
              option-label="name"
              :options="insigniaTypeFilter"
              option-value="id"
              :readonly="false"
              :borderless="false"
              style="width: 300px"
              @update:model-value="selectorInsignia"
              @filter="(inputValue:any,
                      doneFn:Function) => filterSelector(inputValue, doneFn,'insigniaTypeFilter'
                      ) "
            >
              <template v-if="DataStore.insignia" v-slot:append>
                <q-icon
                  name="cancel"
                  @click.stop.prevent="
                    clearInsigniaFilters('insigniaTypeFilter'),
                      selectorInsignia()
                  "
                  class="cursor-pointer"
                />
              </template>
              <template v-slot:no-option>
                <q-item>
                  <q-item-section class="text-grey">
                    ไม่มีข้อมูล
                  </q-item-section>
                </q-item>
              </template>
            </q-select>
            <q-space />
            <div class="items-center" style="display: flex">
              <!-- ค้นหาข้อความใน table -->
              <q-input
                standout
                dense
                v-model="filter"
                ref="filterRef"
                outlined
                debounce="300"
                placeholder="ค้นหา"
                style="max-width: 200px"
                class="q-ml-sm"
              >
                <template v-slot:append>
                  <q-icon v-if="filter == ''" name="search" />
                  <q-icon
                    v-if="filter !== ''"
                    name="clear"
                    class="cursor-pointer"
                    @click="resetFilter"
                  />
                </template>
              </q-input>
              <!-- แสดงคอลัมน์ใน table -->
              <q-select
                v-model="visibleColumns"
                :display-value="$q.lang.table.columns"
                multiple
                outlined
                dense
                :options="columns"
                options-dense
                option-value="name"
                map-options
                emit-value
                style="min-width: 150px"
                class="gt-xs q-ml-sm"
              />
            </div>
          </div>
          <div class="row col-12 q-mb-sm q-col-gutter-xs">
            <q-select
              v-model="DataStore.invoiceType"
              dense
              outlined
              lazy-rules
              hide-bottom-space
              :label="`${'ใบกำกับ'}`"
              emit-value
              map-options
              use-input
              option-label="name"
              :options="filterInvoice"
              option-value="id"
              :readonly="false"
              :borderless="false"
              style="width: 250px"
              @update:model-value="
                DataStore.searchData(
                  DataStore.invoiceType,
                  DataStore.employeeClass
                )
              "
              @filter="(inputValue:any,
                      doneFn:Function) => filterSelector(inputValue, doneFn,'filterInvoice'
                      ) "
            >
              <template v-if="DataStore.invoiceType !== 'all'" v-slot:append>
                <q-icon
                  name="cancel"
                  @click.stop.prevent="
                    clearInsigniaFilters('filterInvoice'),
                      DataStore.searchData(
                        DataStore.invoiceType,
                        DataStore.employeeClass
                      )
                  "
                  class="cursor-pointer"
                />
              </template>
              <template v-slot:no-option>
                <q-item>
                  <q-item-section class="text-grey">
                    ไม่มีข้อมูล
                  </q-item-section>
                </q-item>
              </template>
            </q-select>
            <q-select
              v-model="DataStore.employeeClass"
              dense
              outlined
              lazy-rules
              hide-bottom-space
              :label="`${'สถานภาพ'}`"
              emit-value
              map-options
              use-input
              option-label="name"
              :options="filterEmployee"
              option-value="id"
              :readonly="false"
              :borderless="false"
              style="width: 280px"
              @update:model-value="
                DataStore.searchData(
                  DataStore.invoiceType,
                  DataStore.employeeClass
                )
              "
              @filter="(inputValue:any,
                    doneFn:Function) => filterSelector(inputValue, doneFn,'filterEmployee'
                    ) "
            >
              <template v-if="DataStore.employeeClass !== 'all'" v-slot:append>
                <q-icon
                  name="cancel"
                  @click.stop.prevent="
                    clearInsigniaFilters('filterEmployee'),
                      DataStore.searchData(
                        DataStore.invoiceType,
                        DataStore.employeeClass
                      )
                  "
                  class="cursor-pointer"
                />
              </template>
              <template v-slot:no-option>
                <q-item>
                  <q-item-section class="text-grey">
                    ไม่มีข้อมูล
                  </q-item-section>
                </q-item>
              </template>
            </q-select>
            <div>
              <q-btn
                v-if="checkPermission($route)?.attrIsCreate"
                @click="addData()"
                flat
                round
                color="add"
                icon="mdi-plus"
              >
                <q-tooltip>เพิ่ม</q-tooltip>
              </q-btn>
            </div>
          </div>
          <d-table
            :rows="DataStore.rows"
            :columns="columns"
            :visible-columns="visibleColumns"
            :filter="filter"
            row-key="name"
            :pagination-label="paginationLabel"
            v-model:pagination="pagination"
          >
            <template v-slot:body-cell="props">
              <q-td :props="props">
                <div v-if="props.col.name == 'no'">
                  {{ props.rowIndex + 1 }}
                </div>

                <div v-else-if="props.col.name == 'action'">
                  <q-btn
                    v-if="
                      checkPermission($route)?.attrIsGet &&
                      checkPermission($route)?.attrIsUpdate
                    "
                    flat
                    round
                    dense
                    icon="edit"
                    color="edit"
                    @click.stop="editData(props.row)"
                  >
                    <q-tooltip> แก้ไขข้อมูล</q-tooltip>
                  </q-btn>

                  <q-btn
                    v-if="
                      checkPermission($route)?.attrIsGet &&
                      checkPermission($route)?.attrIsUpdate
                    "
                    flat
                    round
                    dense
                    icon="mdi-information-outline"
                    color="blue"
                    @click.stop="OpenModal(props.row)"
                  >
                    <q-tooltip> รับ-คืนเครื่องราชฯ</q-tooltip>
                  </q-btn>
                </div>
                <div v-else>
                  {{ props.value }}
                </div>
              </q-td>
            </template>
          </d-table>
        </div>
      </q-tab-panel>
      <q-tab-panel name="doc" class="q-pa-none">
        <fileUploadview :roundId="selectRound" />
      </q-tab-panel>
    </q-tab-panels>
  </q-card>
  <q-card v-else>
    <div class="q-pa-md q-gutter-sm">
      <q-banner inline-actions rounded class="bg-grey-1 text-center">
        ไม่มีข้อมูลรอบการเสนอขอพระราชทานเครื่องราชอิสริยาภรณ์
      </q-banner>
    </div>
  </q-card>

  <!-- รับ-คืนเครื่องราชฯ -->
  <Dialogbody
    :modal="ModalDialog"
    :close="close"
    :dateCheckReceive="dateCheckReceive"
    :dateCheckReturn="dateCheckReturn"
    :dataModal="dataModal"
    :personId="personId"
    :fecthlistInsignia="fecthlistInsignia"
  />
  <!-- DialogForm -->
  <DialogForm
    :modal="modal"
    :save="save"
    :close="close"
    :roundId="selectRound"
    :action="action"
    :personId="personId"
    :profileType="profileType"
    :fecthlistInsignia="fecthlistInsignia"
  />

  <!-- ยืนยันรายการข้อมูล -->
  <q-dialog v-model="modelPerview">
    <q-card style="width: 850px; max-width: 80vw">
      <DialogHeader tittle="ยืนยันรายการข้อมูล" :close="closeDialogPerview" />
      <q-card-section class="q-pt-none">
        <d-table
          :rows="rowspreview"
          :columns="columns"
          :visible-columns="visibleColumns"
          :filter="filter"
          row-key="name"
        >
          <template v-slot:body-cell="props">
            <q-td :props="props">
              <div v-if="props.col.name == 'no'">
                {{ props.rowIndex + 1 }}
              </div>
              <div v-else>
                {{ props.value ?? "-" }}
              </div>
            </q-td>
          </template>
        </d-table>
      </q-card-section>
      <q-card-actions align="right" class="text-primary">
        <q-btn
          unelevated
          dense
          color="public"
          label="บันทึก"
          @click="uploadFile(fileInsignia, typepreview)"
        />
      </q-card-actions>
    </q-card>
  </q-dialog>
</template>
<style lang="scss" scoped>
.arrow {
  transition: transform 0.5s;
}

.arrow-active {
  transition: transform 0.5s;
  transform: rotate(-90deg);
}

.bg-base {
  background-color: #f3f3f398;
}

.v-enter-active,
.v-leave-active {
  transition: opacity 0.5s ease;
}

.v-enter-from,
.v-leave-to {
  opacity: 0;
}

.flexsave {
  display: flex;
  justify-content: flex-end;
}
</style>
