Files
nademitex_admin/dist/assets/OrdersView-fyJwK9JB.js
T

1 line
29 KiB
JavaScript
Raw Normal View History

2026-09-13 15:39:08 +03:30
import{A as e,At as t,E as n,G as r,I as i,K as a,Mt as o,N as s,Nt as c,O as l,P as u,U as d,Z as f,a as ee,b as p,c as m,et as h,f as g,g as _,h as v,j as y,m as b,nt as x,o as S,p as C,t as w,u as T,ut as E,v as D,x as O,y as k}from"./http-WTIyGIuL.js";import{F as A,L as j,N as M,P as N,R as P,S as F,U as I,V as L,a as R,g as z,h as B,i as te,k as V,n as H,o as U,x as W,y as G}from"./index-BOMJTziC.js";import{t as K}from"./AdminSelect-BVy_0-3W.js";import{r as q}from"./adminLabels-Cz9ccm1Z.js";import{c as J,i as Y,n as X,o as Z,s as Q,t as ne}from"./orderStatus-CYVblRJB.js";import{t as re}from"./StatusBadge-C_awmXg1.js";function ie(){let t=N(),n=A(),r=ee(),i=x([]),a=x([]),o=new Set(X.map(e=>e.key));function s(){let e=typeof t.query.tab==`string`?t.query.tab:``;return o.has(e)?e:`all`}let c=x([]),l=x(s()),u=x(``),f=x(``),p=x(!1),m=x(!1),_=x(!1),v=x(``),y=x(!1),b=()=>({customerId:``,customerName:``,customerPhone:``,items:[]}),S=h(b()),C=g(()=>S.customerId.length>0&&S.items.length>0),T=g(()=>{let e=[...a.value];return e.sort((e,t)=>Number(t.isActive)-Number(e.isActive)||e.name.localeCompare(t.name,`fa`)),e});function E(e){let t=a.value.find(t=>t.id===e);S.customerId=e,S.customerName=t?.name??``,S.customerPhone=t?.phone??``}async function D(){try{a.value=await z.list()}catch(e){r.error(e instanceof w?e.message:`بارگذاری مشتریان انجام نشد.`)}}let O=g(()=>{let e=c.value;if(l.value!==`all`&&(e=e.filter(e=>e.status===l.value)),f.value.trim()){let t=f.value.trim();e=e.filter(e=>e.orderNumber.includes(t)||e.customerName.includes(t))}return e}),k=g(()=>c.value.find(e=>e.id===u.value)??null);function j(e){let t=e.trim();if(t)return c.value.find(e=>e.id===t||e.orderNumber.toUpperCase()===t.toUpperCase())}async function M(){let e=typeof t.query.order==`string`?t.query.order:``;if(!e||!c.value.length)return;let r=j(e);if(!r){f.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),f.value=r.orderNumber}async function P(){try{let[e,t,n]=await Promise.all([W.list(),B.list(),z.list()]);c.value=e.map(e=>G(e)),i.value=t,a.value=n,await M()}catch(e){r.error(e instanceof w?e.message:`بارگذاری سفارش‌ها انجام نشد.`)}}e(()=>{P()}),d(()=>[t.query.order,t.query.focus],()=>{M()}),d(()=>t.query.tab,()=>{let e=s();l.value!==e&&(l.value=e)}),d(l,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){u.value=e.id,t&&(m.value=!0)}function I(e){u.value=e.id,_.value=!0}function L(){m.value=!1}function R(){_.value=!1}function te(e){return e?e===`check`?`چکی`:`نقدی`:`انتخاب‌نشده`}let V=x(!1);async function H(e){if(V.value)return null;V.value=!0;try{let t=await W.updateStatus(e.orderId,{status:e.status,note:e.note,reason:e.reason,force:e.force}),n=G(t),i=c.value.findIndex(t=>t.id===e.orderId);return i>=0&&(c.value[i]={...c.value[i],...n}),r.success(`وضعیت سفارش به «${J(e.status)}» تغییر کرد.`),n}catch(e){return r.error(e instanceof w?e.message:`تغییر وضعیت انجام نشد.`),null}finally{V.value=!1}}function U(e){n.push(`/orders/${e.id}/pricing`)}function K(e){n.push(`/orders/${e.id}/checks`)}function q(e){n.push({path:`/cash-payments`,query:{order:e.orderNumber}})}function Y(){Object.assign(S,b()),v.value=``,p.value=!0,D()}function Z(){p.value=!1,v.value=``}function Q(e){return S.items.some(t=>t.productId===e.productId)?(v.value=`این محصول قبلاً به سفارش اضافه شده است.`,!1):(S.items.push(e),v.value=``,!0)}function ne(e){S.items=S.items.filter(t=>t.productId!==e)}async function re(){if(!C.value){v.value=`انتخاب مشتری و حداقل یک محصول الزامی است.`;return}y.value=!0;try{let e=await W.create({customerId:S.customerId||void 0,userId:S.customerId||void 0,customerName:S.customerName.trim(),customerPhone:S.customerPhone.trim()||void 0,items:S.it