Files
nademitex_user/dist/assets/CustomerCreateOverlay-4geBn3dg.js
T
2026-09-30 09:54:04 +03:30

1 line
4.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{D as e,G as t,M as n,Pt as r,U as i,_ as a,c as o,d as s,f as c,g as l,l as u,nt as d,o as f,t as p,u as m,v as h}from"./_plugin-vue_export-helper-1xMDlcEE.js";import{n as g,u as _}from"./BasicIcon-ba1FsUKx.js";import{l as v}from"./format-C72AoJ2H.js";import{a as y}from"./validation-Duyyve7l.js";import{t as b}from"./http-CU_N-R2R.js";import{l as x,r as S}from"./index-BPUhS8CY.js";import{t as C}from"./FormErrorBanner-Ud1D04xf.js";import{n as w,r as T,t as E}from"./formErrors-DglFjYkZ.js";import{t as D}from"./crm-BKPKhzCX.js";import{t as O}from"./BaseInput-CpE3bVJZ.js";var k={class:`customer-create-form`},A={key:0,class:`customer-create-form__intro`},j={class:`customer-create-form__fields`},M=p(h({__name:`CustomerCreateForm`,props:{customerId:{},initial:{}},emits:[`success`],setup(e,{expose:o,emit:f}){let p=e,m=f,h=x(),g=D(),_=d(``),M=d(``),N=d(``),P=d(``),F=d({}),I=d(``),L=d(!1),R=()=>!!p.customerId;function z(e){_.value=e?.firstName??``,M.value=e?.lastName??``,N.value=e?.phone??``,P.value=e?.businessName??``,F.value={},I.value=``}i(()=>p.initial,e=>z(e),{immediate:!0});function B(e){F.value=w(F.value,e),T(F.value)||(I.value=``)}async function V(){if(F.value={},I.value=``,!h.isAgent){I.value=`فقط واسطه می‌تواند مشتری به لیست خود اضافه کند.`;return}let e=v(N.value),t={};if(_.value.trim()||(t.firstName=`نام الزامی است.`),M.value.trim()||(t.lastName=`نام خانوادگی الزامی است.`),y(e)||(t.phone=`شماره موبایل معتبر نیست.`),T(t)){F.value=t,I.value=E;return}let n={firstName:_.value.trim(),lastName:M.value.trim(),phone:e,businessName:P.value.trim()||void 0};L.value=!0;try{if(R()&&p.customerId){let e=await g.updateCustomer(p.customerId,n);m(`success`,e?.id??p.customerId);return}let e=await g.registerCustomer(n);m(`success`,e?.id)}catch(e){I.value=e instanceof b||e instanceof Error?e.message:R()?`ویرایش مشتری ناموفق بود.`:`ثبت مشتری ناموفق بود.`}finally{L.value=!1}}return o({submit:V,saving:L}),(e,i)=>(n(),c(`div`,k,[R()?s(``,!0):(n(),c(`p`,A,` مشتری به لیست شما اضافه می‌شود و بعد از ورود با همین شماره، سفارش‌هایش به حساب شما وصل می‌ماند. `)),a(C,{message:I.value},null,8,[`message`]),u(`div`,j,[a(O,{modelValue:_.value,"onUpdate:modelValue":[i[0]||=e=>_.value=e,i[1]||=e=>B(`firstName`)],label:`نام`,placeholder:`نام مشتری`,error:F.value.firstName},null,8,[`modelValue`,`error`]),a(O,{modelValue:M.value,"onUpdate:modelValue":[i[2]||=e=>M.value=e,i[3]||=e=>B(`lastName`)],label:`نام خانوادگی`,placeholder:`نام خانوادگی`,error:F.value.lastName},null,8,[`modelValue`,`error`]),a(O,{modelValue:N.value,"onUpdate:modelValue":[i[4]||=e=>N.value=e,i[5]||=e=>B(`phone`)],label:`شماره موبایل`,type:`tel`,inputmode:`tel`,dir:`ltr`,placeholder:`۰۹۱۲۳۴۵۶۷۸۹`,error:F.value.phone},null,8,[`modelValue`,`error`]),a(O,{modelValue:P.value,"onUpdate:modelValue":i[6]||=e=>P.value=e,label:`نام فروشگاه یا برند (اختیاری)`,placeholder:`مثلاً بوتیک رز`},null,8,[`modelValue`])]),a(S,{block:``,loading:L.value,disabled:L.value,onClick:V},{default:t(()=>[l(r(R()?`ذخیره تغییرات`:`ثبت مشتری`),1)]),_:1},8,[`loading`,`disabled`])]))}}),[[`__scopeId`,`data-v-4f911c6f`]]),N={class:`customer-create-sheet`},P={class:`customer-create-sheet__head`},F={id:`customer-create-title`},I=p(h({__name:`CustomerCreateOverlay`,props:{open:{type:Boolean},customerId:{},initial:{},title:{}},emits:[`close`,`success`],setup(l,{emit:d}){let p=l,h=o(()=>p.title??(p.customerId?`ویرایش مشتری`:`افزودن مشتری`)),v=d;function y(){v(`close`)}function b(e){v(`success`,e)}function x(e){e.key===`Escape`&&p.open&&y()}return i(()=>p.open,e=>{document.body.style.overflow=e?`hidden`:``,e?window.addEventListener(`keydown`,x):window.removeEventListener(`keydown`,x)},{immediate:!0}),e(()=>{document.body.style.overflow=``,window.removeEventListener(`keydown`,x)}),(e,i)=>(n(),m(f,{to:`body`},[a(g,{name:`customer-create-sheet`},{default:t(()=>[l.open?(n(),c(`div`,{key:0,class:`customer-create-overlay`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`customer-create-title`,onClick:_(y,[`self`])},[u(`div`,N,[i[0]||=u(`div`,{class:`customer-create-sheet__handle`,"aria-hidden":`true`},null,-1),u(`header`,P,[u(`h2`,F,r(h.value),1),u(`button`,{type:`button`,class:`customer-create-sheet__close`,"aria-label":`بستن`,onClick:y},` × `)]),a(M,{"customer-id":l.customerId,initial:l.initial,onSuccess:b},null,8,[`customer-id`,`initial`])])])):s(``,!0)]),_:1})]))}}),[[`__scopeId`,`data-v-ac91feb8`]]);export{I as t};