Files
nademitex_admin/dist/assets/ProductsView-D1KGixmP.js
T

1 line
9.9 KiB
JavaScript
Raw Normal View History

2026-09-10 16:10:23 +03:30
import{A as e,B as t,G as n,H as r,I as ee,K as i,L as a,P as o,Q as s,T as te,U as c,V as ne,X as l,_ as u,at as d,ct as f,et as p,ft as m,it as h,j as re,k as ie,lt as g,n as _,o as v,q as y,st as ae,u as oe,w as b,z as x}from"./index-dG7O4aC2.js";import{t as S}from"./AdminSelect-BsjBHdZj.js";import{n as se,r as ce,t as C}from"./ActiveSwitchCell-DxxSF-SL.js";import{t as le}from"./AdminCurrencyInput-Bo4teStb.js";var ue={class:`products-page`},de={class:`products-page__filters admin-card`},fe={class:`products-page__search`},pe={key:1,class:`products-page__table admin-card desktop-only`},me={class:`admin-table-wrap`},he={class:`admin-table`},ge={class:`numeric`},_e={class:`numeric`},ve={class:`numeric`},ye={class:`numeric`},w={class:`status`},T={class:`actions`},E=[`onClick`],D={key:2,class:`compact-only admin-card-list`},O={class:`admin-card-item__header`},k={class:`admin-card-item__title`},A={class:`admin-card-item__header-actions`},j=[`onClick`],M={class:`admin-card-item__meta`},N={key:0,class:`admin-form__error`,role:`alert`},P={class:`admin-form__field`},be={class:`admin-form__row`},xe={class:`admin-form__field`},Se={class:`admin-form__field`},F={class:`admin-form__field`},Ce={class:`admin-form__row`},we={class:`admin-form__field`},Te={class:`admin-form__field`},Ee={class:`admin-form__row`},De={class:`admin-form__field`},Oe={class:`admin-form__field`},ke={class:`admin-form__field`},Ae=[`disabled`],I=re(y({__name:`ProductsView`,setup(re){let y=f([]),I=f([]),L=f(``),R=f(`all`),z=f(null),B=f(null),V=f(``),H=f(!1),U=e(),je=x(()=>[{value:`all`,label:`همه کالیته‌ها`},...I.value.map(e=>({value:e.id,label:`${e.code} — ${e.name}`}))]),Me=x(()=>I.value.map(e=>({value:e.id,label:`${e.code} — ${e.name} (${e.companyName})`}))),W=()=>({catalogId:I.value[0]?.id??``,name:``,color:``,productCode:``,minMeterage:100,orderStep:50,price:null,internalStock:0,isActive:!0}),G=ae(W()),Ne=x(()=>z.value!==null),Pe=x(()=>z.value===`edit`?`ویرایش محصول`:`افزودن محصول`),K=x(()=>G.name.trim()&&G.catalogId&&G.minMeterage>0),q=x(()=>L.value.trim().length>0||R.value!==`all`),J=x(()=>{let e=y.value;R.value!==`all`&&(e=e.filter(e=>e.catalogId===R.value));let t=L.value.trim();return t&&(e=e.filter(e=>e.name.includes(t)||e.color.includes(t)||e.productCode.includes(t)||e.catalogCode.includes(t))),e});async function Fe(){try{let[e,t]=await Promise.all([u.list(),oe.list()]);y.value=e,I.value=t}catch(e){U.error(e instanceof b?e.message:`بارگذاری محصولات انجام نشد.`)}}l(()=>{Fe()});function Ie(e){return I.value.find(t=>t.id===e)}function Y(){z.value=`add`,B.value=null,Object.assign(G,W()),V.value=``}function X(e){z.value=`edit`,B.value=e.id,G.catalogId=e.catalogId,G.name=e.name,G.color=e.color,G.productCode=e.productCode,G.minMeterage=e.minMeterage,G.orderStep=e.orderStep,G.price=e.price,G.internalStock=e.internalStock,G.isActive=e.isActive,V.value=``}function Z(){z.value=null,B.value=null,V.value=``}async function Q(){if(!K.value){V.value=`نام محصول، کالیته و حداقل متراژ الزامی هستند.`;return}let e=Ie(G.catalogId);if(!e){V.value=`کالیته معتبر انتخاب کنید.`;return}let t=G.productCode.trim()||`${e.code}-NEW`;H.value=!0;try{if(z.value===`edit`&&B.value){let e=await u.update(B.value,{catalogId:G.catalogId,name:G.name.trim(),color:G.color.trim()||`—`,code:t,productCode:t,minMeterage:G.minMeterage,orderStep:G.orderStep,price:G.price,internalStock:G.internalStock,isActive:G.isActive}),n=y.value.findIndex(e=>e.id===B.value);n!==-1&&(y.value[n]={...y.value[n],...e}),U.success(`اطلاعات محصول به‌روزرسانی شد.`)}else{let n=await u.create({companyId:e.companyId,catalogId:G.catalogId,name:G.name.trim(),color:G.color.trim()||`—`,code:t,productCode:t,minMeterage:G.minMeterage,orderStep:G.orderStep,price:G.price,internalStock:G.internalStock,isActive:G.isActive});y.value.push(n),U.success(`محصول جدید ثبت شد.`)}Z()}catch(e){U.error(e instanceof b?e.message:`ذخیره محصول انجام نشد.`)}finally{H.value