Files
tehran_taj/apps/admin-panel/dist/assets/create-o94Sy72S.js
T

2 lines
11 KiB
JavaScript
Raw Normal View History

import{Y as he,y as P,d as be,v as xe,u as we,x as ke,a as U,w as i,i as Q,m as V,r as p,o as d,c as s,h as I,f as b,Z as Ie,b as x,e as B,F as C,p as z,$ as Ce,t as w,E as qe,W as Se,H as Ue,z as j,s as F,G as E,l as Ne,_ as Oe}from"./index-CUVhAJ_v.js";import{X as ze}from"./model-DR3zqbM8.js";import{b as Pe}from"./productListModel-B2nylg2C.js";import{u as $e}from"./auth-BT2lQXaZ.js";import"./filters-DD-YZKmq.js";import"./index-CNUFPjp-.js";import"./SettingOutlined-CYLMzKTF.js";const H="admin_cart_items",Ve=he("cart",{state:()=>({items:[]}),actions:{addToCart(l){const y=this.items.findIndex(_=>_.pid==l.pid&&_.vid==l.vid),v=l.product.variants_all.filter(_=>_.id===l.vid)[0];v&&!(!v.is_pre_order&&v.qty===0)&&(y==-1?this.items.push(l):(this.items[y].product=l.product,this.items[y].qty=l.qty))},setItems(l){this.items=l,localStorage.setItem(H,JSON.stringify(l))},add(l){this.addToCart(l),this.setItems(this.items)},remove(l){const y=this.items.findIndex(v=>v.pid==l.pid&&v.vid==l.vid);y>-1&&this.items.splice(y,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(H)??"[]")||[],y=l.map(_=>_.product.id);if(y.length===0){this.setItems([]);return}const{data:v}=await P.post("product/variant",{products_id:y});if(v){const _=[];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||_.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(_)}}catch(l){console.log("error in cart",l)}}}}),Be=["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"},K="/img/no-items.png",je=be({__name:"create",setup(l){const y=Ne(),v=xe(),_=we(),N=$e(),u=Ve(),L=t=>!!_.hasPermission(t),Y=Pe(_.isSuperAdmin),Z=V(null),O=V(!1),W=V([]),A=V({}),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:""}}),f=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 k(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)??K}const ie=F(()=>{let t=0;for(const e of h.value)t+=Number(k(e).grams??0);return t});function ne(t){return Number(k(t).grams??0)*t.qty}function oe(t){const e=h.value[t];if(!e)return 1/0;const o=Number(k(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=k(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 P.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