Files
hedena_gold/apps/admin-panel/dist/assets/create-CfYi58IZ.js
T

2 lines
10 KiB
JavaScript
Raw Normal View History

import{Y as ht,y as P,d as bt,v as xt,u as wt,x as kt,a as S,w as i,i as M,m as T,r as p,o as d,c as s,h as k,f as b,Z as It,b as x,e as V,F as I,p as z,$ as Ct,t as w,E as qt,W as Ut,H as St,z as Q,s as j,G as B,l as Nt,_ as Ot}from"./index-D8WOpuoz.js";import{o as zt}from"./select--BgT6D7O.js";import{X as Pt}from"./model-sNEj62t9.js";import{b as $t}from"./productListModel-k38YfOF9.js";import{u as Tt}from"./auth-CRH9VIb7.js";import"./filters-bFnvQ7Jm.js";import"./index-modnNLze.js";import"./SettingOutlined-Dlcw9QxB.js";const X="admin_cart_items",Vt=ht("cart",{state:()=>({items:[]}),actions:{addToCart(o){const g=this.items.findIndex(v=>v.pid==o.pid&&v.vid==o.vid),c=o.product.variants_all.filter(v=>v.id===o.vid)[0];c&&!(!c.is_pre_order&&c.qty===0)&&(g==-1?this.items.push(o):(this.items[g].product=o.product,this.items[g].qty=o.qty))},setItems(o){this.items=o,localStorage.setItem(X,JSON.stringify(o))},add(o){this.addToCart(o),this.setItems(this.items)},remove(o){const g=this.items.findIndex(c=>c.pid==o.pid&&c.vid==o.vid);g>-1&&this.items.splice(g,1),this.setItems(this.items)},updateItemQuantity(o){this.items[o.index].qty=o.quantity,this.setItems(this.items)},clear(){this.items=[],this.setItems(this.items)},async init(){try{const o=JSON.parse(localStorage.getItem(X)??"[]")||[],g=o.map(v=>v.product.id);if(g.length===0){this.setItems([]);return}const{data:c}=await P.post("product/variant",{products_id:g});if(c){const v=[];for(const N of o){const u=c.find(E=>E.id==N.product.id);u&&(!u.variants_all[0].is_pre_order&&u.variants_all[0].qty===0||v.push({vid:N.vid,pid:u.id,product:u,qty:N.qty,promotion_id:u.promotion&&u.promotion.id?u.promotion.id:null}))}this.setItems(v)}}catch(o){console.log("error in cart",o)}}}}),Bt=["src"],Et={key:1,class:"flex items-center"},Lt=["src"],Rt={key:4,class:"flex"},Mt={style:{width:"max-content"}},Qt={class:"grid-5"},jt={class:"totals"},H="/img/no-items.png",Ft=bt({__name:"create",setup(o){const g=Nt(),c=xt(),v=wt(),N=Tt(),u=Vt(),E=e=>!!v.hasPermission(e),K=$t(v.isSuperAdmin),Y=T(null),O=T(!1),F=T([]),W=T({}),Z={1:"ثبت سفارش",2:"تایید مدیر سیستم",3:"در حال تامین",4:"در حال آماده سازی",5:"ارسال",6:"تحویل مشتری"},n=Q({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:""}}),_=Q({}),tt=j(()=>{var e;return(e=N.user)==null?void 0:e.id}),y=j(()=>u.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=Q({});function C(e){return e.product.variants_all.find(t=>t.id===e.vid)??{}}function at(e){var t,l,h;return((t=e==null?void 0:e.thumb)==null?void 0:t.full)??((h=(l=e==null?void 0:e.ProductImage)==null?void 0:l[0])==null?void 0:h.image)??H}const st=j(()=>{let e=0;for(const t of y.value)e+=Number(C(t).grams??0);return e});function it(e){return Number(C(e).grams??0)*e.qty}function nt(e){const t=y.value[e];if(!t)return 1/0;const l=Number(C(t).qty??0);return l>0?l:1/0}function ot(e,t){u.updateItemQuantity({index:e,quantity:Number(t)})}function lt(e,t){rt(e,String(t.key))}function rt(e,t){u.add({vid:t,pid:e.id,product:e,qty:1,promotion_id:e.promotion&&e.promotion.id?e.promotion.id:null}),B.info("اضافه شد")}function dt(e){const t=C(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 l=y.value.find(h=>h.vid===m.id);await P.post("add/variant",{product_id:l==null?void 0:l.pid,title:`${m.grams} گرم`,grams:m.grams}),await u.init(),m.id=void 0,m.grams=void 0}catch(l){B.error(((t=(e=l==null?void 0:l.response)==null?void 0:e.data)==null?void 0:t.message)??"خطا در ثبت وزن")}finally{O.value=!1}}function pt(e,t){r