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