<script setup lang="ts">
import { onMounted, ref } from "vue";
import { useQuasar } from "quasar";

import { useRoute, useRouter } from "vue-router";
import { useCounterMixin } from "@/stores/mixin";
import { checkPermission } from "@/utils/permissions";
import http from "@/plugins/http";
import config from "@/app.config";

import type { QTableProps, QForm } from "quasar";
import type { MainData } from "@/modules/05_placement/interface/index/Main";
import type {
  ResponseTitle,
  DataProfile,
} from "@/modules/05_placement/interface/response/Receive";
import type {
  Information,
  DataOption,
  DataOptioninfo,
  DocList,
  InformationOps,
} from "@/modules/05_placement/interface/index/ProfileType";
import { defaultInformation } from "@/modules/05_placement/interface/index/ProfileType";

import CardProfile from "@/components/CardProfile.vue";

const $q = useQuasar();
const route = useRoute();
const router = useRouter();
const mixin = useCounterMixin();

const paramsId = route.params.id;
const {
  date2Thai,
  dialogMessage,
  messageError,
  showLoader,
  hideLoader,
  success,
  convertDateToAPI,
  dialogConfirm,
} = mixin;

const dataProfile = ref<DataProfile>(); //ข้อมุลส่วนตัว
const title = ref<ResponseTitle>({
  fullname: "",
  organizationPositionOld: "",
  positionLevelOld: "",
  positionTypeOld: "",
});

const status = ref<string>("");

const myForm = ref<QForm | null>(null);
const edit = ref<boolean>(false); //การแก้ไข
const informaData = ref<Information>(defaultInformation); //ข้อมูลส่วนตัว
const rows = ref<DocList[]>([]); //เอกสารเพิ่มเติม
const columns = ref<QTableProps["columns"]>([
  {
    name: "no",
    align: "left",
    label: "ลำดับ",
    sortable: true,
    field: "no",
    headerStyle: "font-size: 14px",
    style: "font-size: 14px",
  },
  {
    name: "fileName",
    align: "left",
    label: "ชื่อไฟล์",
    sortable: true,
    field: "fileName",
    headerStyle: "font-size: 14px",
    style: "font-size: 14px",
  },
  {
    name: "btnMicrosoft",
    align: "right",
    label: "ปุ่ม",
    sortable: true,
    field: "btnMicrosoft",
    headerStyle: "font-size: 14px",
    style: "font-size: 14px",
  },
]);
const profileId = ref<string>("");
const educationOld = ref<string>(""); //วุฒิ/สาขา
const organizationPositionOld = ref<string>(""); //ตำแหน่ง/สังกัด
const positionTypeOld = ref<string>(""); //ตำแหน่งประเภท
const positionLevelOld = ref<string>(""); //ระดับตำแหน่ง
const posNo = ref<string>(""); //เลขที่
const salary = ref<number>(0); //เงินเดือน
const reason = ref<string>(""); //หมายเหตุ
const defaultCitizenData = ref<string>(""); //เลขประจำตัวประชาชน
const mianData = ref<MainData>();

//รายการตัวเลือก
const Ops = ref<InformationOps>({
  prefixOps: [],
  prefixOldOps: [],
  genderOps: [],
  bloodOps: [],
  statusOps: [],
  religionOps: [],
  employeeClassOps: [
    { id: "perm", name: "ลูกจ้างประจำ" },
    { id: "temp", name: "ลูกจ้างชั่วคราว" },
  ],
  employeeTypeOps: [
    { id: "gov", name: "งบประมาณเงินอุดหนุนรัฐบาล" },
    { id: "bkk", name: "งบประมาณกรุงเทพมหานคร" },
  ],
});
const OpsFilter = ref<InformationOps>({
  prefixOps: [],
  prefixOldOps: [],
  genderOps: [],
  bloodOps: [],
  statusOps: [],
  religionOps: [],
  employeeClassOps: [
    { id: "perm", name: "ลูกจ้างประจำ" },
    { id: "temp", name: "ลูกจ้างชั่วคราว" },
  ],
  employeeTypeOps: [
    { id: "gov", name: "งบประมาณเงินอุดหนุนรัฐบาล" },
    { id: "bkk", name: "งบประมาณกรุงเทพมหานคร" },
  ],
});

