芝麻web文件管理V1.00
编辑当前文件:/home/pulsehostuk9/public_html/invoicer.pulsehost.co.uk/public/build/assets/Create-DPfMJMlk.js
import{at as X,au as Z,F as ee,E as te,v as ae,L as ne,e as oe,M as se,f as $,k as c,j as le,Q as re,r as s,o as y,m as V,w as l,a as o,b as C,l as a,p as U,t as k,K as P,J as ie,q as ue,g as h,h as me,I as ce,ai as de}from"./main-WS8l16KQ.js";import{_ as pe}from"./ItemUnitModal-D55JMGib.js";const ve={__name:"Create",setup(_e){const t=X(),S=Z(),v=ee(),E=te(),{t:d}=ae.useI18n(),f=ne(),N=oe(),q=se(),_=$(!1),B=$(E.selectedCompanySettings.tax_per_item);let r=$(!1);t.$reset(),j();const b=c({get:()=>t.currentItem.price/100,set:e=>{t.currentItem.price=Math.round(e*100)}}),T=c({get:()=>{var e,n;return(n=(e=t==null?void 0:t.currentItem)==null?void 0:e.taxes)==null?void 0:n.map(m=>{if(m)return{...m,tax_type_id:m.id,tax_name:m.name+" ("+m.percent+"%)"}})},set:e=>{t.currentItem.taxes=e}}),g=c(()=>f.name==="items.edit"),w=c(()=>g.value?d("items.edit_item"):d("items.new_item")),L=c(()=>S.taxTypes.map(e=>({...e,tax_type_id:e.id,tax_name:e.name+" ("+e.percent+"%)"}))),z=c(()=>B.value==="YES"),A=c(()=>({currentItem:{name:{required:h.withMessage(d("validation.required"),me),minLength:h.withMessage(d("validation.name_min_length",{count:2}),ce(2))},description:{maxLength:h.withMessage(d("validation.description_maxlength"),de(65e3))}}})),u=le(A,t);async function G(){v.openModal({title:d("settings.customization.items.add_item_unit"),componentName:"ItemUnitModal",size:"sm"})}async function j(){if(r.value=!0,await t.fetchItemUnits({limit:"all"}),q.hasAbilities(re.VIEW_TAX_TYPE)&&await S.fetchTaxTypes({limit:"all"}),g.value){let e=f.params.id;await t.fetchItem(e),t.currentItem.tax_per_item===1?B.value="YES":B.value="NO"}r.value=!1}async function D(){if(u.value.currentItem.$touch(),u.value.currentItem.$invalid)return!1;_.value=!0;try{let n={id:f.params.id,...t.currentItem};t.currentItem&&t.currentItem.taxes&&(n.taxes=t.currentItem.taxes.map(p=>({tax_type_id:p.tax_type_id,amount:b.value*p.percent,percent:p.percent,name:p.name,collective_tax:0}))),await(g.value?t.updateItem:t.addItem)(n),_.value=!1,N.push("/admin/items"),e()}catch{_.value=!1;return}function e(){v.closeModal(),setTimeout(()=>{t.resetCurrentItem(),v.$reset(),u.value.$reset()},300)}}return(e,n)=>{const m=s("BaseBreadcrumbItem"),p=s("BaseBreadcrumb"),Y=s("BasePageHeader"),F=s("BaseInput"),I=s("BaseInputGroup"),H=s("BaseMoney"),x=s("BaseIcon"),R=s("BaseSelectAction"),M=s("BaseMultiselect"),J=s("BaseTextarea"),K=s("BaseButton"),O=s("BaseInputGrid"),Q=s("BaseCard"),W=s("BasePage");return y(),V(W,null,{default:l(()=>[o(Y,{title:w.value},{default:l(()=>[o(p,null,{default:l(()=>[o(m,{title:e.$t("general.home"),to:"dashboard"},null,8,["title"]),o(m,{title:e.$t("items.item",2),to:"/admin/items"},null,8,["title"]),o(m,{title:w.value,to:"#",active:""},null,8,["title"])]),_:1})]),_:1},8,["title"]),o(pe),C("form",{class:"grid lg:grid-cols-2 mt-6",action:"submit",onSubmit:ue(D,["prevent"])},[o(Q,{class:"w-full"},{default:l(()=>[o(O,{layout:"one-column"},{default:l(()=>[o(I,{label:e.$t("items.name"),"content-loading":a(r),required:"",error:a(u).currentItem.name.$error&&a(u).currentItem.name.$errors[0].$message},{default:l(()=>[o(F,{modelValue:a(t).currentItem.name,"onUpdate:modelValue":n[0]||(n[0]=i=>a(t).currentItem.name=i),"content-loading":a(r),invalid:a(u).currentItem.name.$error,onInput:n[1]||(n[1]=i=>a(u).currentItem.name.$touch())},null,8,["modelValue","content-loading","invalid"])]),_:1},8,["label","content-loading","error"]),o(I,{label:e.$t("items.price"),"content-loading":a(r)},{default:l(()=>[o(H,{modelValue:b.value,"onUpdate:modelValue":n[2]||(n[2]=i=>b.value=i),"content-loading":a(r)},null,8,["modelValue","content-loading"])]),_:1},8,["label","content-loading"]),o(I,{"content-loading":a(r),label:e.$t("items.unit")},{default:l(()=>[o(M,{modelValue:a(t).currentItem.unit_id,"onUpdate:modelValue":n[3]||(n[3]=i=>a(t).currentItem.unit_id=i),"content-loading":a(r),label:"name",options:a(t).itemUnits,"value-prop":"id",placeholder:e.$t("items.select_a_unit"),searchable:"","track-by":"name"},{action:l(()=>[o(R,{onClick:G},{default:l(()=>[o(x,{name:"PlusIcon",class:"h-4 mr-2 -ml-2 text-center text-primary-400"}),U(" "+k(e.$t("settings.customization.items.add_item_unit")),1)]),_:1})]),_:1},8,["modelValue","content-loading","options","placeholder"])]),_:1},8,["content-loading","label"]),z.value?(y(),V(I,{key:0,label:e.$t("items.taxes"),"content-loading":a(r)},{default:l(()=>[o(M,{modelValue:T.value,"onUpdate:modelValue":n[4]||(n[4]=i=>T.value=i),"content-loading":a(r),options:L.value,mode:"tags",label:"tax_name",class:"w-full","value-prop":"id","can-deselect":!1,"can-clear":!1,searchable:"","track-by":"tax_name",object:""},null,8,["modelValue","content-loading","options"])]),_:1},8,["label","content-loading"])):P("",!0),o(I,{label:e.$t("items.description"),"content-loading":a(r),error:a(u).currentItem.description.$error&&a(u).currentItem.description.$errors[0].$message},{default:l(()=>[o(J,{modelValue:a(t).currentItem.description,"onUpdate:modelValue":n[5]||(n[5]=i=>a(t).currentItem.description=i),"content-loading":a(r),name:"description",row:2,rows:"2",onInput:n[6]||(n[6]=i=>a(u).currentItem.description.$touch())},null,8,["modelValue","content-loading"])]),_:1},8,["label","content-loading","error"]),C("div",null,[o(K,{"content-loading":a(r),type:"submit",loading:_.value},{left:l(i=>[_.value?P("",!0):(y(),V(x,{key:0,name:"SaveIcon",class:ie(i.class)},null,8,["class"]))]),default:l(()=>[U(" "+k(g.value?e.$t("items.update_item"):e.$t("items.save_item")),1)]),_:1},8,["content-loading","loading"])])]),_:1})]),_:1})],32)]),_:1})}}};export{ve as default};