2 lines
9.0 KiB
JavaScript
2 lines
9.0 KiB
JavaScript
import{Q as g}from"./QBtn-Bl8V3g1s.js";import{Q as L}from"./QSeparator-D1JYPgu2.js";import{Q as O,a as x,e as R,b as N,f as ve,c as ge,A as be,g as Ce}from"./AddressModal-33esE-yw.js";import{Q as ye,b as _e,c as I}from"./QList-CPm2VhlR.js";import{Q as Ve}from"./QFile-DVWif_Vn.js";import{Q as H,a as j,_ as Ne}from"./IndexPage-CTPnu3LT.js";import{u as ke}from"./children-Dx8AhorD.js";import{I as we,r as b,G as J,a as Ae,o as qe,e as T,w as P,J as M,M as c,K as u,N as a,O as i,Q as m,U as r,R as C,W as k,S as Fe,T as De,P as E}from"./index-BFHpqQMc.js";import{u as Qe}from"./vue-i18n.runtime-CGMLV8bE.js";import"./use-router-link-niyq3CDa.js";import"./LocalStorage-Bg7wwOV9.js";const xe={class:"row items-center"},Te={class:"col"},Me={class:"text-h6"},Ue={class:"col-auto"},$e={class:"row items-center"},Se={class:"col"},Be={class:"col-auto"},Le={key:0,class:"q-mt-md"},Oe={class:"text-subtitle2 q-mb-sm"},Re={class:"text-weight-bold"},Ie={key:1,class:"q-mt-md"},He={class:"text-h6"},je={class:"row items-center q-gutter-sm"},Je={class:"col"},Pe={key:0,class:"q-mt-sm"},Ee={key:0,class:"q-ml-lg q-mt-sm"},Ye={class:"row items-center q-gutter-sm q-mb-xs"},ze={class:"col-auto"},Ge={class:"col"},Ke={class:"text-caption"},We={class:"q-pa-sm bg-grey-2 q-pa-md"},Xe={key:0,class:"text-negative"},Ze={key:1},el=we({__name:"ChildrenStep",props:{step:{}},emits:["next","prev"],setup(Y,{expose:z,emit:G}){const U=Y,$=G,{t:n}=Qe(),h=ke(),F=b(null),K=(l="Required")=>{const e=n("validation.required");return e&&e!=="validation.required"?e:l},D=l=>e=>{const t=K();return e==null?t:typeof e=="string"?e.trim()!==""||t:Array.isArray(e)?e.length>0||t:!0},S=(l,e)=>t=>{const d=`${n("validation.minLength")||`Minimum ${l} chars`}`;return t==null?!0:typeof t=="string"?t.trim().length>=l||d:!0},W=(l,e)=>t=>{const d=n("validation.maxAgeFromJan1"),v=typeof d=="string"?d:`Age must be at most ${l} years from Jan 1 of this year`;if(!t)return!0;let q;if(t instanceof Date)q=t;else if(typeof t=="string")q=new Date(t);else return v;if(isNaN(q.getTime()))return v;const fe=new Date,pe=new Date(fe.getFullYear()-l,0,1);return q>=pe||v};function B(l){const e=s[l]??"",t=typeof e=="string"?e.trim():String(e);if(!t){s[l]="";return}s[l]=t.charAt(0).toUpperCase()+t.slice(1)}function X(l){if(!l)return"";const e=new Date(l);if(isNaN(e.getTime()))return"";const t=new Date;let d=t.getFullYear()-e.getFullYear();const v=t.getMonth()-e.getMonth();return(v<0||v===0&&t.getDate()<e.getDate())&&d--,d<0?"":`${d} anni`}const Q=()=>({firstName:"",lastName:"",birthDate:"",sameHousehold:!0,school:"",careCosts:null,alimentiVersati:!1}),o=J({hasChildren:!1,children:[],moreThanFiveChildrenNote:""}),w=b(!1),f=b(!1),y=b(null),s=J({...Q()}),A=b(null),V=b(!1),_=b(null),Z=Ae(()=>{const l=_.value;return l?ie(l):""}),ee=[D(),S(2)],le=[D(),S(2)],te=[D(),W(25)];async function ae(){y.value=null,Object.assign(s,Q()),s.address=null,f.value=!0,await T(),A.value?.resetValidation?.()}async function se(l){y.value=l;const e=o.children[l];Object.assign(s,{...Q(),...e}),s.address=e.address||null,_.value=s.address||null,f.value=!0,await T(),A.value?.resetValidation?.()}function ne(){f.value=!1}function oe(){s.address?_.value=s.address:_.value=null,V.value=!0}function re(){V.value=!1}function ie(l){function e(d){return typeof d=="object"&&d!==null&&Object.prototype.hasOwnProperty.call(d,"name")}const t=l.country&&typeof l.country=="object"&&e(l.country)?l.country.name:l.country||"";return`${l.street||""} ${l.zip||""} ${l.city||""} ${t||""}`}function de(l){_.value=l,s.address=l,V.value=!1}async function ue(){try{if(await(A.value?.validate?.()??!0)===!1)return}catch{return}if(y.value===null){if(o.children.length>=5){f.value=!1,w.value=!0;return}if(o.children.push({...s}),h.setChildren(p()),o.children.length===5){f.value=!1,w.value=!0;return}}else o.children[y.value]={...s},h.setChildren(p());f.value=!1}function ce(l){o.children.splice(l,1),h.setChildren(p())}qe(async()=>{const l=h.getChildren();if(l){if(o.hasChildren=!!l.hasChildren,Array.isArray(l.children)&&l.children.length)for(let e=0;e<5;e++)l.children[e]&&(o.children[e]={...o.children[e],...l.children[e]});o.moreThanFiveChildrenNote=l.moreThanFiveChildrenNote||"",(l.moreThanFiveChildrenNote||Array.isArray(l.children)&&l.children.length>=5)&&(w.value=!0)}await T(),F.value?.resetValidation?.()}),P(()=>o.hasChildren,()=>{h.setChildren(p())}),P(()=>o.moreThanFiveChildrenNote,()=>{h.setChildren(p())});function p(){const l={hasChildren:o.hasChildren,children:o.children.filter(e=>e.firstName||e.lastName||e.birthDate),moreThanFiveChildrenNote:o.moreThanFiveChildrenNote};return l.children=l.children.slice(0,5),l}async function me(){try{if(await(F.value?.validate?.()??!0)===!1)return}catch{return}const l=p();h.setChildren(l),$("next",U.step?.next)}function he(){const l=p();h.setChildren(l),$("prev",U.step?.prev)}return z({buildPayload:p}),(l,e)=>(c(),M(j,{flat:"",class:"full-width q-pa-none"},{default:u(()=>[a(H,{class:"full-width"},{default:u(()=>[i("div",xe,[i("div",Te,[i("div",Me,m(r(n)("CHD")),1)]),i("div",Ue,[a(g,{flat:"",label:r(n)("button.prev"),onClick:he,class:"q-mr-sm"},null,8,["label"]),a(g,{color:"primary",label:r(n)("button.next"),onClick:me},null,8,["label"])])]),a(L,{class:"q-my-sm"}),a(O,{ref_key:"formRef",ref:F,class:"q-gutter-md q-mt-md"},{default:u(()=>[i("div",$e,[i("div",Se,[a(x,{modelValue:o.hasChildren,"onUpdate:modelValue":e[0]||(e[0]=t=>o.hasChildren=t),label:r(n)("children.hasChildren")},null,8,["modelValue","label"])]),i("div",Be,[o.hasChildren?(c(),M(g,{key:0,disable:o.children.length>=5,color:"primary",label:`+ ${r(n)("children.addChild")}`,onClick:ae},null,8,["disable","label"])):k("",!0)])]),o.hasChildren?(c(),C("div",Le,[i("div",Oe,m(r(n)("children.listTitle")),1),a(ye,{bordered:""},{default:u(()=>[(c(!0),C(Fe,null,De(o.children,(t,d)=>(c(),M(_e,{key:d,clickable:""},{default:u(()=>[a(I,null,{default:u(()=>[a(R,null,{default:u(()=>[i("span",Re,m(t.firstName||"-")+" "+m(t.lastName||""),1)]),_:2},1024),a(R,null,{default:u(()=>[E(m(X(t.birthDate)),1)]),_:2},1024)]),_:2},1024),a(I,{side:"",class:"row items-center q-gutter-sm"},{default:u(()=>[a(g,{dense:"",flat:"",round:"",icon:"edit",onClick:v=>se(d)},null,8,["onClick"]),a(g,{dense:"",flat:"",round:"",icon:"delete",color:"negative",onClick:v=>ce(d)},null,8,["onClick"])]),_:2},1024)]),_:2},1024))),128))]),_:1})])):k("",!0),w.value||o.children.length>=5?(c(),C("div",Ie,[a(N,{type:"textarea",modelValue:o.moreThanFiveChildrenNote,"onUpdate:modelValue":e[1]||(e[1]=t=>o.moreThanFiveChildrenNote=t),label:r(n)("children.moreThanFiveChildrenNote"),autogrow:""},null,8,["modelValue","label"])])):k("",!0)]),_:1},512),a(ve,{modelValue:f.value,"onUpdate:modelValue":e[12]||(e[12]=t=>f.value=t),persistent:""},{default:u(()=>[a(j,{class:"contained-card child-modal"},{default:u(()=>[a(H,null,{default:u(()=>[i("div",He,m(y.value===null?r(n)("children.addChild"):r(n)("children.editChild")),1),a(L,{class:"q-my-sm"}),a(O,{ref_key:"modalFormRef",ref:A,class:"q-gutter-md q-mt-md"},{default:u(()=>[a(N,{modelValue:s.firstName,"onUpdate:modelValue":e[2]||(e[2]=t=>s.firstName=t),label:r(n)("children.firstName"),rules:ee,onBlur:e[3]||(e[3]=t=>B("firstName"))},null,8,["modelValue","label"]),a(N,{modelValue:s.lastName,"onUpdate:modelValue":e[4]||(e[4]=t=>s.lastName=t),label:r(n)("children.lastName"),rules:le,onBlur:e[5]||(e[5]=t=>B("lastName"))},null,8,["modelValue","label"]),a(N,{modelValue:s.birthDate,"onUpdate:modelValue":e[6]||(e[6]=t=>s.birthDate=t),type:"date",label:r(n)("children.birthDate"),rules:te},null,8,["modelValue","label"]),i("div",je,[i("div",Je,[a(x,{modelValue:s.sameHousehold,"onUpdate:modelValue":e[7]||(e[7]=t=>s.sameHousehold=t),label:r(n)("children.sameHousehold")},null,8,["modelValue","label"]),s.sameHousehold?k("",!0):(c(),C("div",Pe,[a(x,{modelValue:s.alimentiVersati,"onUpdate:modelValue":e[8]||(e[8]=t=>s.alimentiVersati=t),label:r(n)("children.alimentiVersati")},null,8,["modelValue","label"])]))])]),s.sameHousehold?k("",!0):(c(),C("div",Ee,[i("div",Ye,[i("div",ze,[a(g,{dense:"",flat:"",round:"",icon:"edit",onClick:oe},{default:u(()=>[a(ge,{class:"bg-primary text-white"},{default:u(()=>[E(m(r(n)("children.editAddress")),1)]),_:1})]),_:1})]),i("div",Ge,[i("div",Ke,m(r(n)("children.addressLabel")),1)])]),i("div",We,[s.address?(c(),C("div",Ze,m(Z.value),1)):(c(),C("div",Xe,m(r(n)("validation.insertAddress")),1))])])),a(N,{modelValue:s.school,"onUpdate:modelValue":e[9]||(e[9]=t=>s.school=t),label:r(n)("children.school")},null,8,["modelValue","label"]),a(Ve,{modelValue:s.careCosts,"onUpdate:modelValue":e[10]||(e[10]=t=>s.careCosts=t),label:r(n)("children.careCosts"),"hide-upload-btn":""},null,8,["modelValue","label"])]),_:1},512)]),_:1}),a(be,{modelValue:V.value,"onUpdate:modelValue":e[11]||(e[11]=t=>V.value=t),modelAddress:_.value,allowForeign:!1,onSave:de,onCancel:re},null,8,["modelValue","modelAddress"]),a(Ce,{align:"right"},{default:u(()=>[a(g,{flat:"",label:r(n)("button.cancel"),onClick:ne},null,8,["label"]),a(g,{color:"primary",label:y.value===null?r(n)("button.add"):r(n)("button.save"),onClick:ue},null,8,["label"])]),_:1})]),_:1})]),_:1},8,["modelValue"])]),_:1})]),_:1}))}}),ml=Ne(el,[["__scopeId","data-v-9e040cdc"]]);export{ml as default};
|