Files
nademitex_admin/dist/assets/OrdersView-l4QUSOVE.js
T
2026-10-29 15:24:44 +03:30

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