Files
tehran_tala/apps/admin-panel/dist/assets/create-Bb7_0pXn.js
T

2 lines
10 KiB
JavaScript
Raw Normal View History

2026-10-11 17:00:31 +03:30
import{J as yt,x as z,d as ht,u as bt,v as xt,a as N,w as i,i as j,l as $,r as u,o as d,c as s,h as S,f as x,K as kt,b as k,e as B,F as C,n as P,L as wt,t as w,E as It,N as Ct,A as qt,y as F,p as J,z as E,k as Ut,_ as Nt}from"./index-B00xW-Kd.js";import{X as St}from"./model-DXtOrm9u.js";import{b as Ot}from"./productListModel-HFzrHsWE.js";import{u as Pt}from"./auth-DJWimMfh.js";import"./filters-Dx0gg9S-.js";import"./index-x0rvHszp.js";import"./SettingOutlined-BbiswSpA.js";const G="admin_cart_items",zt=yt("cart",{state:()=>({items:[]}),actions:{addToCart(l){const v=this.items.findIndex(g=>g.pid==l.pid&&g.vid==l.vid),f=l.product.variants_all.filter(g=>g.id===l.vid)[0];f&&!(!f.is_pre_order&&f.qty===0)&&(v==-1?this.items.push(l):(this.items[v].product=l.product,this.items[v].qty=l.qty))},setItems(l){this.items=l,localStorage.setItem(G,JSON.stringify(l))},add(l){this.addToCart(l),this.setItems(this.items)},remove(l){const v=this.items.findIndex(f=>f.pid==l.pid&&f.vid==l.vid);v>-1&&this.items.splice(v,1),this.setItems(this.items)},updateItemQuantity(l){this.items[l.index].qty=l.quantity,this.setItems(this.items)},clear(){this.items=[],this.setItems(this.items)},async init(){try{const l=JSON.parse(localStorage.getItem(G)??"[]")||[],v=l.map(g=>g.product.id);if(v.length===0){this.setItems([]);return}const{data:f}=await z.post("product/variant",{products_id:v});if(f){const g=[];for(const y of l){const h=f.find(L=>L.id==y.product.id);h&&(!h.variants_all[0].is_pre_order&&h.variants_all[0].qty===0||g.push({vid:y.vid,pid:h.id,product:h,qty:y.qty,promotion_id:h.promotion&&h.promotion.id?h.promotion.id:null}))}this.setItems(g)}}catch(l){console.log("error in cart",l)}}}}),Vt=["src"],$t={key:1,class:"flex items-center"},Bt=["src"],Et={key:4,class:"flex"},Lt={style:{width:"max-content"}},Rt={class:"grid-5"},Tt={class:"totals"},H="/img/no-items.png",Qt=ht({__name:"create",setup(l){const v=Ut(),f=bt(),g=Pt(),y=zt(),h=e=>!!f.hasPermission(e),L=Ot(),Y=$(null),O=$(!1),M=$([]),A=$({}),Z={1:"ثبت سفارش",2:"تایید مدیر سیستم",3:"در حال تامین",4:"در حال آماده سازی",5:"ارسال",6:"تحویل مشتری"},n=F({customer_id:void 0,sts:void 0,type:void 0,note:"",shipping_address:{reciver_fname:"",reciver_lname:"",province:"",city:"",zipcode:"",reciver_phone:"",reciver_fixed_phone:"",address:""}}),c=F({}),tt=J(()=>{var e;return(e=g.user)==null?void 0:e.id}),b=J(()=>y.items),et=[{title:"حذف",dataIndex:"delete",width:60,align:"center"},{title:"کد محصول",dataIndex:"pid",align:"center",width:90},{title:"محصول",dataIndex:"product"},{title:"اجرت",dataIndex:"wage",align:"center"},{title:"تعداد",dataIndex:"qty",align:"center",width:140},{title:"وزن",dataIndex:"weight",align:"center",width:90},{title:"مجموع",dataIndex:"total",align:"center"}],m=F({});function I(e){return e.product.variants_all.find(t=>t.id===e.vid)??{}}function at(e){var t,o,p;return((t=e==null?void 0:e.thumb)==null?void 0:t.full)??((p=(o=e==null?void 0:e.ProductImage)==null?void 0:o[0])==null?void 0:p.image)??H}const st=J(()=>{let e=0;for(const t of b.value)e+=Number(I(t).grams??0);return e});function it(e){return Number(I(e).grams??0)*e.qty}function nt(e){const t=b.value[e];if(!t)return 1/0;const o=Number(I(t).qty??0);return o>0?o:1/0}function ot(e,t){y.updateItemQuantity({index:e,quantity:Number(t)})}function lt(e,t){rt(e,String(t.key))}function rt(e,t){y.add({vid:t,pid:e.id,product:e,qty:1,promotion_id:e.promotion&&e.promotion.id?e.promotion.id:null}),E.info("اضافه شد")}function dt(e){const t=I(e);m.id=t.id,m.grams=Number(t.grams??0)}async function ut(){var e,t;if(!(!m.id||!m.grams))try{O.value=!0;const o=b.value.find(p=>p.vid===m.id);await z.post("add/variant",{product_id:o==null?void 0:o.pid,title:`${m.grams} گرم`,grams:m.grams}),await y.init(),m.id=void 0,m.grams=void 0}catch(o){E.error(((t=(e=o==null?void 0:o.response)==null?void 0:e.data)==null?void 0:t.message)??"خطا در ثبت وزن")}finally{O.value=!1}}function pt(e,t){var o,p;return String(((p=(o=t==null?void 0:t.children)==null?void 0:o[0