/** ฟังก์ชันดึงข้อมูลรายการข้อมูลเกี่ยวกับบุคคล (dropdown list)*/
async function fetchPerson() {
  showLoader();
  await http
    .get(config.API.profileNewMetaMain)
    .then((res) => {
      const data = res.data.result;
      let optionbloodGroups: DataOption[] = [];
      data.bloodGroups.map((r: DataOptioninfo) => {
        optionbloodGroups.push({
          id: r.id.toString(),
          name: r.name.toString(),
        });
      });
      Ops.value.bloodOps = optionbloodGroups;
      OpsFilter.value.bloodOps = optionbloodGroups;

      let optiongenders: DataOption[] = [];
      data.genders.map((r: DataOptioninfo) => {
        optiongenders.push({
          id: r.id.toString(),
          name: r.name.toString(),
        });
      });
      Ops.value.genderOps = optiongenders;
      OpsFilter.value.genderOps = optiongenders;

      let optionprefixs: DataOption[] = [];
      optionprefixs = data.prefixs.map((v: any) => ({
        id: v.id,
        name: v.name,
      }));

      Ops.value.prefixOps = optionprefixs;
      OpsFilter.value.prefixOps = optionprefixs;

      let optionrelationships: DataOption[] = [];
      data.relationships.map((r: DataOptioninfo) => {
        optionrelationships.push({
          id: r.id.toString(),
          name: r.name.toString(),
        });
      });
      Ops.value.statusOps = optionrelationships;
      OpsFilter.value.statusOps = optionrelationships;

      let optionreligions: DataOption[] = [];
      data.religions.map((r: DataOptioninfo) => {
        optionreligions.push({
          id: r.id.toString(),
          name: r.name.toString(),
        });
      });
      Ops.value.religionOps = optionreligions;
      OpsFilter.value.religionOps = optionreligions;
    })
    .catch((e) => {
      messageError($q, e);
    })
    .finally(() => {
      hideLoader();
    });
}

/** ฟังก์ชันดึงข้อมูลรายละเอียดการรับโอน*/
async function getData() {
  showLoader();
  await http
    .get(config.API.receiveDataId(paramsId.toString()))
    .then(async (res) => {
      const data = res.data.result;
      mianData.value = data;
      dataProfile.value = res.data.result as unknown as DataProfile;
      let list: DocList[] = [];
      if (data.docs.length > 0) {
        data.docs.map((doc: DocList) => {
          list.push({
            pathName: doc.pathName ?? "",
            fileName: doc.fileName ?? "",
          });
        });
      }
      rows.value = list;
      profileId.value = data.profileId;
      title.value.fullname = `${data.prefix ?? ""}${data.firstName ?? ""} ${
        data.lastName ?? ""
      }`;
      title.value.organizationPositionOld = data.organizationPositionOld ?? "-";
      title.value.positionLevelOld = data.positionLevelOld ?? "-";
      title.value.positionTypeOld = data.positionTypeOld ?? "-";
      defaultCitizenData.value = data.citizenId == null ? "" : data.citizenId;
      informaData.value = {
        cardid: data.citizenId ?? "",
        age: calculateAge(data.dateOfBirth),
        prefix: "",
        prefixId:
          (data.prefix == "00000000-0000-0000-0000-000000000000"
            ? null
            : data.prefix) ?? "",
        firstname: data.firstName ?? "",
        lastname: data.lastName ?? "",
        birthDate:
          data.dateOfBirth !== null ? new Date(data.dateOfBirth) : null,
        genderId:
          (data.gender == "00000000-0000-0000-0000-000000000000"
            ? null
            : data.gender) ?? "",
        bloodId:
          (data.bloodGroup == "00000000-0000-0000-0000-000000000000"
            ? null
            : data.bloodGroup) ?? "",
        nationality: data.nationality ?? "",
        ethnicity: data.race ?? "",
        statusId:
          (data.relationship == "00000000-0000-0000-0000-000000000000"
            ? null
            : data.relationship) ?? "",
        religionId:
          (data.religion == "00000000-0000-0000-0000-000000000000"
            ? null
            : data.religion) ?? "",
        tel: data.telephoneNumber ?? "",
        employeeType: "",
        employeeClass: "",
        profileType: "",
      };
      educationOld.value = data.educationOld ?? "";
      organizationPositionOld.value = data.organizationPositionOld ?? "";
      positionTypeOld.value = data.positionTypeOld ?? "";
      positionLevelOld.value = data.positionLevelOld ?? "";
      posNo.value = data.positionNumberOld ?? "";
      salary.value = data.amountOld ?? 0;
      reason.value = data.reason ?? "";
      status.value = data.status ?? "";

      calculateAge(data.dateOfBirth);
    })
    .catch((e) => {
      messageError($q, e);
    })
    .finally(async () => {
      hideLoader();
    });
}
/** ฟังก์ชันยกเลิกการแก้ไขข้อมูล*/
async function oncanceledit() {
  edit.value = !edit.value;
  if (myForm.value !== null) {
    fetchData(mianData.value);
    myForm.value?.resetValidation();
  }
}

