<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 { useProfileDataStore } from "@/modules/08_registryEmployee/store";
import CurrencyInput from "@/components/CurruncyInput.vue";
import type { QTableProps, QForm } from "quasar";
import type { ResponseTitle } from "@/modules/05_placement/interface/response/Receive";
import type { InformationOps } from "@/modules/04_registry/interface/index/Main";
import type {
  Information,
  DataOption,
} from "@/modules/04_registry/components/profileType";

import { defaultInformation } from "@/modules/04_registry/components/profileType";

import http from "@/plugins/http";
import config from "@/app.config";

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

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

const profileStore = useProfileDataStore();
const { changeRetireText } = profileStore;

const title = ref<ResponseTitle>({
  fullname: "",
  organizationPositionOld: "",
  positionLevelOld: "",
  positionTypeOld: "",
});

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

const myForm = ref<QForm | null>(null);
const edit = ref<boolean>(false);
const rows = ref<any[]>([]);
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 avatar = ref<string>("");
// const organization = ref<string>("");
// const date = ref<Date | null>(null);
const reason = ref<string>("");

const informaData = ref<Information>(defaultInformation);
const dateBefore = ref<Date>(new Date());
const defaultCitizenData = ref<string>("");
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: "งบประมาณกรุงเทพมหานคร" },
  ],
});

onMounted(async () => {
  await fetchPerson();
  await getData();
});

const fetchPerson = async () => {
  showLoader();
  await http
    .get(config.API.person)
    .then((res) => {
      const data = res.data.result;
      let optionbloodGroups: DataOption[] = [];
      data.bloodGroups.map((r: any) => {
        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: any) => {
        optiongenders.push({
          id: r.id.toString(),
          name: r.name.toString(),
        });
      });
      Ops.value.genderOps = optiongenders;
      OpsFilter.value.genderOps = optiongenders;

      let optionprefixs: DataOption[] = [];
      data.prefixs.map((r: any) => {
        optionprefixs.push({
          id: r.id.toString(),
          name: r.name.toString(),
        });
      });
      Ops.value.prefixOps = optionprefixs;
      OpsFilter.value.prefixOps = optionprefixs;

      let optionrelationships: DataOption[] = [];
      data.relationships.map((r: any) => {
        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: any) => {
        optionreligions.push({
          id: r.id.toString(),
          name: r.name.toString(),
        });
      });
      Ops.value.religionOps = optionreligions;
      OpsFilter.value.religionOps = optionreligions;
    })
    .catch((e: any) => {})
    .finally(() => {
      //   hideLoader();
    });
};

