1 line
33 KiB
JavaScript
1 line
33 KiB
JavaScript
import{$ as e,A as t,At as n,B as r,D as i,Dt as a,E as o,H as s,J as c,M as l,U as u,Z as d,a as f,c as p,d as m,g as h,h as g,k as _,kt as v,l as y,m as b,p as x,r as S,s as C,st as w,t as T,u as E,w as D,x as O}from"./_plugin-vue_export-helper-QrIvvHC8.js";import{a as k,f as ee,m as A,t as j}from"./http-BjLkjdQu.js";import{B as M,C as N,D as P,E as F,H as I,P as L,R,T as z,c as B,i as V,o as H,s as U,v as W,y as G,z as K}from"./index-BzcByePp.js";import{t as q}from"./AdminSelect-8XDtPu3U.js";import{t as J}from"./AdminImageLightbox-CE3ZJ5-o.js";import{n as Y,r as X}from"./adminLabels-Cz9ccm1Z.js";import{a as te,n as Z,o as ne,s as Q,t as re}from"./orderStatus-CeC05Cv4.js";import{t as ie}from"./StatusBadge-jGFZVW4C.js";function ae(){let t=K(),n=M(),i=k(),a=e([]),s=e([]),c=new Set(Z.map(e=>e.key));function l(){let e=typeof t.query.tab==`string`?t.query.tab:``;return c.has(e)?e:`all`}let u=e([]),f=e(l()),p=e(``),m=e(``),h=e(!1),g=e(!1),_=e(!1),v=e(``),y=e(!1),b=()=>({customerId:``,customerName:``,customerPhone:``,items:[]}),x=d(b()),S=C(()=>x.customerId.length>0&&x.items.length>0),w=C(()=>{let e=[...s.value];return e.sort((e,t)=>Number(t.isActive)-Number(e.isActive)||e.name.localeCompare(t.name,`fa`)),e});function T(e){let t=s.value.find(t=>t.id===e);x.customerId=e,x.customerName=t?.name??``,x.customerPhone=t?.phone??``}async function E(){try{s.value=await G.list()}catch(e){i.error(e instanceof j?e.message:`بارگذاری مشتریان انجام نشد.`)}}let D=C(()=>{let e=u.value;if(f.value!==`all`&&(e=e.filter(e=>e.status===f.value)),m.value.trim()){let t=m.value.trim();e=e.filter(e=>e.orderNumber.includes(t)||e.customerName.includes(t))}return e}),O=C(()=>u.value.find(e=>e.id===p.value)??null);function ee(e){let t=e.trim();if(t)return u.value.find(e=>e.id===t||e.orderNumber.toUpperCase()===t.toUpperCase())}async function A(){let e=typeof t.query.order==`string`?t.query.order:``;if(!e||!u.value.length)return;let r=ee(e);if(!r){m.value=e;return}let i=typeof t.query.focus==`string`?t.query.focus:``;if(i===`pricing`){await n.replace(`/orders/${r.id}/pricing`);return}if(i===`checks`){await n.replace(`/orders/${r.id}/checks`);return}I(r),m.value=r.orderNumber}async function P(){try{let[e,t,n]=await Promise.all([z.list(),W.list(),G.list()]);u.value=e.map(e=>N(e)),a.value=t,s.value=n,await A()}catch(e){i.error(e instanceof j?e.message:`بارگذاری سفارشها انجام نشد.`)}}o(()=>{P()}),r(()=>[t.query.order,t.query.focus],()=>{A()}),r(()=>t.query.tab,()=>{let e=l();f.value!==e&&(f.value=e)}),r(f,e=>{let r=typeof t.query.tab==`string`?t.query.tab:`all`,i=e===`all`?void 0:e;(r===`all`?void 0:r)!==i&&n.replace({query:{...t.query,tab:i}})});function F(e,t=!1){p.value=e.id,t&&(g.value=!0)}async function I(e){p.value=e.id,_.value=!0;try{let t=N(await z.get(e.id)),n=u.value.findIndex(t=>t.id===e.id);n>=0&&(u.value[n]={...u.value[n],...t})}catch{}}function L(){g.value=!1}function R(){_.value=!1}function B(e){return e?e===`check`?`چکی`:`نقدی`:`انتخابنشده`}let V=e(!1);async function H(e){if(V.value)return null;V.value=!0;try{let t=await z.updateStatus(e.orderId,{status:e.status,note:e.note}),n=N(t),r=u.value.findIndex(t=>t.id===e.orderId);return r>=0&&(u.value[r]={...u.value[r],...n}),i.success(`وضعیت سفارش به «${Q(e.status)}» تغییر کرد.`),n}catch(e){return i.error(e instanceof j?e.message:`تغییر وضعیت انجام نشد.`),null}finally{V.value=!1}}function U(e){n.push(`/orders/${e.id}/pricing`)}function q(e){n.push(`/orders/${e.id}/checks`)}function J(e){n.push({path:`/cash-payments`,query:{order:e.orderNumber}})}function Y(){Object.assign(x,b()),v.value=``,h.value=!0,E()}function X(){h.value=!1,v.value=``}function te(e){return x.items.some(t=>t.productId===e.productId)?(v.value=`این محصول قبلاً به سفارش اضافه شده است.`,!1):(x.items.push(e),v.value=``,!0)}function ne(e){x.items=x.items.filter(t=>t.productId!==e)}async function re(){if(!S.value){v.value=`انتخاب مشتری و حداقل یک محصول الزامی است.`;re
|