/**
 * ฟังก์ชันรีเช็ตข้อมูลแนบท้ายเป็น ข้อมูล Default
 * @param data  ข้อมูล Default
 */
async function fetchData(data: any) {
  informaData.value = {
    cardid: data.citizenId ?? "",
    age: calculateAge(data.dateOfBirth),
    prefix: "",
    prefixId:
      (data.prefix == "00000000-0000-0000-0000-000000000000"
        ? null
        : data.prefix) ?? "",
    firstname: data.firstName ?? "",
    lastname: data.lastName ?? "",
    birthDate: data.dateOfBirth !== null ? new Date(data.dateOfBirth) : null,
    genderId:
      (data.gender == "00000000-0000-0000-0000-000000000000"
        ? null
        : data.gender) ?? "",
    bloodId:
      (data.bloodGroup == "00000000-0000-0000-0000-000000000000"
        ? null
        : data.bloodGroup) ?? "",
    nationality: data.nationality ?? "",
    ethnicity: data.race ?? "",
    statusId:
      (data.relationship == "00000000-0000-0000-0000-000000000000"
        ? null
        : data.relationship) ?? "",
    religionId:
      (data.religion == "00000000-0000-0000-0000-000000000000"
        ? null
        : data.religion) ?? "",
    tel: data.telephoneNumber ?? "",
    employeeType: "",
    employeeClass: "",
    profileType: "",
  };
  educationOld.value = data.educationOld ?? "";
  organizationPositionOld.value = data.organizationPositionOld ?? "";
  positionTypeOld.value = data.positionTypeOld ?? "";
  positionLevelOld.value = data.positionLevelOld ?? "";
  posNo.value = data.positionNumberOld ?? "";
  salary.value = data.amountOld ?? 0;
  reason.value = data.reason ?? "";
  status.value = data.status ?? "";
}

/**
 * ฟังก์ชันตรวจสอบเลขบัตรประจำตัวประชาชน
 * @param value เลขบัตรประจำตัวประชาชน
 */
async function changeCardID(value: string | number | null) {
  if (value != null && typeof value == "string") {
    if (value.length == 13 && value != defaultCitizenData.value) {
      await checkCitizen(value);
    }
  }
}

/**
 * ฟังก์ชันยิง API ตรวจสอบเลขบัตรประจำตัวประชาชนซ้ำ
 * @param value เลขบัตรประจำตัวประชาชน
 */
async function checkCitizen(id: string) {
  showLoader();
  await http
    .get(config.API.profileCitizenId(id))
    .then((res) => {
      const data = res.data.result.citizen;

      if (!data) {
        dialogMessage(
          $q,
          "ข้อความแจ้งเตือน",
          "เลขประจำตัวประชาชนนี้มีการใช้งานแล้ว",
          "warning",
          undefined,
          "orange",
          undefined,
          undefined,
          true
        );
        informaData.value.cardid = defaultCitizenData.value;
      }
    })
    .catch((e) => {
      messageError($q, e);
    })
    .finally(() => {
      hideLoader();
    });
}

/**
 * ฟังก์ชันค้นหาข้อมูลในรายการตัวเลือก
 * @param val คำค้นหา
 * @param update ฟังก์ชัน
 * @param refData ประเภทของตัวเลือก
 */
