เพิ่ม currency input

This commit is contained in:
AnandaTon 2023-10-19 13:47:54 +07:00
parent e300009dc3
commit cd1a733ef6
4 changed files with 235 additions and 246 deletions

View file

@ -26,7 +26,10 @@ import { ref, useSlots, watch } from "vue";
const slots = ref<any>(useSlots()); const slots = ref<any>(useSlots());
const props = defineProps({ const props = defineProps({
modelValue: Number, modelValue: {
type: Number,
default: undefined,
},
dense: { dense: {
type: Boolean, type: Boolean,
default: true, default: true,

View file

@ -0,0 +1,60 @@
<template>
<q-input
ref="inputRef"
v-model="formattedValue"
:dense="dense"
:outlined="edit"
:class="
edit == true
? 'full-width inputgreen cursor-pointer'
: 'full-width cursor-pointer'
"
:readonly="!edit"
:borderless="!edit"
hide-bottom-space
>
<template v-for="slot in slots">
<slot :name="slot" />
</template>
</q-input>
</template>
<script setup lang="ts">
import { useCurrencyInput } from "vue-currency-input";
import { ref, useSlots, watch } from "vue";
const slots = ref<any>(useSlots());
const props = defineProps({
modelValue: {
type: Number,
default: undefined,
},
dense: {
type: Boolean,
default: true,
},
edit: {
type: Boolean,
},
});
const { inputRef, formattedValue, setValue } = useCurrencyInput({
locale: "th-TH",
currency: "THB",
currencyDisplay: "hidden" as any,
hideCurrencySymbolOnFocus: true,
hideGroupingSeparatorOnFocus: true,
hideNegligibleDecimalDigitsOnFocus: true,
autoDecimalDigits: false,
useGrouping: true,
accountingSign: false,
});
watch(
() => props.modelValue,
(value: any) => {
setValue(value);
}
);
</script>

View file

@ -1,212 +1,138 @@
<!-- card ตำแหนงปจจ --> <!-- card ตำแหนงปจจ -->
<template> <template>
<HeaderTop <HeaderTop
v-model:edit="edit" v-model:edit="edit"
header="ตำแหน่งปัจจุบัน" header="ตำแหน่งปัจจุบัน"
icon="mdi-briefcase" icon="mdi-briefcase"
:addData="true" :addData="true"
:editOnly="false" :editOnly="false"
:editData="false" :editData="false"
/> />
<q-form ref="myform"> <q-form ref="myform">
<div class="row col-12 items-center"> <div class="row col-12 items-center">
<div class="col-12 q-pb-sm"> <div class="col-12 q-pb-sm">
<q-radio <q-radio
v-model="defaultOccupation.positionType" v-model="defaultOccupation.positionType"
label="ลูกจ้างประจำ" label="ลูกจ้างประจำ"
color="teal" color="teal"
val="prem" val="prem"
:disable=" :disable="!(status == 'checkRegister' || status == 'payment')"
!(status == 'checkRegister' || status == 'payment') />
" <q-radio
/> v-model="defaultOccupation.positionType"
<q-radio label="ลูกจ้างชั่วคราว"
v-model="defaultOccupation.positionType" color="teal"
label="ลูกจ้างชั่วคราว" val="temp"
color="teal" :disable="!(status == 'checkRegister' || status == 'payment')"
val="temp" />
:disable=" <q-radio
!(status == 'checkRegister' || status == 'payment') v-model="defaultOccupation.positionType"
" label="ผู้ปฏิบัติงานอื่นในกรุงเทพมหานคร"
/> color="teal"
<q-radio val="other"
v-model="defaultOccupation.positionType" :disable="!(status == 'checkRegister' || status == 'payment')"
label="ผู้ปฏิบัติงานอื่นในกรุงเทพมหานคร" />
color="teal" </div>
val="other" <div class="col-12 row q-col-gutter-sm">
:disable=" <div class="col-4">
!(status == 'checkRegister' || status == 'payment') <q-input
" :class="getClass(status == 'checkRegister' || status == 'payment')"
/> :outlined="status == 'checkRegister' || status == 'payment'"
</div> dense
<div class="col-12 row q-col-gutter-sm"> lazy-rules
<div class="col-4"> autogrow
<q-input :readonly="!(status == 'checkRegister' || status == 'payment')"
:class=" :borderless="!(status == 'checkRegister' || status == 'payment')"
getClass( v-model="defaultOccupation.position"
status == 'checkRegister' || status == 'payment' :rules="[(val) => !!val || `${'กรุณากรอก ชื่อตำแหน่ง'}`]"
) :label="`${'ชื่อตำแหน่ง'}`"
" />
:outlined=" </div>
status == 'checkRegister' || status == 'payment' <div class="col-4">
" <CurrencyInput
dense :class="getClass(status == 'checkRegister' || status == 'payment')"
lazy-rules :outlined="status == 'checkRegister' || status == 'payment'"
autogrow :options="{
:readonly=" currency: 'THB',
!(status == 'checkRegister' || status == 'payment') }"
" v-model="defaultOccupation.salary"
:borderless=" :readonly="!(status == 'checkRegister' || status == 'payment')"
!(status == 'checkRegister' || status == 'payment') :borderless="!(status == 'checkRegister' || status == 'payment')"
" :rules="[(val:number| undefined) => !!val || `${'กรุณากรอก เงินเดือน'}`]"
v-model="defaultOccupation.position" :label="`${'เงินเดือน'}`"
:rules="[ />
(val) => !!val || `${'กรุณากรอก ชื่อตำแหน่ง'}`, </div>
]"
:label="`${'ชื่อตำแหน่ง'}`"
/>
</div>
<div class="col-4">
<q-input
:class="
getClass(
status == 'checkRegister' || status == 'payment'
)
"
:outlined="
status == 'checkRegister' || status == 'payment'
"
dense
lazy-rules
type="number"
autogrow
:readonly="
!(status == 'checkRegister' || status == 'payment')
"
:borderless="
!(status == 'checkRegister' || status == 'payment')
"
v-model="defaultOccupation.salary"
:rules="[(val) => !!val || `${'กรุณากรอก เงินเดือน'}`]"
:label="`${'เงินเดือน'}`"
/>
</div>
<div class="col-4"> <div class="col-4">
<q-input <q-input
:class=" :class="getClass(status == 'checkRegister' || status == 'payment')"
getClass( :outlined="status == 'checkRegister' || status == 'payment'"
status == 'checkRegister' || status == 'payment' dense
) lazy-rules
" autogrow
:outlined=" :readonly="!(status == 'checkRegister' || status == 'payment')"
status == 'checkRegister' || status == 'payment' :borderless="!(status == 'checkRegister' || status == 'payment')"
" v-model="defaultOccupation.group"
dense :rules="[(val) => !!val || `${'กรุณากรอก กลุ่ม/ฝ่าย'}`]"
lazy-rules :label="`${'กลุ่ม/ฝ่าย'}`"
autogrow />
:readonly=" </div>
!(status == 'checkRegister' || status == 'payment') <div class="col-4">
" <q-input
:borderless=" :class="getClass(status == 'checkRegister' || status == 'payment')"
!(status == 'checkRegister' || status == 'payment') :outlined="status == 'checkRegister' || status == 'payment'"
" dense
v-model="defaultOccupation.group" lazy-rules
:rules="[(val) => !!val || `${'กรุณากรอก กลุ่ม/ฝ่าย'}`]" autogrow
:label="`${'กลุ่ม/ฝ่าย'}`" :readonly="!(status == 'checkRegister' || status == 'payment')"
/> :borderless="!(status == 'checkRegister' || status == 'payment')"
</div> v-model="defaultOccupation.pile"
<div class="col-4"> :rules="[(val) => !!val || `${'กรุณากรอก กอง'}`]"
<q-input :label="`${'กอง'}`"
:class=" />
getClass( </div>
status == 'checkRegister' || status == 'payment' <div class="col-4">
) <q-input
" :class="getClass(status == 'checkRegister' || status == 'payment')"
:outlined=" :outlined="status == 'checkRegister' || status == 'payment'"
status == 'checkRegister' || status == 'payment' dense
" lazy-rules
dense autogrow
lazy-rules :readonly="!(status == 'checkRegister' || status == 'payment')"
autogrow :borderless="!(status == 'checkRegister' || status == 'payment')"
:readonly=" v-model="defaultOccupation.org"
!(status == 'checkRegister' || status == 'payment') :rules="[(val) => !!val || `${'กรุณากรอก สังกัด'}`]"
" :label="`${'สังกัด'}`"
:borderless=" />
!(status == 'checkRegister' || status == 'payment') </div>
" <div class="col-4">
v-model="defaultOccupation.pile" <q-input
:rules="[(val) => !!val || `${'กรุณากรอก กอง'}`]" :class="getClass(status == 'checkRegister' || status == 'payment')"
:label="`${'กอง'}`" :outlined="status == 'checkRegister' || status == 'payment'"
/> dense
</div> :counter="
<div class="col-4"> status == 'checkRegister' || status == 'payment' ? true : false
<q-input "
:class=" maxlength="10"
getClass( lazy-rules
status == 'checkRegister' || status == 'payment' type="tel"
) mask="##########"
" autogrow
:outlined=" :readonly="!(status == 'checkRegister' || status == 'payment')"
status == 'checkRegister' || status == 'payment' :borderless="!(status == 'checkRegister' || status == 'payment')"
" v-model="defaultOccupation.tel"
dense :rules="[
lazy-rules (val) => !!val || '* กรุณากรอกข้อมูลหมายเลขโทรศัพท์',
autogrow (val) =>
:readonly=" (val.length >= 9 && val.length <= 10 && val.startsWith('0')) ||
!(status == 'checkRegister' || status == 'payment') 'กรุณากรอกข้อมูลหมายเลขโทรศัพท์ให้ถูกต้อง',
" ]"
:borderless=" :label="`${'เบอร์โทรที่ทำงาน'}`"
!(status == 'checkRegister' || status == 'payment') />
" </div>
v-model="defaultOccupation.org" </div>
:rules="[(val) => !!val || `${'กรุณากรอก สังกัด'}`]" </div>
:label="`${'สังกัด'}`" </q-form>
/>
</div>
<div class="col-4">
<q-input
:class="
getClass(
status == 'checkRegister' || status == 'payment'
)
"
:outlined="
status == 'checkRegister' || status == 'payment'
"
dense
:counter="
status == 'checkRegister' || status == 'payment'
? true
: false
"
maxlength="10"
lazy-rules
type="tel"
mask="##########"
autogrow
:readonly="
!(status == 'checkRegister' || status == 'payment')
"
:borderless="
!(status == 'checkRegister' || status == 'payment')
"
v-model="defaultOccupation.tel"
:rules="[
(val) =>
!!val || '* กรุณากรอกข้อมูลหมายเลขโทรศัพท์',
(val) =>
(val.length >= 9 &&
val.length <= 10 &&
val.startsWith('0')) ||
'กรุณากรอกข้อมูลหมายเลขโทรศัพท์ให้ถูกต้อง',
]"
:label="`${'เบอร์โทรที่ทำงาน'}`"
/>
</div>
</div>
</div>
</q-form>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted, watch } from "vue"; import { ref, onMounted, watch } from "vue";
@ -214,24 +140,24 @@ import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import type { Occupation } from "@/modules/03_recruiting/interface/index/Main"; import type { Occupation } from "@/modules/03_recruiting/interface/index/Main";
import { import {
defaultOccupation, defaultOccupation,
changeData, changeData,
} from "@/modules/03_recruiting/interface/index/Main"; } from "@/modules/03_recruiting/interface/index/Main";
import HeaderTop from "@/modules/03_recruiting/components/top.vue"; import HeaderTop from "@/modules/03_recruiting/components/top.vue";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
import CurrencyInput from "@/modules/03_recruiting/components/CurruncyInput.vue";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
const props = defineProps({ const props = defineProps({
status: { status: {
type: String, type: String,
required: true, required: true,
}, },
form: { form: {
type: Object, type: Object,
required: true, required: true,
}, },
}); });
const $q = useQuasar(); const $q = useQuasar();
@ -246,43 +172,43 @@ const { messageError, showLoader, hideLoader } = mixin;
const emit = defineEmits(["update:form"]); const emit = defineEmits(["update:form"]);
watch(myform, async (count: any, prevCount: any) => { watch(myform, async (count: any, prevCount: any) => {
emit("update:form", count); emit("update:form", count);
}); });
watch(defaultOccupation, async (count: Occupation, prevCount: Occupation) => { watch(defaultOccupation, async (count: Occupation, prevCount: Occupation) => {
await changeData("occupation", count); await changeData("occupation", count);
}); });
onMounted(async () => { onMounted(async () => {
await fetchData(); await fetchData();
}); });
const fetchData = async () => { const fetchData = async () => {
showLoader(); showLoader();
await http await http
.get(config.API.candidateOccupation(candidateId.value)) .get(config.API.candidateOccupation(candidateId.value))
.then((res) => { .then((res) => {
const data = res.data.result; const data = res.data.result;
defaultOccupation.value.org = data.occupationOrg; defaultOccupation.value.org = data.occupationOrg;
defaultOccupation.value.pile = data.occupationPile; defaultOccupation.value.pile = data.occupationPile;
defaultOccupation.value.group = data.occupationGroup; defaultOccupation.value.group = data.occupationGroup;
defaultOccupation.value.salary = data.occupationSalary; defaultOccupation.value.salary = data.occupationSalary;
defaultOccupation.value.position = data.occupationPosition; defaultOccupation.value.position = data.occupationPosition;
defaultOccupation.value.positionType = data.occupationPositionType; defaultOccupation.value.positionType = data.occupationPositionType;
defaultOccupation.value.tel = data.occupationTelephone; defaultOccupation.value.tel = data.occupationTelephone;
}) })
.catch((e) => { .catch((e) => {
messageError($q, e); messageError($q, e);
}) })
.finally(() => { .finally(() => {
hideLoader(); hideLoader();
}); });
}; };
const getClass = (val: boolean) => { const getClass = (val: boolean) => {
return { return {
"full-width inputgreen cursor-pointer": val, "full-width inputgreen cursor-pointer": val,
"full-width cursor-pointer": !val, "full-width cursor-pointer": !val,
}; };
}; };
</script> </script>

View file

@ -65,7 +65,7 @@ interface Occupation {
org: string | null; org: string | null;
pile: string | null; pile: string | null;
group: string | null; group: string | null;
salary: string | null; salary: number | undefined;
position: string | null; position: string | null;
positionType: string | null; positionType: string | null;
tel: string | null; tel: string | null;
@ -229,7 +229,7 @@ const defaultOccupation = ref<Occupation>({
org: null, org: null,
pile: null, pile: null,
group: null, group: null,
salary: null, salary: undefined,
position: null, position: null,
positionType: null, positionType: null,
tel: null, tel: null,