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

2 lines
11 KiB
JavaScript
Raw Normal View History

import{X as he,x as z,d as be,s as xe,u as ke,v as we,a as S,w as i,i as Q,l as B,r as p,o as d,c as s,h as I,f as b,Y as Ie,b as x,e as $,F as C,n as P,Z as Ce,t as k,E as qe,V as Ue,G as Se,y as j,q as F,B as E,k as Ne,_ as Oe}from"./index-CJkJkMFX.js";import{X as Pe}from"./model-Dhlo-7J6.js";import{b as ze}from"./productListModel-BuyqvFUk.js";import{u as Ve}from"./auth-SCFNR-pz.js";import"./filters-Bg3NuEZs.js";import"./index-CcPs5_14.js";import"./SettingOutlined-M4ZHugxj.js";const K="admin_cart_items",Be=he("cart",{state:()=>({items:[]}),actions:{addToCart(l){const g=this.items.findIndex(y=>y.pid==l.pid&&y.vid==l.vid),v=l.product.variants_all.filter(y=>y.id===l.vid)[0];v&&!(!v.is_pre_order&&v.qty===0)&&(g==-1?this.items.push(l):(this.items[g].product=l.product,this.items[g].qty=l.qty))},setItems(l){this.items=l,localStorage.setItem(K,JSON.stringify(l))},add(l){this.addToCart(l),this.setItems(this.items)},remove(l){const g=this.items.findIndex(v=>v.pid==l.pid&&v.vid==l.vid);g>-1&&this.items.splice(g,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(K)??"[]")||[],g=l.map(y=>y.product.id);if(g.length===0){this.setItems([]);return}const{data:v}=await z.post("product/variant",{products_id:g});if(v){const y=[];for(const N of l){const u=v.find(L=>L.id==N.product.id);u&&(!u.variants_all[0].is_pre_order&&u.variants_all[0].qty===0||y.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(y)}}catch(l){console.log("error in cart",l)}}}}),$e=["src"],Ee={key:1,class:"flex items-center"},Le=["src"],Re={key:4,class:"flex"},Te={style:{width:"max-content"}},Me={class:"grid-5"},Qe={class:"totals"},Y="/img/no-items.png",je=be({__name:"create",setup(l){const g=Ne(),v=xe(),y=ke(),N=Ve(),u=Be(),L=t=>!!y.hasPermission(t),Z=ze(),H=B(null),O=B(!1),X=B([]),D=B({}),ee={1:"ثبت سفارش",2:"تایید مدیر سیستم",3:"در حال تامین",4:"در حال آماده سازی",5:"ارسال",6:"تحویل مشتری"},n=j({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:""}}),_=j({}),te=F(()=>{var t;return(t=N.user)==null?void 0:t.id}),h=F(()=>u.items),ae=[{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"}],c=j({});function w(t){return t.product.variants_all.find(e=>e.id===t.vid)??{}}function se(t){var e,o,m;return((e=t==null?void 0:t.thumb)==null?void 0:e.full)??((m=(o=t==null?void 0:t.ProductImage)==null?void 0:o[0])==null?void 0:m.image)??Y}const ie=F(()=>{let t=0;for(const e of h.value)t+=Number(w(e).grams??0);return t});function ne(t){return Number(w(t).grams??0)*t.qty}function oe(t){const e=h.value[t];if(!e)return 1/0;const o=Number(w(e).qty??0);return o>0?o:1/0}function le(t,e){u.updateItemQuantity({index:t,quantity:Number(e)})}function re(t,e){de(t,String(e.key))}function de(t,e){u.add({vid:e,pid:t.id,product:t,qty:1,promotion_id:t.promotion&&t.promotion.id?t.promotion.id:null}),E.info("اضافه شد")}function ue(t){const e=w(t);c.id=e.id,c.grams=Number(e.grams??0)}async function pe(){var t,e;if(!(!c.id||!c.grams))try{O.value=!0;const o=h.value.find(m=>m.vid===c.id);await z.post("add/variant",{product_id:o==null?void 0:o.pid,title:`${c.grams} گرم`,grams:c.grams}),await u.init(),c.id=void 0,c.grams=void 0}catch(o){E.error(((e=(t=o==null?void 0:o.response)==null?void 0:t.data)==null?void 0:e.message)??"خطا در ثبت وزن")}finally{O.value=!1}}function me(t,e){var o,m;return String(((m=(o=e==null?void 0:e.children)=