function filterSelector(val: string, update: Function, refData: string) {
  let newVal = val.toLowerCase();
  switch (refData) {
    case "prefixOps":
      update(() => {
        Ops.value.prefixOps = OpsFilter.value.prefixOps.filter(
          (v: DataOption) => v.name.toLowerCase().indexOf(newVal) > -1
        );
      });
      break;
    case "genderOps":
      update(() => {
        Ops.value.genderOps = OpsFilter.value.genderOps.filter(
          (v: DataOption) => v.name.toLowerCase().indexOf(newVal) > -1
        );
      });
      break;
    case "bloodOps":
      update(() => {
        Ops.value.bloodOps = OpsFilter.value.bloodOps.filter(
          (v: DataOption) => v.name.toLowerCase().indexOf(newVal) > -1
        );
      });
      break;
    case "statusOps":
      update(() => {
        Ops.value.statusOps = OpsFilter.value.statusOps.filter(
          (v: DataOption) => v.name.toLowerCase().indexOf(newVal) > -1
        );
      });
      break;
    case "religionOps":
      update(() => {
        Ops.value.religionOps = OpsFilter.value.religionOps.filter(
          (v: DataOption) => v.name.toLowerCase().indexOf(newVal) > -1
        );
      });
      break;
    case "employeeClassOps":
      update(() => {
        Ops.value.employeeClassOps = OpsFilter.value.employeeClassOps.filter(
          (v: DataOption) => v.name.toLowerCase().indexOf(newVal) > -1
        );
      });
      break;
    case "employeeTypeOps":
      update(() => {
        Ops.value.employeeTypeOps = OpsFilter.value.employeeTypeOps.filter(
          (v: DataOption) => v.name.toLowerCase().indexOf(newVal) > -1
        );
      });
      break;

    default:
      break;
  }
}

/** ฟังก์ชันบันทึกข้อมูลการแก้ไขบัญชีแนบท้าย*/
function saveData() {
  dialogConfirm(
    $q,
    () => {
      const body = {
        citizenId: informaData.value.cardid,
        prefix: informaData.value.prefixId,
        firstname: informaData.value.firstname,
        lastname: informaData.value.lastname,
        dateOfBirth:
          informaData.value.birthDate !== null
            ? convertDateToAPI(informaData.value.birthDate)
            : null,
        gender: informaData.value.genderId,
        nationality: informaData.value.nationality,
        race: informaData.value.ethnicity,
        religion: informaData.value.religionId,
        bloodGroup: informaData.value.bloodId,
        relationship: informaData.value.statusId,
        telephoneNumber: informaData.value.tel,
        reason: reason.value,
        educationOld: educationOld.value,
        organizationPositionOld: organizationPositionOld.value,
        positionTypeOld: positionTypeOld.value,
        positionLevelOld: positionLevelOld.value,
        positionNumberOld: posNo.value,
        amount: 0,
        amountOld: salary.value,
      };
      showLoader();
      http
        .put(config.API.receiveDataId(route.params.id.toString()), body)
        .then(async () => {
          await getData();
          await success($q, "แก้ไขข้อมูลเพื่อลงบัญชีแนบท้ายสำเร็จ");
          edit.value = false;
        })
        .catch((e) => {
          messageError($q, e);
        })
        .finally(async () => {
          hideLoader();
        });
    },
    "ต้องการแก้ไขข้อมูลหรือไม่?",
    "แก้ไขข้อมูลเพื่อลงบัญชีแนบท้าย"
  );
}

/**
 * ฟังก์ชันสำหรับคืนค่าชื่อคลาสตามค่าที่กำหนด
 * @param val ค่าที่ใช้กำหนดคลาส
 */
function getClass(val: boolean) {
  return {
    "full-width inputgreen cursor-pointer": val,
    "full-width cursor-pointer": !val,
  };
}

/** function เช็คอายุไม่เกิน 18 ปี */
function calculateMaxDate() {
  const today = new Date();
  today.setFullYear(today.getFullYear() - 18);
  return today;
}

/**
 * ฟังก์ชันคำนวนอายุ
 * @param birthDate  วันเดือยปีเกิด
 * @returns  อายุ แบบ ปี เดือน วัน
 */
function calculateAge(birthDate: Date | null) {
  if (!birthDate) return null;
  const birthDateTimeStamp = new Date(birthDate).getTime();
  const now = new Date();
  const diff = now.getTime() - birthDateTimeStamp;

  const ageDate = new Date(diff);
  const years = ageDate.getUTCFullYear() - 1970;
  const months = ageDate.getUTCMonth();
  const days = ageDate.getUTCDate() - 1;
  const retire = new Date(birthDate);
  retire.setFullYear(retire.getFullYear() + 60);

  if (years > 60) {
    return "อายุเกิน 60 ปี";
  }

  return `${years} ปี ${months} เดือน ${days} วัน`;
}