const getData = async () => {
  showLoader();
  await http
    .get(config.API.receiveDataId(paramsId.toString()))
    .then(async (res: any) => {
      const data = res.data.result;
      console.log(data);
      let list: any[] = [];
      if (data.docs.length > 0) {
        data.docs.map((doc: any) => {
          list.push({
            pathName: doc.pathName ?? "",
            fileName: doc.fileName ?? "",
          });
        });
      }
      rows.value = list;
      profileId.value = data.profileId;
      avatar.value = data.avatar ?? "";
      title.value.fullname = `${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: "",
        prefix: "",
        prefixId:
          (data.prefixId == "00000000-0000-0000-0000-000000000000"
            ? null
            : data.prefixId) ?? "",
        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 ?? "";

      await calRetire(new Date(dateToISO(new Date(data.dateOfBirth))));
      dateBefore.value = new Date(data.dateOfBirth);
    })
    .catch((e) => {
      messageError($q, e);
    })
    .finally(async () => {
      hideLoader();
    });
};

const cancel = async () => {
  edit.value = !edit.value;
  if (myForm.value !== null) {
    await getData();
    myForm.value.reset();
  }
};

const changeCardID = async (value: string | number | null) => {
  if (value != null && typeof value == "string") {
    if (value.length == 13 && value != defaultCitizenData.value) {
      await checkCitizen(value);
      //   informaData.value.cardid = defaultCitizenData.value;
    }
  }
};

const checkCitizen = async (id: string) => {
  console.log("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();
    });
};

const filterSelector = (val: any, update: Function, refData: string) => {
  switch (refData) {
    case "prefixOps":
      update(() => {
        Ops.value.prefixOps = OpsFilter.value.prefixOps.filter(
          (v: DataOption) => v.name.indexOf(val) > -1
        );
      });
      break;
    case "genderOps":
      update(() => {
        Ops.value.genderOps = OpsFilter.value.genderOps.filter(
          (v: DataOption) => v.name.indexOf(val) > -1
        );
      });
      break;
    case "bloodOps":
      update(() => {
        Ops.value.bloodOps = OpsFilter.value.bloodOps.filter(
          (v: DataOption) => v.name.indexOf(val) > -1
        );
      });
      break;
    case "statusOps":
      update(() => {
        Ops.value.statusOps = OpsFilter.value.statusOps.filter(
          (v: DataOption) => v.name.indexOf(val) > -1
        );
      });
      break;
    case "religionOps":
      update(() => {
        Ops.value.religionOps = OpsFilter.value.religionOps.filter(
          (v: DataOption) => v.name.indexOf(val) > -1
        );
      });
      break;
    case "employeeClassOps":
      update(() => {
        Ops.value.employeeClassOps = OpsFilter.value.employeeClassOps.filter(
          (v: DataOption) => v.name.indexOf(val) > -1
        );
      });
      break;
    case "employeeTypeOps":
      update(() => {
        Ops.value.employeeTypeOps = OpsFilter.value.employeeTypeOps.filter(
          (v: DataOption) => v.name.indexOf(val) > -1
        );
      });
      break;

    default:
      break;
  }
};

const handleDate = async (modelData: Date) => {
  informaData.value.birthDate = modelData;
  await calRetire(modelData);
};

const calRetire = async (birth: Date) => {
  const body = {
    birthDate: dateToISO(birth),
  };
  //   if (dateToISO(dateBefore.value) != dateToISO(birth)) {
  showLoader();
  await http
    .post(config.API.profileCalRetire, body)
    .then((res: any) => {
      const data = res.data.result;
      informaData.value.age = data.age;
      changeRetireText(data.retireDate);
      dateBefore.value = birth;
    })
    .catch((e: any) => {
      messageError($q, e);
      const retire = new Date(`${birth.getFullYear() + 60}-09-30`);
      informaData.value.birthDate = dateBefore.value;
      changeRetireText(date2Thai(retire));
    })
    .finally(() => {
      hideLoader();
    });
  //   }
};

const conditionSave = async () => {
  if (myForm.value !== null) {
    myForm.value.validate().then((success) => {
      if (success) {
        dialogConfirm(
          $q,
          async () => await saveData(),
          "ต้องการแก้ไขข้อมูลหรือไม่?",
          "แก้ไขข้อมูลเพื่อลงบัญชีแนบท้าย"
        );
      }
    });
  }
};

const saveData = async () => {
  const body = {
    citizenId: informaData.value.cardid,
    prefixId: informaData.value.prefixId,
    firstname: informaData.value.firstname,
    lastname: informaData.value.lastname,
    dateOfBirth:
      informaData.value.birthDate !== null
        ? dateToISO(informaData.value.birthDate)
        : null,
    genderId: informaData.value.genderId,
    nationality: informaData.value.nationality,
    race: informaData.value.ethnicity,
    religionId: informaData.value.religionId,
    bloodGroupId: informaData.value.bloodId,
    relationshipId: 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();
  await http
    .put(config.API.receiveDataId(route.params.id.toString()), body)
    .then((res: any) => {
      //   const data = res.data.result;
      //   console.log(data);
      success($q, "แก้ไขข้อมูลเพื่อลงบัญชีแนบท้ายสำเร็จ");
      edit.value = false;
    })
    .catch((e) => {
      messageError($q, e);
    })
    .finally(async () => {
      await getData();
      hideLoader();
    });
};

const getClass = (val: boolean) => {
  return {
    "full-width inputgreen cursor-pointer": val,
    "full-width cursor-pointer": !val,
  };
};
</script>

<template>
  <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.go(-1)"
    />
    รายละเอียดการรับโอนของ {{ title.fullname }}
  </div>
  <q-card bordered class="row col-12 text-dark">
    <div class="bg-grey-1 q-pa-sm col-12 row items-center text-primary">
      <div class="q-pl-sm text-weight-bold text-subtitle2">
        {{ title.fullname }}
      </div>
      <q-space />
      <!-- <q-btn
        outline
        color="blue"
        dense
        icon-right="mdi-open-in-new"
        class="q-px-sm"
        label="ดูข้อมูลทะเบียนประวัติ"
        @click="router.push(`/registry/${paramsId}`)"
      /> -->
    </div>
    <div class="col-12"><q-separator /></div>
    <div class="row col-12 q-pa-md">
      <div class="col-12 row bg-white q-col-gutter-md">
        <div class="col-xs-3 col-sm-2 col-md-1 row">
          <q-img :src="avatar" v-if="avatar !== ''" />
          <q-img v-else src="@/assets/avatar_user.jpg" />
        </div>
        <div class="col-xs-6 col-sm-3 row items-center">
          <div class="col-12 q-pl-md">
            <div class="col-12 text-top">ตำแหน่งในสายงาน</div>
            <div class="col-12 text-detail">
              {{ title.positionTypeOld }}
            </div>
          </div>
        </div>
        <div class="col-xs-6 col-sm-3 row items-center">
          <div class="col-12">
            <div class="col-12 text-top">ระดับ</div>
            <div class="col-12 text-detail">
              {{ title.positionLevelOld }}
            </div>
          </div>
        </div>
        <div class="col-xs-6 col-sm-3 row items-center">
          <div class="col-12">
            <div class="col-12 text-top">สังกัด</div>
            <div class="col-12 text-detail">
              {{ title.organizationPositionOld }}
            </div>
          </div>
        </div>
      </div>
    </div>
  </q-card>

  <q-card bordered class="row col-12 text-dark q-mt-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>
      <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')"
        />
      </div>
      <div class="q-gutter-sm" v-else>
        <q-btn
          outline
          color="public"
          dense
          class="q-px-sm"
          label="บันทึก"
          style="width: 80px"
          @click="conditionSave"
        />
        <q-btn
          outline
          color="red"
          dense
          class="q-px-sm"
          label="ยกเลิก"
          style="width: 80px"
          @click="cancel"
        />
      </div>
    </div>
    <div class="col-12"><q-separator /></div>
    <q-form ref="myForm">
      <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
                :rules="[
              (val:string) => !!val || `${'กรุณากรอก เลขประจำตัวประชาชน'}`,
              (val:string) =>
                val.length >= 13 ||
                `${'กรุณากรอกเลขประจำตัวประชาชนให้ครบ'}`,
            ]"
                :readonly="!edit"
                :borderless="!edit"
                label="เลขประจำตัวประชาชน"
                maxlength="13"
                mask="#############"
              />
              <!-- :rules="[(val:any) =>val.length != 13 ||`${'กรุณากรอกเลขประจำตัวประชาชนให้ครบ'}`,]" -->
            </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"
                :rules="[(val:string) => !!val || `${'กรุณาเลือก คำนำหน้าชื่อ'}`]"
                :outlined="edit"
                dense
                lazy-rules
                v-model="informaData.prefixId"
                emit-value
                map-options
                option-label="name"
                :options="Ops.prefixOps"
                option-value="id"
                :label="`${'คำนำหน้าชื่อ'}`"
                use-input
                input-debounce="0"
                @filter="(inputValue:any,
                        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"
                :rules="[(val:string) => !!val || `${'กรุณากรอก ชื่อ'}`]"
                :label="`${'ชื่อ'}`"
              />
            </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.lastname"
                :rules="[(val:string) => !!val || `${'กรุณากรอก นามสกุล'}`]"
                :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="new Date()"
                :disabled="!edit"
                @update:model-value="handleDate"
              >
                <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
                    lazy-rules
                    :readonly="!edit"
                    :borderless="!edit"
                    :model-value="
                      informaData.birthDate == null
                        ? null
                        : date2Thai(informaData.birthDate)
                    "
                    :rules="[(val:string) => !!val || `${'กรุณาเลือก วัน/เดือน/ปี เกิด'}`]"
                    :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
                option-label="name"
                :options="Ops.genderOps"
                option-value="id"
                :label="`${'เพศ'}`"
                use-input
                input-debounce="0"
                :rules="[(val:string) => !!val || `${'กรุณาเลือก เพศ'}`]"
                @filter="(inputValue:any,
                        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
                option-label="name"
                :options="Ops.statusOps"
                option-value="id"
                :label="`${'สถานภาพ'}`"
                use-input
                input-debounce="0"
                :rules="[(val:string) => !!val || `${'กรุณาเลือก สถานภาพ'}`]"
                @filter="(inputValue:any,
                        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="`${'สัญชาติ'}`"
                :rules="[(val:string) => !!val || `${'กรุณากรอก สัญชาติ'}`]"
              />
            </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="`${'เชื้อชาติ'}`"
                :rules="[(val:string) => !!val || `${'กรุณากรอก เชื้อชาติ'}`]"
              />
            </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
                map-options
                option-label="name"
                :options="Ops.religionOps"
                option-value="id"
                :label="`${'ศาสนา'}`"
                use-input
                input-debounce="0"
                :rules="[(val:string) => !!val || `${'กรุณาเลือก ศาสนา'}`]"
                @filter="(inputValue:any,
                        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
                option-label="name"
                :options="Ops.bloodOps"
                option-value="id"
                :label="`${'หมู่เลือด'}`"
                use-input
                input-debounce="0"
                :rules="[(val:string) => !!val || `${'กรุณาเลือก หมู่เลือด'}`]"
                @filter="(inputValue:any,
                        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="##########"
                :rules="[(val:string) => !!val || `${'กรุณากรอก เบอร์โทร'}`]"
              />
            </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:any,
                        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:any,
                        doneFn:Function) => filterSelector(inputValue, doneFn,'employeeClassOps'
                        ) "
              />
            </div>
            <div class="col-xs-12">
              <div class="text-weight-bold text-grey">
                ตำแหน่งและหน่วยงานเดิม
              </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) => !!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) => !!val || `${'กรุณากรอกตำแหน่ง/สังกัด'}`]"
                hide-bottom-space
                :label="`${'ตำแหน่ง/สังกัด'}`"
                type="textarea"
              />
            </div>
            <div class="col-xs-6 col-sm-3">
              <q-input
                :class="getClass(edit)"
                :outlined="edit"
                dense
                lazy-rules
                :readonly="!edit"
                :borderless="!edit"
                v-model="positionTypeOld"
                :rules="[(val) => !!val || `${'กรุณากรอกตำแหน่งประเภท'}`]"
                hide-bottom-space
                :label="`${'ตำแหน่งประเภท'}`"
              />
            </div>
            <div class="col-xs-6 col-sm-3">
              <q-input
                :class="getClass(edit)"
                :outlined="edit"
                dense
                lazy-rules
                :readonly="!edit"
                :borderless="!edit"
                v-model="positionLevelOld"
                :rules="[(val) => !!val || `${'กรุณากรอกระดับ'}`]"
                hide-bottom-space
                :label="`${'ระดับ'}`"
              />
            </div>
            <div class="col-xs-6 col-sm-3">
              <q-input
                :class="getClass(edit)"
                :outlined="edit"
                dense
                lazy-rules
                :readonly="!edit"
                :borderless="!edit"
                v-model="posNo"
                :rules="[(val) => !!val || `${'กรุณากรอกเลขที่'}`]"
                hide-bottom-space
                :label="`${'เลขที่'}`"
              />
            </div>
            <div class="col-xs-6 col-sm-3">
              <!-- <q-input
                :class="getClass(edit)"
                :outlined="edit"
                dense
                lazy-rules
                :readonly="!edit"
                :borderless="!edit"
                v-model="salary"
                :rules="[(val) => !!val || `${'กรุณากรอกเงินเดือน'}`]"
                hide-bottom-space
                :label="`${'เงินเดือน'}`"
                type="number"
              /> -->
              <CurrencyInput
                v-model="salary"
                :edit="edit"
                :options="{
                  currency: 'THB',
                }"
                :label="`${'เงินเดือน'}`"
              />
            </div>
            <div class="col-xs-12">
              <q-input
                :class="getClass(edit)"
                :outlined="edit"
                dense
                lazy-rules
                :readonly="!edit"
                :borderless="!edit"
                v-model="reason"
                :rules="[(val) => !!val || `${'กรุณากรอกหมายเหตุ '}`]"
                hide-bottom-space
                :label="`${'หมายเหตุ '}`"
                type="textarea"
              />
            </div>
          </div>
        </div>
      </div>
    </q-form>
    <q-card bordered class="row col-12 text-dark q-mt-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>
  </q-card>
</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>
