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

1 line
29 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{$ as e,B as t,F as n,I as r,J as i,K as a,N as o,P as s,Q as c,R as l,S as u,St as d,V as f,W as p,X as m,Y as h,Z as g,_t as _,a as v,at as y,bt as b,ct as x,et as S,g as C,gt as w,h as T,ht as E,i as D,it as O,k,lt as A,mt as j,n as M,nt as N,o as P,ot as F,pt as I,q as L,rt as R,st as z,tt as B,ut as V,vt as H,x as U,xt as W,y as G,yt as K,z as q}from"./index-BHqDDh7X.js";import{t as J}from"./AdminSelect-BjB6PHdr.js";import{r as Y}from"./adminLabels-Cz9ccm1Z.js";import{c as X,i as Z,n as Q,o as ee,s as te,t as ne}from"./orderStatus-CYVblRJB.js";import{t as re}from"./StatusBadge-BMzuiwOg.js";function ie(){let e=n(),t=r(),i=q(),a=H([]),s=H([]),c=new Set(Q.map(e=>e.key));function l(){let t=typeof e.query.tab==`string`?e.query.tab:``;return c.has(t)?t:`all`}let u=H([]),d=H(l()),f=H(``),p=H(``),m=H(!1),g=H(!1),v=H(!1),y=H(``),b=H(!1),x=()=>({customerId:``,customerName:``,customerPhone:``,items:[]}),S=_(x()),w=h(()=>S.customerId.length>0&&S.items.length>0),E=h(()=>{let e=[...s.value];return e.sort((e,t)=>Number(t.isActive)-Number(e.isActive)||e.name.localeCompare(t.name,`fa`)),e});function D(e){let t=s.value.find(t=>t.id===e);S.customerId=e,S.customerName=t?.name??``,S.customerPhone=t?.phone??``}async function O(){try{s.value=await C.list()}catch(e){i.error(e instanceof o?e.message:`بارگذاری مشتریان انجام نشد.`)}}let k=h(()=>{let e=u.value;if(d.value!==`all`&&(e=e.filter(e=>e.status===d.value)),p.value.trim()){let t=p.value.trim();e=e.filter(e=>e.orderNumber.includes(t)||e.customerName.includes(t))}return e}),A=h(()=>u.value.find(e=>e.id===f.value)??null);function j(e){let t=e.trim();if(t)return u.value.find(e=>e.id===t||e.orderNumber.toUpperCase()===t.toUpperCase())}async function M(){let n=typeof e.query.order==`string`?e.query.order:``;if(!n||!u.value.length)return;let r=j(n);if(!r){p.value=n;return}let i=typeof e.query.focus==`string`?e.query.focus:``;if(i===`pricing`){await t.replace(`/orders/${r.id}/pricing`);return}if(i===`checks`){await t.replace(`/orders/${r.id}/checks`);return}L(r),p.value=r.orderNumber}async function N(){try{let[e,t,n]=await Promise.all([U.list(),T.list(),C.list()]);u.value=e.map(e=>G(e)),a.value=t,s.value=n,await M()}catch(e){i.error(e instanceof o?e.message:`بارگذاری سفارش‌ها انجام نشد.`)}}F(()=>{N()}),I(()=>[e.query.order,e.query.focus],()=>{M()}),I(()=>e.query.tab,()=>{let e=l();d.value!==e&&(d.value=e)}),I(d,n=>{let r=typeof e.query.tab==`string`?e.query.tab:`all`,i=n===`all`?void 0:n;(r===`all`?void 0:r)!==i&&t.replace({query:{...e.query,tab:i}})});function P(e,t=!1){f.value=e.id,t&&(g.value=!0)}function L(e){f.value=e.id,v.value=!0}function R(){g.value=!1}function z(){v.value=!1}function B(e){return e?e===`check`?`چکی`:`نقدی`:`انتخاب‌نشده`}let V=H(!1);async function W(e){if(V.value)return null;V.value=!0;try{let t=await U.updateStatus(e.orderId,{status:e.status,note:e.note,reason:e.reason,force:e.force}),n=G(t),r=u.value.findIndex(t=>t.id===e.orderId);return r>=0&&(u.value[r]={...u.value[r],...n}),i.success(`وضعیت سفارش به «${X(e.status)}» تغییر کرد.`),n}catch(e){return i.error(e instanceof o?e.message:`تغییر وضعیت انجام نشد.`),null}finally{V.value=!1}}function K(e){t.push(`/orders/${e.id}/pricing`)}function J(e){t.push(`/orders/${e.id}/checks`)}function Y(e){t.push({path:`/cash-payments`,query:{order:e.orderNumber}})}function Z(){Object.assign(S,x()),y.value=``,m.value=!0,O()}function ee(){m.value=!1,y.value=``}function te(e){return S.items.some(t=>t.productId===e.productId)?(y.value=`این محصول قبلاً به سفارش اضافه شده است.`,!1):(S.items.push(e),y.value=``,!0)}function ne(e){S.items=S.items.filter(t=>t.productId!==e)}async function re(){if(!w.value){y.value=`انتخاب مشتری و حداقل یک محصول الزامی است.`;return}b.value=!0;try{let e=await U.create({customerId:S.customerId||void 0,userId:S.customerId||void 0,customerName:S.customerName.trim(),customerPhone:S.customerPhone.trim()||void 0,items:S.items.map(e=>({productId:e.productId,meterage:e.meterage}))}),t=G(e);u.value.unshift(t),f.value=t.id,i.success(`سفارش جدید ثبت شد.`),ee()}catch(e){i.error(e instanceof o?e.message:`ثبت سفارش انجام نشد.`)}finally{b.value=!1}}return{companies:a,customers:s,activeCustomers:E,applyCustomer:D,loadCustomers:O,orderList:u,activeTab:d,selectedOrderId:f,searchQuery:p,showAddModal:m,showDetailPanel:g,showDetailModal:v,formError:y,form:S,addFormItem:te,removeFormItem:ne,isFormValid:w,filteredOrders:k,selectedOrder:A,selectOrder:P,openOrderDetail:L,closeDetailPanel:R,closeDetailModal:z,settlementLabel:B,changeStatus:W,statusSaving:V,goPricing:K,goChecks:J,goCashReceipt:Y,openAddModal:Z,closeAddModal:ee,submitAddOrder:re,saving:b}}var ae=Symbol(`orders-page`);function oe(){let e=ie();return A(ae,e),e}function se(){let e=O(ae);if(!e)throw Error(`Orders page context is missing`);return e}var ce={class:`order-detail__hero`},$={class:`order-detail__hero-text`},le={class:`order-detail__id`},ue={key:0,class:`order-detail__raw-status`},de={class:`order-detail__actions no-print`},fe=[`disabled`],pe={class:`order-detail__panels`},me={class:`order-detail__section`},he={class:`order-detail__info`},ge={class:`order-detail__info-row`},_e={class:`order-detail__info-value`},ve={class:`order-detail__info-row`},ye={class:`order-detail__info-value order-detail__info-value--phone`,dir:`ltr`},be={class:`order-detail__info-row`},xe={class:`order-detail__info-value`},Se={class:`order-detail__info-row`},Ce={class:`order-detail__info-value`},we={class:`order-detail__section`},Te={class:`order-detail__info`},Ee={class:`order-detail__info-row`},De={class:`order-detail__info-value`},Oe={class:`order-detail__info-row`},ke={class:`order-detail__info-value`},Ae={class:`order-detail__info-row`},je={class:`order-detail__info-value`},Me={class:`order-detail__info-row`},Ne={class:`order-detail__info-value`},Pe={key:0,class:`order-detail__section`},Fe={key:0,class:`admin-table-wrap order-detail__table`},Ie={class:`admin-table admin-table--compact`},Le={key:1,class:`order-detail__items`},Re={class:`order-detail__item-head`},ze={class:`order-detail__item-meta`},Be={key:0},Ve={key:1},He={key:2,class:`order-detail__item-total`},Ue={class:`order-detail__section order-detail__status no-print`},We={class:`order-detail__status-head`},Ge={class:`order-detail__manual`},Ke={key:0,class:`order-detail__status-hint`},qe={key:1,class:`order-detail__status-hint`},Je={key:2,class:`order-detail__status-form`},Ye={class:`admin-form__field`},Xe={class:`admin-form__field`},Ze={for:`status-note`},Qe=[`disabled`],$e=t(R({__name:`OrderDetailContent`,props:{order:{},settlementLabel:{},layout:{default:`compact`},statusSaving:{type:Boolean}},emits:[`pricing`,`checks`,`cashReceipt`,`finalApprove`,`status`],setup(t,{emit:n}){let r=t,i=n,a=H(!1),o=H(``),l=H(``),u=Object.keys(Z),g=h(()=>r.order.allowedTransitions??[]),_=h(()=>a.value?u.filter(e=>e!==r.order.rawStatus):[...g.value]),y=h(()=>[{value:``,label:`انتخاب کنید…`},..._.value.map(e=>({value:e,label:X(e)}))]),S=h(()=>a.value),C=h(()=>!!o.value&&(!S.value||l.value.trim().length>0)),w=h(()=>r.layout===`desktop`),T=h(()=>ne[r.order.status]?.label??r.order.status),D=h(()=>{let e=X(r.order.rawStatus);return!e||e===T.value?``:e}),O=h(()=>{let e=r.order.customerType;return e?Y[e]??r.order.customerType??`—`:`—`}),k=h(()=>te(r.order)),A=h(()=>ee(r.order)),j=h(()=>r.order.settlementMethod===`check`&&!k.value),F=h(()=>r.order.settlementMethod===`cash`&&!k.value&&r.order.rawStatus!==`cash_confirmed`),R=h(()=>k.value?`pricing`:A.value?`final`:j.value?`checks`:F.value?`cash`:null);I([()=>r.order.id,a],()=>{o.value=``,l.value=``});function z(){if(!o.value||!C.value)return;let e=l.value.trim()||void 0;i(`status`,{orderId:r.order.id,status:o.value,note:e,reason:a.value?e:void 0,force:a.value||void 0}),o.value=``,l.value=``}return(n,r)=>(x(),e(`div`,{class:b([`order-detail`,`order-detail--${t.layout}`])},[m(`header`,ce,[m(`div`,$,[m(`div`,le,[m(`strong`,null,d(t.order.orderNumber),1),N(re,{status:t.order.status},null,8,[`status`])]),D.value?(x(),e(`p`,ue,d(D.value),1)):c(``,!0)]),m(`div`,de,[k.value?(x(),e(`button`,{key:0,type:`button`,class:b([`admin-btn admin-btn--sm`,R.value===`pricing`?`admin-btn--primary`:`admin-btn--outline`]),onClick:r[0]||=e=>i(`pricing`)},` قیمت‌گذاری سفارش `,2)):c(``,!0),j.value?(x(),e(`button`,{key:1,type:`button`,class:b([`admin-btn admin-btn--sm`,R.value===`checks`?`admin-btn--primary`:`admin-btn--outline`]),onClick:r[1]||=e=>i(`checks`)},` مدیریت چک‌ها `,2)):c(``,!0),F.value?(x(),e(`button`,{key:2,type:`button`,class:b([`admin-btn admin-btn--sm`,R.value===`cash`?`admin-btn--primary`:`admin-btn--outline`]),onClick:r[2]||=e=>i(`cashReceipt`)},` رسید پرداخت `,2)):c(``,!0),A.value?(x(),e(`button`,{key:3,type:`button`,class:b([`admin-btn admin-btn--sm`,R.value===`final`?`admin-btn--primary`:`admin-btn--outline`]),disabled:t.statusSaving,onClick:r[3]||=e=>i(`finalApprove`)},` تأیید نهایی `,10,fe)):c(``,!0)])]),m(`div`,pe,[m(`section`,me,[r[11]||=m(`h3`,{class:`order-detail__section-title`},`اطلاعات مشتری`,-1),m(`div`,he,[m(`div`,ge,[N(s,{name:`building`,size:16}),r[7]||=m(`span`,{class:`order-detail__info-label`},`مشتری`,-1),m(`span`,_e,d(t.order.customerName),1)]),m(`div`,ve,[N(s,{name:`phone`,size:16}),r[8]||=m(`span`,{class:`order-detail__info-label`},`تلفن`,-1),m(`span`,ye,d(t.order.customerPhone??`—`),1)]),m(`div`,be,[N(s,{name:`id-card`,size:16}),r[9]||=m(`span`,{class:`order-detail__info-label`},`شناسه ملی`,-1),m(`span`,xe,d(t.order.customerNationalId??`—`),1)]),m(`div`,Se,[N(s,{name:`user`,size:16}),r[10]||=m(`span`,{class:`order-detail__info-label`},`نوع مشتری`,-1),m(`span`,Ce,d(O.value),1)])])]),m(`section`,we,[r[16]||=m(`h3`,{class:`order-detail__section-title`},`اطلاعات سفارش`,-1),m(`div`,Te,[m(`div`,Ee,[r[12]||=m(`span`,{class:`order-detail__info-label`},`شرکت`,-1),m(`span`,De,d(t.order.companyName),1)]),m(`div`,Oe,[r[13]||=m(`span`,{class:`order-detail__info-label`},`روش تسویه`,-1),m(`span`,ke,d(t.settlementLabel(t.order.settlementMethod)),1)]),m(`div`,Ae,[r[14]||=m(`span`,{class:`order-detail__info-label`},`متراژ کل`,-1),m(`span`,je,d(K(v)(t.order.meterage)),1)]),m(`div`,Me,[r[15]||=m(`span`,{class:`order-detail__info-label`},`مبلغ کل`,-1),m(`span`,Ne,d(t.order.totalAmount==null?`پس از قیمت‌گذاری`:K(M)(t.order.totalAmount)),1)])])])]),t.order.items?.length?(x(),e(`section`,Pe,[r[18]||=m(`h3`,{class:`order-detail__section-title`},`محصولات سفارش`,-1),w.value?(x(),e(`div`,Fe,[m(`table`,Ie,[r[17]||=m(`thead`,null,[m(`tr`,null,[m(`th`,null,`شرکت`),m(`th`,null,`کالیته`),m(`th`,null,`محصول`),m(`th`,null,`رنگ`),m(`th`,null,`متراژ`),m(`th`,null,`قیمت`),m(`th`,null,`مبلغ`)])],-1),m(`tbody`,null,[(x(!0),e(L,null,V(t.order.items,n=>(x(),e(`tr`,{key:n.id},[m(`td`,null,d(n.companyName||t.order.companyName),1),m(`td`,null,d(n.catalogCode),1),m(`td`,null,d(n.productName),1),m(`td`,null,d(n.color),1),m(`td`,null,d(K(P)(n.confirmedMeterage??n.requestedMeterage)),1),m(`td`,null,d(n.supplyPrice==null?`—`:K(M)(n.supplyPrice)),1),m(`td`,null,d(n.totalAmount==null?`—`:K(M)(n.totalAmount)),1)]))),128))])])])):(x(),e(`ul`,Le,[(x(!0),e(L,null,V(t.order.items,t=>(x(),e(`li`,{key:t.id,class:`order-detail__item`},[m(`div`,Re,[m(`strong`,null,d(t.productName),1),m(`span`,null,d(t.catalogCode),1)]),m(`div`,ze,[t.companyName?(x(),e(`span`,Be,d(t.companyName),1)):c(``,!0),m(`span`,null,d(t.color),1),m(`span`,null,d(K(v)(t.confirmedMeterage??t.requestedMeterage)),1),t.supplyPrice==null?c(``,!0):(x(),e(`span`,Ve,d(K(M)(t.supplyPrice)),1)),t.totalAmount==null?c(``,!0):(x(),e(`span`,He,d(K(M)(t.totalAmount)),1))])]))),128))]))])):c(``,!0),m(`section`,Ue,[m(`div`,We,[r[20]||=m(`h3`,{class:`order-detail__section-title`},`تغییر وضعیت`,-1),m(`label`,Ge,[E(m(`input`,{"onUpdate:modelValue":r[4]||=e=>a.value=e,type:`checkbox`},null,512),[[f,a.value]]),r[19]||=m(`span`,null,`تغییر دستی`,-1)])]),a.value?(x(),e(`p`,Ke,` این گذر خارج از روال استاندارد است؛ ثبت یادداشت اجباری است. `)):_.value.length?c(``,!0):(x(),e(`p`,qe,` در این وضعیت گذر خودکاری وجود ندارد. برای تغییر، حالت دستی را فعال کنید. `)),_.value.length?(x(),e(`div`,Je,[m(`div`,Ye,[r[21]||=m(`label`,null,`وضعیت بعدی`,-1),N(J,{modelValue:o.value,"onUpdate:modelValue":r[5]||=e=>o.value=e,block:``,"aria-label":`وضعیت بعدی`,placeholder:`انتخاب کنید…`,options:y.value},null,8,[`modelValue`,`options`])]),m(`div`,Xe,[m(`label`,Ze,` یادداشت`+d(S.value?` (اجباری)`:` (اختیاری)`),1),E(m(`input`,{id:`status-note`,"onUpdate:modelValue":r[6]||=e=>l.value=e,type:`text`,class:`admin-input`,placeholder:`دلیل یا توضیح این تغییر`},null,512),[[p,l.value]])]),m(`button`,{type:`button`,class:`admin-btn admin-btn--primary admin-btn--sm`,disabled:!C.value||t.statusSaving,onClick:z},d(t.statusSaving?`در حال ثبت…`:`ثبت وضعیت`),9,Qe)])):c(``,!0)])],2))}}),[[`__scopeId`,`data-v-bfe77a62`]]),et={class:`orders-page`},tt={class:`orders-page__list-panel admin-card`},nt={class:`orders-page__list-header`},rt={class:`orders-page__list-actions`},it={type:`button`,class:`admin-btn admin-btn--outline admin-btn--sm`},at={class:`orders-page__search`},ot={class:`admin-tabs`},st=[`onClick`],ct={class:`admin-table-wrap`},lt={class:`admin-table admin-table--compact`},ut=[`onClick`],dt={class:`orders-page__actions-cell`},ft=[`aria-expanded`,`onClick`],pt={type:`button`,class:`admin-btn admin-btn--outline admin-btn--sm`},mt=t(R({__name:`DesktopOrdersPage`,setup(t){let n=k(`(min-width: 1280px)`),{activeTab:r,selectedOrderId:o,searchQuery:u,filteredOrders:f,selectedOrder:h,showDetailModal:_,openOrderDetail:C,closeDetailModal:T,settlementLabel:O,goPricing:A,goChecks:P,goCashReceipt:I,changeStatus:R,statusSaving:U,openAddModal:G}=se(),q=H(null),J=H({});function Y(){q.value=null}async function X(e,t){if(t.stopPropagation(),q.value?.id===e.id){Y();return}let n=t.currentTarget.getBoundingClientRect();q.value=e,await y();let r=Math.min(Math.max(8,n.right-168),window.innerWidth-168-8);J.value={position:`fixed`,top:`${n.bottom+4}px`,left:`${r}px`,width:`168px`}}function Z(){Y()}F(()=>{document.addEventListener(`click`,Z),window.addEventListener(`scroll`,Y,!0),window.addEventListener(`resize`,Y)}),z(()=>{document.removeEventListener(`click`,Z),window.removeEventListener(`scroll`,Y,!0),window.removeEventListener(`resize`,Y)});function ne(){h.value&&(T(),A(h.value))}function ie(){h.value&&(T(),P(h.value))}function ae(){h.value&&(T(),I(h.value))}function oe(){h.value&&R({orderId:h.value.id,status:`final_approved`,note:`تأیید نهایی سفارش`})}function ce(){if(!h.value)return;document.documentElement.classList.add(`printing-order-detail`);let e=()=>{document.documentElement.classList.remove(`printing-order-detail`),window.removeEventListener(`afterprint`,e)};window.addEventListener(`afterprint`,e),window.setTimeout(e,6e4),window.print()}function $(e){let t=q.value;if(t){if(Y(),e===`detail`){C(t);return}if(e===`pricing`){A(t);return}if(e===`checks`){P(t);return}if(e===`final`){R({orderId:t.id,status:`final_approved`,note:`تأیید نهایی سفارش`});return}I(t)}}return(t,y)=>(x(),e(`div`,et,[m(`div`,tt,[m(`div`,nt,[y[9]||=m(`div`,null,[m(`h2`,{class:`orders-page__list-title`},`سفارش‌ها`)],-1),m(`div`,rt,[m(`button`,it,[N(s,{name:`filter`,size:16}),y[8]||=B(` فیلتر `,-1)]),m(`button`,{type:`button`,class:`admin-btn admin-btn--primary admin-btn--sm`,onClick:y[0]||=(...e)=>K(G)&&K(G)(...e)},` سفارش جدید `)])]),m(`div`,at,[N(s,{name:`search`,size:18}),E(m(`input`,{"onUpdate:modelValue":y[1]||=e=>w(u)?u.value=e:null,type:`search`,placeholder:`جستجو در شماره سفارش، مشتری...`,class:`orders-page__search-input`},null,512),[[p,K(u)]])]),m(`div`,ot,[(x(!0),e(L,null,V(K(Q),t=>(x(),e(`button`,{key:t.key,type:`button`,class:b([`admin-tab`,{active:K(r)===t.key}]),onClick:e=>r.value=t.key},[B(d(t.label)+` `,1),`count`in t&&t.count?(x(),e(L,{key:0},[B(` (`+d(t.count)+`)`,1)],64)):c(``,!0)],10,st))),128))]),m(`div`,ct,[m(`table`,lt,[y[10]||=m(`thead`,null,[m(`tr`,null,[m(`th`,null,`شماره سفارش`),m(`th`,null,`مشتری`),m(`th`,null,`روش تسویه`),m(`th`,null,`مبلغ کل`),m(`th`,null,`متراژ`),m(`th`,null,`وضعیت`),m(`th`,null,`تاریخ ثبت`),m(`th`,null,`عملیات`)])],-1),m(`tbody`,null,[(x(!0),e(L,null,V(K(f),t=>(x(),e(`tr`,{key:t.id,class:b({"is-selected":K(o)===t.id}),onClick:e=>K(C)(t)},[m(`td`,null,d(t.orderNumber),1),m(`td`,null,d(t.customerName),1),m(`td`,null,d(K(O)(t.settlementMethod)),1),m(`td`,null,d(t.totalAmount?K(M)(t.totalAmount):`—`),1),m(`td`,null,d(K(v)(t.meterage)),1),m(`td`,null,[N(re,{status:t.status},null,8,[`status`])]),m(`td`,null,d(K(D)(t.createdAt)),1),m(`td`,dt,[m(`button`,{type:`button`,class:`orders-page__more-btn`,"aria-expanded":q.value?.id===t.id,"aria-haspopup":`menu`,"aria-label":`عملیات سفارش`,onClick:e=>X(t,e)},[N(s,{name:`more`,size:18})],8,ft)])],10,ut))),128))])])]),y[11]||=S(`<div class="admin-pagination" data-v-cfed03e1><span data-v-cfed03e1>نمایش ۱ تا ۷ از ۱۰۳ سفارش</span><div class="admin-pagination__pages" data-v-cfed03e1><button type="button" class="admin-pagination__page active" data-v-cfed03e1>۱</button><button type="button" class="admin-pagination__page" data-v-cfed03e1>۲</button><button type="button" class="admin-pagination__page" data-v-cfed03e1>۳</button><span data-v-cfed03e1>...</span><button type="button" class="admin-pagination__page" data-v-cfed03e1>۱۲</button></div></div>`,1)]),(x(),g(i,{to:`body`},[q.value?(x(),e(`div`,{key:0,class:`orders-page__menu`,role:`menu`,style:W(J.value),onClick:y[7]||=a(()=>{},[`stop`])},[m(`button`,{type:`button`,role:`menuitem`,class:`orders-page__menu-item`,onClick:y[2]||=e=>$(`detail`)},` جزئیات سفارش `),q.value&&K(te)(q.value)?(x(),e(`button`,{key:0,type:`button`,role:`menuitem`,class:`orders-page__menu-item`,onClick:y[3]||=e=>$(`pricing`)},` قیمت‌گذاری `)):c(``,!0),q.value.settlementMethod===`check`?(x(),e(`button`,{key:1,type:`button`,role:`menuitem`,class:`orders-page__menu-item`,onClick:y[4]||=e=>$(`checks`)},` مدیریت چک‌ها `)):c(``,!0),q.value.settlementMethod===`cash`&&q.value.rawStatus!==`cash_confirmed`?(x(),e(`button`,{key:2,type:`button`,role:`menuitem`,class:`orders-page__menu-item`,onClick:y[5]||=e=>$(`cash`)},` رسید پرداخت `)):c(``,!0),K(ee)(q.value)?(x(),e(`button`,{key:3,type:`button`,role:`menuitem`,class:`orders-page__menu-item`,onClick:y[6]||=e=>$(`final`)},` تأیید نهایی `)):c(``,!0)],4)):c(``,!0)])),N(l,{open:K(n)&&K(_)&&!!K(h),title:`جزئیات سفارش`,size:`xl`,onClose:K(T)},{footer:j(()=>[m(`button`,pt,[N(s,{name:`sms`,size:16}),y[12]||=B(` ارسال پیامک `,-1)]),m(`button`,{type:`button`,class:`admin-btn admin-btn--outline admin-btn--sm`,onClick:ce},[N(s,{name:`print`,size:16}),y[13]||=B(` چاپ `,-1)])]),default:j(()=>[K(h)?(x(),g($e,{key:0,order:K(h),layout:`desktop`,"settlement-label":K(O),"status-saving":K(U),onPricing:ne,onChecks:ie,onCashReceipt:ae,onFinalApprove:oe,onStatus:K(R)},null,8,[`order`,`settlement-label`,`status-saving`,`onStatus`])):c(``,!0)]),_:1},8,[`open`,`onClose`])]))}}),[[`__scopeId`,`data-v-cfed03e1`]]),ht={class:`compact-orders`},gt={class:`compact-page-header`},_t={class:`compact-page-header__row`},vt={class:`compact-page-header__actions`},yt={key:0,class:`compact-orders__filter-dot`,"aria-hidden":`true`},bt={class:`orders-page__search admin-card`},xt={key:0,class:`compact-orders__filter-chip admin-card`},St={key:1,class:`admin-tabs compact-orders__tabs`},Ct=[`onClick`],wt={class:`compact-orders__filter-form`,role:`listbox`,"aria-label":`وضعیت سفارش`},Tt=[`aria-selected`,`onClick`],Et={key:0,class:`compact-orders__filter-check`,"aria-hidden":`true`},Dt={class:`admin-card-list`},Ot=[`onClick`],kt={class:`admin-card-item__header`},At={class:`admin-card-item__title`},jt={class:`admin-card-item__meta`},Mt={key:0,class:`admin-detail-panel__inner`},Nt={class:`admin-detail-panel__header`},Pt={class:`admin-detail-panel__body`},Ft=t(R({__name:`CompactOrdersPage`,setup(t){let n=k(`(max-width: 767px)`),r=k(`(max-width: 1279px)`),{activeTab:i,selectedOrderId:a,searchQuery:o,filteredOrders:u,selectedOrder:f,showDetailPanel:_,showDetailModal:y,selectOrder:S,openOrderDetail:C,closeDetailPanel:T,closeDetailModal:O,settlementLabel:A,goPricing:P,goChecks:F,goCashReceipt:I,changeStatus:R,statusSaving:z,openAddModal:U}=se(),W=H(!1),G=h(()=>i.value!==`all`),q=h(()=>Q.find(e=>e.key===i.value)?.label??`همه`);function J(){W.value=!0}function Y(){W.value=!1}function X(){i.value=`all`,W.value=!1}function Z(e){i.value=e,W.value=!1}function ee(e){if(n.value){S(e,!0);return}C(e)}function te(){f.value&&(O(),T(),P(f.value))}function ne(){f.value&&(O(),T(),F(f.value))}function ie(){f.value&&(O(),T(),I(f.value))}function ae(){f.value&&R({orderId:f.value.id,status:`final_approved`,note:`تأیید نهایی سفارش`})}return(t,h)=>(x(),e(`div`,ht,[m(`div`,gt,[m(`div`,_t,[h[4]||=m(`div`,null,[m(`h2`,{class:`compact-page-header__title`},`سفارش‌ها`)],-1),m(`div`,vt,[m(`button`,{type:`button`,class:b([`admin-btn admin-btn--outline admin-btn--sm`,{"admin-btn--filter-active":G.value}]),onClick:J},[N(s,{name:`filter`,size:16}),h[3]||=B(` فیلتر `,-1),G.value?(x(),e(`span`,yt)):c(``,!0)],2),m(`button`,{type:`button`,class:`admin-btn admin-btn--primary admin-btn--sm`,onClick:h[0]||=(...e)=>K(U)&&K(U)(...e)},` سفارش جدید `)])])]),m(`div`,bt,[N(s,{name:`search`,size:18}),E(m(`input`,{"onUpdate:modelValue":h[1]||=e=>w(o)?o.value=e:null,type:`search`,placeholder:`جستجو در شماره سفارش، مشتری...`,class:`orders-page__search-input`},null,512),[[p,K(o)]])]),K(n)&&G.value?(x(),e(`div`,xt,[m(`span`,null,`وضعیت: `+d(q.value),1),m(`button`,{type:`button`,class:`compact-orders__filter-clear`,onClick:X},`پاک کردن`)])):c(``,!0),K(n)?c(``,!0):(x(),e(`div`,St,[(x(!0),e(L,null,V(K(Q),t=>(x(),e(`button`,{key:t.key,type:`button`,class:b([`admin-tab`,{active:K(i)===t.key}]),onClick:e=>i.value=t.key},[B(d(t.label)+` `,1),`count`in t&&t.count?(x(),e(L,{key:0},[B(` (`+d(t.count)+`)`,1)],64)):c(``,!0)],10,Ct))),128))])),N(l,{open:W.value,title:`فیلتر سفارش‌ها`,onClose:Y},{footer:j(()=>[m(`button`,{type:`button`,class:`admin-btn admin-btn--outline`,onClick:X},` پاک کردن `),m(`button`,{type:`button`,class:`admin-btn admin-btn--primary`,onClick:Y},` بستن `)]),default:j(()=>[m(`div`,wt,[(x(!0),e(L,null,V(K(Q),t=>(x(),e(`button`,{key:t.key,type:`button`,class:b([`compact-orders__filter-option`,{"is-active":K(i)===t.key}]),role:`option`,"aria-selected":K(i)===t.key,onClick:e=>Z(t.key)},[m(`span`,null,d(t.label),1),K(i)===t.key?(x(),e(`span`,Et,`✓`)):c(``,!0)],10,Tt))),128))])]),_:1},8,[`open`]),m(`div`,Dt,[(x(!0),e(L,null,V(K(u),t=>(x(),e(`button`,{key:t.id,type:`button`,class:b([`admin-card-item`,{selected:K(a)===t.id}]),onClick:e=>ee(t)},[m(`div`,kt,[m(`p`,At,d(t.orderNumber),1),N(re,{status:t.status},null,8,[`status`])]),m(`div`,jt,[m(`span`,null,[h[5]||=m(`strong`,null,`مشتری:`,-1),B(` `+d(t.customerName),1)]),m(`span`,null,[h[6]||=m(`strong`,null,`متراژ:`,-1),B(` `+d(K(v)(t.meterage)),1)]),m(`span`,null,[h[7]||=m(`strong`,null,`مبلغ:`,-1),B(` `+d(t.totalAmount?K(M)(t.totalAmount):`—`),1)]),m(`span`,null,d(K(D)(t.createdAt)),1)])],10,Ot))),128))]),m(`div`,{class:b([`admin-detail-panel compact-orders__mobile-panel`,{open:K(n)&&K(_)&&K(f)}])},[K(f)?(x(),e(`div`,Mt,[m(`div`,Nt,[m(`button`,{type:`button`,class:`admin-detail-panel__back`,"aria-label":`بازگشت به لیست`,onClick:h[2]||=(...e)=>K(T)&&K(T)(...e)},[N(s,{name:`chevron-back`,size:20})]),h[8]||=m(`h2`,{class:`admin-detail-panel__title`},`جزئیات سفارش`,-1)]),m(`div`,Pt,[N($e,{order:K(f),"settlement-label":K(A),"status-saving":K(z),onPricing:te,onChecks:ne,onCashReceipt:ie,onFinalApprove:ae,onStatus:K(R)},null,8,[`order`,`settlement-label`,`status-saving`,`onStatus`])])])):c(``,!0)],2),N(l,{open:K(r)&&!K(n)&&K(y)&&!!K(f),title:`جزئیات سفارش`,size:`xl`,onClose:K(O)},{default:j(()=>[K(f)?(x(),g($e,{key:0,order:K(f),"settlement-label":K(A),"status-saving":K(z),onPricing:te,onChecks:ne,onCashReceipt:ie,onFinalApprove:ae,onStatus:K(R)},null,8,[`order`,`settlement-label`,`status-saving`,`onStatus`])):c(``,!0)]),_:1},8,[`open`,`onClose`])]))}}),[[`__scopeId`,`data-v-fe86c1c8`]]),It={key:0,class:`admin-form__error`,role:`alert`},Lt={class:`admin-form__field`},Rt={key:0,class:`admin-form__hint`},zt={class:`admin-form__row`},Bt={class:`admin-form__field`},Vt={class:`admin-form__field`},Ht={key:1,class:`order-add__items`},Ut=[`onClick`],Wt={key:2,class:`admin-form__hint`},Gt=[`disabled`],Kt=t(R({__name:`OrderAddModal`,setup(t){let{showAddModal:n,formError:r,form:i,isFormValid:s,activeCustomers:f,applyCustomer:v,addFormItem:y,removeFormItem:b,closeAddModal:S,submitAddOrder:C}=se(),w=q(),T=H([]),D=_({productId:``,meterage:0}),O=h(()=>f.value.map(e=>{let t=e.phone?` — ${e.phone}`:``,n=e.isActive===!1?` (غیرفعال)`:``;return{value:e.id,label:`${e.name}${t}${n}`}})),k=h(()=>T.value.filter(e=>e.isActive!==!1).map(e=>({value:e.id,label:`${e.name} — ${e.catalogCode} (${e.companyName})`}))),A=h(()=>T.value.find(e=>e.id===D.productId)??null);I(()=>i.customerId,e=>{if(!e){i.customerName=``,i.customerPhone=``;return}v(e)}),I(n,async e=>{if(e){D.productId=``,D.meterage=0;try{T.value=await u.list({activeOnly:!0})}catch(e){w.error(e instanceof o?e.message:`بارگذاری محصولات انجام نشد.`)}}}),I(()=>D.productId,e=>{let t=T.value.find(t=>t.id===e);t&&(D.meterage=t.rollMeters||t.minMeterage||t.orderStep||50)});function M(){let e=A.value;if(!e){r.value=`محصول را انتخاب کنید.`;return}if(!D.meterage||D.meterage<=0){r.value=`متراژ باید بزرگ‌تر از صفر باشد.`;return}y({productId:e.id,productName:e.name,catalogCode:e.catalogCode,meterage:D.meterage}),D.productId=``,D.meterage=0}return(t,o)=>(x(),g(l,{open:K(n),title:`پیش‌سفارش جدید`,size:`lg`,onClose:K(S)},{footer:j(()=>[m(`button`,{type:`button`,class:`admin-btn admin-btn--outline`,onClick:o[4]||=(...e)=>K(S)&&K(S)(...e)},` انصراف `),m(`button`,{type:`button`,class:`admin-btn admin-btn--primary`,disabled:!K(s),onClick:o[5]||=(...e)=>K(C)&&K(C)(...e)},` ثبت پیش‌سفارش `,8,Gt)]),default:j(()=>[m(`form`,{class:`admin-form`,onSubmit:o[3]||=a((...e)=>K(C)&&K(C)(...e),[`prevent`])},[K(r)?(x(),e(`p`,It,d(K(r)),1)):c(``,!0),o[9]||=m(`p`,{class:`admin-form__hint`},` مثل سفارش مشتری: ابتدا اقلام ثبت می‌شود، قیمت‌گذاری و تسویه بعداً انجام می‌شود. `,-1),m(`div`,Lt,[o[6]||=m(`label`,{id:`order-customer-label`},[B(` مشتری `),m(`span`,{class:`admin-form__required`},`*`)],-1),N(J,{id:`order-customer`,modelValue:K(i).customerId,"onUpdate:modelValue":o[0]||=e=>K(i).customerId=e,block:``,searchable:``,"aria-label":`انتخاب مشتری از لیست`,placeholder:`انتخاب مشتری از لیست`,"search-placeholder":`جستجوی نام یا موبایل…`,options:O.value},null,8,[`modelValue`,`options`]),O.value.length?c(``,!0):(x(),e(`p`,Rt,` مشتری‌ای در سیستم نیست. ابتدا از بخش «مشتریان» یک مشتری ثبت کنید. `))]),m(`div`,zt,[m(`div`,Bt,[o[7]||=m(`label`,null,`محصول`,-1),N(J,{modelValue:D.productId,"onUpdate:modelValue":o[1]||=e=>D.productId=e,block:``,searchable:``,"aria-label":`انتخاب محصول`,placeholder:`جستجو و انتخاب محصول`,"search-placeholder":`نام، کد یا کالیته…`,options:k.value},null,8,[`modelValue`,`options`])]),m(`div`,Vt,[o[8]||=m(`label`,{for:`order-item-meterage`},`متراژ (متر)`,-1),E(m(`input`,{id:`order-item-meterage`,"onUpdate:modelValue":o[2]||=e=>D.meterage=e,type:`number`,min:`1`,class:`admin-input`},null,512),[[p,D.meterage,void 0,{number:!0}]])])]),m(`button`,{type:`button`,class:`admin-btn admin-btn--outline admin-btn--sm`,onClick:M},` افزودن به اقلام `),K(i).items.length?(x(),e(`div`,Ht,[(x(!0),e(L,null,V(K(i).items,t=>(x(),e(`div`,{key:t.productId,class:`order-add__item`},[m(`div`,null,[m(`strong`,null,d(t.productName),1),m(`span`,null,`کالیته `+d(t.catalogCode)+` — `+d(K(P)(t.meterage))+` متر`,1)]),m(`button`,{type:`button`,class:`admin-btn admin-btn--outline-danger admin-btn--xs`,onClick:e=>K(b)(t.productId)},` حذف `,8,Ut)]))),128))])):(x(),e(`p`,Wt,`هنوز محصولی به پیش‌سفارش اضافه نشده است.`))],32)]),_:1},8,[`open`,`onClose`]))}}),[[`__scopeId`,`data-v-291a46f0`]]),qt=R({__name:`OrdersView`,setup(t){return oe(),(t,n)=>(x(),e(L,null,[N(mt,{class:`desktop-only`}),N(Ft,{class:`compact-only`}),N(Kt)],64))}});export{qt as default};