/**
 * ฟังก์ชันอัปเดทวันเดือนปีเกิด
 * @param v  วันเดือยปีเกิด
 */
function updateBirthDate(v: Date) {
  informaData.value.age = calculateAge(v);
}

/** ทำงานเมื่อมีการเรียกใช้ Components*/
onMounted(async () => {
  await fetchPerson();
  await getData();
});
</script>

<template>
  <div class="q-gutter-sm q-pa-sm">
    <div class="toptitle text-dark col-12 row items-center">
      <q-btn
        icon="mdi-arrow-left"
        unelevated
        round
        dense
        flat
        color="primary"
        class="q-mr-sm"
        @click="router.push(`/placement/receive`)"
      />
      รายละเอียดการรับโอน {{ title.fullname }}
    </div>
    <CardProfile :data="dataProfile as DataProfile" />

    <q-card bordered class="row col-12 text-dark q-mt-sm">
      <q-form
        greedy
        @submit.prevent
        @validation-success="saveData"
        ref="myForm"
      >
        <div class="bg-grey-1 q-pa-sm col-12 row items-center text-primary">
          <div class="q-pl-sm text-weight-bold text-dark">
            แก้ไขข้อมูลเพื่อลงบัญชีแนบท้าย
          </div>
          <q-space />
          <div class="q-gutter-sm" v-if="!edit">
            <q-btn
              outline
              color="primary"
              dense
              icon-right="mdi-file-edit-outline"
              class="q-px-sm"
              label="แก้ไข"
              style="width: 80px"
              @click="edit = !edit"
              v-if="
                !(status == 'REPORT' || status == 'DONE') &&
                checkPermission($route)?.attrIsUpdate
              "
            />
          </div>
          <div class="q-gutter-sm" v-else>
            <q-btn
              type="submit"
              outline
              color="public"
              dense
              class="q-px-sm"
              label="บันทึก"
              style="width: 80px"
            />
            <q-btn
              outline
              color="red"
              dense
              class="q-px-sm"
              label="ยกเลิก"
              style="width: 80px"
              @click="oncanceledit"
            />
          </div>
        </div>
        <div class="col-12"><q-separator /></div>

        <div class="row col-12 q-pa-md">
          <div class="col-12 row bg-white">
            <div class="col-xs-12 row q-col-gutter-md">
              <div class="col-xs-12">
                <div class="text-weight-bold text-grey">ข้อมูลส่วนตัว</div>
              </div>
              <div class="col-xs-6 col-sm-3 col-md-3">
                <q-input
                  :class="getClass(edit)"
                  hide-bottom-space
                  :outlined="edit"
                  v-model="informaData.cardid"
                  dense
                  @update:model-value="changeCardID"
                  lazy-rules
                  :readonly="!edit"
                  :borderless="!edit"
                  label="เลขประจำตัวประชาชน"
                  maxlength="13"
                  mask="#############"
                />
              </div>
              <div class="col-xs-6 col-sm-3 col-md-3">
                <selector
                  :hide-dropdown-icon="!edit"
                  hide-bottom-space
                  :class="getClass(edit)"
                  :readonly="!edit"
                  :borderless="!edit"
                  :outlined="edit"
                  dense
                  lazy-rules
                  v-model="informaData.prefixId"
                  emit-value
                  map-options
                  hide-selected
                  fill-input
                  option-label="name"
                  :options="Ops.prefixOps"
                  option-value="name"
                  :label="`${'คำนำหน้าชื่อ'}`"
                  use-input
                  input-debounce="0"
                  @filter="(inputValue:string, doneFn:Function) => filterSelector(inputValue, doneFn,'prefixOps' ) "
                />
              </div>
              <div class="col-xs-6 col-sm-3 col-md-3">
                <q-input
                  :class="getClass(edit)"
                  hide-bottom-space
                  :outlined="edit"
                  dense
                  lazy-rules
                  :readonly="!edit"
                  :borderless="!edit"
                  v-model="informaData.firstname"
                  :label="`${'ชื่อ'}`"
                />
              </div>
              <div class="col-xs-6 col-sm-3 col-md-3">
                <q-input
                  :class="getClass(edit)"
                  hide-bottom-space
                  :outlined="edit"
                  dense
                  :readonly="!edit"
                  :borderless="!edit"
                  v-model="informaData.lastname"
                  lazy-rules
                  :label="`${'นามสกุล'}`"
                />
              </div>
              <div class="col-xs-6 col-sm-2 col-md-2">
                <datepicker
                  v-model="informaData.birthDate"
                  :locale="'th'"
                  autoApply
                  :enableTimePicker="false"
                  week-start="0"
                  :max-date="calculateMaxDate()"
                  :disabled="!edit"
                  @update:model-value="updateBirthDate"
                >
                  <template #year="{ year }">
                    {{ year + 543 }}
                  </template>
                  <template #year-overlay-value="{ value }">
                    {{ parseInt(value + 543) }}
                  </template>
                  <template #trigger>
                    <q-input
                      :class="getClass(edit)"
                      hide-bottom-space
                      :outlined="edit"
                      dense
                      :readonly="!edit"
                      :borderless="!edit"
                      :model-value="
                        informaData.birthDate == null
                          ? null
                          : date2Thai(informaData.birthDate)
                      "
                      :label="`${'วัน/เดือน/ปี เกิด'}`"
                    >
                      <template v-slot:prepend>
                        <q-icon
                          name="event"
                          class="cursor-pointer"
                          :style="
                            edit
                              ? 'color: var(--q-primary)'
                              : 'color: var(--q-grey)'
                          "
                        >
                        </q-icon>
                      </template>
                    </q-input>
                  </template>
                </datepicker>
              </div>
              <div class="col-xs-6 col-sm-2 col-md-2">
                <q-input
                  :class="getClass(false)"
                  hide-bottom-space
                  dense
                  lazy-rules
                  readonly
                  borderless
                  :style="!edit ? '' : 'padding:0 12px;'"
                  :model-value="informaData.age"
                  :label="`${'อายุ'}`"
                />
              </div>
              <div class="col-xs-6 col-sm-2 col-md-2">
                <selector
                  :hide-dropdown-icon="!edit"
                  hide-bottom-space
                  :class="getClass(edit)"
                  :readonly="!edit"
                  :borderless="!edit"
                  :outlined="edit"
                  dense
                  lazy-rules
                  v-model="informaData.genderId"
                  emit-value
                  map-options
                  hide-selected
                  fill-input
                  option-label="name"
                  :options="Ops.genderOps"
                  option-value="name"
                  :label="`${'เพศ'}`"
                  use-input
                  input-debounce="0"
                  @filter="(inputValue:string,doneFn:Function) => filterSelector(inputValue, doneFn,'genderOps') "
                />
              </div>
              <div class="col-xs-6 col-sm-2 col-md-2">
                <selector
                  :hide-dropdown-icon="!edit"
                  hide-bottom-space
                  :class="getClass(edit)"
                  :readonly="!edit"
                  :borderless="!edit"
                  :outlined="edit"
                  dense
                  lazy-rules
                  v-model="informaData.statusId"
                  emit-value
                  map-options
                  hide-selected
                  fill-input
                  option-label="name"
                  :options="Ops.statusOps"
                  option-value="name"
                  :label="`${'สถานภาพ'}`"
                  use-input
                  input-debounce="0"
                  @filter="(inputValue:string, doneFn:Function) => filterSelector(inputValue, doneFn,'statusOps' ) "
                />
              </div>
              <div class="col-xs-6 col-sm-2 col-md-2">
                <q-input
                  :class="getClass(edit)"
                  hide-bottom-space
                  :outlined="edit"
                  dense
                  lazy-rules
                  :readonly="!edit"
                  :borderless="!edit"
                  v-model="informaData.nationality"
                  :label="`${'สัญชาติ'}`"
                />
              </div>
              <div class="col-xs-6 col-sm-2 col-md-2">
                <q-input
                  :class="getClass(edit)"
                  hide-bottom-space
                  :outlined="edit"
                  dense
                  lazy-rules
                  :readonly="!edit"
                  :borderless="!edit"
                  v-model="informaData.ethnicity"
                  :label="`${'เชื้อชาติ'}`"
                />
              </div>
              <div class="col-xs-6 col-sm-2 col-md-2">
                <selector
                  :hide-dropdown-icon="!edit"
                  hide-bottom-space
                  :class="getClass(edit)"
                  :readonly="!edit"
                  :borderless="!edit"
                  :outlined="edit"
                  dense
                  lazy-rules
                  v-model="informaData.religionId"
                  emit-value
                  hide-selected
                  fill-input
                  map-options
                  option-label="name"
                  :options="Ops.religionOps"
                  option-value="name"
                  :label="`${'ศาสนา'}`"
                  use-input
                  input-debounce="0"
                  @filter="(inputValue:string,
                        doneFn:Function) => filterSelector(inputValue, doneFn,'religionOps'
                        ) "
                />
              </div>
              <div class="col-xs-6 col-sm-2 col-md-2">
                <selector
                  :hide-dropdown-icon="!edit"
                  hide-bottom-space
                  :class="getClass(edit)"
                  :readonly="!edit"
                  :borderless="!edit"
                  :outlined="edit"
                  dense
                  lazy-rules
                  v-model="informaData.bloodId"
                  emit-value
                  map-options
                  hide-selected
                  fill-input
                  option-label="name"
                  :options="Ops.bloodOps"
                  option-value="name"
                  :label="`${'หมู่เลือด'}`"
                  use-input
                  input-debounce="0"
                  @filter="(inputValue:string,
                        doneFn:Function) => filterSelector(inputValue, doneFn,'bloodOps'
                        ) "
                  clearable
                />
              </div>
              <div class="col-xs-6 col-sm-2 col-md-2">
                <q-input
                  hide-bottom-space
                  :outlined="edit"
                  dense
                  lazy-rules
                  type="tel"
                  :class="getClass(edit)"
                  :readonly="!edit"
                  :borderless="!edit"
                  v-model="informaData.tel"
                  :label="`${'เบอร์โทร'}`"
                  mask="##########"
                />
              </div>
              <div
                class="col-xs-6 col-sm-3 col-md-3"
                v-if="informaData.profileType == 'employee'"
              >
                <selector
                  :hide-dropdown-icon="!edit"
                  hide-bottom-space
                  :class="getClass(edit)"
                  :readonly="!edit"
                  :borderless="!edit"
                  :rules="[(val:string) => !!val || `${'กรุณาเลือก ประเภทการจ้าง'}`]"
                  :outlined="edit"
                  dense
                  lazy-rules
                  v-model="informaData.employeeType"
                  emit-value
                  map-options
                  option-label="name"
                  :options="Ops.employeeTypeOps"
                  option-value="id"
                  :label="`${'ประเภทการจ้าง'}`"
                  use-input
                  input-debounce="0"
                  @filter="(inputValue:string, doneFn:Function) => filterSelector(inputValue, doneFn,'employeeTypeOps' ) "
                />
              </div>
              <div
                class="col-xs-6 col-sm-3 col-md-3"
                v-if="informaData.profileType == 'employee'"
              >
                <selector
                  :hide-dropdown-icon="!edit"
                  hide-bottom-space
                  :class="getClass(edit)"
                  :readonly="!edit"
                  :borderless="!edit"
                  :rules="[(val:string) => !!val || `${'กรุณาเลือก ประเภทลูกจ้าง'}`]"
                  :outlined="edit"
                  dense
                  lazy-rules
                  v-model="informaData.employeeClass"
                  emit-value
                  map-options
                  option-label="name"
                  :options="Ops.employeeClassOps"
                  option-value="id"
                  :label="`${'ประเภทลูกจ้าง'}`"
                  use-input
                  input-debounce="0"
                  @filter="(inputValue:string, doneFn:Function) => filterSelector(inputValue, doneFn,'employeeClassOps' ) "
                />
              </div>
              <div class="col-xs-12">
                <div class="text-weight-bold">ตำแหน่ง/สังกัดเดิม</div>
              </div>
              <div class="col-xs-12">
                <q-input
                  :class="getClass(edit)"
                  :outlined="edit"
                  dense
                  lazy-rules
                  :readonly="!edit"
                  :borderless="!edit"
                  v-model="educationOld"
                  :rules="[(val:string) => !!val || `${'กรุณากรอกวุฒิ/สาขา'}`,]"
                  hide-bottom-space
                  :label="`${'วุฒิ/สาขา'}`"
                  type="textarea"
                  autogrow
                />
              </div>
              <div class="col-xs-12">
                <q-input
                  :class="getClass(edit)"
                  :outlined="edit"
                  dense
                  lazy-rules
                  :readonly="!edit"
                  :borderless="!edit"
                  v-model="organizationPositionOld"
                  :rules="[(val:string) => !!val || `${'กรุณากรอกตำแหน่ง/สังกัด'}`]"
                  hide-bottom-space
                  :label="`${'ตำแหน่ง/สังกัด'}`"
                  type="textarea"
                />
              </div>
              <div class="col-xs-6 col-sm-4">
                <q-input
                  :class="getClass(edit)"
                  :outlined="edit"
                  dense
                  lazy-rules
                  :readonly="!edit"
                  :borderless="!edit"
                  v-model="positionTypeOld"
                  :rules="[(val:string) => !!val || `${'กรุณากรอกตำแหน่งประเภท'}`]"
                  hide-bottom-space
                  :label="`${'ตำแหน่งประเภท'}`"
                />
              </div>
              <div class="col-xs-6 col-sm-4">
                <q-input
                  :class="getClass(edit)"
                  :outlined="edit"
                  dense
                  lazy-rules
                  :readonly="!edit"
                  :borderless="!edit"
                  v-model="positionLevelOld"
                  :rules="[(val:string) => !!val || `${'กรุณากรอกระดับตำแหน่ง'}`]"
                  hide-bottom-space
                  :label="`${'ระดับตำแหน่ง'}`"
                />
              </div>
              <div class="col-xs-6 col-sm-4">
                <q-input
                  :class="getClass(edit)"
                  :outlined="edit"
                  dense
                  lazy-rules
                  :readonly="!edit"
                  :borderless="!edit"
                  v-model="posNo"
                  :rules="[(val:string) => !!val || `${'กรุณากรอกเลขที่'}`]"
                  hide-bottom-space
                  :label="`${'เลขที่'}`"
                />
              </div>
              <!-- <div class="col-xs-6 col-sm-3">
                <q-input
                  :class="getClass(edit)"
                  v-model="salary"
                  :outlined="edit"
                  dense
                  :readonly="!edit"
                  hide-bottom-space
                  :borderless="!edit"
                  :label="`${'เงินเดือน'}`"
                  :rules="[(val:number) => !!val || `${'กรุณากรอกเงินเดือน'}`]"
                  lazy-rules
                  mask="###,###,###,###"
                  reverse-fill-mask
                />
              </div> -->
              <div class="col-xs-12">
                <q-input
                  :class="getClass(edit)"
                  :outlined="edit"
                  dense
                  lazy-rules
                  :readonly="!edit"
                  :borderless="!edit"
                  v-model="reason"
                  hide-bottom-space
                  :label="`${'หมายเหตุ '}`"
                  type="textarea"
                />
              </div>
            </div>
          </div>
        </div>
      </q-form>
    </q-card>

    <q-card
      v-if="rows.length > 0"
      bordered
      class="row col-12 text-dark q-my-sm"
    >
      <div class="bg-grey-1 q-pa-sm col-12 row items-center text-primary">
        <div class="q-pl-sm text-weight-bold text-dark">เอกสารเพิ่มเติม</div>
      </div>
      <div class="col-12"><q-separator /></div>
      <div class="col-12">
        <d-table
          :rows="rows"
          :columns="columns"
          row-key="fileName"
          hide-header
          hide-bottom
        >
          <template v-slot:body="props">
            <q-tr :props="props" class="cursor-pointer">
              <q-td key="no" :props="props">
                {{ props.rowIndex + 1 }}
              </q-td>
              <q-td key="fileName" :props="props">
                {{ props.row.fileName }}
              </q-td>
              <q-td key="btnMicrosoft" :props="props">
                <q-btn
                  type="a"
                  target="_blank"
                  :href="props.row.pathName"
                  flat
                  dense
                  round
                  color="red"
                  icon="picture_as_pdf"
                >
                  <q-tooltip>ไฟล์ PDF</q-tooltip>
                </q-btn>
              </q-td>
            </q-tr>
          </template>
        </d-table>
      </div>
    </q-card>
  </div>
</template>

<style lang="scss" scope>
.q-img {
  border-radius: 5px;
  height: 70px;
}
.text-top {
  color: gray;
  font-weight: 400;
  padding-bottom: 3px;
}
.text-detail {
  font-weight: 500;
}
</style>
